Learning a Newick Tree

PhD is a tough battle, a lot of days I debate whether I am smart enough for this line of work? I had this crazy idea but it crumbled before me today and it actually did make me really sad. I’m going through some crazy emotions right now and maybe my code is getting weirder or better? You can decide. Something that came out of this was I needed to model how cheminformatics relates to things.

So I went with a Newick tree was some tree algorithm to draw phylogenetic trees for sequences that aligned with each other. It can tell relations like children, parents, grandparents, and so on….the goal was to see if I can use it to represent cheminformatics’s placement in the world.

Newick tree comes like a 1D SMILES format — very similar architecture with parenthesis adjoining things that are bound to it like so:

(Cheminformatics:1,(MolecularDynamics:1, OrganicChemistry: 1))

In this instance we have Cheminformatics starting as the parent and MolecularDynamics and OrganicChemistry as the children. Well after copying this pattern repeatedly, I came up with this as my .tre file.

(Cheminformatics:1,(MolecularDynamics:1,(p38-alpha:1, (RSCB:1, (X-RayCrystallography: 1, SWISSMODEL:1, PROPKA:1), MAPK:1, ATP:1, ImidazoleInhibitors:1), Chamber:1,(CHARMM:1, (AtomTyping:1, PenaltyScores: 1, (Charge:1, Geomtery:1), Compass:1):0.5, Amber:1):0.5):0.5):0.5, SMILES:1,(EnamineDB: 1, DimorphiteDL: 1, (Protonation:1), IUPAC:1,(Synthesis:1, (ReactionPathway:1, NMR:1,(NOESY 2D: 1, Imidazole: 1)), SMARTS:1)), (Python:1, (Plotly:1, RDKit:1, Modin:1, CuDF:1, TinyDB:1, (BufferedMemoryDBs:1))), (ContinousIntegration: 1, (TravisCI: 1, ConcourseCI:1), Apache Spark: 1));

Next, I want to visualize it. I went with toytree and it was actually pretty simple.

import toyplot
import toytree
ttre = toytree.tree('test.tre', seed=100)
ttre.draw(
layout='c',
edge_type='b',
edge_style={
'stroke': toyplot.color.brewer.palette("BlueGreen")[4],
'stroke-opacity': 0.75,
"stroke-width": 12.75,
"stroke-dasharray": "2,5" },
node_markers="c",
node_sizes=[16 if i else 0 for i in ttre.get_node_values()],
node_style={"stroke": "black"},
width=2500,
height=2500,
tip_labels_style={
"fill": "#262626",
"font-size": "30px",
"-toyplot-anchor-shift": "15px",}
);

Makes it look something like this:

Full Code with Colors: don’t judge me on code the colors — I had to code fast:

import toytree
ttre = toytree.tree('test.tre', seed=100)
import toyplot
# # edge mapping 1: enter a dictionary mapping clade members to colors
ecolors = ttre.get_edge_values_mapped({
1: toytree.colors[0], # <- using tips to define a clade
2: toytree.colors[1],# <- using tips to define a clade
11: toytree.colors[2],
3: toytree.colors[3],
4: toytree.colors[4],
5: toytree.colors[5],
6: toytree.colors[6],
7: toytree.colors[7],
8: toytree.colors[1],
9: toytree.colors[2],
10: toytree.colors[3],
11: toytree.colors[4],
12: toytree.colors[5],
13: toytree.colors[6],
14: toytree.colors[7],
15: toytree.colors[1],
15: toytree.colors[2],
16: toytree.colors[3],
17: toytree.colors[4],
18: toytree.colors[5],
19: toytree.colors[6],
20: toytree.colors[7],
21: toytree.colors[1],
22: toytree.colors[2],
23: toytree.colors[3],
24: toytree.colors[4],
25: toytree.colors[5],
26: toytree.colors[6],
27: toytree.colors[7],
28: toytree.colors[1],
29: toytree.colors[2],
30: toytree.colors[3],
31: toytree.colors[4],
32: toytree.colors[5],
33: toytree.colors[6],
34: toytree.colors[7],
35: toytree.colors[1],
})ttre.draw(
layout='c',
edge_type='b',
edge_style={
'stroke': toyplot.color.brewer.palette("BlueGreen")[4],
'stroke-opacity': 0.75,
"stroke-width": 12.75,
"stroke-dasharray": "2,5" # size of dash, spacing of dashes
},
edge_colors=ecolors,
node_markers="c",
node_sizes=[16 if i else 0 for i in ttre.get_node_values()],
node_style={"stroke": "black"},
width=2500,
height=2500,
tip_labels_style={
"fill": "#262626",
"font-size": "30px",
"-toyplot-anchor-shift": "15px",
}
);

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store