npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

phyloxml

v1.0.0

Published

phyloxml.js is a JavaScript program for reading (SAX style parser) and writing phylogenetic trees in phyloXML format.

Downloads

16

Readme

phyloxml.js

phyloxml.js is a JavaScript program for reading (SAX style parser) and writing phylogenetic trees in phyloXML format.

phyloXML website: http://www.phyloxml.org/

Availability

  • npm: https://www.npmjs.com/package/phyloxml
  • GitHub: https://github.com/cmzmasek/phyloxml-js

Dependencies

  • sax.js (1.2.4): https://www.npmjs.com/package/sax/v/1.2.4

Example

This basic example shows how to parse a phyloXML formatted String into to a object representing a phylogenetic tree. Followed by printing some elements and then converting the object back to a phyloXML formatted String.

Change './phyloxml' to 'phyloxml' if you use this code outside of this package

var phyloXml = require('./phyloxml').phyloXml;

phlyoXmlFormattedString = '<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
    'xmlns="http://www.phyloxml.org" ' +
    'xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd">' +
    '<phylogeny rooted="true" rerootable="false">' +
    '<clade><branch_length>0.2</branch_length>' +
    '<clade><branch_length>0.4</branch_length><name>A</name></clade>' +
    '<clade><branch_length>0.6</branch_length><name>B</name></clade>' +
    '</clade>' +
    '</phylogeny>' +
    '</phyloxml>';

var phylogeneticTree = phyloXml.parse(phlyoXmlFormattedString, {trim: true, normalize: true})[0];

console.log('Root branch length  : ' + phylogeneticTree.children[0].branch_length);
console.log('Node A name         : ' + phylogeneticTree.children[0].children[0].name);
console.log('Node A branch length: ' + phylogeneticTree.children[0].children[0].branch_length);
console.log('Node B name         : ' + phylogeneticTree.children[0].children[1].name);
console.log('Node B branch length: ' + phylogeneticTree.children[0].children[1].branch_length);

console.log('Entire tree in phyloXML format:');
console.log(phyloXml.toPhyloXML(phylogeneticTree, 4));

The output should be:

Root branch length  : 0.2
Node A name         : A
Node A branch length: 0.4
Node B name         : B
Node B branch length: 0.6
Entire tree in phyloXML format:
<?xml version="1.0" encoding="UTF-8"?>
<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.20/phyloxml.xsd" xmlns="http://www.phyloxml.org">
 <phylogeny rooted="true" rerootable="false">
  <clade>
   <branch_length>0.2</branch_length>
   <clade>
    <name>A</name>
    <branch_length>0.4</branch_length>
   </clade>
   <clade>
    <name>B</name>
    <branch_length>0.6</branch_length>
   </clade>
  </clade>
 </phylogeny>
</phyloxml>

Synchronous parsing of phyloXML-formatted String

var px = require('./phyloxml').phyloXml;
var phys = px.parse(phyloxmlText, {trim: true, normalize: true});
console.log(px.toPhyloXML(phys[0], 6));

Asynchronous parsing of phyloXML-formatted Stream

var fs = require('fs');
var px = require('./phyloxml').phyloXml;
var stream = fs.createReadStream(xmlFile, {encoding: 'utf8'});
px.parseAsync(stream, {trim: true, normalize: true});