truder / bioruby-jplace

Jplace format file parser for ruby for phylogenetic tree insertion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bio-jplace

Build Status

Jplace format file parser for ruby. Parses the file format described at http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0031009

Installation

gem install bio-jplace

Usage

An example jplace format file, from https://en.wikipedia.org/wiki/Stockholm_format

{
 "tree": "((A:0.2{0},B:0.09{1}):0.7{2},C:0.5{3}){4};",
 "placements":
 [
  {"p":
   [[1, -578.16, 0.777385, 0.004132, 0.0006],
   [0, -580.15, 0.107065, 0.000009, 0.0153]
   ],
  "n": ["fragment1", "fragment2"]
  },
  {"p": [[2, -576.46, 1.0, 0.003555, 0.000006]],
   "nm": [["fragment3", 1.5], ["fragment4", 2]]}
 ],
 "metadata":
 {"invocation":
  "pplacer -c tiny.refpkg frags.fasta"
 },
 "version": 3,
 "fields":
 ["edge_num", "likelihood", "like_weight_ratio",
    "distal_length", "pendant_length"]
}
require 'bio-jplace'

jplace = Bio::Jplace.parse('spec/data/example.jplace') #=> Bio::Jplace object

jplace.version #=> 3 (Integer)
jplace.tree #=> Bio::Jplace::Tree object, containing the tree "((A:0.2{0},B:0.09{1}):0.7{2},C:0.5{3}){4};"
jplace.tree.newick #=> "((A:0.2,B:0.09):0.7,C:0.5);"

jplace.each_placement_set do |name, placement_set, multiplicity|
  # In the first iteration,
  name #=> "fragment1"

  placement_set #=> Bio::Jplace::PlacementSet object, which contains none or more Bio::Jplace::Placement objects
  placement_set[0]['edge_num'] #=> "1"

  multiplicity #=> nil (would be 1.5 for fragment3, for instance)
end

jplace.fields #=> ["edge_num", "likelihood", "like_weight_ratio", "distal_length", "pendant_length"]

The API doc is online. For more code examples see the test files in the source tree.

Project home page

Information on the source tree, documentation, examples, issues and how to contribute, see

http://github.com/wwood/bioruby-jplace

The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.

Cite

If you use this software, please cite one of

Biogems.info

This Biogem is published at (http://biogems.info/index.html#bio-jplace)

Copyright

Copyright (c) 2013 Ben J. Woodcroft. See LICENSE.txt for further details.

About

Jplace format file parser for ruby for phylogenetic tree insertion

License:MIT License


Languages

Language:Ruby 100.0%