morrislab / pairtree

Pairtree is a method for reconstructing cancer evolutionary history in individual patients, and analyzing intratumor genetic heterogeneity. Pairtree focuses on scaling to many more cancer samples and cancer cell subpopulations than other algorithms, and on producing concise and informative interactive characterizations of posterior uncertainty.
MIT License
37 stars 11 forks source link

Is there a way to overlay samples' ratio or frequency on the tree nodes? #23

Closed ba3lwi closed 2 years ago

ba3lwi commented 2 years ago

Hi,

Thank you for developing such a great tool.

Is there a way to overlay samples' ratio or frequency on the tree nodes? i.e. color nodes of the tree based on the ratio of contribution from each sample?

ethanumn commented 2 years ago

There is -- though it's undocumented. It can be done in one of two ways.

  1. If you've already run plottree, then you can modify the html of the file that is outputted. In order to do this, you need to modify the variable tree_json which you can find in the file by opening it in a text editor and performing a search (CTRL F). This variable is a JSON (Javascript Object Notation) string, which consists of key-value pairs. In order to assign colors to each sample such that the tree will overlay each node with an opacity that's proportional to the samples contribution to the subclone, we need to modify the value of the key samp_colours. The value needs to be a list of lists, where each sublist contains the name of the sample, then the color that you'd like assigned to it. Here's an example of what this should look like: "samp_colours": [["Sample 1", "#E53F1C"], ["Sample 2", "#72EC06"], ["Sample 3", "#0698EC"]]. The names of the samples mentioned in each sublist need to match the names of the samples you provided in your parameters file (.params.json). The order is strict, where the first element in each sublist must be the sample name, and the second element in each sublist must be the color assigned to the sample.

  2. You can add the "samp_colours" key to your parameters file that you provided to pairtree (.params.json) and set its values to a list of lists where each sublist contains the name of the sample, then the color that you'd like assigned to it. This will look the same as the example above except it is placed into your parameter file along with your cluster assignments, garbage list, and list of sample names: "samp_colours": [["Sample 1", "#E53F1C"], ["Sample 2", "#72EC06"], ["Sample 3", "#0698EC"]]. Then if you run plottree and pass your parameters file with the samp_colors defined it should overlay the nodes in the tree accordingly.

Here's an example of how this will change the coloring of your tree outputted by plottree:

node-overlay

Similarly, you may want to specify a particular color for each subclone population shown in your tree. This can be done by specifying the key pop_colours either in the html file outputted by plottree, or by placing it in your parameters file prior to running plottree. The only difference here is you'll use a single list containing hex colors, where the order of the colors corresponds to the order of the clusters listed in your parameters file. Here's an example of what this should look like: "pop_colours": ["#E53F1C", "#72EC06", "#0698EC", "#EC06D0","#ECE430"].

Here's an example of how this will change the coloring of your tree outputted by plottree:

pop-colors