Giter VIP home page Giter VIP logo

phylotree.js's Introduction

phylotree.js

A JavaScript library for developing applications and interactive visualizations involving phylogenetic trees, written as an extension of the D3 hierarchy layout. It generates high quality SVG vector graphics, allows a great degree of customizability (CSS or JavaScript callbacks), and comes with a lot of built-in convenience features.

Example Notebooks

Standalone web application

A full-featured web application based on phylotree.js, implemented in index.html.

Features

  • Capable of handling multiple selection categories for comparative analysis.
  • Several mechanisms for selecting branches, including by clade, path to root, individual branches, internal branches, leaves, and branches that are nearby after layout.
  • Runs entirely in the browser, including Newick/PhyloXML/NexML parsing.
  • Can handle trees with thousands of tips.
  • Supports linear, radial, scaled branch, tip-aligned, and scaled tip size views.
  • The viewer can be constrained to fit in a given SVG box, or scale based on the size of the tree.
  • Numerous interactive features, including
    • Scaling
    • Animated rerooting
    • Ladderization
    • Clade collapse and hiding to explore large trees
    • Node, clade, and subtree selection
    • Tools to automatically select subsets of tree branches based on conditions.
  • Style customizations based on CSS and JavaScript callbacks
    • Color branches and tips, including gradient shading for continuous traits.
    • Customize the way tip names are displayed
    • Transform branch lengths based on branch attributes (e.g. a non-linear scale).
    • Redefine the way a tree is displayed by writing custom CSS
  • Available on npm to facilitate modern JavaScript development.

Installation

If you use NPM, npm install phylotree. Otherwise, the latest release can be installed locally using the following commands.

git clone https://github.com/veg/phylotree.js.git
yarn
yarn serve

This will run rollup in watch mode and start a local server (default port is 8080). Refresh upon editing to view changes.

Fundamentals

This section describes basic commands for displaying trees, such as those found in the Introduction section.

Note that many methods follow the getter/setter pattern, commonly used in D3. That is, they can either be used to retrieve an underlying parameter by being invoked without arguments (get), or can be used to change an underlying parameter by being invoked with the proper arguments (set).

Supported Formats

Phylotree supports the Newick format, as well the extension of this format that is used by HyPhy. This allows assigning a category to each branch by the use of curly braces directly after identifiers, e.g.:

((((Pig:0.147969,Cow:0.21343):0.085099,Horse:0.165787,Cat:0.264806):0.058611, ((RhMonkey{Foreground}:0.002015,Baboon{Foreground}:0.003108){Foreground}:0.022733 ,(Human{Foreground}:0.004349,Chimp{Foreground}:0.000799){Foreground}:0.011873):0.101856) :0.340802,Rat:0.050958,Mouse:0.09795)

Examples

Options

phylotree.js supports a variety of options for common features, which can be set using the following function.

The following are a list of possible options, along with their types, meanings, and possible values.

left-right-spacing

(String) Determines layout size from left to right. Defaults to "fixed-step".

  • "fixed-step" - Determine width from padding and spacing.
  • "fit-to-size" - Determine width from size array.

top-bottom-spacing

(String) Determines layout size from top to bottom. Defaults to "fixed-step".

  • "fixed-step" - Determine width from padding and spacing.
  • "fit-to-size" - Determine width from size array.

brush

(Boolean) Whether or not the brush should be activated. Defaults to true.

hide

(Boolean) Whether or not hiding a given node or subtree is enabled. Defaults to true.

reroot

(Boolean) Whether or not rerooting on a given node is enabled. Defaults to true.

compression

(Number) The percentage of original size for a collapsed node. Defaults to .2.

show-scale

(Boolean) Determines whether or not scale bar for branch lengths is shown.

left-offset

(Number) Amount of space on left side of phylotree. Defaults to 0.

draw-size-bubbles

(Boolean) Determines whether nodes are drawn with a given size. Defaults to false.

max-radius

(Number) Set an upper bound on the radius in a radial layout. Defaults to 768.

collapsible

(Boolean) Determines whether or not nodes are collapsible. Defaults to true.

selectable

(Boolean) Determines whether or not individual branches are selectable. Defaults to true.

zoom

(Boolean) Determines whether or not zooming is enabled. Defaults to false.

restricted-selectable

(Array) Determines what types of global selection actions are possible. Defaults to false.

  • false - No restrictions placed on global selection.
  • "all" - Allow users to select all branches.
  • "none" - Allow users to unselect all branches.
  • "all-leaf-nodes" - Allow users to select all leaf nodes.
  • "all-internal-branches" - Allow users to select all internal branches.

align-tips

(Boolean) Determines whether tip names are aligned or not. Defaults to false.

maximum-per-node-spacing

(Number) Determines maximum node spacing allocated when laying out left to right. Defaults to 100.

minimum-per-node-spacing

(Number) Determines minimum node spacing allocated when laying out left to right. Defaults to 2.

maximum-per-level-spacing

(Number) Determines maximum node spacing allocated when laying out top to bottom. Defaults to 100.

minimum-per-level-spacing

(Number) Determines minimum node spacing allocated when laying out top to bottom. Defaults to 10.

API Reference

A complete list of available functions can be found at API.md

phylotree.js's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar gaurav avatar guignonv avatar kemaleren avatar oteri avatar sjspielman avatar spond avatar sshank avatar stephenshank avatar stevenweaver avatar thomasstjerne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phylotree.js's Issues

Node annotation on tree creation

Allow a callback function to be passed to the tree constructor, so that nodes can be annotated with things like size and other attributes before the first pass through the layout algorithm.

Modify the context menu

Hi
I was wondering if there is a way to modify the context menu shown when clicking on nodes/edges.
Currently I managed doing it when using some naive d3 manipulation:
d3.select("#d3_layout_phylotree_context_menu").append('li').text('test').attr('id','testid')
However, in this way every time the menu is hidden the additions disappear as well and I need to re apply them every time the menu becomes available.

Help will be much appreciated.
Best
Tal

Root internal node label is overwritten with "root"

I wanted to display internal labels (just like #56), so I wrote a custom node styler. This works fine for internal nodes anywhere in the phylogeny except at the root, where the node is always relabeled "root" when loading from Newick. I could come up with a workaround at my end, but I wondered if it might be relatively easy to fix in Phylotree.js by using some other method to flag the root node. I might be able to spend a bit of time working on that bug for work and sending you a pull request if that might be helpful.

Thank you for writing just a great library!

Clade space

Good afternoon! After modifying the style to make the clades invisible:
.clade {
fill :white;
stroke :white;
}
I'm still left with a huge empty space (after collapsing 100 nodes at the beggining of the tree), how can I control the space/size of the clades when collapsing?
image

Thanks again!

g attribute transform error

Got the "g attribute transform error" from the console and it seems to be the map polyfill issue where the translate coordinates was miscalculated for the initial state.

the issue can be reproduced from the official demo.

issue

I think I found a fix and will send in a PR after confirm it's working.

Export in svg

Dear @spond,

I would like to easily export the generated tree in svg or png. How could i do that since i am relatively new in javascript.

Thanks in advance

Add semi-colon

Hi @sshank,

It would be useful to have a semi-colon as the trailing character for tree export. Many programs require a semi-colon to be there for proper parsing as part of canonical newick format.

-Stephanie

update_controls() function removes branch-tracer

Hi,
I have a function that is called when I need some data to be drawn on top of the labels.
At the very beginning of the function, I call tree.align_tips() as I want to draw metadata only on the extended tree.
Once the data is drawn, after calling tree.layout() I want to update the button ".phylotree-align-toggler") so I call update_controls() which is defined as follows:
function update_controls () { // $("[data-mode='" + (tree.radial() ? 'radial' : 'linear') + "']").click(); $("[data-align='" + (tree.align_tips () ? 'right' : 'left') + "']").click(); }
This should activate the "align" button switching it to tips aligned. It does that (so i can see that the data-align = "right" button is selected ) but then the branch-tracers are not drawn (more specifically they are drawn but the opacity is set to 0). this doesn't happen if i remove the update_controls() function.
Exactly the same behaviour is observed if I add $("[data-align='" + (tree.align_tips () ? 'right' : 'left') + "']").click(); after the call of the function that draws the metadata.

This is how I see the tree with:
lay5

Is there a reason for that ?

Why node names have spaces removed?

I wonder why spaces are being removed from node names. It appears to be done on purpose (lines 2964, 3022-3024) but I don't understand the reason and there are no comment explaining why.
I have trees with node names mixing spaces and underscores and they don't display well with spaces being removed. Would it be a problem to keep spaces in node labels?

Add a 'rotate' function for a node

It would be useful to be able to 'rotate' a node switching the order of the child nodes. This could be part of the API but also an optional menu item for a node. There could be two variants: one just flips the node itself, the other flips all the descendant nodes (thus reflecting the whole subtree).

Another option would be to sort the tree order by number of tips (perhaps providing a sort compare function).

FastTree output does not fit to phylotree.js

First of all, I would like thank you guys for contributing to this project.

When I tried to feed Phylotree.js with the following input (FastTree output) using the template http://bl.ocks.org/spond/f6b51aa6f34561f7006f, I could not get a desired tree visualization ( issues with scaling?).
.nwk
(BRAOA12048:0.00054,BRANA02666:0.00991,((BRAJU21777:0.03087,(ARATH07668:0.01134,ARALY20685:0.03085)1.000:0.13667)0.926:0.02726,(BRANA29265:0.00325,(BRAJU98226:0.00055,BRARP02331:0.00055)0.882:0.00661)0.956:0.01496)0.809:0.00513);

As there is no error messages pop up from the browser console it is very different for me to debug it.

While I copy it to Trex Newick Viewer, it works fine.

Could you help me? I am looking forward to hearing from you.

Kind regards,

Jiao

Contributing.md?

I'm trying to package a local copy of this repo so that I can start doing some customization, but I've been unable to do so with yarn run develop. First, installing yarn is broken in Ubuntu 18.04 (similar to this issue), so I did a local install of release 1.11. Next, running this command yielded the following:

yarn run v1.11.1
$ concurrently "webpack --watch --mode=development" "http-server"
/bin/sh: 1: concurrently: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Is there a specific version of yarn I should be using, and can you please list any other dependencies for development?

Merge color chart svg into phylotree.

Hello,

Currently, the color chart feature is in a separate svg. Please merge both of these items into the same svg, or find a convenient method to export both svgs into one png.

Kind Regards,
Steven

screen shot 2015-10-12 at 14 00 31

Reference Error - d3_phylotree_newick_parser

Getting the following error: ReferenceError: d3_phylotree_newick_parser is not defined when trying to view any tree. this screenshot is from one the examples on the live demo interface.

phylotree_err

Large tree option which syncs all available actions

The large tree example:

http://phylotree.hyphy.org/examples/large-tree/

currently syncs certain actions (such as selecting branches) between the "detailed" tree and "guide" tree. Other behaviors, such as collapsing/hiding nodes are not yet supported.

In the ideal case, a flag such as large: True could be provided to options in any tree, and a tree like the large tree would render, with all available actions synced between the detailed tree and guide tree.

PhyloXML support

Add support for parsing and writing various PhyloXML formats.

Slatkin Maddison

Dear @stephenshank,

We should also implement a web app and a standalone command line tool for performing the Slatkin Maddison test for compartmentalization with visual feedback, such as labeling the branches where transitions occur, and coloring branches based on the results of the permutation test.

All the components are already there, like the parsimony state reconstruction, so the test should be easy to implement.

The standalone (node) version should request branch partitioning regular expression from the command line. You can run through the S-M implementation in HyPhy to get a sense of what the result should be.

Best,
Sergei

get tree's updated data after changes made

I'm using your great library In my app, and i need to perform changes on the tree, is there way getting the tree's data after the changes made? (i.e. "tree" method)

Thanks,
Liza

D3 v4

This is a great project. Thanks!

Just a question: Do you have plans / thoughts about moving to D3 v4 ?
Seems that that D3 v4 introduced some breaking changes.

Bug in escape_string: only the first occurrence of single quotes are escaped

The escape_string(nn) function escapes single quotes by doubling them:

phylotree.js/src/main.js

Lines 1106 to 1110 in 35ec807

function escape_string(nn) {
var need_escape = /[\s\[\]\,\)\(\:\'\"]/;
var enquote = need_escape.test(nn);
return enquote ? "'" + nn.replace("'", "''") + "'" : nn;
}

Unfortunately, String.replace with a string first argument only replaces the first occurrence of the provided string. This could be fixed by using regular expressions instead, e.g. nn.replace(/\'/g, "''").

Here's a JSFiddle showing what I mean: https://jsfiddle.net/eywraw8t/422467/

Read external Newick file

A beautiful piece of work!
We would like to customize your structure.
For starters, we'll update your menus based on our customization.
But we also would like to load Newick strings from external files.
Do you have a version that does so?
We've not been able to successfully process an external Newick file modifying this loading structure:

$("#example_GVZ").on ("click", function (e) {
    default_tree_settings ();

    function GVZ_colorizer (element, data) {
        element.style ('stroke-width', 4)
               .style ('stroke-linejoin', 'round')
               .style ('stroke-linecap', 'round');
    }
    var GVZ = 

As shown here: https://github.com/veg/phylotree.js/blob/master/index.html

If a modification is difficult, we'll follow your structure as-is and load the specific strings we choose to feature.

/jay gray

Give the root node an additional class

The root node has class 'internal-node'. It would be useful if it could also have the class 'root-node' so that it can be styled differently through CSS.

svg element is too large for radial tree

The calculations for the size of the svg element are off, making the element too large. I suspect that tree.pad_width is incorrectly computed for radial trees by somehow using measurements from the non-radial layout.

In FLEA, this problem pushes the entire layout right off the page.

Here is a picture, showing the svg element in blue:
radial-svg-size

More informative collapsed subtrees

Currently, when I collapse a subtree, it is difficult to know what is inside that tree quickly without re-inflating. It would be helpful if there was at least some sort of tooltip to inform the user (or person/individual for those sensitive to the word user) of the branches that live within.

screen shot 2017-11-21 at 12 30 08 pm

Demo HTML page does not work

On page https://bl.ocks.org/spond clicking on "Hello World" example opens a page without any tree display, with console message ReferenceError: require is not defined from phyloTree.js line 1

Tried on Firefox ESR 52.7.3 and on Chrome 66.0.3359.139 (Official Build) (64-bit)

need a way to scale bubble sizes

Leaf nodes with large copy numbers get huge bubbles. I have attempted a fix in this commit: kemaleren/phylotree.js@947d5cf. Not submitting a pull request yet, because changing relative_node_span changes the extent. For some reason, it is making the trees much wider than before.

Here is an example of the problem. The tree has a node with a copy number of 7,757.
huge-bubble-size

And the same tree in radial layout:
radial-bubbles

Callback when layout is done

Hi
I was wondering if there is a callback option for tree.layout() or tree.update() ?
I am trying to add some function that use the tree's nodes coordinates so I have to make sure it's already drawn.
thank you
Tal

color branches and annotate internal node with bootstrap values

Hi,
Could you provide examples on how to:

  • color branches according to clustering. A clustering is usually in the form of a list of indices which associates to each data a cluster id.
  • add bootstrap values to internal node; convenient to easily see whether or not a specific subtree is statistically significant.

Possibility to add metadata overlay?

Hi,
we've been working with phylotree for a while now and ran into the need to display metadata in addition to the phylogram. An initial hack got us 80% towards that goal (see below) but it is still very buggy and does not work on the circular tree at all. I was wondering if such a feature, or an interface/plugin to customize any sort of data overlay would a) be of interest to others and b) could be added to the code base. We are unfortunately not savvy enough to just fork and add the feature ourselves.

Example of our current hack, showing 5 metadata points overlaid with the sample in the tree. Other ideas like colored symbols or even pie charts per leaf would be great to have in the future.
image

Thanks,
Patrick

Multiple styles on node name

Hello
I would like to display a node label that contains a text with several colors/styles.
Is it possible to do it?
thank you

Create option to export selected subtree

If an entire subtree is selected, we should provide the option to export the subtree's newick string. It would be helpful when trying to report on specific parts of the phylogeny.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.