Perl.pm

filter: Statementstmt 73.9% 139 / 188 Branchbran 55.8% 48 / 86 Conditioncond 50.0% 7 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 76.1% 16 / 21 Podpod 100% 13 / 13 totaltotal 67.8% 224 / 330 CC 51 SCAR 24.4
CC
51
Cov
67%
write_sequence
20.8
reverse_complement
20.0
blast_sequence
16.4
CRAP 11.4
↑ Summary Procedural.pm »
1  
2 package Bio::Perl;
3 2 $Bio::Perl::VERSION = '1.7.3';
4 2 ▶use vars qw(@EXPORT @EXPORT_OK $DBOKAY);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bio::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Bio::Root::Version '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 BEGIN {
12 2 ▶ eval {
Subroutine BEGIN: called CC=2 SCAR=7.1
13 2 require Bio::DB::EMBL;
14 2 require Bio::DB::GenBank;
15 2 require Bio::DB::SwissProt;
16 2 require Bio::DB::RefSeq;
17 2 require Bio::DB::GenPept;
18 };
19 2 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 2 2
20 0 $DBOKAY = 0;
21 } else {
22 2 $DBOKAY = 1;
23 }
24 }
25  
26 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 @EXPORT = qw(read_sequence read_all_sequences write_sequence
29 new_sequence get_sequence translate translate_as_string
30 reverse_complement revcom revcom_as_string
31 reverse_complement_as_string blast_sequence write_blast);
32  
33 2 @EXPORT_OK = @EXPORT;
34  
35  
36  
37 sub read_sequence{
38 2 ▶ my ($filename,$format) = @_;
Subroutine read_sequence: called CC=3 SCAR=11.1
Pod documented
39  
40 2 ▶ if( !defined $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 2 2
41 0 confess "read_sequence($filename) - usage incorrect";
42 }
43  
44 2 my $seqio;
45  
46 2 ▶ if( defined $format ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $format) { } 1 1 2
47 1 $seqio = Bio::SeqIO->new( '-file' => $filename, '-format' => $format);
48 } else {
49 1 $seqio = Bio::SeqIO->new( '-file' => $filename);
50 }
51  
52 2 my $seq = $seqio->next_seq();
53  
54 2 return $seq;
55 }
56  
57  
58  
59 sub read_all_sequences{
60 1 ▶ my ($filename,$format) = @_;
Subroutine read_all_sequences: called CC=4 SCAR=14.4
Pod documented
61  
62 1 ▶ if( !defined $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 1 1
63 0 confess "read_all_sequences($filename) - usage incorrect";
64 }
65  
66 1 my $seqio;
67  
68 1 ▶ if( defined $format ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $format) { } 1 0 1
69 1 $seqio = Bio::SeqIO->new( '-file' => $filename, '-format' => $format);
70 } else {
71 0 $seqio = Bio::SeqIO->new( '-file' => $filename);
72 }
73  
74 1 my @seq_array;
75  
76 1 ▶ while( my $seq = $seqio->next_seq() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $seq = $seqio->next_seq) 2 1 3
77 2 push(@seq_array,$seq);
78 }
79  
80 1 return @seq_array;
81 }
82  
83  
84  
85 sub write_sequence{
86 1 ▶ my ($filename,$format,@sequence_objects) = @_;
Subroutine write_sequence: called CC=9 SCAR=30.4
Pod documented
87  
88 1 ▶ if( scalar(@sequence_objects) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @sequence_objects == 0) 0 1 1
89 0 confess("write_sequence(filename,format,sequence_object)");
90 }
91  
92 1 my $error = 0;
93 1 my $seqname = "sequence1";
94  
95 # catch users who haven't passed us a filename we can open
96 1 ▶ if( $filename !~ /^\>/ && $filename !~ /^|/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ /^\>/ or $filename =~ /^|/) 0 1 1
Condition33%1/3
$filename =~ /^\>/ or $filename =~ /^|/
l!l&&r!l&&!r
100
MC/DC0%0/2
$filename =~ /^\>/ or $filename =~ /^|/
$filename =~ /^\>/ $filename =~ /^|/
Truth table33%1/3
A or B
A= $filename =~ /^\>/B= $filename =~ /^|/
ABresult
1X1
011
000
97 0 $filename = ">".$filename;
98 }
99  
100 1 my $seqio = Bio::SeqIO->new('-file' => $filename, '-format' => $format);
101  
102 1 foreach my $seq ( @sequence_objects ) {
103 1 my $seq_obj;
104  
105 1 ▶ if( !ref $seq ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $seq) { } 0 1 1
106 0 ▶ if( length $seq > 50 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $seq > 50) { } 0 0 0
107 # odds are this is a sequence as a string, and someone has not figured out
108 # how to make objects. Warn him/her and then make a sequence object
109 # from this
110 0 ▶ if( $error == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error == 0) 0 0 0
111 0 carp("WARNING: You have put in a long string into write_sequence.\n".
112 "I suspect this means that this is the actual sequence\n".
113 "In the future try the\n".
114 " new_sequence method of this module to make a new sequence object.\n".
115 "Doing this for you here\n");
116 0 $error = 1;
117 }
118  
119 0 $seq_obj = new_sequence($seq,$seqname);
120 0 $seqname++;
121 } else {
122 0 confess("You have a non object [$seq] passed to write_sequence. It maybe that you".
123 "want to use new_sequence to make this string into a sequence object?");
124 }
125 } else {
126 1 ▶ if( !$seq->isa("Bio::SeqI") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seq->isa("Bio::SeqI")) 0 1 1
127 0 confess("object [$seq] is not a Bio::Seq object; can't write it out");
128 }
129 1 $seq_obj = $seq;
130 }
131  
132 # finally... we get to write out the sequence!
133 1 $seqio->write_seq($seq_obj);
134 }
135 1 1;
136 }
137  
138  
139 sub new_sequence{
140 1 ▶ my ($seq,$name,$accession) = @_;
Subroutine new_sequence: called CC=4 SCAR=15.0
Pod documented
141  
142 1 ▶ if( !defined $seq ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seq) 0 1 1
143 0 confess("new_sequence(sequence_as_string) usage");
144 }
145  
146 1 ▶ $name ||= "no-name-for-sequence";
Condition50%1/2
$name ||= "no-name-for-sequence"
l!l
10
MC/DC0%0/1
$name ||= "no-name-for-sequence"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
147  
148 1 my $seq_object = Bio::Seq->new( -seq => $seq, -id => $name);
149  
150 1 ▶ $accession && $seq_object->accession_number($accession);
Branch: 1 branch
BranchTrueFalseTotal
$accession and $seq_object->accession_number($accession) 1 0 1
151  
152 1 return $seq_object;
153 }
154  
155  
156 sub blast_sequence {
157 1 ▶ my ($seq,$verbose) = @_;
Subroutine blast_sequence: called CC=12 SCAR=28.0
Pod documented
158  
159 1 ▶ if( !defined $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $verbose) 0 1 1
160 0 $verbose = 1;
161 }
162  
163 1 ▶ if( !ref $seq ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $seq) { } 0 1 1
elsif (not $seq->isa('Bio::PrimarySeqI')) { } 0 1 1
164 0 $seq = Bio::Seq->new( -seq => $seq, -id => 'blast-sequence-temp-id');
165 } elsif ( !$seq->isa('Bio::PrimarySeqI') ) {
166 0 croak("[$seq] is an object, but not a Bio::Seq object, cannot be blasted");
167 }
168  
169 1 require Bio::Tools::Run::RemoteBlast;
170  
171 1 ▶ my $prog = ( $seq->alphabet eq 'protein' ) ? 'blastp' : 'blastn';
Branch: 1 branch
BranchTrueFalseTotal
$seq->alphabet eq 'protein' ? : 1 0 1
172 1 my $e_val= '1e-10';
173  
174 1 my @params = ( '-prog' => $prog,
175 '-expect' => $e_val,
176 '-readmethod' => 'SearchIO' );
177  
178 1 my $factory = Bio::Tools::Run::RemoteBlast->new(@params);
179  
180 1 my $r = $factory->submit_blast($seq);
181 1 ▶ if( $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 1 1
182 0 print STDERR "Submitted Blast for [".$seq->id."] ";
183 }
184 1 sleep 5;
185  
186 1 my $result;
187  
188 LOOP :
189 1 ▶ while( my @rids = $factory->each_rid) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@rids) = $factory->each_rid) 283 0 283
190 283 foreach my $rid ( @rids ) {
191 283 my $rc = $factory->retrieve_blast($rid);
192 283 ▶ if( !ref($rc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $rc) { } 282 1 283
193 282 ▶ if( $rc < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc < 0) 0 282 282
194 0 $factory->remove_rid($rid);
195 }
196 282 ▶ if( $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 282 282
197 0 print STDERR ".";
198 }
199 282 sleep 10;
200 } else {
201 1 $result = $rc->next_result();
202 1 $factory->remove_rid($rid);
203 1 last LOOP;
204 }
205 }
206 }
207  
208 1 ▶ if( $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 1 1
209 0 print STDERR "\n";
210 }
211 1 return $result;
212 }
213  
214  
215 sub write_blast {
216 0 ▶ my ($filename,$blast) = @_;
Subroutine write_blast: not called CC=3 SCAR=24.8
Pod documented
217  
218 0 ▶ if( $filename !~ /^\>/ && $filename !~ /^|/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ /^\>/ or $filename =~ /^|/) 0 0 0
Condition0%0/3
$filename =~ /^\>/ or $filename =~ /^|/
l!l&&r!l&&!r
000
MC/DC0%0/2
$filename =~ /^\>/ or $filename =~ /^|/
$filename =~ /^\>/ $filename =~ /^|/
Truth table0%0/3
A or B
A= $filename =~ /^\>/B= $filename =~ /^|/
ABresult
1X1
011
000
219 0 $filename = ">".$filename;
220 }
221  
222 0 my $output = Bio::SearchIO->new( -output_format => 'blast', -file => $filename);
223  
224 0 $output->write_result($blast);
225  
226 }
227  
228  
229 2 my $genbank_db = undef;
230 2 my $genpept_db = undef;
231 2 my $embl_db = undef;
232 2 my $swiss_db = undef;
233 2 my $refseq_db = undef;
234  
235 sub get_sequence{
236 5 ▶ my ($db_type,$identifier) = @_;
Subroutine get_sequence: called CC=15 SCAR=27.4
Pod documented
237 5 ▶ if( ! $DBOKAY ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Bio::Perl::DBOKAY) 0 5 5
238 0 confess ("Your system does not have one of LWP, HTTP::Request::Common, IO::String\n".
239 "installed so the DB retrieval method is not available.\n".
240 "Full error message is:\n $!\n");
241 0 return;
242 }
243 5 $db_type = lc($db_type);
244  
245 5 my $db;
246  
247 5 ▶ if( $db_type =~ /genbank/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type =~ /genbank/) 2 3 5
248 2 ▶ if( !defined $genbank_db ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $genbank_db) 1 1 2
249 1 $genbank_db = Bio::DB::GenBank->new();
250 }
251 2 $db = $genbank_db;
252 }
253 5 ▶ if( $db_type =~ /genpept/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type =~ /genpept/) 1 4 5
254 1 ▶ if( !defined $genpept_db ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $genpept_db) 1 0 1
255 1 $genpept_db = Bio::DB::GenPept->new();
256 }
257 1 $db = $genpept_db;
258 }
259  
260 5 ▶ if( $db_type =~ /swiss/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type =~ /swiss/) 1 4 5
261 1 ▶ if( !defined $swiss_db ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $swiss_db) 1 0 1
262 1 $swiss_db = Bio::DB::SwissProt->new();
263 }
264 1 $db = $swiss_db;
265 }
266  
267 5 ▶ if( $db_type =~ /embl/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type =~ /embl/) 1 4 5
268 1 ▶ if( !defined $embl_db ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $embl_db) 1 0 1
269 1 $embl_db = Bio::DB::EMBL->new();
270 }
271 1 $db = $embl_db;
272 }
273  
274 5 ▶ if( $db_type =~ /refseq/ or ($db_type !~ /swiss/ and
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type =~ /refseq/ or not $db_type =~ /swiss/ and $identifier =~ /^\s*N\S+_/) 1 4 5
Condition83%5/6
$db_type =~ /refseq/ or not $db_type =~ /swiss/ and $identifier =~ /^\s*N\S+_/
l!l&&r!l&&!r
014
not $db_type =~ /swiss/ and $identifier =~ /^\s*N\S+_/
!ll&&!rl&&r
131
MC/DC33%1/3
$db_type =~ /refseq/ or not $db_type =~ /swiss/ and $identifier =~ /^\s*N\S+_/
$db_type =~ /refseq/ not $db_type =~ /swiss/ $identifier =~ /^\s*N\S+_/
Truth table50%2/4
A or not(B) and C
A= $db_type =~ /refseq/B= not $db_type =~ /swiss/C= $identifier =~ /^\s*N\S+_/
ABCresult
1XX1
0111
00X0
0100
275 $identifier =~ /^\s*N\S+_/)) {
276 1 ▶ if( !defined $refseq_db ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $refseq_db) 1 0 1
277 1 $refseq_db = Bio::DB::RefSeq->new();
278 }
279 1 $db = $refseq_db;
280 }
281  
282 5 my $seq;
283  
284 5 ▶ if( $identifier =~ /^\w+\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier =~ /^\w+\d+$/) { } 4 1 5
285 4 $seq = $db->get_Seq_by_acc($identifier);
286 } else {
287 1 $seq = $db->get_Seq_by_id($identifier);
288 }
289  
290 5 return $seq;
291 }
292  
293  
294  
295 sub translate {
296 4 ▶ my ($scalar) = shift;
Subroutine translate: called CC=4 SCAR=14.4
Pod documented
297  
298 4 my $obj;
299 4 ▶ if( ref $scalar ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $scalar) { } 2 2 4
300 2 ▶ if( !$scalar->isa("Bio::PrimarySeqI") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $scalar->isa('Bio::PrimarySeqI')) { } 0 2 2
301 0 confess("Expecting a sequence object not a $scalar");
302 } else {
303 2 $obj= $scalar;
304 }
305 } else {
306 # check this looks vaguely like DNA
307 2 my $n = ( $scalar =~ tr/ATGCNatgcn/ATGCNatgcn/ );
308 2 ▶ if( $n < length($scalar) * 0.85 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < length($scalar) * "0.85") 0 2 2
309 0 confess("Sequence [$scalar] is less than 85% ATGCN, which doesn't look very DNA to me");
310 }
311 2 $obj = Bio::PrimarySeq->new(-id => 'internalbioperlseq',-seq => $scalar);
312 }
313 4 return $obj->translate();
314 }
315  
316  
317  
318 sub translate_as_string {
319 2 ▶ my ($scalar) = shift;
Subroutine translate_as_string: called CC=1 SCAR=0.0
Pod documented
320 2 my $obj = Bio::Perl::translate($scalar);
321 2 return $obj->seq;
322 }
323  
324  
325  
326 sub reverse_complement {
327 0 ▶ my ($scalar) = shift;
Subroutine reverse_complement: not called CC=4 SCAR=30.0
Pod documented
328  
329 0 my $obj;
330  
331 0 ▶ if( ref $scalar ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $scalar) { } 0 0 0
332 0 ▶ if( !$scalar->isa("Bio::PrimarySeqI") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $scalar->isa('Bio::PrimarySeqI')) { } 0 0 0
333 0 confess("Expecting a sequence object not a $scalar");
334 } else {
335 0 $obj= $scalar;
336 }
337  
338 } else {
339  
340 # check this looks vaguely like DNA
341 0 my $n = ( $scalar =~ tr/ATGCNatgcn/ATGCNatgcn/ );
342  
343 0 ▶ if( $n < length($scalar) * 0.85 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < length($scalar) * "0.85") 0 0 0
344 0 confess("Sequence [$scalar] is less than 85% ATGCN, which doesn't look very DNA to me");
345 }
346  
347 0 $obj = Bio::PrimarySeq->new(-id => 'internalbioperlseq',-seq => $scalar);
348 }
349  
350 0 return $obj->revcom();
351 }
352  
353  
354 sub revcom {
355 0 ▶ return &Bio::Perl::reverse_complement(@_);
Subroutine revcom: not called CC=1 SCAR=6.9
Pod documented
356 }
357  
358  
359  
360 sub reverse_complement_as_string {
361 0 ▶ my ($scalar) = shift;
Subroutine reverse_complement_as_string: not called CC=1 SCAR=6.9
Pod documented
362 0 my $obj = &Bio::Perl::reverse_complement($scalar);
363 0 return $obj->seq;
364 }
365  
366  
367  
368 sub revcom_as_string {
369 0 ▶ my ($scalar) = shift;
Subroutine revcom_as_string: not called CC=1 SCAR=6.9
Pod documented
370 0 my $obj = &Bio::Perl::reverse_complement($scalar);
371 0 return $obj->seq;
372 }
373  
374  
375 2 1;
376  
377  
378 # ABSTRACT: Functional access to BioPerl for people who don't know objects
379 # AUTHOR: Ewan Birney <birney@ebi.ac.uk>
380 # OWNER: many people (see the individual modules for their copyright holders)
381 # LICENSE: Perl_5
382  
383 __END__
↑ Summary Procedural.pm »