Skip to content
Sergei Pond edited this page Jul 13, 2015 · 14 revisions

Supporting ("internal") functions used by phylotree.js, some of which are accessible (and even essential) for applications.

# d3_phylotree_newick_parser(string, [bootstrap])

Converts a Newick tree string into an hierarchical object suitable for consumption by phylotree.js. If specified and truthy, bootstrap instructs d3_phylotree_newick_parser to treat internal node names as bootstrap support values. Returns an object with two fields:

  • error : null if parsing was successful, otherwise a description of the error
  • json : an hierarchical representation of the tree object (see below) if successfully parsed, otherwise null.

The json key is instantiated with node objects that will be populated by the function (also see examples below)

Examples

var newick_string = ((a:0.1[color=red],b:0.2)0.9:0.1, c:0.05, d:0.075);
d3_phylotree_newick_parser (newick_string);

yields

{"error": null
 "json" : {
    "name": "root",
    "children": [
        {
            "name": "0.9",
            "original_child_order": 1,
            "children": [
                {
                    "name": "a",
                    "original_child_order": 1,
                    "attribute": "0.1",
                    "annotation": "color=red"
                },
                {
                    "name": "b",
                    "original_child_order": 2,
                    "attribute": "0.2",
                    "annotation": ""
                }
            ],
            "attribute": "0.1",
            "annotation": ""
        },
        {
            "name": "c",
            "original_child_order": 2,
            "attribute": "0.05",
            "annotation": ""
        },
        {
            "name": "d",
            "original_child_order": 3,
            "attribute": "0.075",
            "annotation": ""
        }
    ]
 }
}

whereas, calling

d3_phylotree_newick_parser (newick_string, true);

modifies the entry for the only non-root internal node to

{
    "name": null,
    "original_child_order": 1,
    "children": [
        {
            "name": "a",
            "original_child_order": 1,
            "attribute": "0.1",
            "annotation": ""
        },
        {
            "name": "b",
            "original_child_order": 2,
            "attribute": "0.2",
            "annotation": ""
        }
    ],
    "bootstrap_values": "0.9",
    "attribute": "0.1",
    "annotation": ""
},
Clone this wiki locally