| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
2
|
|
|
|
|
|
|
# PACKAGE : Bio::SeqIO::raw |
|
3
|
|
|
|
|
|
|
# AUTHOR : Ewan Birney |
|
4
|
|
|
|
|
|
|
# CREATED : Feb 16 1999 |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# Copyright (c) 1997-9 bioperl, Ewan Birney. All Rights Reserved. |
|
7
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
|
8
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# _History_ |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# Ewan Birney developed the SeqIO |
|
13
|
|
|
|
|
|
|
# schema and the first prototype modules. |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# This code is based on his Bio::SeqIO::Fasta module with |
|
16
|
|
|
|
|
|
|
# the necessary minor tweaks necessary to get it to read |
|
17
|
|
|
|
|
|
|
# and write raw formatted sequences made by |
|
18
|
|
|
|
|
|
|
# chris dagdigian |
|
19
|
|
|
|
|
|
|
# |
|
20
|
|
|
|
|
|
|
# October 18, 1999 Largely rewritten by Lincoln Stein |
|
21
|
|
|
|
|
|
|
# |
|
22
|
|
|
|
|
|
|
# Copyright Ewan Birney |
|
23
|
|
|
|
|
|
|
# |
|
24
|
|
|
|
|
|
|
# You may distribute this module under the same terms as perl itself |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# POD documentation - main docs before the code |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Bio::SeqIO::raw - raw sequence file input/output stream |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Do not use this module directly. Use it via the L class. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This object can transform Bio::Seq objects to and from raw flat |
|
39
|
|
|
|
|
|
|
file databases. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 FEEDBACK |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 Mailing Lists |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
User feedback is an integral part of the evolution of this and other |
|
46
|
|
|
|
|
|
|
Bioperl modules. Send your comments and suggestions preferably to one |
|
47
|
|
|
|
|
|
|
of the Bioperl mailing lists. Your participation is much appreciated. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
bioperl-l@bioperl.org - General discussion |
|
50
|
|
|
|
|
|
|
http://bioperl.org/wiki/Mailing_lists - About the mailing lists |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 Support |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Please direct usage questions or support issues to the mailing list: |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
I |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
rather than to the module maintainer directly. Many experienced and |
|
59
|
|
|
|
|
|
|
reponsive experts will be able look at the problem and quickly |
|
60
|
|
|
|
|
|
|
address it. Please include a thorough description of the problem |
|
61
|
|
|
|
|
|
|
with code and data examples if at all possible. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 Reporting Bugs |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Report bugs to the Bioperl bug tracking system to help us keep track |
|
66
|
|
|
|
|
|
|
the bugs and their resolution. |
|
67
|
|
|
|
|
|
|
Bug reports can be submitted via the web: |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
https://github.com/bioperl/bioperl-live/issues |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHORS |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Ewan Birney Ebirney@ebi.ac.ukE |
|
74
|
|
|
|
|
|
|
Lincoln Stein Elstein@cshl.orgE |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Jason Stajich Ejason@bioperl.org |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 APPENDIX |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The rest of the documentation details each of the object methods. |
|
83
|
|
|
|
|
|
|
Internal methods are usually preceded with a _ |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Let the code begin... |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
package Bio::SeqIO::raw; |
|
91
|
3
|
|
|
3
|
|
361
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
75
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
3
|
|
|
3
|
|
234
|
use Bio::Seq::SeqFactory; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
66
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
3
|
|
|
3
|
|
10
|
use base qw(Bio::SeqIO); |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
1201
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
our %variant = ( 'multiple' => undef, # default |
|
98
|
|
|
|
|
|
|
'single' => undef ); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _initialize { |
|
101
|
11
|
|
|
11
|
|
19
|
my($self,@args) = @_; |
|
102
|
11
|
|
|
|
|
24
|
$self->SUPER::_initialize(@args); |
|
103
|
11
|
|
|
|
|
30
|
my ($variant) = $self->_rearrange([qw(VARIANT)], @args); |
|
104
|
11
|
|
100
|
|
|
35
|
$variant ||= 'multiple'; |
|
105
|
11
|
|
|
|
|
26
|
$self->variant($variant); |
|
106
|
11
|
100
|
|
|
|
28
|
$self->{record_separator} = $variant eq 'single' ? undef : $/; |
|
107
|
11
|
50
|
|
|
|
30
|
if( ! defined $self->sequence_factory ) { |
|
108
|
11
|
|
|
|
|
31
|
$self->sequence_factory(Bio::Seq::SeqFactory->new |
|
109
|
|
|
|
|
|
|
(-verbose => $self->verbose(), |
|
110
|
|
|
|
|
|
|
-type => 'Bio::Seq')); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
11
|
|
|
|
|
31
|
$self->variant; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 next_seq |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Title : next_seq |
|
118
|
|
|
|
|
|
|
Usage : $seq = $stream->next_seq() |
|
119
|
|
|
|
|
|
|
Function: returns the next sequence in the stream |
|
120
|
|
|
|
|
|
|
Returns : Bio::Seq object |
|
121
|
|
|
|
|
|
|
Args : |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub next_seq{ |
|
127
|
20
|
|
|
20
|
1
|
30
|
my ($self,@args) = @_; |
|
128
|
|
|
|
|
|
|
## When its 1 sequence per line with no formatting at all, |
|
129
|
|
|
|
|
|
|
## grabbing it should be easy :) |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
## adding an option to assume the file is one sequence |
|
132
|
20
|
|
|
|
|
64
|
local $/ = $self->{record_separator}; |
|
133
|
20
|
|
|
|
|
47
|
my $nextline = $self->_readline(); |
|
134
|
20
|
100
|
|
|
|
38
|
return unless defined $nextline; |
|
135
|
|
|
|
|
|
|
|
|
136
|
18
|
|
|
|
|
29
|
my $sequence = uc($nextline); |
|
137
|
18
|
|
|
|
|
82
|
$sequence =~ s/\W//g; |
|
138
|
18
|
100
|
|
|
|
35
|
return unless $sequence; |
|
139
|
17
|
50
|
|
|
|
52
|
return $self->sequence_factory->create(-seq => $sequence) if $sequence; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 write_seq |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Title : write_seq |
|
145
|
|
|
|
|
|
|
Usage : $stream->write_seq($seq) |
|
146
|
|
|
|
|
|
|
Function: writes the $seq object into the stream |
|
147
|
|
|
|
|
|
|
Returns : 1 for success and 0 for error |
|
148
|
|
|
|
|
|
|
Args : Array of Bio::PrimarySeqI objects |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub write_seq { |
|
154
|
5
|
|
|
5
|
1
|
14
|
my ($self,@seq) = @_; |
|
155
|
5
|
|
|
|
|
11
|
foreach my $seq (@seq) { |
|
156
|
5
|
50
|
33
|
|
|
34
|
$self->throw("Must provide a valid Bio::PrimarySeqI object") |
|
|
|
|
33
|
|
|
|
|
|
157
|
|
|
|
|
|
|
unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI'); |
|
158
|
5
|
50
|
|
|
|
8
|
$self->_print($seq->seq, "\n") or return; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
5
|
50
|
33
|
|
|
9
|
$self->flush if $self->_flush_on_write && defined $self->_fh; |
|
161
|
5
|
|
|
|
|
9
|
return 1; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 write_qual |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Title : write_qual |
|
167
|
|
|
|
|
|
|
Usage : $stream->write_qual($seq) |
|
168
|
|
|
|
|
|
|
Function: writes the $seq object into the stream |
|
169
|
|
|
|
|
|
|
Returns : 1 for success and 0 for error |
|
170
|
|
|
|
|
|
|
Args : Bio::Seq::Quality object |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub write_qual { |
|
176
|
0
|
|
|
0
|
1
|
|
my ($self,@seq) = @_; |
|
177
|
0
|
|
|
|
|
|
my @qual = (); |
|
178
|
0
|
|
|
|
|
|
foreach (@seq) { |
|
179
|
0
|
0
|
|
|
|
|
unless ($_->isa("Bio::Seq::Quality")){ |
|
180
|
0
|
|
|
|
|
|
warn("You cannot write raw qualities without supplying a Bio::Seq::". |
|
181
|
|
|
|
|
|
|
"Quality object! You passed a ".ref($_)."\n"); |
|
182
|
0
|
|
|
|
|
|
next; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
0
|
|
|
|
|
|
@qual = @{$_->qual}; |
|
|
0
|
|
|
|
|
|
|
|
185
|
0
|
0
|
|
|
|
|
if(scalar(@qual) == 0) { |
|
186
|
0
|
|
|
|
|
|
$qual[0] = "\n"; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
0
|
0
|
|
|
|
|
$self->_print (join " ", @qual,"\n") or return; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
0
|
|
|
|
|
|
return 1; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 variant |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Title : variant |
|
196
|
|
|
|
|
|
|
Usage : $format = $obj->variant(); |
|
197
|
|
|
|
|
|
|
Function: Get and set method for the sequence variant. For raw sequence, this |
|
198
|
|
|
|
|
|
|
indicates whether to treat the input as multiple sequences (the |
|
199
|
|
|
|
|
|
|
default) or as a single sequence. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Current values accepted are: |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
'single' single sequence |
|
204
|
|
|
|
|
|
|
'multiple' multiple sequences (default) |
|
205
|
|
|
|
|
|
|
Returns : string |
|
206
|
|
|
|
|
|
|
Args : new value, string |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# variant() method inherited from Bio::Root::IO |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# private method for testing record separator |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub _separator { |
|
215
|
0
|
|
|
0
|
|
|
shift->{record_separator}; |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
1; |