line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# BioPerl module for Bio::SeqIO::ace |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Please direct questions and support issues to |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Cared for by James Gilbert |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# You may distribute this module under the same terms as perl itself |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# POD documentation - main docs before the code |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Bio::SeqIO::ace - ace sequence input/output stream |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Do not use this module directly. Use it via the Bio::SeqIO class. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This object can transform Bio::Seq objects to and |
23
|
|
|
|
|
|
|
from ace file format. It only parses a DNA or |
24
|
|
|
|
|
|
|
Peptide objects contained in the ace file, |
25
|
|
|
|
|
|
|
producing PrimarySeq objects from them. All |
26
|
|
|
|
|
|
|
other objects in the files will be ignored. It |
27
|
|
|
|
|
|
|
doesn't attempt to parse any annotation attatched |
28
|
|
|
|
|
|
|
to the containing Sequence or Protein objects, |
29
|
|
|
|
|
|
|
which would probably be impossible, since |
30
|
|
|
|
|
|
|
everyone's ACeDB schema can be different. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
It won't parse ace files containing Timestamps |
33
|
|
|
|
|
|
|
correctly either. This can easily be added if |
34
|
|
|
|
|
|
|
considered necessary. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 FEEDBACK |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 Mailing Lists |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
User feedback is an integral part of the evolution of this and other |
41
|
|
|
|
|
|
|
Bioperl modules. Send your comments and suggestions preferably to one |
42
|
|
|
|
|
|
|
of the Bioperl mailing lists. Your participation is much appreciated. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
bioperl-l@bioperl.org - General discussion |
45
|
|
|
|
|
|
|
http://bioperl.org/wiki/Mailing_lists - About the mailing lists |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 Support |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Please direct usage questions or support issues to the mailing list: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
I |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
rather than to the module maintainer directly. Many experienced and |
54
|
|
|
|
|
|
|
reponsive experts will be able look at the problem and quickly |
55
|
|
|
|
|
|
|
address it. Please include a thorough description of the problem |
56
|
|
|
|
|
|
|
with code and data examples if at all possible. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 Reporting Bugs |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Report bugs to the Bioperl bug tracking system to help us keep track |
61
|
|
|
|
|
|
|
the bugs and their resolution. |
62
|
|
|
|
|
|
|
Bug reports can be submitted via the web: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
https://github.com/bioperl/bioperl-live/issues |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHORS - James Gilbert |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Email: jgrg@sanger.ac.uk |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 APPENDIX |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The rest of the documentation details each of the object |
73
|
|
|
|
|
|
|
methods. Internal methods are usually preceded with a _ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#' |
78
|
|
|
|
|
|
|
# Let the code begin... |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
package Bio::SeqIO::ace; |
81
|
3
|
|
|
3
|
|
11
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
86
|
|
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
3
|
|
381
|
use Bio::Seq; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
83
|
|
84
|
3
|
|
|
3
|
|
364
|
use Bio::Seq::SeqFactory; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
63
|
|
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
3
|
|
11
|
use base qw(Bio::SeqIO); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
1658
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _initialize { |
89
|
5
|
|
|
5
|
|
10
|
my($self,@args) = @_; |
90
|
5
|
|
|
|
|
15
|
$self->SUPER::_initialize(@args); |
91
|
5
|
50
|
|
|
|
16
|
if( ! defined $self->sequence_factory ) { |
92
|
5
|
|
|
|
|
19
|
$self->sequence_factory(Bio::Seq::SeqFactory->new(-verbose => $self->verbose(), -type => 'Bio::PrimarySeq')); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 next_seq |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Title : next_seq |
99
|
|
|
|
|
|
|
Usage : $seq = $stream->next_seq() |
100
|
|
|
|
|
|
|
Function: returns the next sequence in the stream |
101
|
|
|
|
|
|
|
Returns : Bio::Seq object |
102
|
|
|
|
|
|
|
Args : NONE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
my %bio_mol_type = ( |
108
|
|
|
|
|
|
|
'dna' => 'dna', |
109
|
|
|
|
|
|
|
'peptide' => 'protein', |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub next_seq { |
113
|
7
|
|
|
7
|
1
|
434
|
my( $self ) = @_; |
114
|
7
|
|
|
|
|
19
|
local $/ = ""; # Split input on blank lines |
115
|
|
|
|
|
|
|
|
116
|
7
|
|
|
|
|
23
|
my $fh = $self->_filehandle; |
117
|
7
|
|
|
|
|
7
|
my( $type, $id ); |
118
|
7
|
|
|
|
|
54
|
while (<$fh>) { |
119
|
12
|
100
|
|
|
|
84
|
if (($type, $id) = /^(DNA|Peptide)[\s:]+(.+?)\s*\n/si) { |
120
|
6
|
|
|
|
|
18
|
s/^.+$//m; # Remove first line |
121
|
6
|
|
|
|
|
38
|
s/\s+//g; # Remove whitespace |
122
|
6
|
|
|
|
|
9
|
last; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
# Return if there weren't any DNA or peptide objects |
126
|
7
|
100
|
|
|
|
13
|
return unless $type; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Choose the molecule type |
129
|
6
|
50
|
|
|
|
15
|
my $mol_type = $bio_mol_type{lc $type} |
130
|
|
|
|
|
|
|
or $self->throw("Can't get Bio::Seq molecule type for '$type'"); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Remove quotes from $id |
133
|
6
|
|
|
|
|
24
|
$id =~ s/^"|"$//g; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Un-escape forward slashes, double quotes, percent signs, |
136
|
|
|
|
|
|
|
# semi-colons, tabs, and backslashes (if you're mad enough |
137
|
|
|
|
|
|
|
# to have any of these as part of object names in your acedb |
138
|
|
|
|
|
|
|
# database). |
139
|
6
|
|
|
|
|
14
|
$id =~ s/\\([\/"%;\t\\])/$1/g; |
140
|
|
|
|
|
|
|
#" |
141
|
|
|
|
|
|
|
# Called as next_seq(), so give back a Bio::Seq |
142
|
6
|
|
|
|
|
12
|
return $self->sequence_factory->create( |
143
|
|
|
|
|
|
|
-seq => $_, |
144
|
|
|
|
|
|
|
-primary_id => $id, |
145
|
|
|
|
|
|
|
-display_id => $id, |
146
|
|
|
|
|
|
|
-alphabet => $mol_type, |
147
|
|
|
|
|
|
|
); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 write_seq |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Title : write_seq |
154
|
|
|
|
|
|
|
Usage : $stream->write_seq(@seq) |
155
|
|
|
|
|
|
|
Function: writes the $seq object into the stream |
156
|
|
|
|
|
|
|
Returns : 1 for success and 0 for error |
157
|
|
|
|
|
|
|
Args : Bio::Seq object(s) |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub write_seq { |
163
|
4
|
|
|
4
|
1
|
16
|
my ($self, @seq) = @_; |
164
|
|
|
|
|
|
|
|
165
|
4
|
|
|
|
|
5
|
foreach my $seq (@seq) { |
166
|
4
|
50
|
33
|
|
|
32
|
$self->throw("Did not provide a valid Bio::PrimarySeqI object") |
|
|
|
33
|
|
|
|
|
167
|
|
|
|
|
|
|
unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI'); |
168
|
4
|
|
|
|
|
9
|
my $mol_type = $seq->alphabet; |
169
|
4
|
|
|
|
|
100
|
my $id = $seq->display_id; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Escape special charachers in id |
172
|
4
|
|
|
|
|
22
|
$id =~ s/([\/"%;\t\\])/\\$1/g; |
173
|
|
|
|
|
|
|
#" |
174
|
|
|
|
|
|
|
# Print header for DNA or Protein object |
175
|
4
|
100
|
|
|
|
10
|
if ($mol_type eq 'dna') { |
|
|
50
|
|
|
|
|
|
176
|
3
|
|
|
|
|
31
|
$self->_print( |
177
|
|
|
|
|
|
|
qq{\nSequence : "$id"\nDNA "$id"\n}, |
178
|
|
|
|
|
|
|
qq{\nDNA : "$id"\n}, |
179
|
|
|
|
|
|
|
); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
elsif ($mol_type eq 'protein') { |
182
|
1
|
|
|
|
|
11
|
$self->_print( |
183
|
|
|
|
|
|
|
qq{\nProtein : "$id"\nPeptide "$id"\n}, |
184
|
|
|
|
|
|
|
qq{\nPeptide : "$id"\n}, |
185
|
|
|
|
|
|
|
); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
else { |
188
|
0
|
|
|
|
|
0
|
$self->throw("Don't know how to produce ACeDB output for '$mol_type'"); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Print the sequence |
192
|
4
|
|
|
|
|
10
|
my $str = $seq->seq; |
193
|
4
|
|
|
|
|
5
|
my( $formatted_seq ); |
194
|
4
|
|
|
|
|
16
|
while ($str =~ /(.{1,60})/g) { |
195
|
21
|
|
|
|
|
59
|
$formatted_seq .= "$1\n"; |
196
|
|
|
|
|
|
|
} |
197
|
4
|
|
|
|
|
11
|
$self->_print($formatted_seq, "\n"); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
4
|
50
|
33
|
|
|
6
|
$self->flush if $self->_flush_on_write && defined $self->_fh; |
201
|
4
|
|
|
|
|
8
|
return 1; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1; |