Bio/SeqIO/ace.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 75.0% 15 / 20 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 81.9% 77 / 94 CC 15 SCAR 19.8
CC
15
Cov
85%
write_seq
12.0
next_seq
5.0
_initialize
2.0
CRAP 7.3
« Bio/AlignIO/pfam.pm ↑ Summary Bio/Matrix/PSM/InstanceSite.pm »
1 #
2 # BioPerl module for Bio::SeqIO::ace
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by James Gilbert <jgrg@sanger.ac.uk>
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 attached
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<bioperl-l@bioperl.org>
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 $Bio::SeqIO::ace::VERSION = '1.7.8';
82 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 3 ▶use Bio::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 3 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 3 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 4 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=7.0
90 4 my($self,@args) = @_;
91 4 $self->SUPER::_initialize(@args);
92 4 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 4 0 4
93 4 $self->sequence_factory(Bio::Seq::SeqFactory->new(-verbose => $self->verbose(), -type => 'Bio::PrimarySeq'));
94 }
95 }
96  
97 =head2 next_seq
98  
99 Title : next_seq
100 Usage : $seq = $stream->next_seq()
101 Function: returns the next sequence in the stream
102 Returns : Bio::Seq object
103 Args : NONE
104  
105 =cut
106  
107 {
108 3 my %bio_mol_type = (
109 'dna' => 'dna',
110 'peptide' => 'protein',
111 );
112  
113 6 ▶ sub next_seq {
Subroutine next_seq: called CC=5 SCAR=16.1
Pod documented
114 6 my( $self ) = @_;
115 6 local $/ = ""; # Split input on blank lines
116  
117 6 my $fh = $self->_filehandle;
118 6 my( $type, $id );
119 6 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 10 1 11
120 10 ▶ if (($type, $id) = /^(DNA|Peptide)[\s:]+(.+?)\s*\n/si) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = /^(DNA|Peptide)[\s:]+(.+?)\s*\n/is) 5 5 10
121 5 s/^.+$//m; # Remove first line
122 5 s/\s+//g; # Remove whitespace
123 5 last;
124 }
125 }
126 # Return if there weren't any DNA or peptide objects
127 6 ▶ return unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 5 6
128  
129 # Choose the molecule type
130 5 ▶ my $mol_type = $bio_mol_type{lc $type}
Branch: 1 branch
BranchTrueFalseTotal
my $mol_type = $bio_mol_type{lc $type} or $self->throw("Can't get Bio::Seq molecule type for '${type}'") 5 0 5
131 or $self->throw("Can't get Bio::Seq molecule type for '$type'");
132  
133 # Remove quotes from $id
134 5 $id =~ s/^"|"$//g;
135  
136 # Un-escape forward slashes, double quotes, percent signs,
137 # semi-colons, tabs, and backslashes (if you're mad enough
138 # to have any of these as part of object names in your acedb
139 # database).
140 5 $id =~ s/\\([\/"%;\t\\])/$1/g;
141 #"
142 # Called as next_seq(), so give back a Bio::Seq
143 5 return $self->sequence_factory->create(
144 -seq => $_,
145 -primary_id => $id,
146 -display_id => $id,
147 -alphabet => $mol_type,
148 );
149 }
150 }
151  
152 =head2 write_seq
153  
154 Title : write_seq
155 Usage : $stream->write_seq(@seq)
156 Function: writes the $seq object into the stream
157 Returns : 1 for success and 0 for error
158 Args : Bio::Seq object(s)
159  
160  
161 =cut
162  
163 3 ▶sub write_seq {
Subroutine write_seq: called CC=10 SCAR=24.8
Pod documented
164 4 my ($self, @seq) = @_;
165  
166 4 foreach my $seq (@seq) {
167 4 ▶ $self->throw("Did not provide a valid Bio::PrimarySeqI object")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI") 0 4 4
Condition33%2/6
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
004
defined $seq and ref $seq
!ll&&!rl&&r
004
MC/DC0%0/3
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
defined $seq ref $seq $seq->isa("Bio::PrimarySeqI")
Truth table25%1/4
A and B and C
A= defined $seqB= ref $seqC= $seq->isa("Bio::PrimarySeqI")
ABCresult
0XX0
10X0
1100
1111
168 unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI');
169 4 my $mol_type = $seq->alphabet;
170 4 my $id = $seq->display_id;
171  
172 # Escape special charachers in id
173 4 $id =~ s/([\/"%;\t\\])/\\$1/g;
174 #"
175 # Print header for DNA or Protein object
176 4 ▶ if ($mol_type eq 'dna') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mol_type eq 'dna') { } 3 1 4
elsif ($mol_type eq 'protein') { } 1 0 1
177 3 $self->_print(
178 qq{\nSequence : "$id"\nDNA "$id"\n},
179 qq{\nDNA : "$id"\n},
180 );
181 }
182 elsif ($mol_type eq 'protein') {
183 1 $self->_print(
184 qq{\nProtein : "$id"\nPeptide "$id"\n},
185 qq{\nPeptide : "$id"\n},
186 );
187 }
188 else {
189 0 $self->throw("Don't know how to produce ACeDB output for '$mol_type'");
190 }
191  
192 # Print the sequence
193 4 my $str = $seq->seq;
194 4 my( $formatted_seq );
195 4 ▶ while ($str =~ /(.{1,60})/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(.{1,60})/g) 21 4 25
196 21 $formatted_seq .= "$1\n";
197 }
198 4 $self->_print($formatted_seq, "\n");
199 }
200  
201 4 ▶ $self->flush if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 4 0 4
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
004
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
202 4 return 1;
203 }
204  
205 3 1;
« Bio/AlignIO/pfam.pm ↑ Summary Bio/Matrix/PSM/InstanceSite.pm »