2 # BioPerl module for Bio::SeqIO::asciitree
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Chris Mungall <cjm@fruitfly.org>
8 # Copyright Chris Mungall
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::SeqIO::asciitree - asciitree sequence input/output stream
20 # It is probably best not to use this object directly, but
21 # rather go through the SeqIO handler system. Go:
23 $instream = Bio::SeqIO->new(-file => $filename,
24 -format => 'chadoxml');
25 $outstream = Bio::SeqIO->new(-file => $filename,
26 -format => 'asciitree');
28 while ( my $seq = $instream->next_seq() ) {
29 $outstream->write_seq();
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
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.
48 bioperl-l@bioperl.org - General discussion
49 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
53 Please direct usage questions or support issues to the mailing list:
55 I<bioperl-l@bioperl.org>
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.
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:
67 https://github.com/bioperl/bioperl-live/issues
69 =head1 AUTHOR - Chris Mungall
71 Email cjm@fruitfly.org
75 The rest of the documentation details each of the object
76 methods. Internal methods are usually preceded with a _
80 # Let the code begin...
82 package Bio
::SeqIO
::asciitree
;
87 use base
qw(Bio::SeqIO);
92 $self->SUPER::_initialize
(@args);
93 # hash for functions for decoding keys.
99 Usage : $obj->show_detail($newval)
102 Returns : value of show_detail (a scalar)
103 Args : on set, new value (a scalar or undef, optional)
111 return $self->{'show_detail'} = shift if @_;
112 return $self->{'show_detail'};
119 Usage : $seq = $stream->next_seq()
120 Function: returns the next sequence in the stream
121 Returns : Bio::Seq object
127 my ($self,@args) = @_;
128 $self->throw("This is a WRITE-ONLY adapter");
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
143 my ($self,@seqs) = @_;
145 foreach my $seq ( @seqs ) {
146 $self->throw("Attempting to write with no seq!") unless defined $seq;
148 if( ! ref $seq || ! $seq->isa('Bio::SeqI') ) {
149 $self->warn(" $seq is not a SeqI compliant module. Attempting to dump, but may fail!");
151 $self->_print("Seq: ".$seq->accession_number);
153 my @top_sfs = $seq->get_SeqFeatures;
154 $self->write_indented_sf(1, @top_sfs);
158 sub write_indented_sf
{
162 foreach my $sf (@sfs) {
164 if ($sf->has_tag('standard_name')) {
165 ($label) = $sf->get_tag_values('standard_name');
167 if ($sf->has_tag('product')) {
168 ($label) = $sf->get_tag_values('product');
173 if ($self->show_detail) {
174 my @tags = $sf->all_tags;
175 foreach my $tag (@tags) {
176 my @vals = $sf->get_tag_values($tag);
177 foreach my $val (@vals) {
182 substr($val, 0, $COLS - length($lines[-1]), '')) {
183 $lines[-1] .= "$cut";
191 my $detail = join("\n", @lines);
193 my @sub_sfs = $sf->get_SeqFeatures;
196 $locstr = $self->_locstr($sf);
198 my $col1 = sprintf("%s%s $label",
199 ' ' x
$indent, $sf->primary_tag);
200 my $line = sprintf("%-50s %s\n",
201 substr($col1, 0, 50), $locstr);
202 $self->_print($line);
204 $self->_print($detail."\n");
206 $self->write_indented_sf($indent+1, @sub_sfs);
214 my $strand = $sf->strand || 0;
216 $ss = '+' if $strand > 0;
217 $ss = '-' if $strand < 0;
219 my $splitlocstr = '';
220 if ($sf->isa("Bio::SeqFeatureI")) {
221 my @locs = ($sf->location);
222 if ($sf->location->isa("Bio::Location::SplitLocationI")) {
223 @locs = $sf->location->each_Location;
224 $splitlocstr = "; SPLIT: ".join(" ",
225 map {$self->_locstr($_)} @locs);
231 sprintf("%d..%d[%s] $splitlocstr", $sf->start, $sf->end, $ss);