Tools/Run/Alignment/Sim4.pm

filter: Statementstmt 41.1% 56 / 136 Branchbran 15.3% 8 / 52 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 73.6% 14 / 19 Podpod 100% 5 / 5 totaltotal 36.7% 83 / 226 CC 33 SCAR 37.5
CC
33
Cov
32%
_setinput
110.0
_run
72.0
align
56.0
CRAP 42.4
« Tools/Run/Phylo/Phylip/DrawTree.pm ↑ Summary Tools/Run/Phylo/Phast/PhastCons.pm »
1 # BioPerl module for Bio::Tools::Run::Alignment::Sim4
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by
6 #
7 # Copyright Shawn Hoon
8 #
9 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
11  
12 =head1 NAME
13  
14 Bio::Tools::Run::Alignment::Sim4 - Wrapper for Sim4 program that allows
15 for alignment of cdna to genomic sequences
16  
17 =head1 SYNOPSIS
18  
19 use Bio::Tools::Run::Alignment::Sim4;
20  
21 my @params = (W=>15,K=>17,D=>10,N=>10,cdna_seq=>"mouse_cdna.fa",genomic_seq=>"mouse_genomic.fa");
22 my $sim4 = Bio::Tools::Run::Alignment::Sim4->new(@params);
23  
24 my @exon_sets = $sim4->align;
25  
26 foreach my $set(@exon_sets){
27 foreach my $exon($set->sub_SeqFeature){
28 print $exon->start."\t".$exon->end."\t".$exon->strand."\n";
29 print "\tMatched ".$exon->est_hit->seq_id."\t".$exon->est_hit->start."\t".$exon->est_hit->end."\n";
30 }
31 }
32  
33 One can also provide a est database
34  
35 $sio = Bio::SeqIO->new(-file=>"est.fa",-format=>"fasta");
36 @est_seq=();
37 while(my $seq = $sio->next_seq){
38 push @est_seq,$seq;
39 }
40  
41 my @exon_sets = $factory->align(\@est_seq,$genomic);
42  
43 =head1 DESCRIPTION
44  
45 Sim4 program is developed by Florea et al. for aligning cdna/est
46 sequence to genomic sequences
47  
48 Florea L, Hartzell G, Zhang Z, Rubin GM, Miller W.
49 A computer program for aligning a cDNA sequence with a genomic DNA sequence.
50 Genome Res 1998 Sep;8(9):967-74
51  
52 The program is available for download here:
53 http://globin.cse.psu.edu/
54  
55 =head1 FEEDBACK
56  
57 =head2 Mailing Lists
58  
59 User feedback is an integral part of the evolution of this and other
60 Bioperl modules. Send your comments and suggestions preferably to one
61 of the Bioperl mailing lists. Your participation is much appreciated.
62  
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
65  
66 =head2 Support
67  
68 Please direct usage questions or support issues to the mailing list:
69  
70 I<bioperl-l@bioperl.org>
71  
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
76  
77 =head2 Reporting Bugs
78  
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 the bugs and their resolution. Bug reports can be submitted via the
81 web:
82  
83 http://redmine.open-bio.org/projects/bioperl/
84  
85 =head1 AUTHOR - Shawn Hoon
86  
87 Email shawnh@fugu-sg.org
88  
89 =head1 APPENDIX
90  
91 The rest of the documentation details each of the object
92 methods. Internal methods are usually preceded with a _
93  
94 =cut
95  
96  
97 package Bio::Tools::Run::Alignment::Sim4;
98 1 ▶use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
Subroutine BEGIN: called CC=1 SCAR=0.0
99 1 @SIM4_PARAMS @OTHER_PARAMS @OTHER_SWITCHES %OK_FIELD);
100 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 ▶use Bio::SimpleAlign;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
105 1 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
106 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 1 ▶use Bio::Tools::Sim4::Results;
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
110  
111 # You will need to enable Sim4 to find the Sim4 program. This
112 # can be done in (at least) two ways:
113 #
114 # 1. define an environmental variable SIM4DIR
115 # export SIM4DIR =/usr/local/share/sim4
116 # where the sim4 package is installed
117 #
118 # 2. include a definition of an environmental variable SIM4 in
119 # every script that will use Sim4.pm
120 # $ENV{SIMR4DIR} = '/usr/local/share/sim4';
121  
122 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
123  
124 1 @SIM4_PARAMS= qw(A W X K C R D H P N B);
125 1 @OTHER_PARAMS= qw(CDNA_SEQ GENOMIC_SEQ OUTFILE);
126 1 @OTHER_SWITCHES = qw(SILENT QUIET VERBOSE);
127  
128 # Authorize attribute fields
129 1 foreach my $attr ( @SIM4_PARAMS, @OTHER_PARAMS,
130 17 @OTHER_SWITCHES) { $OK_FIELD{$attr}++; }
131 }
132  
133 =head2 program_name
134  
135 Title : program_name
136 Usage : $factory->program_name()
137 Function: holds the program name
138 Returns: string
139 Args : None
140  
141 =cut
142  
143 6 ▶sub program_name {
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
144 6 return 'sim4';
145 }
146  
147 =head2 program_dir
148  
149 Title : program_dir
150 Usage : $factory->program_dir(@params)
151 Function: returns the program directory, obtained from ENV variable.
152 Returns: string
153 Args :
154  
155 =cut
156  
157 3 ▶sub program_dir {
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
158 3 ▶ return Bio::Root::IO->catfile($ENV{SIM4DIR}) if $ENV{SIM4DIR};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SIM4DIR"} 0 3 3
159 }
160  
161 1 ▶sub new {
Subroutine new: called CC=5 SCAR=17.1
Pod documented
162 1 my ($class, @args) = @_;
163 1 my $self = $class->SUPER::new(@args);
164 # to facilitiate tempfile cleanup
165 1 $self->io->_initialize_io();
166 1 $self->A(0); # default
167 1 my ($attr, $value);
168
169 1 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 6 1 7
170 6 $attr = shift @args;
171 6 $value = shift @args;
172 6 ▶ if ($attr =~/est_first/i ) { #NEW
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /est_first/i) 0 6 6
173 0 $self->{est_first} = $value; #NEW
174 0 next; #NEW
175 } #NEW
176 6 ▶ next if( $attr =~ /^-/ ); # don't want named parameters
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^-/ 0 6 6
177 6 ▶ if ($attr =~/'PROGRAM'/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /'PROGRAM'/i) 0 6 6
178 0 $self->executable($value);
179 0 next;
180 }
181 6 $self->$attr($value);
182 }
183 1 return $self;
184 }
185  
186 7 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=11.2
187 7 my $self = shift;
188 7 my $attr = $AUTOLOAD;
189 7 $attr =~ s/.*:://;
190 7 $attr = uc $attr;
191 7 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::Alignment::Sim4::OK_FIELD{$attr} 0 7 7
192 7 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 7 0 7
193 7 return $self->{$attr};
194 }
195  
196 =head2 version
197  
198 Title : version
199 Usage : not supported
200 Function: Cannot determine from program
201 Example :
202 Returns : float or undef
203 Args : none
204  
205 =cut
206  
207 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
208 0 my ($self) = @_;
209 0 return undef;
210 }
211  
212 =head2 align
213  
214 Title : align
215 Usage :
216 $cdna = 't/data/cdna.fa';
217 $genomic = 't/data/cdna.fa';
218 @exon_set = $factory->align($cdna,$genomic);
219 or
220 #@seq_array is array of Seq objs
221 $cdna = \@seq_array;
222 @exon_set = $factory->align($cdna,$genomic);
223 of
224 @exon_set = $factory->align($cdna->[0],$genomic)
225  
226 Function: Perform a Sim4 alignment
227 Returns : An array of Bio::SeqFeature::Generic objects which has
228 exons as sub seqfeatures.
229 Args : Name of two files containing fasta sequences,
230 or 2 Bio::SeqI objects
231 or a combination of both
232 first is assumed to be cdna
233 second is assumed to be genomic
234 More than one cdna may be provided. If an object,
235 assume that its an array ref.
236  
237 =cut
238  
239 0 ▶sub align {
Subroutine align: not called CC=7 SCAR=40.3
Pod documented
240  
241 0 my ($self,$cdna,$genomic) = @_;
242  
243 0 ▶ $self->cdna_seq($cdna) if $cdna;
Branch: 1 branch
BranchTrueFalseTotal
if $cdna 0 0 0
244 0 ▶ $self->throw("Need to provide a cdna sequence") unless $self->cdna_seq;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->cdna_seq 0 0 0
245  
246 0 ▶ $self->genomic_seq($genomic) if $genomic;
Branch: 1 branch
BranchTrueFalseTotal
if $genomic 0 0 0
247 0 ▶ $self->throw("Need to provide a genomic sequence") unless $self->genomic_seq;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->genomic_seq 0 0 0
248
249 0 my ($temp,$infile1, $infile2, $est_first,$seq);
250 0 my ($attr, $value, $switch);
251  
252 # Create input file pointer
253 0 ($est_first,$infile1,$infile2)= $self->_setinput($self->cdna_seq,$self->genomic_seq);
254 0 ▶ if (!($infile1 && $infile2)) {$self->throw("Bad input data (sequences need an id ) or less than 2 sequences in align!");}
Branch: 1 branch
BranchTrueFalseTotal
unless ($infile1 and $infile2) 0 0 0
Condition0%0/3
$infile1 and $infile2
!ll&&!rl&&r
000
MC/DC0%0/2
$infile1 and $infile2
$infile1 $infile2
Truth table0%0/3
A and B
A= $infile1B= $infile2
ABresult
0X0
100
111
255  
256 # Create parameter string to pass to Sim4 program
257 0 my $param_string = $self->_setparams();
258  
259 # run Sim4
260 0 my @exon_sets = $self->_run($est_first,$infile1,$infile2,$param_string);
261 0 return @exon_sets;
262 }
263  
264 #################################################
265 #internal methods
266  
267 =head2 _run
268  
269 Title : _run
270 Usage : Internal function, not to be called directly
271 Function: makes actual system call to Sim4 program
272 Example :
273 Returns : nothing; Sim4 output is written to a temp file
274 Args : Name of a file containing a set of unaligned fasta sequences
275 and hash of parameters to be passed to Sim4
276  
277 =cut
278  
279 0 ▶sub _run {
Subroutine _run: not called CC=8 SCAR=42.8
280 0 my ($self,$estfirst,$infile1,$infile2,$param_string) = @_;
281 0 my $instring;
282 0 $self->debug( "Program ".$self->executable."\n");
283 0 ▶ if(! $self->outfile){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->outfile) 0 0 0
284 0 my ($tfh, $outfile) = $self->io->tempfile(-dir=>$self->tempdir);
285 0 close($tfh);
286 0 undef $tfh;
287 0 $self->outfile($outfile);
288 }
289 0 my $outfile = $self->outfile();
290 0 my $commandstring = $self->executable." $infile1 $infile2 $param_string > $outfile";
291 0 ▶ if($self->quiet || $self->silent || ($self->verbose < 0)){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->quiet or $self->silent or $self->verbose < 0) 0 0 0
Condition0%0/6
$self->quiet or $self->silent or $self->verbose < 0
l!l&&r!l&&!r
000
$self->quiet or $self->silent
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->quiet or $self->silent or $self->verbose < 0
$self->quiet $self->silent $self->verbose < 0
Truth table0%0/4
A or B or C
A= $self->quietB= $self->silentC= $self->verbose < 0
ABCresult
1XX1
01X1
0011
0000
292 0 ▶ my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin/i ? : 0 0 0
293 0 $commandstring .= " 2>$null";
294 }
295 0 $self->debug( "Sim4 command = $commandstring");
296 0 my $status = system($commandstring);
297 0 ▶ $self->throw( "Sim4 call ($commandstring) crashed: $? \n") unless $status==0;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 0 0 0 0
298  
299 #use Sim4 parser
300 0 my $sim4_parser = Bio::Tools::Sim4::Results->new(-file=>$outfile,-estfirst=>$estfirst);
301 0 my @out;
302 0 ▶ while(my $exonset = $sim4_parser->next_exonset){
Branch: 1 branch
BranchTrueFalseTotal
if (my $exonset = $sim4_parser->next_exonset) 0 0 0
303 0 push @out, $exonset;
304 }
305 0 return @out;
306 }
307  
308 =head2 _setinput()
309  
310 Title : _setinput
311 Usage : Internal function, not to be called directly
312 Function: Create input file for Sim4 program
313 Example :
314 Returns : name of file containing Sim4 data input
315 Args : Seq or Align object reference or input file name
316  
317 =cut
318  
319 0 ▶sub _setinput {
Subroutine _setinput: not called CC=10 SCAR=47.0
320 0 my ($self, $cdna,$genomic) = @_;
321 0 my ($infilename, $seq, $temp, $tfh1,$tfh2,$outfile1,$outfile2);
322 #my $estfirst=1;
323 0 ▶ my $estfirst= defined($self->{est_first}) ? $self->{_est_first} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'est_first'} ? : 0 0 0
324 0 my ($cdna_file,$genomic_file);
325 #a sequence obj
326 0 ▶ if(ref($cdna)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cdna) { } 0 0 0
327 0 ▶ my @cdna = ref $cdna eq "ARRAY" ? @{$cdna} : ($cdna);
Branch: 1 branch
BranchTrueFalseTotal
ref $cdna eq 'ARRAY' ? : 0 0 0
328 0 ($tfh1,$cdna_file) = $self->io->tempfile(-dir=>$self->tempdir);
329 0 my $seqio = Bio::SeqIO->new(-fh=>$tfh1,-format=>'fasta');
330 0 foreach my $c (@cdna){
331 0 $seqio->write_seq($c);
332 }
333 0 close $tfh1;
334 0 undef $tfh1;
335  
336 #if we have a est database, then input will go second
337 0 ▶ if($#cdna > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($#cdna > 0) 0 0 0
338 0 $estfirst=0;
339 }
340 }
341 else {
342 0 my $sio = Bio::SeqIO->new(-file=>$cdna,-format=>"fasta");
343 0 my $count = 0;
344 0 ▶ while(my $seq = $sio->next_seq){
Branch: 1 branch
BranchTrueFalseTotal
if (my $seq = $sio->next_seq) 0 0 0
345 0 $count++;
346 }
347 0 ▶ $estfirst = $count > 1 ? 0:1;
Branch: 1 branch
BranchTrueFalseTotal
$count > 1 ? : 0 0 0
348 0 $cdna_file = $cdna;
349 }
350 0 ▶ if( ref($genomic) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $genomic) { } 0 0 0
351 0 ($tfh1,$genomic_file) = $self->io->tempfile(-dir=>$self->tempdir);
352 0 my $seqio = Bio::SeqIO->new(-fh=>$tfh1,-format=>'fasta');
353 0 $seqio->write_seq($genomic);
354 0 close $tfh1;
355 0 undef $tfh1;
356 }
357 else {
358 0 $genomic_file = $genomic;
359 }
360 0 ▶ return ($estfirst,$cdna_file,$genomic_file) if $estfirst;
Branch: 1 branch
BranchTrueFalseTotal
if $estfirst 0 0 0
361 0 return ($estfirst,$genomic_file,$cdna_file);
362 }
363  
364  
365 =head2 _setparams()
366  
367 Title : _setparams
368 Usage : Internal function, not to be called directly
369 Function: Create parameter inputs for Sim4 program
370 Example :
371 Returns : parameter string to be passed to Sim4
372 during align or profile_align
373 Args : name of calling object
374  
375 =cut
376  
377 0 ▶sub _setparams {
Subroutine _setparams: not called CC=3 SCAR=24.8
378 0 my ($attr, $value, $self);
379  
380 0 $self = shift;
381  
382 0 my $param_string = "";
383 0 for $attr ( @SIM4_PARAMS ) {
384 0 $value = $self->$attr();
385 0 ▶ next unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
386 0 my $attr_key = uc $attr; #put params in format expected by Sim4
387 0 $attr_key = ' '.$attr_key;
388 0 $param_string .= $attr_key.'='.$value;
389 }
390  
391 0 return $param_string;
392 }
393  
394 1 1; # Needed to keep compiler happy
« Tools/Run/Phylo/Phylip/DrawTree.pm ↑ Summary Tools/Run/Phylo/Phast/PhastCons.pm »