Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Tree/NodeNHX.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 # $Id: NodeNHX.pm,v 1.5.2.1 2003/09/14 19:00:35 jason Exp $ | |
2 # | |
3 # BioPerl module for Bio::Tree::NodeNHX | |
4 # | |
5 # Cared for by Aaron Mackey <amackey@virginia.edu> | |
6 # | |
7 # Copyright Aaron Mackey | |
8 # | |
9 # You may distribute this module under the same terms as perl itself | |
10 | |
11 # POD documentation - main docs before the code | |
12 | |
13 =head1 NAME | |
14 | |
15 Bio::Tree::NodeNHX - A Simple Tree Node with support for NHX tags | |
16 | |
17 =head1 SYNOPSIS | |
18 | |
19 use Bio::Tree::NodeNHX; | |
20 my $nodeA = new Bio::Tree::NodeNHX(); | |
21 my $nodeL = new Bio::Tree::NodeNHX(); | |
22 my $nodeR = new Bio::Tree::NodeNHX(); | |
23 | |
24 my $node = new Bio::Tree::NodeNHX(); | |
25 $node->add_Descendents($nodeL); | |
26 $node->add_Descendents($nodeR); | |
27 | |
28 print "node is not a leaf \n" if( $node->is_leaf); | |
29 | |
30 =head1 DESCRIPTION | |
31 | |
32 Makes a Tree Node with NHX tags, suitable for building a Tree. See | |
33 L<Bio::Tree::Node> for a full list of functionality. | |
34 | |
35 =head1 FEEDBACK | |
36 | |
37 =head2 Mailing Lists | |
38 | |
39 User feedback is an integral part of the evolution of this and other | |
40 Bioperl modules. Send your comments and suggestions preferably to | |
41 the Bioperl mailing list. Your participation is much appreciated. | |
42 | |
43 bioperl-l@bioperl.org - General discussion | |
44 http://bioperl.org/MailList.shtml - About the mailing lists | |
45 | |
46 =head2 Reporting Bugs | |
47 | |
48 Report bugs to the Bioperl bug tracking system to help us keep track | |
49 of the bugs and their resolution. Bug reports can be submitted via | |
50 the web: | |
51 | |
52 http://bugzilla.bioperl.org/ | |
53 | |
54 =head1 AUTHOR - Aaron Mackey | |
55 | |
56 Email amackey@virginia.edu | |
57 | |
58 =head1 CONTRIBUTORS | |
59 | |
60 The NHX (New Hampshire eXtended) format was created by Chris Zmasek, | |
61 and is described at: | |
62 | |
63 http://www.genetics.wustl.edu/eddy/forester/NHX.html | |
64 | |
65 =head1 APPENDIX | |
66 | |
67 The rest of the documentation details each of the object methods. | |
68 Internal methods are usually preceded with a _ | |
69 | |
70 =cut | |
71 | |
72 | |
73 # Let the code begin... | |
74 | |
75 package Bio::Tree::NodeNHX; | |
76 use vars qw(@ISA); | |
77 use strict; | |
78 | |
79 use Bio::Tree::Node; | |
80 | |
81 @ISA = qw(Bio::Tree::Node); | |
82 | |
83 =head2 new | |
84 | |
85 Title : new | |
86 Usage : my $obj = new Bio::Tree::NodeNHX(); | |
87 Function: Builds a new Bio::Tree::NodeNHX object | |
88 Returns : Bio::Tree::NodeNHX | |
89 Args : -left => pointer to Left descendent (optional) | |
90 -right => pointer to Right descenent (optional) | |
91 -branch_length => branch length [integer] (optional) | |
92 -bootstrap => value bootstrap value (string) | |
93 -description => description of node | |
94 -id => unique id for node | |
95 -nhx => hashref of NHX tags and values | |
96 | |
97 =cut | |
98 | |
99 sub new { | |
100 my($class,@args) = @_; | |
101 | |
102 my $self = $class->SUPER::new(@args); | |
103 my ($nhx) = $self->_rearrange([qw(NHX)], @args); | |
104 $self->nhx_tag($nhx); | |
105 return $self; | |
106 } | |
107 | |
108 sub DESTROY { | |
109 my ($self) = @_; | |
110 # try to insure that everything is cleaned up | |
111 $self->SUPER::DESTROY(); | |
112 if( defined $self->{'_desc'} && | |
113 ref($self->{'_desc'}) =~ /ARRAY/i ) { | |
114 while( my ($nodeid,$node) = each %{ $self->{'_desc'} } ) { | |
115 $node->{'_ancestor'} = undef; # insure no circular references | |
116 $node->DESTROY(); | |
117 $node = undef; | |
118 } | |
119 $self->{'_desc'} = {}; | |
120 } | |
121 } | |
122 | |
123 sub to_string{ | |
124 my ($self) = @_; | |
125 return sprintf("%s%s%s", | |
126 defined $self->id ? $self->id : '', | |
127 defined $self->branch_length ? ':' . | |
128 $self->branch_length : ' ', | |
129 '[' . join(":", "&&NHX", | |
130 map { "$_=" .join(',', | |
131 $self->get_tag_values($_))} | |
132 $self->get_all_tags() ) . ']' | |
133 ); | |
134 } | |
135 | |
136 =head2 nhx_tag | |
137 | |
138 Title : nhx_tag | |
139 Usage : my $tag = $nodenhx->nhx_tag(%tags); | |
140 Function: Set tag-value pairs for NHX nodes | |
141 Returns : none | |
142 Args : hashref to update the tags/value pairs | |
143 OR | |
144 with a scalar value update the bootstrap value by default | |
145 | |
146 | |
147 =cut | |
148 | |
149 sub nhx_tag { | |
150 my ($self, $tags) = @_; | |
151 if (defined $tags && (ref($tags) =~ /HASH/i)) { | |
152 while( my ($tag,$val) = each %$tags ) { | |
153 if( ref($val) =~ /ARRAY/i ) { | |
154 for my $v ( @$val ) { | |
155 $self->add_tag_value($tag,$v); | |
156 } | |
157 } else { | |
158 $self->add_tag_value($tag,$val); | |
159 } | |
160 } | |
161 if (exists $tags->{'B'}) { | |
162 $self->bootstrap($tags->{'B'}); | |
163 } | |
164 } elsif (defined $tags and ! ref ($tags)) { | |
165 print STDERR "here with $tags\n"; | |
166 # bootstrap by default | |
167 $self->bootstrap($tags); | |
168 } | |
169 } | |
170 | |
171 1; |