SeqIO/nexml.pm

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