Bio/Seq/LargePrimarySeq.pm

filter: Statementstmt 85.4% 82 / 96 Branchbran 71.4% 40 / 56 Conditioncond 70.0% 14 / 20 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 78.7% 159 / 202 CC 37 SCAR 28.1
CC
37
Cov
79%
subseq
35.2
new
6.1
DESTROY
6.0
CRAP 16.6
« Bio/DB/Registry.pm ↑ Summary Bio/Search/Hit/HitI.pm »
1 #
2 # BioPerl module for Bio::Seq::LargePrimarySeq
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
7 #
8 # Copyright Ewan Birney
9 #
10 # You may distribute this module under the same terms as perl itself
11 #
12 # updated to utilize File::Temp - jason 2000-12-12
13 # POD documentation - main docs before the code
14  
15 =head1 NAME
16  
17 Bio::Seq::LargePrimarySeq - PrimarySeq object that stores sequence as
18 files in the tempdir (as found by File::Temp) or the default method in
19 Bio::Root::Root
20  
21 =head1 SYNOPSIS
22  
23 # normal primary seq usage
24  
25 =head1 DESCRIPTION
26  
27 This object stores a sequence as a series of files in a temporary
28 directory. The aim is to allow someone the ability to store very large
29 sequences (eg, E<gt> 100MBases) in a file system without running out
30 of memory (eg, on a 64 MB real memory machine!).
31  
32 Of course, to actually make use of this functionality, the programs
33 which use this object B<must> not call $primary_seq-E<gt>seq otherwise
34 the entire sequence will come out into memory and probably paste your
35 machine. However, calls $primary_seq-E<gt>subseq(10,100) will cause
36 only 90 characters to be brought into real memory.
37  
38 =head1 FEEDBACK
39  
40 =head2 Mailing Lists
41  
42 User feedback is an integral part of the evolution of this and other
43 Bioperl modules. Send your comments and suggestions preferably to one
44 of the Bioperl mailing lists. Your participation is much appreciated.
45  
46 bioperl-l@bioperl.org - General discussion
47 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
48  
49 =head2 Support
50  
51 Please direct usage questions or support issues to the mailing list:
52  
53 I<bioperl-l@bioperl.org>
54  
55 rather than to the module maintainer directly. Many experienced and
56 reponsive experts will be able look at the problem and quickly
57 address it. Please include a thorough description of the problem
58 with code and data examples if at all possible.
59  
60 =head2 Reporting Bugs
61  
62 Report bugs to the Bioperl bug tracking system to help us keep track
63 the bugs and their resolution. Bug reports can be submitted via the
64 web:
65  
66 https://github.com/bioperl/bioperl-live/issues
67  
68 =head1 AUTHOR - Ewan Birney, Jason Stajich
69  
70 Email birney@ebi.ac.uk
71 Email jason@bioperl.org
72  
73 =head1 APPENDIX
74  
75 The rest of the documentation details each of the object
76 methods. Internal methods are usually preceded with a _
77  
78 =cut
79  
80  
81 # Let the code begin...
82  
83  
84 package Bio::Seq::LargePrimarySeq;
85 8 $Bio::Seq::LargePrimarySeq::VERSION = '1.7.8';
86 8 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
87 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89  
90 8 ▶use base qw(Bio::PrimarySeq Bio::Root::IO Bio::Seq::LargeSeqI);
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 22 ▶sub new {
Subroutine new: called CC=6 SCAR=18.0
Pod documented
93 22 my ($class, %params) = @_;
94
95 # don't let PrimarySeq set seq until we have
96 # opened filehandle
97  
98 22 ▶ my $seq = $params{'-seq'} || $params{'-SEQ'};
Condition66%2/3
$params{'-seq'} || $params{'-SEQ'}
l!l&&r!l&&!r
10012
MC/DC50%1/2
$params{'-seq'} || $params{'-SEQ'}
$params{'-seq'} $params{'-SEQ'}
Truth table66%2/3
A || B
A= $params{'-seq'}B= $params{'-SEQ'}
ABresult
1X1
011
000
99 22 ▶ if($seq ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 10 12 22
100 10 delete $params{'-seq'};
101 10 delete $params{'-SEQ'};
102 }
103 22 my $self = $class->SUPER::new(%params);
104 22 $self->_initialize_io(%params);
105 22 my $tempdir = $self->tempdir( CLEANUP => 1);
106 22 my ($tfh,$file) = $self->tempfile( DIR => $tempdir );
107 22 $self->{tempdir} = $tempdir;
108 22 ▶ $tfh && $self->_fh($tfh);
Branch: 1 branch
BranchTrueFalseTotal
$tfh and $self->_fh($tfh) 22 0 22
109 22 ▶ $file && $self->_filename($file);
Branch: 1 branch
BranchTrueFalseTotal
$file and $self->_filename($file) 22 0 22
110 22 $self->length(0);
111 22 ▶ $seq && $self->seq($seq);
Branch: 1 branch
BranchTrueFalseTotal
$seq and $self->seq($seq) 10 12 22
112  
113 22 return $self;
114 }
115  
116  
117 =head2 length
118  
119 Title : length
120 Usage :
121 Function:
122 Example :
123 Returns :
124 Args :
125  
126  
127 =cut
128  
129 14185 ▶sub length {
Subroutine length: called CC=3 SCAR=11.0
Pod documented
130 14185 my ($obj,$value) = @_;
131 14185 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 5649 8536 14185
132 5649 $obj->{'length'} = $value;
133 }
134 14185 ▶ return (defined $obj->{'length'}) ? $obj->{'length'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $obj->{'length'} ? : 14185 0 14185
135 }
136  
137 =head2 seq
138  
139 Title : seq
140 Usage :
141 Function:
142 Example :
143 Returns :
144 Args :
145  
146  
147 =cut
148  
149 29 ▶sub seq {
Subroutine seq: called CC=3 SCAR=11.2
Pod documented
150 29 my ($self, $data) = @_;
151 29 ▶ if( defined $data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) 11 18 29
152 11 ▶ if( $self->length() == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->length == 0) { } 11 0 11
153 11 $self->add_sequence_as_string($data);
154 } else {
155 0 $self->warn("Trying to reset the seq string, cannot do this with a LargePrimarySeq - must allocate a new object");
156 }
157 }
158 29 return $self->subseq(1,$self->length);
159 }
160  
161 =head2 subseq
162  
163 Title : subseq
164 Usage :
165 Function:
166 Example :
167 Returns :
168 Args :
169  
170  
171 =cut
172  
173 2859 ▶sub subseq{
Subroutine subseq: called CC=19 SCAR=35.6
Pod documented
174 2859 my ($self,$start,$end) = @_;
175 2859 my $string;
176 2859 my $fh = $self->_fh();
177  
178 2859 ▶ if( ref($start) && $start->isa('Bio::LocationI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $start and $start->isa("Bio::LocationI")) 3 2856 2859
Condition66%2/3
ref $start and $start->isa("Bio::LocationI")
!ll&&!rl&&r
285603
MC/DC50%1/2
ref $start and $start->isa("Bio::LocationI")
ref $start $start->isa("Bio::LocationI")
Truth table66%2/3
A and B
A= ref $startB= $start->isa("Bio::LocationI")
ABresult
0X0
100
111
179 3 my $loc = $start;
180 3 ▶ if( $loc->length == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($loc->length == 0) { } 0 3 3
elsif ($loc->end < $loc->start) { } 0 3 3
181 0 $self->warn("Expect location lengths to be > 0");
182 0 return '';
183 } elsif( $loc->end < $loc->start ) {
184 # what about circular seqs
185 0 $self->warn("Expect location start to come before location end");
186 }
187 3 my $seq = '';
188 3 ▶ if( $loc->isa('Bio::Location::SplitLocationI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loc->isa('Bio::Location::SplitLocationI')) { } 1 2 3
189 1 foreach my $subloc ( $loc->sub_Location ) {
190 2 ▶ if(! seek($fh,$subloc->start() - 1,0)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $fh, $subloc->start - 1, 0) 0 2 2
191 0 $self->throw("Unable to seek on file $start:$end $!");
192 }
193 2 my $ret = read($fh, $string, $subloc->length());
194 2 ▶ if( !defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret) 0 2 2
195 0 $self->throw("Unable to read $start:$end $!");
196 }
197 2 ▶ if( $subloc->strand < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subloc->strand < 0) 1 1 2
198 1 $string = Bio::PrimarySeq->new(-seq => $string)->revcom()->seq();
199 }
200 2 $seq .= $string;
201 }
202 } else {
203 2 ▶ if(! seek($fh,$loc->start()-1,0)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $fh, $loc->start - 1, 0) 0 2 2
204 0 $self->throw("Unable to seek on file ".$loc->start.":".
205 $loc->end ." $!");
206 }
207 2 my $ret = read($fh, $string, $loc->length());
208 2 ▶ if( !defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret) 0 2 2
209 0 $self->throw("Unable to read ".$loc->start.":".
210 $loc->end ." $!");
211 }
212 2 $seq = $string;
213 }
214 3 ▶ if( defined $loc->strand &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $loc->strand and $loc->strand < 0) 0 3 3
Condition66%2/3
defined $loc->strand and $loc->strand < 0
!ll&&!rl&&r
120
MC/DC0%0/2
defined $loc->strand and $loc->strand < 0
defined $loc->strand $loc->strand < 0
Truth table66%2/3
A and B
A= defined $loc->strandB= $loc->strand < 0
ABresult
0X0
100
111
215 $loc->strand < 0 ) {
216 0 $seq = Bio::PrimarySeq->new(-seq => $seq)->revcom()->seq();
217 }
218 3 return $seq;
219 }
220 2856 ▶ if( $start <= 0 || $end > $self->length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start <= 0 or $end > $self->length) 0 2856 2856
Condition33%1/3
$start <= 0 or $end > $self->length
l!l&&r!l&&!r
002856
MC/DC0%0/2
$start <= 0 or $end > $self->length
$start <= 0 $end > $self->length
Truth table33%1/3
A or B
A= $start <= 0B= $end > $self->length
ABresult
1X1
011
000
221 0 $self->throw("Attempting to get a subseq out of range $start:$end vs ".
222 $self->length);
223 }
224 2856 ▶ if( $end < $start ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end < $start) 0 2856 2856
225 0 $self->throw("Attempting to subseq with end ($end) less than start ($start). To revcom use the revcom function with trunc");
226 }
227  
228 2856 ▶ if(! seek($fh,$start-1,0)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $fh, $start - 1, 0) 0 2856 2856
229 0 $self->throw("Unable to seek on file $start:$end $!");
230 }
231 2856 my $ret = read($fh, $string, $end-$start+1);
232 2856 ▶ if( !defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret) 0 2856 2856
233 0 $self->throw("Unable to read $start:$end $!");
234 }
235 2856 return $string;
236 }
237  
238 =head2 add_sequence_as_string
239  
240 Title : add_sequence_as_string
241 Usage : $seq->add_sequence_as_string("CATGAT");
242 Function: Appends additional residues to an existing LargePrimarySeq object.
243 This allows one to build up a large sequence without storing
244 entire object in memory.
245 Returns : Current length of sequence
246 Args : string to append
247  
248 =cut
249  
250 5635 ▶sub add_sequence_as_string{
Subroutine add_sequence_as_string: called CC=2 SCAR=7.1
Pod documented
251 5635 my ($self,$str) = @_;
252 5635 my $len = $self->length + CORE::length($str);
253 5635 my $fh = $self->_fh();
254 5635 ▶ if(! seek($fh,0,2)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $fh, 0, 2) 0 5635 5635
255 0 $self->throw("Unable to seek end of file: $!");
256 }
257 5635 $self->_print($str);
258 5635 $self->length($len);
259 }
260  
261  
262 =head2 _filename
263  
264 Title : _filename
265 Usage : $obj->_filename($newval)
266 Function:
267 Example :
268 Returns : value of _filename
269 Args : newvalue (optional)
270  
271  
272 =cut
273  
274 59 ▶sub _filename{
Subroutine _filename: called CC=2 SCAR=6.9
275 59 my ($obj,$value) = @_;
276 59 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 14 45 59
277 14 $obj->{'_filename'} = $value;
278 }
279 59 return $obj->{'_filename'};
280  
281 }
282  
283  
284 =head2 alphabet
285  
286 Title : alphabet
287 Usage : $obj->alphabet($newval)
288 Function:
289 Example :
290 Returns : value of alphabet
291 Args : newvalue (optional)
292  
293  
294 =cut
295  
296 29 ▶sub alphabet{
Subroutine alphabet: called CC=3 SCAR=11.0
Pod documented
297 29 my ($self,$value) = @_;
298 29 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 14 15 29
299 14 $self->SUPER::alphabet($value);
300 }
301 29 ▶ return $self->SUPER::alphabet() || 'dna';
Condition100%2/2
$self->SUPER::alphabet || 'dna'
l!l
236
MC/DC100%1/1
$self->SUPER::alphabet || 'dna'
$self->SUPER::alphabet
Truth table100%2/2
A
A= $self->SUPER::alphabet
Aresult
11
00
302  
303 }
304  
305 27 ▶sub DESTROY {
Subroutine DESTROY: called CC=6 SCAR=17.9
306 27 my $self = shift;
307 27 my $fh = $self->_fh();
308 27 ▶ close($fh) if( defined $fh );
Branch: 1 branch
BranchTrueFalseTotal
if defined $fh 22 5 27
309 # this should be handled by Tempfile removal, but we'll unlink anyways.
310 27 ▶ unlink $self->_filename() if defined $self->_filename() && -e $self->_filename;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_filename and -e $self->_filename 14 13 27
Condition100%3/3
defined $self->_filename and -e $self->_filename
!ll&&!rl&&r
5814
MC/DC100%2/2
defined $self->_filename and -e $self->_filename
defined $self->_filename -e $self->_filename
Truth table100%3/3
A and B
A= defined $self->_filenameB= -e $self->_filename
ABresult
0X0
100
111
311 # remove tempdirs as well
312 27 ▶ rmdir $self->{tempdir} if defined $self->{tempdir} && -e $self->{tempdir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"tempdir"} and -e $self->{"tempdir"} 22 5 27
Condition66%2/3
defined $self->{"tempdir"} and -e $self->{"tempdir"}
!ll&&!rl&&r
5022
MC/DC50%1/2
defined $self->{"tempdir"} and -e $self->{"tempdir"}
defined $self->{"tempdir"} -e $self->{"tempdir"}
Truth table66%2/3
A and B
A= defined $self->{"tempdir"}B= -e $self->{"tempdir"}
ABresult
0X0
100
111
313 27 $self->SUPER::DESTROY();
314 }
315  
316 8 1;
« Bio/DB/Registry.pm ↑ Summary Bio/Search/Hit/HitI.pm »