AlignIO/nexml.pm

filter: Statementstmt 30.9% 17 / 55 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 45.4% 5 / 11 Podpod 100% 4 / 4 totaltotal 31.3% 26 / 83 CC 6 SCAR 19.7
CC
6
Cov
26%
_parse
20.0
next_aln
6.0
doc
6.0
CRAP 7.2
« NexmlIO.pm ↑ Summary SeqIO/nexml.pm »
1 #
2 # BioPerl module for Bio::AlignIO::nexml
3 #
4 # Copyright Chase Miller
5 #
6 # You may distribute this module under the same terms as perl itself
7 # POD documentation - main docs before the code
8  
9 =head1 NAME
10  
11 Bio::AlignIO::nexml - NeXML format sequence alignment input/output stream driver
12  
13 =head1 SYNOPSIS
14  
15 Do not use this module directly. Use it via the L<Bio::AlignIO> class.
16  
17 =head1 DESCRIPTION
18  
19 This object can transform L<Bio::SimpleAlign> objects to and from
20 NeXML format. For more information on NeXML, visit L<http://www.nexml.org>.
21  
22 =head1 FEEDBACK
23  
24 =head2 Support
25  
26 Please direct usage questions or support issues to the mailing list:
27  
28 I<bioperl-l@bioperl.org>
29  
30 rather than to the module maintainer directly. Many experienced and
31 reponsive experts will be able look at the problem and quickly
32 address it. Please include a thorough description of the problem
33 with code and data examples if at all possible.
34  
35 =head2 Reporting Bugs
36  
37 Report bugs to the Bioperl bug tracking system to help us keep track
38 the bugs and their resolution. Bug reports can be submitted via the
39 web:
40  
41 https://github.com/bioperl/bioperl-live/issues
42  
43 =head1 AUTHORS
44  
45 Chase Miller
46  
47 =head1 CONTRIBUTORS
48  
49 Mark Jensen, maj@fortinbras.us
50 Rutger Vos, rutgeraldo@gmail.com
51  
52 =head1 APPENDIX
53  
54 The rest of the documentation details each of the object
55 methods. Internal methods are usually preceded with a _
56  
57 =cut
58  
59 # Let the code begin...
60  
61 package Bio::AlignIO::nexml;
62 4 $Bio::AlignIO::nexml::VERSION = '1.7.3';
63  
64 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 4 ▶use lib '../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 4 ▶use Bio::Nexml::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 4 ▶use Bio::Phylo::IO qw(parse unparse);
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 4 ▶use base qw(Bio::AlignIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71  
72 0 ▶sub _initialize {
Subroutine _initialize: not called CC=1 SCAR=6.9
73 0 my($self,@args) = @_;
74 0 $self->SUPER::_initialize(@args);
75 0 $self->{_doc} = undef;
76 }
77  
78 =head2 next_aln
79  
80 Title : next_aln
81 Usage : $aln = $stream->next_aln
82 Function: returns the next alignment in the stream.
83 Returns : Bio::Align::AlignI object - returns 0 on end of file
84 or on error
85 Args :
86  
87 See L<Bio::Align::AlignI>
88  
89 =cut
90  
91 0 ▶sub next_aln {
Subroutine next_aln: not called CC=2 SCAR=17.9
Pod documented
92 0 my ($self) = @_;
93 0 ▶ unless ( $self->{'_parsed'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_parsed"}) 0 0 0
94 #use a parse function to load all the alignment objects found in the nexml file at once
95 0 $self->_parse;
96 }
97 0 return $self->{'_alns'}->[ $self->{'_alnsiter'}++ ];
98 }
99  
100 =head2 rewind
101  
102 Title : rewind
103 Usage : $alnio->rewind
104 Function: Resets the stream
105 Returns : none
106 Args : none
107  
108  
109 =cut
110  
111 0 ▶sub rewind {
Subroutine rewind: not called CC=1 SCAR=6.9
Pod documented
112 0 my $self = shift;
113 0 $self->{'_alniter'} = 0;
114 }
115  
116 =head2 doc
117  
118 Title : doc
119 Usage : $treeio->doc
120 Function: Returns the biophylo nexml document object
121 Returns : Bio::Phylo::Project
122 Args : none or Bio::Phylo::Project object
123  
124 =cut
125  
126 0 ▶sub doc {
Subroutine doc: not called CC=2 SCAR=17.9
Pod documented
127 0 my ($obj,$value) = @_;
128 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
129 0 $obj->{'_doc'} = $value;
130 }
131 0 return $obj->{'_doc'};
132 }
133  
134 0 ▶sub _parse {
Subroutine _parse: not called CC=4 SCAR=30.0
135 0 my ($self) = @_;
136  
137 0 $self->{'_parsed'} = 1;
138 0 $self->{'_alnsiter'} = 0;
139 0 my $fac = Bio::Nexml::Factory->new();
140  
141 # Only pass filename if filehandle is not available,
142 # or "Bio::Phylo" will create a new filehandle that ends
143 # out of scope and can't be closed directly, leaving 2 open
144 # filehandles for the same file (so file can't be deleted)
145 0 my $file_arg;
146 my $file_value;
147 0 ▶ if ( exists $self->{'_filehandle'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_filehandle'} and defined $self->{'_filehandle'}) { } 0 0 0
Condition0%0/3
exists $self->{"_filehandle"} and defined $self->{"_filehandle"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"_filehandle"} and defined $self->{"_filehandle"}
exists $self->{"_filehandle"} defined $self->{"_filehandle"}
Truth table0%0/3
A and B
A= exists $self->{"_filehandle"}B= defined $self->{"_filehandle"}
ABresult
0X0
100
111
148 and defined $self->{'_filehandle'}
149 ) {
150 0 $file_arg = '-handle';
151 0 $file_value = $self->{'_filehandle'};
152 }
153 else {
154 0 $file_arg = '-file';
155 0 $file_value = $self->{'_file'};
156 }
157  
158 0 $self->doc(parse(
159 $file_arg => $file_value,
160 '-format' => 'nexml',
161 '-as_project' => '1'
162 )
163 );
164 0 $self->{'_alns'} = $fac->create_bperl_aln($self);
165  
166 0 ▶ if(@{ $self->{'_alns'} } == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_alns"};} == 0) 0 0 0
167 0 self->debug("no seqs in $self->{_file}");
168 }
169 }
170  
171 =head2 write_aln
172  
173 Title : write_aln
174 Usage : $stream->write_aln(@aln)
175 Function: writes the $aln object into the stream in nexml format
176 Returns : 1 for success and 0 for error
177 Args : L<Bio::Align::AlignI> object
178  
179 See L<Bio::Align::AlignI>
180  
181 =cut
182  
183 0 ▶sub write_aln {
Subroutine write_aln: not called CC=1 SCAR=6.9
Pod documented
184 0 my ($self, $aln) = @_;
185
186 0 my $fac = Bio::Nexml::Factory->new();
187 0 my $taxa = $fac->create_bphylo_taxa($aln);
188 0 my ($matrix) = $fac->create_bphylo_aln($aln, $taxa);
189 0 $matrix->set_taxa($taxa);
190
191 0 $self->doc(Bio::Phylo::Factory->create_project());
192 0 $self->doc->insert($matrix);
193 0 my $ret = $self->_print($self->doc->to_xml());
194 0 $self->flush;
195 0 return $ret;
196 }
197  
198  
199  
200  
201  
202  
203  
204  
205 4 1;
« NexmlIO.pm ↑ Summary SeqIO/nexml.pm »