| 1 | # | ||||||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::Tools::Run::Phylo::PhyloBase | ||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||
| 6 | # Cared for by Sendu Bala <bix@sendu.me.uk> | ||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||
| 8 | # Copyright Sendu Bala | ||||||||||||||||||||||||||||||||||||
| 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::Tools::Run::Phylo::PhyloBase- base module for phylo wrappers | ||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | use base qw(Bio::Tools::Run::Phylo::PhyloBase); | ||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | For use by Bio::Tools::Run::Phylo modules as a base in place of | ||||||||||||||||||||||||||||||||||||
| 25 | Bio::Tools::Run::WrapperBase. | ||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | This is based on WrapperBase but provides additional phylo-related private | ||||||||||||||||||||||||||||||||||||
| 28 | helper subs. | ||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||||||
| 35 | Bioperl modules. Send your comments and suggestions preferably to | ||||||||||||||||||||||||||||||||||||
| 36 | the Bioperl mailing list. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||||||
| 39 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | =head2 Support | ||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||
| 45 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||
| 48 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||
| 49 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||
| 50 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||||||
| 55 | of the bugs and their resolution. Bug reports can be submitted via | ||||||||||||||||||||||||||||||||||||
| 56 | the web: | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | http://redmine.open-bio.org/projects/bioperl/ | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | =head1 AUTHOR - Sendu Bala | ||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | Email bix@sendu.me.uk | ||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | The rest of the documentation details each of the object methods. | ||||||||||||||||||||||||||||||||||||
| 67 | Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | package Bio::Tools::Run::Phylo::PhyloBase; | ||||||||||||||||||||||||||||||||||||
| 72 | 1 | $Bio::Tools::Run::Phylo::PhyloBase::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | use Bio::AlignIO; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | use Bio::TreeIO; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | use base qw(Bio::Tools::Run::WrapperBase); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | =head2 _alignment | ||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||
| 83 | Title : _alignment | ||||||||||||||||||||||||||||||||||||
| 84 | Usage : $aln = $obj->_alignment() | ||||||||||||||||||||||||||||||||||||
| 85 | Function: Get/set an alignment object, generating one from a file if desired. | ||||||||||||||||||||||||||||||||||||
| 86 | Returns : Bio::Align::AlignI (probably a Bio::SimpleAlign) | ||||||||||||||||||||||||||||||||||||
| 87 | Args : none to get | ||||||||||||||||||||||||||||||||||||
| 88 | OR filename & input format of the alignment file (latter defaults to | ||||||||||||||||||||||||||||||||||||
| 89 | guess) to set from file | ||||||||||||||||||||||||||||||||||||
| 90 | OR Bio::Align::AlignI to set | ||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub _alignment { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_alignment: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||
| 95 | 0 | my ($self, $thing, $format) = @_; | |||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (ref($thing) && $thing->isa('Bio::Align::AlignI')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $thing and $thing->isa("Bio::Align::AlignI")
MC/DC0%0/2
ref $thing and $thing->isa("Bio::Align::AlignI")
ref $thing
$thing->isa("Bio::Align::AlignI")
Truth table0%0/3
A and B
A= ref $thingB= $thing->isa("Bio::Align::AlignI")
| |||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->{_align_obj} = $thing; | |||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||
| 100 | ▶ | elsif ($thing && -e $thing) { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$thing and -e $thing
MC/DC0%0/2
$thing and -e $thing
$thing
-e $thing
Truth table0%0/3
A and B
A= $thingB= -e $thing
| |||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $align_in = Bio::AlignIO->new(-verbose => $self->verbose, -file => $thing, $format ? (-format => $format) : ()); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $aln = $align_in->next_aln || $self->throw("Alignment file '$thing' had no alignment!"); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$align_in->next_aln || $self->throw("Alignment file '${thing}' had no alignment!")
MC/DC0%0/2
$align_in->next_aln || $self->throw("Alignment file '${thing}' had no alignment!")
$align_in->next_aln
$self->throw("Alignment file '${thing}' had no alignment!")
Truth table0%0/3
A || B
A= $align_in->next_alnB= $self->throw("Alignment file '${thing}' had no alignment!")
| |||||||||||||||||||||||||||||||||||||
| 103 | 0 | $align_in->close(); | |||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->{_align_obj} = $aln; | |||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | 0 | return $self->{_align_obj}; | |||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||
| 110 | =head2 _write_alignment | ||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||
| 112 | Title : _write_alignment | ||||||||||||||||||||||||||||||||||||
| 113 | Usage : $obj->_write_alignment() | ||||||||||||||||||||||||||||||||||||
| 114 | Function: Writes the alignment object returned by _alignment() out in the | ||||||||||||||||||||||||||||||||||||
| 115 | desired format to a temp file. | ||||||||||||||||||||||||||||||||||||
| 116 | Returns : filename | ||||||||||||||||||||||||||||||||||||
| 117 | Args : string to describe format (default 'fasta'), any other options to pass | ||||||||||||||||||||||||||||||||||||
| 118 | to AlignIO | ||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub _write_alignment { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_write_alignment: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||
| 123 | 0 | my ($self, $format, @options) = @_; | |||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $align = $self->_alignment || $self->throw("_write_alignment called when _alignment had not been set"); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_alignment || $self->throw('_write_alignment called when _alignment had not been set')
MC/DC0%0/2
$self->_alignment || $self->throw('_write_alignment called when _alignment had not been set')
$self->_alignment
$self->throw('_write_alignment called when _alignment had not been set')
Truth table0%0/3
A || B
A= $self->_alignmentB= $self->throw('_write_alignment called when _alignment had not been set')
| |||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $format ||= 'fasta'; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$format ||= "fasta"
MC/DC0%0/1
$format ||= "fasta"
$format
Truth table0%0/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | 0 | my ($tfh, $tempfile) = $self->io->tempfile(-dir => $self->tempdir); | |||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $out = Bio::AlignIO->new(-verbose => $self->verbose, '-fh' => $tfh, '-format' => $format, @options); | |||||||||||||||||||||||||||||||||||
| 130 | 0 | $align->set_displayname_flat; | |||||||||||||||||||||||||||||||||||
| 131 | 0 | $out->write_aln($align); | |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | 0 | $out->close(); | |||||||||||||||||||||||||||||||||||
| 134 | 0 | $out = undef; | |||||||||||||||||||||||||||||||||||
| 135 | 0 | close($tfh); | |||||||||||||||||||||||||||||||||||
| 136 | 0 | undef $tfh; | |||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | 0 | return $tempfile; | |||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||
| 141 | =head2 _tree | ||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||
| 143 | Title : _tree | ||||||||||||||||||||||||||||||||||||
| 144 | Usage : $tree = $obj->_tree() | ||||||||||||||||||||||||||||||||||||
| 145 | Function: Get/set a tree object, generating one from a file/database if desired | ||||||||||||||||||||||||||||||||||||
| 146 | Returns : Bio::Tree::TreeI | ||||||||||||||||||||||||||||||||||||
| 147 | Args : none to get, OR to set: | ||||||||||||||||||||||||||||||||||||
| 148 | OR filename & input format of the tree file (latter defaults to | ||||||||||||||||||||||||||||||||||||
| 149 | guess) to set from file | ||||||||||||||||||||||||||||||||||||
| 150 | OR Bio::Tree::TreeI | ||||||||||||||||||||||||||||||||||||
| 151 | OR Bio::DB::Taxonomy when _alignment() has been set and where | ||||||||||||||||||||||||||||||||||||
| 152 | sequences in the alignment have ids matching species in the taxonomy | ||||||||||||||||||||||||||||||||||||
| 153 | database | ||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub _tree { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_tree: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||
| 158 | 0 | my ($self, $thing, $format) = @_; | |||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($thing) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $tree; | |||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if (ref($thing) && $thing->isa('Bio::Tree::TreeI')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
ref $thing and $thing->isa("Bio::Tree::TreeI")
MC/DC0%0/2
ref $thing and $thing->isa("Bio::Tree::TreeI")
ref $thing
$thing->isa("Bio::Tree::TreeI")
Truth table0%0/3
A and B
A= ref $thingB= $thing->isa("Bio::Tree::TreeI")
| |||||||||||||||||||||||||||||||||||||
| 163 | 0 | $tree = $thing; | |||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||
| 165 | ▶ | elsif (ref($thing) && $thing->isa('Bio::DB::Taxonomy')) { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $thing and $thing->isa("Bio::DB::Taxonomy")
MC/DC0%0/2
ref $thing and $thing->isa("Bio::DB::Taxonomy")
ref $thing
$thing->isa("Bio::DB::Taxonomy")
Truth table0%0/3
A and B
A= ref $thingB= $thing->isa("Bio::DB::Taxonomy")
| |||||||||||||||||||||||||||||||||||||
| 166 | # get all the alignment sequence names | ||||||||||||||||||||||||||||||||||||
| 167 | 0 | my @species_names = $self->_get_seq_names; | |||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | 0 | $tree = $thing->get_tree(@species_names); | |||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||
| 171 | # convert node ids to their seq_ids for correct output with TreeIO | ||||||||||||||||||||||||||||||||||||
| 172 | 0 | foreach my $node ($tree->get_nodes) { | |||||||||||||||||||||||||||||||||||
| 173 | 0 | my $seq_id = $node->name('supplied'); | |||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $seq_id = $seq_id ? shift @{$seq_id} : ($node->node_name ? $node->node_name : $node->id); | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||
| 176 | 0 | $node->id($seq_id); | |||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||
| 179 | elsif (-e $thing) { | ||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $tree_in = Bio::TreeIO->new(-verbose => $self->verbose, -file => $thing, $format ? (-format => $format) : ()); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $tree = $tree_in->next_tree || $self->throw("Tree file '$thing' had no tree!"); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$tree_in->next_tree || $self->throw("Tree file '${thing}' had no tree!")
MC/DC0%0/2
$tree_in->next_tree || $self->throw("Tree file '${thing}' had no tree!")
$tree_in->next_tree
$self->throw("Tree file '${thing}' had no tree!")
Truth table0%0/3
A || B
A= $tree_in->next_treeB= $self->throw("Tree file '${thing}' had no tree!")
| |||||||||||||||||||||||||||||||||||||
| 182 | 0 | $tree_in->close; | |||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $self->{_tree_obj} = $tree || $self->throw("'$thing' supplied but unable to generate a tree from it"); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$tree || $self->throw("'${thing}' supplied but unable to generate a tree from it")
MC/DC0%0/2
$tree || $self->throw("'${thing}' supplied but unable to generate a tree from it")
$tree
$self->throw("'${thing}' supplied but unable to generate a tree from it")
Truth table0%0/3
A || B
A= $treeB= $self->throw("'${thing}' supplied but unable to generate a tree from it")
| |||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||
| 188 | 0 | return $self->{_tree_obj}; | |||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | =head2 _write_tree | ||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||
| 193 | Title : _write_tree | ||||||||||||||||||||||||||||||||||||
| 194 | Usage : $obj->_write_tree() | ||||||||||||||||||||||||||||||||||||
| 195 | Function: Writes the tree object returned by _tree() out in the desired format | ||||||||||||||||||||||||||||||||||||
| 196 | to a temp file. | ||||||||||||||||||||||||||||||||||||
| 197 | Returns : filename | ||||||||||||||||||||||||||||||||||||
| 198 | Args : string to describe format (default 'newick') | ||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub _write_tree { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_write_tree: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||
| 203 | 0 | my ($self, $format) = @_; | |||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $tree = $self->_tree || $self->throw("_write_tree called when _tree had not been set"); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_tree || $self->throw('_write_tree called when _tree had not been set')
MC/DC0%0/2
$self->_tree || $self->throw('_write_tree called when _tree had not been set')
$self->_tree
$self->throw('_write_tree called when _tree had not been set')
Truth table0%0/3
A || B
A= $self->_treeB= $self->throw('_write_tree called when _tree had not been set')
| |||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | $format ||= 'newick'; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$format ||= "newick"
MC/DC0%0/1
$format ||= "newick"
$format
Truth table0%0/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||
| 207 | 0 | my ($tfh, $tempfile) = $self->io->tempfile(-dir => $self->tempdir); | |||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||
| 209 | 0 | my $out = Bio::TreeIO->new(-verbose => $self->verbose, -fh => $tfh, -format => $format); | |||||||||||||||||||||||||||||||||||
| 210 | 0 | $out->write_tree($tree); | |||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||
| 212 | 0 | $out->close(); | |||||||||||||||||||||||||||||||||||
| 213 | 0 | $out = undef; | |||||||||||||||||||||||||||||||||||
| 214 | 0 | close($tfh); | |||||||||||||||||||||||||||||||||||
| 215 | 0 | undef $tfh; | |||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||
| 217 | 0 | return $tempfile; | |||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||
| 220 | =head2 _get_seq_names | ||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||
| 222 | Title : _get_seq_names | ||||||||||||||||||||||||||||||||||||
| 223 | Usage : @names = $obj->_get_seq_names() | ||||||||||||||||||||||||||||||||||||
| 224 | Function: Get all the sequence names (from id()) of the sequenes in the | ||||||||||||||||||||||||||||||||||||
| 225 | alignment. _alignment() must be set prior to calling this. | ||||||||||||||||||||||||||||||||||||
| 226 | Returns : list of strings (seq ids) | ||||||||||||||||||||||||||||||||||||
| 227 | Args : none | ||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub _get_seq_names { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_seq_names: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | my $aln = $self->_alignment || $self->throw("_get_seq_names called when _alignment had not been set"); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_alignment || $self->throw('_get_seq_names called when _alignment had not been set')
MC/DC0%0/2
$self->_alignment || $self->throw('_get_seq_names called when _alignment had not been set')
$self->_alignment
$self->throw('_get_seq_names called when _alignment had not been set')
Truth table0%0/3
A || B
A= $self->_alignmentB= $self->throw('_get_seq_names called when _alignment had not been set')
| |||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||
| 235 | 0 | my @names; | |||||||||||||||||||||||||||||||||||
| 236 | 0 | foreach my $seq ($aln->each_seq) { | |||||||||||||||||||||||||||||||||||
| 237 | 0 | push(@names, $seq->id); | |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||
| 240 | 0 | return @names; | |||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||
| 243 | =head2 _get_node_names | ||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||
| 245 | Title : _get_node_names | ||||||||||||||||||||||||||||||||||||
| 246 | Usage : @names = $obj->_get_node_names() | ||||||||||||||||||||||||||||||||||||
| 247 | Function: Get all the node names (from id()) of the nodes in the tree. | ||||||||||||||||||||||||||||||||||||
| 248 | _tree must be set prior to calling this. | ||||||||||||||||||||||||||||||||||||
| 249 | Returns : list of strings (node ids) | ||||||||||||||||||||||||||||||||||||
| 250 | Args : none | ||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||
| 252 | =cut | ||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub _get_node_names { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_node_names: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | my $tree = $self->_tree || $self->throw("_get_node_names called when _tree had not been set"); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_tree || $self->throw('_get_node_names called when _tree had not been set')
MC/DC0%0/2
$self->_tree || $self->throw('_get_node_names called when _tree had not been set')
$self->_tree
$self->throw('_get_node_names called when _tree had not been set')
Truth table0%0/3
A || B
A= $self->_treeB= $self->throw('_get_node_names called when _tree had not been set')
| |||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||
| 258 | 0 | my @names; | |||||||||||||||||||||||||||||||||||
| 259 | 0 | foreach my $node ($tree->get_leaf_nodes) { | |||||||||||||||||||||||||||||||||||
| 260 | 0 | push(@names, $node->id); | |||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||
| 263 | 0 | return @names; | |||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||
| 266 | =head2 _check_names | ||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||
| 268 | Title : _check_names | ||||||||||||||||||||||||||||||||||||
| 269 | Usage : if ($obj->_check_names) { ... } | ||||||||||||||||||||||||||||||||||||
| 270 | Function: Determine if all sequences in the alignment file have a corresponding | ||||||||||||||||||||||||||||||||||||
| 271 | node in the tree file. _alignment() and _tree() must be set | ||||||||||||||||||||||||||||||||||||
| 272 | prior to calling this. | ||||||||||||||||||||||||||||||||||||
| 273 | Returns : boolean (will also warn about the specific problems when returning | ||||||||||||||||||||||||||||||||||||
| 274 | false) | ||||||||||||||||||||||||||||||||||||
| 275 | Args : none | ||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||
| 277 | =cut | ||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub _check_names { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_check_names: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||
| 282 | 0 | my @seq_names = $self->_get_seq_names; | |||||||||||||||||||||||||||||||||||
| 283 | 0 | my %node_names = map { $_ => 1 } $self->_get_node_names; | |||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||
| 285 | # (not interested in tree nodes that don't map to sequence, since we | ||||||||||||||||||||||||||||||||||||
| 286 | # expect the tree to have internal nodes not represented by sequence) | ||||||||||||||||||||||||||||||||||||
| 287 | 0 | foreach my $name (@seq_names) { | |||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | $self->{_unmapped}{$name} = 1 unless defined $node_names{$name}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if (defined($self->{_unmapped})) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $count = scalar(keys %{$self->{_unmapped}}); | |||||||||||||||||||||||||||||||||||
| 293 | 0 | my $unmapped = join(", ", keys %{$self->{_unmapped}}); | |||||||||||||||||||||||||||||||||||
| 294 | 0 | $self->warn("$count unmapped ids between the supplied alignment and tree: $unmapped"); | |||||||||||||||||||||||||||||||||||
| 295 | 0 | return 0; | |||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||
| 298 | 0 | return 1; | |||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||
| 301 | 1 | 1; | |||||||||||||||||||||||||||||||||||