Jplace format file parser for ruby. Parses the file format described at http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0031009
gem install bio-jplace
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.
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.
If you use this software, please cite one of
- BioRuby: bioinformatics software for the Ruby programming language
- Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics
This Biogem is published at (http://biogems.info/index.html#bio-jplace)
Copyright (c) 2013 Ben J. Woodcroft. See LICENSE.txt for further details.