Bio/SeqIO/largefasta.pm

filter: Statementstmt 92.9% 53 / 57 Branchbran 66.6% 16 / 24 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 76.3% 84 / 110 CC 18 SCAR 20.9
CC
18
Cov
81%
next_seq
11.8
write_seq
8.5
_initialize
2.0
CRAP 8.1
« Bio/Tree/NodeNHX.pm ↑ Summary Bio/AlignIO/selex.pm »
1 # BioPerl module for Bio::SeqIO::largefasta
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Jason Stajich
6 #
7 # Copyright Jason Stajich
8 #
9 # You may distribute this module under the same terms as perl itself
10 # _history
11 #
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::SeqIO::largefasta - method i/o on very large fasta sequence files
17  
18 =head1 SYNOPSIS
19  
20 Do not use this module directly. Use it via the Bio::SeqIO class.
21  
22 =head1 DESCRIPTION
23  
24 This object can transform Bio::Seq objects to and from fasta flat
25 file databases.
26  
27 This module handles very large sequence files by using the
28 Bio::Seq::LargePrimarySeq module to store all the sequence data in
29 a file. This can be a problem if you have limited disk space on your
30 computer because this will effectively cause 2 copies of the sequence
31 file to reside on disk for the life of the
32 Bio::Seq::LargePrimarySeq object. The default location for this is
33 specified by the L<File::Spec>-E<gt>tmpdir routine which is usually /tmp
34 on UNIX. If a sequence file is larger than the swap space (capacity
35 of the /tmp dir) this could cause problems for the machine. It is
36 possible to set the directory where the temporary file is located by
37 adding the following line to your code BEFORE calling next_seq. See
38 L<Bio::Seq::LargePrimarySeq> for more information.
39  
40 $Bio::Seq::LargePrimarySeq::DEFAULT_TEMP_DIR = 'newdir';
41  
42 =head1 FEEDBACK
43  
44 =head2 Mailing Lists
45  
46 User feedback is an integral part of the evolution of this and other
47 Bioperl modules. Send your comments and suggestions preferably to one
48 of the Bioperl mailing lists. Your participation is much appreciated.
49  
50 bioperl-l@bioperl.org - General discussion
51 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
52  
53 =head2 Support
54  
55 Please direct usage questions or support issues to the mailing list:
56  
57 I<bioperl-l@bioperl.org>
58  
59 rather than to the module maintainer directly. Many experienced and
60 reponsive experts will be able look at the problem and quickly
61 address it. Please include a thorough description of the problem
62 with code and data examples if at all possible.
63  
64 =head2 Reporting Bugs
65  
66 Report bugs to the Bioperl bug tracking system to help us keep track
67 the bugs and their resolution. Bug reports can be submitted via the web:
68  
69 https://github.com/bioperl/bioperl-live/issues
70  
71 =head1 AUTHORS - Jason Stajich
72  
73 Email: jason@bioperl.org
74  
75 =head1 APPENDIX
76  
77 The rest of the documentation details each of the object
78 methods. Internal methods are usually preceded with a _
79  
80 =cut
81  
82 # Let the code begin...
83  
84 package Bio::SeqIO::largefasta;
85 2 $Bio::SeqIO::largefasta::VERSION = '1.7.8';
86 2 ▶use vars qw($FASTALINELEN);
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 2 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 2 $FASTALINELEN = 60;
92 2 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 3 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=7.0
95 3 my($self,@args) = @_;
96 3 $self->SUPER::_initialize(@args);
97 3 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 3 0 3
98 3 $self->sequence_factory(Bio::Seq::SeqFactory->new
99 (-verbose => $self->verbose(),
100 -type => 'Bio::Seq::LargePrimarySeq'));
101 }
102 }
103  
104 =head2 next_seq
105  
106 Title : next_seq
107 Usage : $seq = $stream->next_seq()
108 Function: returns the next sequence in the stream
109 Returns : A Bio::Seq::LargePrimarySeq object
110 Args : NONE
111  
112 =cut
113  
114 2 ▶sub next_seq {
Subroutine next_seq: called CC=10 SCAR=24.7
Pod documented
115 2 my ($self) = @_;
116 # local $/ = "\n";
117 2 my $largeseq = $self->sequence_factory->create();
118 2 my ($id,$fulldesc,$entry);
119 2 my $count = 0;
120 2 my $seen = 0;
121 2 ▶ while( defined ($entry = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($entry = $self->_readline)) 5624 2 5626
122 5624 ▶ if( $seen == 1 && $entry =~ /^\s*>/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen == 1 and $entry =~ /^\s*>/) 0 5624 5624
Condition66%2/3
$seen == 1 and $entry =~ /^\s*>/
!ll&&!rl&&r
256220
MC/DC0%0/2
$seen == 1 and $entry =~ /^\s*>/
$seen == 1 $entry =~ /^\s*>/
Truth table66%2/3
A and B
A= $seen == 1B= $entry =~ /^\s*>/
ABresult
0X0
100
111
123 0 $self->_pushback($entry);
124 0 return $largeseq;
125 }
126 # if ( ($entry eq '>') || eof($self->_fh) ) { $seen = 1; next; }
127 0 ▶ if ( ($entry eq '>') ) { $seen = 1; next; }
Branch: 2 branches
BranchTrueFalseTotal
if ($entry eq '>') { } 0 5624 5624
elsif ($entry =~ /\s*>(.+?)$/) { } 2 5622 5624
128 elsif( $entry =~ /\s*>(.+?)$/ ) {
129 2 $seen = 1;
130 2 ▶ ($id,$fulldesc) = ($1 =~ /^\s*(\S+)\s*(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
() = $1 =~ /^\s*(\S+)\s*(.*)$/ or $self->warn("Can't parse fasta header") 2 0 2
131 or $self->warn("Can't parse fasta header");
132 2 $largeseq->display_id($id);
133 2 $largeseq->primary_id($id);
134 2 $largeseq->desc($fulldesc);
135 } else {
136 5622 $entry =~ s/\s+//g;
137 5622 $largeseq->add_sequence_as_string($entry);
138 }
139 5624 ▶ (++$count % 1000 == 0 && $self->verbose() > 0) && print "line $count\n";
Branch: 1 branch
BranchTrueFalseTotal
++$count % 1000 == 0 and $self->verbose > 0 and print "line $count\n" 0 5624 5624
Condition66%2/3
++$count % 1000 == 0 and $self->verbose > 0
!ll&&!rl&&r
562040
MC/DC0%0/2
++$count % 1000 == 0 and $self->verbose > 0
++$count % 1000 == 0 $self->verbose > 0
Truth table66%2/3
A and B
A= ++$count % 1000 == 0B= $self->verbose > 0
ABresult
0X0
100
111
140 }
141 2 ▶ return unless $seen;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen 0 2 2
142 2 return $largeseq;
143 }
144  
145 =head2 write_seq
146  
147 Title : write_seq
148 Usage : $stream->write_seq(@seq)
149 Function: writes the $seq object into the stream
150 Returns : 1 for success and 0 for error
151 Args : Bio::Seq object
152  
153  
154 =cut
155  
156 1 ▶sub write_seq {
Subroutine write_seq: called CC=8 SCAR=21.4
Pod documented
157 1 my ($self,@seq) = @_;
158 1 foreach my $seq (@seq) {
159 1 my $top = $seq->id();
160 1 ▶ if ($seq->can('desc') and my $desc = $seq->desc()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->can("desc") and my $desc = $seq->desc) 1 0 1
Condition33%1/3
$seq->can("desc") and my $desc = $seq->desc
!ll&&!rl&&r
001
MC/DC0%0/2
$seq->can("desc") and my $desc = $seq->desc
$seq->can("desc") my $desc = $seq->desc
Truth table33%1/3
A and B
A= $seq->can("desc")B= my $desc = $seq->desc
ABresult
0X0
100
111
161 1 $desc =~ s/\n//g;
162 1 $top .= " $desc";
163 }
164 1 $self->_print (">",$top,"\n");
165 1 my $end = $seq->length();
166 1 my $start = 1;
167 1 ▶ while( $start <= $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start <= $end) 2811 1 2812
168 2811 my $stop = $start + $FASTALINELEN - 1;
169 2811 ▶ $stop = $end if( $stop > $end );
Branch: 1 branch
BranchTrueFalseTotal
if $stop > $end 1 2810 2811
170 2811 $self->_print($seq->subseq($start,$stop), "\n");
171 2811 $start += $FASTALINELEN;
172 }
173 }
174  
175 1 ▶ $self->flush if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 1 0 1
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
001
MC/DC0%0/2
$self->_flush_on_write and defined $self->_fh
$self->_flush_on_write defined $self->_fh
Truth table33%1/3
A and B
A= $self->_flush_on_writeB= defined $self->_fh
ABresult
0X0
100
111
176 1 return 1;
177 }
178  
179 2 1;
« Bio/Tree/NodeNHX.pm ↑ Summary Bio/AlignIO/selex.pm »