Mercurial > repos > willmclaren > ensembl_vep
comparison variant_effect_predictor/Bio/EnsEMBL/Compara/GeneTreeNode.pm @ 0:21066c0abaf5 draft
Uploaded
author | willmclaren |
---|---|
date | Fri, 03 Aug 2012 10:04:48 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:21066c0abaf5 |
---|---|
1 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =head1 NAME | |
20 | |
21 Bio::EnsEMBL::Compara::GeneTreeNode | |
22 | |
23 =head1 DESCRIPTION | |
24 | |
25 Specific subclass of NestedSet to add functionality when the nodes of this tree | |
26 are GeneTreeMember objects and the tree is a representation of a gene derived | |
27 Phylogenetic tree | |
28 | |
29 =head1 INHERITANCE TREE | |
30 | |
31 Bio::EnsEMBL::Compara::GeneTreeNode | |
32 `- Bio::EnsEMBL::Compara::NestedSet | |
33 | |
34 =head1 AUTHORSHIP | |
35 | |
36 Ensembl Team. Individual contributions can be found in the CVS log. | |
37 | |
38 =head1 MAINTAINER | |
39 | |
40 $Author: mm14 $ | |
41 | |
42 =head VERSION | |
43 | |
44 $Revision: 1.15 $ | |
45 | |
46 =head1 APPENDIX | |
47 | |
48 The rest of the documentation details each of the object methods. | |
49 Internal methods are usually preceded with an underscore (_) | |
50 | |
51 =cut | |
52 | |
53 package Bio::EnsEMBL::Compara::GeneTreeNode; | |
54 | |
55 use strict; | |
56 | |
57 use IO::File; | |
58 | |
59 use Bio::EnsEMBL::Utils::Argument; | |
60 use Bio::EnsEMBL::Utils::Exception; | |
61 | |
62 use Bio::EnsEMBL::Compara::AlignedMemberSet; | |
63 | |
64 use base ('Bio::EnsEMBL::Compara::NestedSet'); | |
65 | |
66 | |
67 sub tree { | |
68 my $self = shift; | |
69 if (@_) { | |
70 $self->{'_tree'} = shift; | |
71 } elsif ((not defined $self->{'_tree'}) and (defined $self->adaptor) and (defined $self->{_root_id})) { | |
72 $self->{'_tree'} = $self->adaptor->db->get_GeneTreeAdaptor->fetch_by_root_id($self->{_root_id}); | |
73 } | |
74 return $self->{'_tree'}; | |
75 } | |
76 | |
77 | |
78 # tweaked to take into account the GeneTree object | |
79 sub root { | |
80 my $self = shift; | |
81 if (defined $self->tree) { | |
82 return $self->tree->root; | |
83 } else { | |
84 return $self->SUPER::root; | |
85 } | |
86 } | |
87 | |
88 | |
89 =head2 release_tree | |
90 | |
91 Overview : Removes the to/from GeneTree reference to | |
92 allow freeing memory | |
93 Example : $self->release_tree; | |
94 Returntype : undef | |
95 Exceptions : none | |
96 Caller : general | |
97 | |
98 =cut | |
99 | |
100 sub release_tree { | |
101 my $self = shift; | |
102 | |
103 if (defined $self->tree) { | |
104 delete $self->{'_tree'}->{'_root'}; | |
105 delete $self->{'_tree'}; | |
106 } | |
107 return $self->SUPER::release_tree; | |
108 } | |
109 | |
110 | |
111 #use Data::Dumper; | |
112 | |
113 #sub string_node { | |
114 # my $self = shift; | |
115 # my $str = $self->SUPER::string_node; | |
116 # if (defined $self->{'_tree'}) { | |
117 # my $t = $self->{'_tree'}; | |
118 # $str = chop($str)." $t/root_id=".($self->{'_tree'}->root_id)."/".join("/", map { "$_ => ${$t}{$_}" } keys %$t)."\n"; | |
119 # } | |
120 # return $str; | |
121 #} | |
122 | |
123 sub get_leaf_by_Member { | |
124 my $self = shift; | |
125 my $member = shift; | |
126 | |
127 if($member->isa('Bio::EnsEMBL::Compara::GeneTreeNode')) { | |
128 return $self->find_leaf_by_node_id($member->node_id); | |
129 } elsif ($member->isa('Bio::EnsEMBL::Compara::Member')) { | |
130 return $self->find_leaf_by_name($member->get_canonical_Member->stable_id); | |
131 } else { | |
132 die "Need a Member object!"; | |
133 } | |
134 } | |
135 | |
136 sub get_AlignedMemberSet { | |
137 my $self = shift; | |
138 my $set = Bio::EnsEMBL::Compara::AlignedMemberSet->new( | |
139 -adaptor => $self->adaptor, | |
140 -method_link_species_set_id => $self->tree->method_link_species_set_id, | |
141 -stable_id => $self->tree->stable_id, | |
142 -version => sprintf("%d.%d", $self->tree->version, $self->node_id), | |
143 ); | |
144 foreach my $member (@{$self->get_all_leaves}) { | |
145 $set->add_Member($member) if $member->isa('Bio::EnsEMBL::Compara::GeneTreeMember'); | |
146 } | |
147 return $set; | |
148 } | |
149 | |
150 sub get_SimpleAlign { | |
151 my $self = shift; | |
152 return $self->get_AlignedMemberSet->get_SimpleAlign(@_); | |
153 } | |
154 | |
155 # Takes a protein tree and creates a consensus cigar line from the | |
156 # constituent leaf nodes. | |
157 sub consensus_cigar_line { | |
158 my $self = shift; | |
159 return $self->get_AlignedMemberSet->consensus_cigar_line(@_); | |
160 } | |
161 | |
162 | |
163 | |
164 =head2 remove_nodes_by_taxon_ids | |
165 | |
166 Arg [1] : arrayref of taxon_ids | |
167 Example : my $ret_tree = $tree->remove_nodes_by_taxon_ids($taxon_ids); | |
168 Description : Returns the tree with removed nodes in taxon_id list. | |
169 Returntype : Bio::EnsEMBL::Compara::GeneTreeNode object | |
170 Exceptions : | |
171 Caller : general | |
172 Status : At risk (behaviour on exceptions could change) | |
173 | |
174 =cut | |
175 | |
176 sub remove_nodes_by_taxon_ids { | |
177 my $self = shift; | |
178 my $species_arrayref = shift; | |
179 | |
180 my @tax_ids = @{$species_arrayref}; | |
181 # Turn the arrayref into a hash. | |
182 my %tax_hash; | |
183 map {$tax_hash{$_}=1} @tax_ids; | |
184 | |
185 my @to_delete; | |
186 foreach my $leaf (@{$self->get_all_leaves}) { | |
187 if (exists $tax_hash{$leaf->taxon_id}) { | |
188 push @to_delete, $leaf; | |
189 } | |
190 } | |
191 return $self->remove_nodes(\@to_delete); | |
192 | |
193 } | |
194 | |
195 | |
196 =head2 keep_nodes_by_taxon_ids | |
197 | |
198 Arg [1] : arrayref of taxon_ids | |
199 Example : my $ret_tree = $tree->keep_nodes_by_taxon_ids($taxon_ids); | |
200 Description : Returns the tree with kept nodes in taxon_id list. | |
201 Returntype : Bio::EnsEMBL::Compara::GeneTreeNode object | |
202 Exceptions : | |
203 Caller : general | |
204 Status : At risk (behaviour on exceptions could change) | |
205 | |
206 =cut | |
207 | |
208 | |
209 sub keep_nodes_by_taxon_ids { | |
210 my $self = shift; | |
211 my $species_arrayref = shift; | |
212 | |
213 my @tax_ids = @{$species_arrayref}; | |
214 # Turn the arrayref into a hash. | |
215 my %tax_hash; | |
216 map {$tax_hash{$_}=1} @tax_ids; | |
217 | |
218 my @to_delete; | |
219 foreach my $leaf (@{$self->get_all_leaves}) { | |
220 unless (exists $tax_hash{$leaf->taxon_id}) { | |
221 push @to_delete, $leaf; | |
222 } | |
223 } | |
224 return $self->remove_nodes(\@to_delete); | |
225 | |
226 } | |
227 | |
228 1; | |
229 |