Bio/AlignIO/pfam.pm

filter: Statementstmt 88.2% 45 / 51 Branchbran 56.2% 9 / 16 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 75.0% 63 / 84 CC 12 SCAR 19.8
CC
12
Cov
77%
write_aln
10.9
next_aln
5.2
BEGIN
1.0
CRAP 7.2
« Bio/SearchIO/SearchWriterI.pm ↑ Summary Bio/SeqIO/ace.pm »
1 #
2 # BioPerl module for Bio::AlignIO::pfam
3  
4 # based on the Bio::SeqIO:: modules
5 # by Ewan Birney <birney@ebi.ac.uk>
6 # and Lincoln Stein <lstein@cshl.org>
7 #
8 # and the SimpleAlign.pm module of Ewan Birney
9 #
10 # Copyright Peter Schattner
11 #
12 # You may distribute this module under the same terms as perl itself
13 # _history
14 # September 5, 2000
15 # POD documentation - main docs before the code
16  
17 =head1 NAME
18  
19 Bio::AlignIO::pfam - pfam sequence input/output stream
20  
21 =head1 SYNOPSIS
22  
23 Do not use this module directly. Use it via the L<Bio::AlignIO> class.
24  
25 =head1 DESCRIPTION
26  
27 This object can transform Bio::SimpleAlign objects to and from pfam flat
28 file databases.
29  
30 =head1 FEEDBACK
31  
32 =head2 Support
33  
34 Please direct usage questions or support issues to the mailing list:
35  
36 I<bioperl-l@bioperl.org>
37  
38 rather than to the module maintainer directly. Many experienced and
39 reponsive experts will be able look at the problem and quickly
40 address it. Please include a thorough description of the problem
41 with code and data examples if at all possible.
42  
43 =head2 Reporting Bugs
44  
45 Report bugs to the Bioperl bug tracking system to help us keep track
46 the bugs and their resolution. Bug reports can be submitted via the
47 web:
48  
49 https://github.com/bioperl/bioperl-live/issues
50  
51 =head1 AUTHORS - Peter Schattner
52  
53 Email: schattner@alum.mit.edu
54  
55  
56 =head1 APPENDIX
57  
58 The rest of the documentation details each of the object
59 methods. Internal methods are usually preceded with a _
60  
61 =cut
62  
63 # Let the code begin...
64  
65 package Bio::AlignIO::pfam;
66 5 $Bio::AlignIO::pfam::VERSION = '1.7.8';
67 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 5 ▶use Bio::SimpleAlign;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 5 ▶use base qw(Bio::AlignIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 =head2 next_aln
73  
74 Title : next_aln
75 Usage : $aln = $stream->next_aln()
76 Function: returns the next alignment in the stream
77 Returns : L<Bio::Align::AlignI> object
78 Args : NONE
79  
80 =cut
81  
82 10 ▶sub next_aln {
Subroutine next_aln: called CC=5 SCAR=16.5
Pod documented
83 10 my $self = shift;
84 10 my $entry;
85 my $name;
86 10 my $start;
87 10 my $end;
88 10 my $seq;
89 10 my $add;
90 10 my $acc;
91 10 my %names;
92  
93 10 my $aln = Bio::SimpleAlign->new(-source => 'pfam');
94  
95 10 ▶ while( $entry = $self->_readline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry = $self->_readline) 160 10 170
96 160 chomp $entry;
97 160 ▶ $entry =~ m{^//} && last;
Branch: 1 branch
BranchTrueFalseTotal
$entry =~ m[^//] and last 0 160 160
98 160 ▶ if($entry !~ m{^(\S+)/(\d+)-(\d+)\s+(\S+)\s*} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry =~ m[^(\S+)/(\d+)-(\d+)\s+(\S+)\s*]) 0 160 160
99 0 $self->throw("Found a bad line [$_] in the pfam format alignment");
100 0 next;
101 }
102  
103 160 $name = $1;
104 160 $start = $2;
105 160 $end = $3;
106 160 $seq = $4;
107  
108  
109 160 $add = Bio::LocatableSeq->new('-seq' => $seq,
110 '-display_id' => $name,
111 '-start' => $start,
112 '-end' => $end,
113 '-alphabet' => $self->alphabet,
114 );
115  
116 160 $aln->add_seq($add);
117  
118 }
119  
120 # If $end <= 0, we have either reached the end of
121 # file in <> or we have encountered some other error
122 #
123  
124 10 ▶ return $aln if $aln->num_sequences;
Branch: 1 branch
BranchTrueFalseTotal
if $aln->num_sequences 10 0 10
125 0 return;
126 }
127  
128  
129  
130 =head2 write_aln
131  
132 Title : write_aln
133 Usage : $stream->write_aln(@aln)
134 Function: writes the $aln object into the stream
135 Returns : 1 for success and 0 for error
136 Args : L<Bio::Align::AlignI> object
137  
138  
139 =cut
140  
141 3 ▶sub write_aln {
Subroutine write_aln: called CC=8 SCAR=23.9
Pod documented
142 3 my ($self,@aln) = @_;
143 0 ▶ if( @aln > 1 ) { $self->warn("Only the 1st pfam alignment will be output since the format does not support multiple alignments in the same file"); }
Branch: 1 branch
BranchTrueFalseTotal
if (@aln > 1) 0 3 3
144 3 my $aln = shift @aln;
145 3 ▶ if( ! $aln || ! $aln->isa('Bio::Align::AlignI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aln and $aln->isa("Bio::Align::AlignI")) 0 3 3
Condition33%1/3
$aln and $aln->isa("Bio::Align::AlignI")
!ll&&!rl&&r
003
MC/DC0%0/2
$aln and $aln->isa("Bio::Align::AlignI")
$aln $aln->isa("Bio::Align::AlignI")
Truth table33%1/3
A and B
A= $alnB= $aln->isa("Bio::Align::AlignI")
ABresult
0X0
100
111
146 0 $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
147 0 next;
148 }
149 3 my ($namestr,$seq,$add);
150 3 my ($maxn);
151 3 $maxn = $aln->maxdisplayname_length();
152  
153 3 foreach $seq ( $aln->each_seq() ) {
154 33 $namestr = $aln->displayname($seq->get_nse());
155 33 $add = $maxn - length($namestr) + 2;
156 33 $namestr .= " " x $add;
157 33 ▶ $self->_print (sprintf("%s %s\n",$namestr,$seq->seq())) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_print(sprintf("%s %s\n", $namestr, $seq->seq)) or return 33 0 33
158 }
159 3 ▶ $self->flush() if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 3 0 3
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
003
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
160 3 return 1;
161 }
162  
163 5 1;
« Bio/SearchIO/SearchWriterI.pm ↑ Summary Bio/SeqIO/ace.pm »