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://redmine.open-bio.org/projects/bioperl/
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
;
86 use base
qw(Bio::SeqIO);
91 $self->SUPER::_initialize
(@args);
92 # hash for functions for decoding keys.
98 Usage : $obj->show_detail($newval)
101 Returns : value of show_detail (a scalar)
102 Args : on set, new value (a scalar or undef, optional)
110 return $self->{'show_detail'} = shift if @_;
111 return $self->{'show_detail'};
118 Usage : $seq = $stream->next_seq()
119 Function: returns the next sequence in the stream
120 Returns : Bio::Seq object
126 my ($self,@args) = @_;
127 $self->throw("This is a WRITE-ONLY adapter");
134 Usage : $stream->write_seq($seq)
135 Function: writes the $seq object (must be seq) to the stream
136 Returns : 1 for success and 0 for error
137 Args : array of 1 to n Bio::SeqI objects
142 my ($self,@seqs) = @_;
144 foreach my $seq ( @seqs ) {
145 $self->throw("Attempting to write with no seq!") unless defined $seq;
147 if( ! ref $seq || ! $seq->isa('Bio::SeqI') ) {
148 $self->warn(" $seq is not a SeqI compliant module. Attempting to dump, but may fail!");
150 $self->_print("Seq: ".$seq->accession_number);
152 my @top_sfs = $seq->get_SeqFeatures;
153 $self->write_indented_sf(1, @top_sfs);
157 sub write_indented_sf
{
161 foreach my $sf (@sfs) {
163 if ($sf->has_tag('standard_name')) {
164 ($label) = $sf->get_tag_values('standard_name');
166 if ($sf->has_tag('product')) {
167 ($label) = $sf->get_tag_values('product');
172 if ($self->show_detail) {
173 my @tags = $sf->all_tags;
174 foreach my $tag (@tags) {
175 my @vals = $sf->get_tag_values($tag);
176 foreach my $val (@vals) {
181 substr($val, 0, $COLS - length($lines[-1]), '')) {
182 $lines[-1] .= "$cut";
190 my $detail = join("\n", @lines);
192 my @sub_sfs = $sf->get_SeqFeatures;
195 $locstr = $self->_locstr($sf);
197 my $col1 = sprintf("%s%s $label",
198 ' ' x
$indent, $sf->primary_tag);
199 my $line = sprintf("%-50s %s\n",
200 substr($col1, 0, 50), $locstr);
201 $self->_print($line);
203 $self->_print($detail."\n");
205 $self->write_indented_sf($indent+1, @sub_sfs);
213 my $strand = $sf->strand || 0;
215 $ss = '+' if $strand > 0;
216 $ss = '-' if $strand < 0;
218 my $splitlocstr = '';
219 if ($sf->isa("Bio::SeqFeatureI")) {
220 my @locs = ($sf->location);
221 if ($sf->location->isa("Bio::Location::SplitLocationI")) {
222 @locs = $sf->location->each_Location;
223 $splitlocstr = "; SPLIT: ".join(" ",
224 map {$self->_locstr($_)} @locs);
230 sprintf("%d..%d[%s] $splitlocstr", $sf->start, $sf->end, $ss);