Difference between revisions of "PhyloSoC:BioPerl integration of the NeXML exchange standard and Bio::Phylo toolkit/HOWTO"

From Phyloinformatics
Jump to: navigation, search
m (Reading/Writing Individual Datatypes (e.g. trees))
m (Reading/Writing Individual Datatypes (e.g. trees))
Line 45: Line 45:
  
 
  #Read/Write a Tree
 
  #Read/Write a Tree
 
+
 
  #Create stream object
 
  #Create stream object
 
  my $TreeStream = Bio::TreeIO->new(-file => 'trees.xml', -format => 'Nexml');
 
  my $TreeStream = Bio::TreeIO->new(-file => 'trees.xml', -format => 'Nexml');
 
+
 
  #Read and convert first tree to BioPerl Bio::Tree::Tree object
 
  #Read and convert first tree to BioPerl Bio::Tree::Tree object
 
  my $tree_obj = $TreeStream->next_tree();
 
  my $tree_obj = $TreeStream->next_tree();
 
+
 
  #Use/manipulate tree data (e.g.)
 
  #Use/manipulate tree data (e.g.)
 
  my @nodes = $tree_obj->get_nodes();
 
  my @nodes = $tree_obj->get_nodes();
 
  ...
 
  ...
 
+
 
  #Convert and output BioPerl tree object to nexml
 
  #Convert and output BioPerl tree object to nexml
 
  my $outTree = Bio::TreeIO->new(-file => '>trees_out.xml', -format => 'nexml');
 
  my $outTree = Bio::TreeIO->new(-file => '>trees_out.xml', -format => 'nexml');
Line 62: Line 62:
  
 
  #Read/Write an alignment
 
  #Read/Write an alignment
 
+
 
  #Create stream object
 
  #Create stream object
 
  my $AlnStream = Bio::AlignIO->new(-file => 'characters.xml', -format => 'Nexml');
 
  my $AlnStream = Bio::AlignIO->new(-file => 'characters.xml', -format => 'Nexml');
 
+
 
  #Read and convert first tree to BioPerl Bio::SimpleAlign object
 
  #Read and convert first tree to BioPerl Bio::SimpleAlign object
 
  my $aln_obj = $AlnStream->next_aln();
 
  my $aln_obj = $AlnStream->next_aln();
 
+
 
  #Use/manipulate tree data (e.g.)
 
  #Use/manipulate tree data (e.g.)
 
  ...
 
  ...
 
+
 
  #Convert and output BioPerl alignment object to nexml
 
  #Convert and output BioPerl alignment object to nexml
 
  my $outAln = Bio::AlignIO->new(-file => '>aln_out.xml', -format => 'nexml');
 
  my $outAln = Bio::AlignIO->new(-file => '>aln_out.xml', -format => 'nexml');

Revision as of 08:25, 27 July 2009

Abstract

This is a HOWTO about the Template:PM module, and how to use it to read and write complete Nexml documents. We will also describe how the Template:PM, Template:PM, and Template:PM modules work for outputting individual objects to nexml.

Authors

Chase Miller

Introduction

These nexml modules integrate the NeXML exchange standard into BioPerl, facilitating the adoption of this standard and easing the transition from the overworked NEXUS standard. A wrapper was used to allow BioPerl native access to the preferred NeXML parser (Bio::Phylo), allowing Bio::Phylo and NeXML to co-evolve without being encumbered by BioPerl

Nexml functionality in bioperl consists of four modules that allow the user to interact with nexml data in two different ways. Bio::nexml allows users to read/write an entire nexml document, whereas Bio::SeqIO::nexml, Bio::AlignIO::nexml, and Bio::TreeIO::nexml allow the user to only read/write one data type (seqs, alns, or trees, respectively).

Design

Coming...

Example Nexml Documents

Nexml documents to use with the example code can be found at http://www.nexml.org/nexml/examples/

Reading/Writing Entire Nexml Documents

Reading and writing a whole nexml document is accomplished with the Bio::Nexml module. The Bio::Nexml module can read a nexml document and maintain many of the data associations allowable by Bio::Phylo (however at this point not all data associations are maintained[link to list]). Once read the data can be converted into BioPerl objects (i.e Bio::Tree::Tree, Bio::SimpleAlign, and Bio::Seq) and manipulated before writing back to a nexml document.

Example Code

#Instantiate a Bio::Nexml object and link it to a file
my $in_nexml = Bio::Nexml->new(-file => 'nexml_doc.xml', -format => 'Nexml');

#Read in some data
my $bptree1 = $in_nexml->next_tree();
my $bpaln1  = $in_nexml->next_aln();
my $bpseq1  = $in_nexml->next_seq();

#Use/manipulate data
...

#Write data to nexml file
my $out_nexml = Bio::Nexml->new(-file => '>new_nexml_doc.xml', -format => 'Nexml');
$out_nexml->to_xml();

Reading/Writing Individual Datatypes (e.g. trees)

Sometimes it may be preferable to only work with a single data type. (Also this maintains uniformity with parsers being located within the the Bio::*IO modules.) In these cases the use of the Bio::*IO::nexml modules (Bio::TreeIO::nexml, Bio::AlignIO::nexml, or Bio::SeqIO::nexml) are available.

Example Code

#Read/Write a Tree

#Create stream object
my $TreeStream = Bio::TreeIO->new(-file => 'trees.xml', -format => 'Nexml');

#Read and convert first tree to BioPerl Bio::Tree::Tree object
my $tree_obj = $TreeStream->next_tree();

#Use/manipulate tree data (e.g.)
my @nodes = $tree_obj->get_nodes();
...

#Convert and output BioPerl tree object to nexml
my $outTree = Bio::TreeIO->new(-file => '>trees_out.xml', -format => 'nexml');
$outTree->write_tree($tree_obj);


#Read/Write an alignment

#Create stream object
my $AlnStream = Bio::AlignIO->new(-file => 'characters.xml', -format => 'Nexml');

#Read and convert first tree to BioPerl Bio::SimpleAlign object
my $aln_obj = $AlnStream->next_aln();

#Use/manipulate tree data (e.g.)
...

#Convert and output BioPerl alignment object to nexml
my $outAln = Bio::AlignIO->new(-file => '>aln_out.xml', -format => 'nexml');
$outAln->write_aln($aln_obj);

It's important to note that the xml output does not make a complete nexml document, but only outputs the tree/alignment in nexml format. (This can be changed easily, I'm not sure if it's better to output a whole document or just pieces which possible could allow someone to build their own nexml document from BioPerl, although getting the syntax right would be very difficult.)

Differences in Roundtrip (BETTER NAME)

Some things in biophylo were not implemented in Bioperl because it either was very diffcult or did not make sense to

Associations Maintained

Associations Not Maintained

Alignments and Sequences of odd type (i.e. not DNA, RNA, or Protein)