Bio/SeqIO/asciitree.pm

filter: Statementstmt 79.4% 58 / 73 Branchbran 60.7% 17 / 28 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 87.5% 7 / 8 Podpod 75.0% 3 / 4 totaltotal 71.9% 87 / 121 CC 21 SCAR 23.2
CC
21
Cov
73%
write_indented_sf
19.2
_locstr
6.0
write_seq
5.8
CRAP 10.2
« Bio/Matrix/PSM/ProtPsm.pm ↑ Summary Bio/Ontology/Term.pm »
1 #
2 # BioPerl module for Bio::SeqIO::asciitree
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Chris Mungall <cjm@fruitfly.org>
7 #
8 # Copyright Chris Mungall
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::SeqIO::asciitree - asciitree sequence input/output stream
17  
18 =head1 SYNOPSIS
19  
20 # It is probably best not to use this object directly, but
21 # rather go through the SeqIO handler system. Go:
22  
23 $instream = Bio::SeqIO->new(-file => $filename,
24 -format => 'chadoxml');
25 $outstream = Bio::SeqIO->new(-file => $filename,
26 -format => 'asciitree');
27  
28 while ( my $seq = $instream->next_seq() ) {
29 $outstream->write_seq();
30 }
31  
32  
33 =head1 DESCRIPTION
34  
35 This is a WRITE-ONLY SeqIO module. It writes a Bio::SeqI object
36 containing nested SeqFeature objects in such a way that the SeqFeature
37 containment hierarchy is visible as a tree structure
38  
39  
40 =head1 FEEDBACK
41  
42 =head2 Mailing Lists
43  
44 User feedback is an integral part of the evolution of this and other
45 Bioperl modules. Send your comments and suggestions preferably to one
46 of the Bioperl mailing lists. Your participation is much appreciated.
47  
48 bioperl-l@bioperl.org - General discussion
49 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
50  
51 =head2 Support
52  
53 Please direct usage questions or support issues to the mailing list:
54  
55 I<bioperl-l@bioperl.org>
56  
57 rather than to the module maintainer directly. Many experienced and
58 reponsive experts will be able look at the problem and quickly
59 address it. Please include a thorough description of the problem
60 with code and data examples if at all possible.
61  
62 =head2 Reporting Bugs
63  
64 Report bugs to the Bioperl bug tracking system to help us keep track
65 the bugs and their resolution. Bug reports can be submitted via the web:
66  
67 https://github.com/bioperl/bioperl-live/issues
68  
69 =head1 AUTHOR - Chris Mungall
70  
71 Email cjm@fruitfly.org
72  
73 =head1 APPENDIX
74  
75 The rest of the documentation details each of the object
76 methods. Internal methods are usually preceded with a _
77  
78 =cut
79  
80 # Let the code begin...
81  
82 package Bio::SeqIO::asciitree;
83 2 $Bio::SeqIO::asciitree::VERSION = '1.7.8';
84 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86  
87 2 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 1 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
90 1 my($self,@args) = @_;
91  
92 1 $self->SUPER::_initialize(@args);
93 # hash for functions for decoding keys.
94 }
95  
96 =head2 show_detail
97  
98 Title : show_detail
99 Usage : $obj->show_detail($newval)
100 Function:
101 Example :
102 Returns : value of show_detail (a scalar)
103 Args : on set, new value (a scalar or undef, optional)
104  
105  
106 =cut
107  
108 58 ▶sub show_detail{
Subroutine show_detail: called CC=2 SCAR=7.1
Pod documented
109 58 my $self = shift;
110  
111 58 ▶ return $self->{'show_detail'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 58 58
112 58 return $self->{'show_detail'};
113 }
114  
115  
116 =head2 next_seq
117  
118 Title : next_seq
119 Usage : $seq = $stream->next_seq()
120 Function: returns the next sequence in the stream
121 Returns : Bio::Seq object
122 Args :
123  
124 =cut
125  
126 0 ▶sub next_seq {
Subroutine next_seq: not called CC=1 SCAR=6.9
Pod documented
127 0 my ($self,@args) = @_;
128 0 $self->throw("This is a WRITE-ONLY adapter");
129 }
130  
131  
132 =head2 write_seq
133  
134 Title : write_seq
135 Usage : $stream->write_seq($seq)
136 Function: writes the $seq object (must be seq) to the stream
137 Returns : 1 for success and 0 for error
138 Args : array of 1 to n Bio::SeqI objects
139  
140 =cut
141  
142 1 ▶sub write_seq {
Subroutine write_seq: called CC=5 SCAR=17.5
Pod documented
143 1 my ($self,@seqs) = @_;
144  
145 1 foreach my $seq ( @seqs ) {
146 1 ▶ $self->throw("Attempting to write with no seq!") unless defined $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq 0 1 1
147  
148 1 ▶ if( ! ref $seq || ! $seq->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $seq and $seq->isa("Bio::SeqI")) 0 1 1
Condition33%1/3
ref $seq and $seq->isa("Bio::SeqI")
!ll&&!rl&&r
001
MC/DC0%0/2
ref $seq and $seq->isa("Bio::SeqI")
ref $seq $seq->isa("Bio::SeqI")
Truth table33%1/3
A and B
A= ref $seqB= $seq->isa("Bio::SeqI")
ABresult
0X0
100
111
149 0 $self->warn(" $seq is not a SeqI compliant module. Attempting to dump, but may fail!");
150 }
151 1 $self->_print("Seq: ".$seq->accession_number);
152 1 $self->_print("\n");
153 1 my @top_sfs = $seq->get_SeqFeatures;
154 1 $self->write_indented_sf(1, @top_sfs);
155 }
156 }
157  
158 59 ▶sub write_indented_sf {
Subroutine write_indented_sf: called CC=11 SCAR=29.6
Pod undocumented
159 59 my $self = shift;
160 59 my $indent = shift;
161 59 my @sfs = @_;
162 59 foreach my $sf (@sfs) {
163 58 my $label = '';
164 58 ▶ if ($sf->has_tag('standard_name')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf->has_tag("standard_name")) 0 58 58
165 0 ($label) = $sf->get_tag_values('standard_name');
166 }
167 58 ▶ if ($sf->has_tag('product')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf->has_tag("product")) 37 21 58
168 37 ($label) = $sf->get_tag_values('product');
169 }
170 58 my $COLS = 60;
171 58 my $tab = ' ' x 10;
172 58 my @lines = ();
173 58 ▶ if ($self->show_detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->show_detail) 0 58 58
174 0 my @tags = $sf->all_tags;
175 0 foreach my $tag (@tags) {
176 0 my @vals = $sf->get_tag_values($tag);
177 0 foreach my $val (@vals) {
178 0 $val = "\"$val\"";
179 0 push(@lines,
180 "$tab/$tag=");
181 0 ▶ while (my $cut =
Branch: 1 branch
BranchTrueFalseTotal
if (my $cut = substr($val, 0, $COLS - length($lines[-1]), '')) 0 0 0
182 substr($val, 0, $COLS - length($lines[-1]), '')) {
183 0 $lines[-1] .= "$cut";
184 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
185 0 push(@lines, $tab);
186 }
187 }
188 }
189 }
190 }
191 58 my $detail = join("\n", @lines);
192  
193 58 my @sub_sfs = $sf->get_SeqFeatures;
194 58 my $locstr = '';
195 58 ▶ if (!@sub_sfs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@sub_sfs) 58 0 58
196 58 $locstr = $self->_locstr($sf);
197 }
198 58 my $col1 = sprintf("%s%s $label",
199 ' ' x $indent, $sf->primary_tag);
200 58 my $line = sprintf("%-50s %s\n",
201 substr($col1, 0, 50), $locstr);
202 58 $self->_print($line);
203 58 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) 0 58 58
204 0 $self->_print($detail."\n");
205 }
206 58 $self->write_indented_sf($indent+1, @sub_sfs);
207 }
208 59 return;
209 }
210  
211 164 ▶sub _locstr {
Subroutine _locstr: called CC=6 SCAR=17.9
212 164 my $self = shift;
213 164 my $sf = shift;
214 164 ▶ my $strand = $sf->strand || 0;
Condition50%1/2
$sf->strand || 0
l!l
1640
MC/DC0%0/1
$sf->strand || 0
$sf->strand
Truth table50%1/2
A
A= $sf->strand
Aresult
11
00
215 164 my $ss = '.';
216 164 ▶ $ss = '+' if $strand > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $strand > 0 100 64 164
217 164 ▶ $ss = '-' if $strand < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $strand < 0 64 100 164
218  
219 164 my $splitlocstr = '';
220 164 ▶ if ($sf->isa("Bio::SeqFeatureI")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf->isa("Bio::SeqFeatureI")) 58 106 164
221 58 my @locs = ($sf->location);
222 58 ▶ if ($sf->location->isa("Bio::Location::SplitLocationI")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf->location->isa("Bio::Location::SplitLocationI")) 26 32 58
223 26 @locs = $sf->location->each_Location;
224 $splitlocstr = "; SPLIT: ".join(" ",
225 26 map {$self->_locstr($_)} @locs);
226  
227 }
228 }
229  
230 return
231 164 sprintf("%d..%d[%s] $splitlocstr", $sf->start, $sf->end, $ss);
232 }
233  
234 2 1;
« Bio/Matrix/PSM/ProtPsm.pm ↑ Summary Bio/Ontology/Term.pm »