2 # BioPerl module for Bio::AlignIO::nexml
4 # Copyright Chase Miller
6 # You may distribute this module under the same terms as perl itself
7 # POD documentation - main docs before the code
11 Bio::AlignIO::nexml - NeXML format sequence alignment input/output stream driver
15 Do not use this module directly. Use it via the L<Bio::AlignIO> class.
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>.
26 Please direct usage questions or support issues to the mailing list:
28 I<bioperl-l@bioperl.org>
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.
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
41 https://github.com/bioperl/bioperl-live/issues
49 Mark Jensen, maj@fortinbras.us
50 Rutger Vos, rutgeraldo@gmail.com
54 The rest of the documentation details each of the object
55 methods. Internal methods are usually preceded with a _
59 # Let the code begin...
61 package Bio
::AlignIO
::nexml
;
65 use Bio
::Nexml
::Factory
;
66 use Bio
::Phylo
::IO
qw(parse unparse);
68 use base
qw(Bio::AlignIO);
73 $self->SUPER::_initialize
(@args);
74 $self->{_doc
} = undef;
80 Usage : $aln = $stream->next_aln
81 Function: returns the next alignment in the stream.
82 Returns : Bio::Align::AlignI object - returns 0 on end of file
86 See L<Bio::Align::AlignI>
92 unless ( $self->{'_parsed'} ) {
93 #use a parse function to load all the alignment objects found in the nexml file at once
96 return $self->{'_alns'}->[ $self->{'_alnsiter'}++ ];
102 Usage : $alnio->rewind
103 Function: Resets the stream
112 $self->{'_alniter'} = 0;
119 Function: Returns the biophylo nexml document object
120 Returns : Bio::Phylo::Project
121 Args : none or Bio::Phylo::Project object
126 my ($obj,$value) = @_;
127 if( defined $value) {
128 $obj->{'_doc'} = $value;
130 return $obj->{'_doc'};
136 $self->{'_parsed'} = 1;
137 $self->{'_alnsiter'} = 0;
138 my $fac = Bio
::Nexml
::Factory
->new();
140 # Only pass filename if filehandle is not available,
141 # or "Bio::Phylo" will create a new filehandle that ends
142 # out of scope and can't be closed directly, leaving 2 open
143 # filehandles for the same file (so file can't be deleted)
146 if ( exists $self->{'_filehandle'}
147 and defined $self->{'_filehandle'}
149 $file_arg = '-handle';
150 $file_value = $self->{'_filehandle'};
154 $file_value = $self->{'_file'};
158 $file_arg => $file_value,
159 '-format' => 'nexml',
163 $self->{'_alns'} = $fac->create_bperl_aln($self);
165 if(@
{ $self->{'_alns'} } == 0) {
166 self
->debug("no seqs in $self->{_file}");
173 Usage : $stream->write_aln(@aln)
174 Function: writes the $aln object into the stream in nexml format
175 Returns : 1 for success and 0 for error
176 Args : L<Bio::Align::AlignI> object
178 See L<Bio::Align::AlignI>
183 my ($self, $aln) = @_;
185 my $fac = Bio
::Nexml
::Factory
->new();
186 my $taxa = $fac->create_bphylo_taxa($aln);
187 my ($matrix) = $fac->create_bphylo_aln($aln, $taxa);
188 $matrix->set_taxa($taxa);
190 $self->doc(Bio
::Phylo
::Factory
->create_project());
191 $self->doc->insert($matrix);
192 my $ret = $self->_print($self->doc->to_xml());