from gram import TreeGram read("((A, B), (C, D), (E, (F, G)));") t = var.trees[0] tg = TreeGram(t, showNodeNums=False) tg.font = 'palatino' tg.baseName = 'bracket2' t.draw() longText1 = """A long note \ about this grouping of taxa, \ composed of A and B""" b = tg.setBracket(2, 3, text=longText1, leftNode=None) b.label.style = None b.label.textSize = 'scriptsize' b.label.anchor = 'west' b.label.textWidth = 3.0 b.label.innerSep = 0.2 b = tg.setBracket(6, 10, text='Rotated label', leftNode=None, rotated=True) b.label.textSize = 'large' tg.bracketsLineUp = False #tg.showTextAnchor = True tg.png() tg.svg()
#'node right' #'node upper right' #'node lower right' #'node upper left' #'node lower left' my_gX = 4.0 from gram import TreeGram myScale = 3.5 read('(((A, B)xy, (C, (D, E, F)wxyz, G))wxyz, (H, (I, J)xy)wxyz);') t = var.trees[0] tA = t.dupe() tg = TreeGram(tA) tg.baseName = 'smartNodeLabels' tg.doSmartLabels = False # default True tg.scale = myScale #tg.png() #tg.svg() tB = t.dupe() tgB = TreeGram(tB) tgB.baseName = 'smart_semi' tgB.doSmartLabels = 'semi' # default True tgB.scale = myScale #tgB.png() #tgB.svg() tg.grams.append(tgB) tgB.gX = my_gX
from gram import TreeGram read('(A, (B, (C, (D, (E, F))85)));') t = var.trees[0] tg = TreeGram(t) tg.font = 'helvetica' tg.baseName = 'simplified' tg.leafLabelSize = 'tiny' tg.render() tg.styleDict['bracket label'].textSize = 'Large' for n in t.iterLeavesNoRoot(): n.label.rawText = ' ' t.node(5).label.rawText = 'Euryarchaeota' t.node(7).label.rawText = 'Crenarchaeota / eocytes' t.node(6).label.anchor = 'north east' g = tg.setBracket(1, 3, text='Bacteria', leftNode=0) g.fill = 'blue!15' g = tg.setBracket(5, 7, text='Archaea', leftNode=4) g.fill = 'orange!20' g = tg.setBracket(9, 10, text='Eukaryotes', leftNode=8) g.fill = 'green!30' tg.wrapLeafLabelsAt = 1.3 # svg can't do this tg.pdf() tg.wrapLeafLabelsAt = None tg.svg()
from gram import TreeGram read("((A,B)Wxy,(C,(D,E, F)Xyz)Vwxy);") t = var.trees[0] tg = TreeGram(t.dupe(),showNodeNums=True) tg.baseName = 'stylesForInternalNodes' tgB = TreeGram(t.dupe()) tgB.tree.node(1).label.myStyle = 'node lower left' tgB.tree.node(4).label.myStyle = 'node right' tgB.tree.node(6).label.myStyle = 'node lower right' tgB.gX = 4. tg.grams.append(tgB) tg.svg()
from gram import TreeGram read('((A, B)uvw, (C, D)xyz);') t = var.trees[0] tg = TreeGram(t.dupe(),showNodeNums=True) tg.baseName = 'nodeLabels' tgB = TreeGram(t.dupe()) tgB.tree.node(1).label.anchor = 'north east' tgB.tree.node(4).label.anchor = 'west' tgB.gX = 3. tg.grams.append(tgB) # tg.png() tg.svg()
from gram import TreeGram,TreeGramRadial,Gram read("((A,B)ab,C,(D,E)de)m;") t = var.trees[0] t.node(1).br.uName = 'X' t.node(5).br.uName = 'Y' tg = TreeGram(t, scale=7.) print "a", tg.internalNodeLabelSize tg.baseName = 'twoTreesII' t = t.dupe() tgB = TreeGramRadial(t, scale=8., slopedBrLabels=True, rotate=90) print "b", tg.internalNodeLabelSize tgB.tree.root.label.yShift = 0.1 tgB.gX = 4.8 tgB.gY = -1.5 gr = Gram() g = gr.text(r'$\Longleftrightarrow$', 0, 0) # LaTeX symbol gr.text('equivalence', 0, 0.5) gr.gX = 3.5 gr.gY = 1.0 tg.grams.append(tgB) tg.grams.append(gr) tg.png() g.rawText = '⇔' # unicode symbol tg.svg()
#'node right' #'node upper right' #'node lower right' #'node upper left' #'node lower left' my_gX = 4.0 from gram import TreeGram myScale = 3.5 read('(((A, B)xy, (C, (D, E, F)wxyz, G))wxyz, (H, (I, J)xy)wxyz);') t = var.trees[0] tA = t.dupe() tg = TreeGram(tA) tg.baseName = 'smartNodeLabels' tg.doSmartLabels = False # default True tg.scale = myScale #tg.png() #tg.svg() tB = t.dupe() tgB = TreeGram(tB) tgB.baseName = 'smart_semi' tgB.doSmartLabels = 'semi' # default True tgB.scale = myScale #tgB.png() #tgB.svg() tg.grams.append(tgB) tgB.gX = my_gX
t.draw() nB = t.node('B') nB.name = """This is the very long name of the node that used to be `B'. It needs to have the text wrapped, but that affects the spacing of the leaf taxa. Both wrapping and spacing are handled by setting \\texttt{wrapLeafLabelsAt}.""" nE = t.node('E') thePng = "../../frownie_tongue.png" nE.name = r"\includegraphics[scale=0.3]{%s}" % thePng tg = TreeGram(t, showNodeNums=False) tg.font = 'palatino' tg.latexUsePackages.append('graphicx') tg.wrapLeafLabelsAt = 3.5 tg.baseName = 'fatTaxa' #tg.grid(0,0,5,6) # The style gets in the way, so it is # auto-deleted. With no style, the default # anchor is center, so change that. nE.label.anchor = 'west' tg.extraYSpaceAtNode(nE, extra=1.1) b = tg.setBracket(4, 5, text='A bracket', leftNode=None, rotated=True) bText = r"""Since the size of the picture is unknown to Gram, it needed to have its \texttt{extraYSpaceAtNode} set explicitly. This bracket also needed to have its \texttt{topOverRide} and \texttt{rigthOverRide} set to some
from gram import TreeGram,TreeGramRadial tString = "((A, (B, (C, ((D, E), F)))), G, H);" read(tString) t = var.trees[0] t2 = t.dupe() tg = TreeGram(t) tg.baseName = 'parallelAndRadial' #tg.grid(0,-2,10,6) tgr = TreeGramRadial(t2, maxLinesDim=3.8) tgr.gX = 5.0 tgr.gY = -1.0 tg.grams.append(tgr) if 1: g = tg.text("Parallel, using the", 0.5, -1.) g.anchor = 'west' g = tg.text("TreeGram class", 0.5, -1.6) g.anchor = 'west' g = tg.text("Radial, using the", 6.5, -1.) g.anchor = 'west' g = tg.text("TreeGramRadial class", 6.5, -1.6) g.anchor = 'west' tg.png() tg.svg()
from gram import TreeGram var.nexus_getAllCommandComments = True var.nexus_readBeastTreeCommandComments = True read('treeannotatorOut') t = var.trees[0] tg = TreeGram(t) tg.baseName = 'beastA' for n in t.iterNodes(): if not n.isLeaf: tg.setNodeConfidenceBox(n) tg.pdf() #tg.svg()
#the following needs modules from p4: from p4 import * nC.name = r'Ab{\textcolor{blue}{cde}}fgh {\textcolor{blue}{\ding{110}}}' #recognizes string to recolor parts of text and adds a square at the end tg = TreeGram(t) #tgr = TreeGramRadial(t) #for radial trees n = t.node('B') tg.setBranchULabel(n, 'uLabel') #another way using a function, when tg has been initialized #node names - specified in newick trees? - can be accessed and modified: #n.label.color='red!50' #n.label.textSize='tiny' #big enough #t.doSmartLabels=True #or 'semi'; not sure if not n.label.doSmartLabels, or even tg.doSmartLabels #tg.fixTextOverlaps=True tg.baseName = 'myTree' #conf files to set some user defaults, such as font (def Helvetica) #other useful things: #documentFontSize #pdfViewer #or set these in individual gram scripts: tg.documentFontSize = 5.5 #individually: #tg.leafLabelSize = 'footnotesize' #LARGE compared to document fontsize #tg.internalNodeLabelSize = 'tiny' #tg.branchLabelSize = 'scriptsize' tg.scale=None #use number to set 1.0 scale length in cm - then you can have the same scale for several trees tg.setScaleBar(length=0.2, xOffset=0.0, yOffset=-0.6) #but mostly default values are okay tg.yScale=0.7 #this is the spacing between leaves
t.draw() nB = t.node('B') nB.name = """This is the very long name of the node that used to be `B'. It needs to have the text wrapped, but that affects the spacing of the leaf taxa. Both wrapping and spacing are handled by setting \\texttt{wrapLeafLabelsAt}.""" nE = t.node('E') thePng = "../../frownie_tongue.png" nE.name = r"\includegraphics[scale=0.3]{%s}" % thePng tg = TreeGram(t, showNodeNums=False) tg.font = 'palatino' tg.latexUsePackages.append('graphicx') tg.wrapLeafLabelsAt = 3.5 tg.baseName = 'fatTaxa' #tg.grid(0,0,5,6) # The style gets in the way, so it is # auto-deleted. With no style, the default # anchor is center, so change that. nE.label.anchor = 'west' tg.extraYSpaceAtNode(nE, extra=1.1) b = tg.setBracket(4, 5, text='A bracket', leftNode=None, rotated=True) bText = r"""Since the size of the picture is unknown to Gram, it needed to have its \texttt{extraYSpaceAtNode} set explicitly. This bracket also needed to have its \texttt{topOverRide} and \texttt{rigthOverRide} set to some appropriate values in order to
from gram import TreeGram read("((A,B)89,C,(D,E)95);") t = var.trees[0] tg = TreeGram(t) tg.font = 'palatino' tg.documentFontSize = 10 tg.baseName = 'minimal_palatino' tg.png() tg.svg()
var.nexus_getAllCommandComments = True var.nexus_readBeastTreeCommandComments = True read('treeannotatorOut') t = var.trees[0] # The two cBoxes on the left are too big, and dominate the figure. # Make them text, as a node labels, instead. n = t.root n.name = "(%.1f, %.1f)" % (n.height_95_HPD[1], n.height_95_HPD[0]) n = t.node(1) n.name = "(%.1f, %.1f)" % (n.height_95_HPD[1], n.height_95_HPD[0]) tg = TreeGram(t) tg.font = 'palatino' tg.documentFontSize = 10 tg.baseName = 'beastB' for nNum in [3, 4, 6, 9]: n = t.node(nNum) tg.setNodeConfidenceBox(n) # Define a style from gram import GramText tg.render() tb = GramText('myStyle') tb.textWidth = 1. tb.textSize = 'scriptsize' tb.anchor = 'west' tb.name = 'wrappedNode' tg.styleDict['wrappedNode'] = tb for nNum in [0, 1]:
from gram import TreeGram read("((A,B)Wxy,(C,(D,E, F)Xyz)Vwxy);") t = var.trees[0] tg = TreeGram(t.dupe(), showNodeNums=True) tg.baseName = 'stylesForInternalNodes' tgB = TreeGram(t.dupe()) tgB.tree.node(1).label.myStyle = 'node lower left' tgB.tree.node(4).label.myStyle = 'node right' tgB.tree.node(6).label.myStyle = 'node lower right' tgB.gX = 4. tg.grams.append(tgB) tg.svg()
from p4 import * read("((A,B)89,C,(D,E)95);") t = var.trees[0] n = t.node('A') n.name = r'Ab{\textcolor{blue}{cde}}fgh {\textcolor{blue}{\ding{110}}}' #n.name = r'Ab<tspan fill="blue">cde</tspan>fgh <tspan fill="blue"> ⬛</tspan>' #n.name = r'Ab<tspan fill="blue">cde</tspan>fgh <tspan fill="blue"> ■</tspan>' t.draw() from gram import TreeGram tg = TreeGram(t, scale=None, showNodeNums=False, widthToHeight=0.67) tg.latexUsePackages.append('pifont') tg.baseName = "multiBrackets" #tg.showTextBB=True #tg.showTextAnchor=True #tg.pdflatexOutputGoesToDevNull=False #tg.grid(0,0,4,4) g = tg.setBracket(t.node('D').nodeNum,7, text="Bracket DE", rotated=True) g = tg.setBracket(t.node('B').nodeNum,6, text="Bracket BCD", rotated=True) g.rightExtra = 0.7 g = tg.setBracket(2,4, text="Bracket", rotated=False) tg.bracketsLineUp = False #tg.render() #tg.styleDict['bracket label'].textSize = 'tiny' tg.pdf() n.label.rawText = r'Ab<tspan fill="blue">cde</tspan>fgh <tspan fill="blue"> ▇</tspan>' tg.svg()
from gram import TreeGram read("((A, B), (C, D), (E, (F, G)));") t = var.trees[0] tg = TreeGram(t, showNodeNums=True) tg.baseName = 'bracket1' t.draw() tg.setBracket(2, 3, text='these brackets line', leftNode=1) tg.setBracket(6, 10, text='up with each other', leftNode=None, rotated=True) tg.pdf() tg.svg()
from gram import TreeGram read('easyTreeA.nex') read('easyTreeB.nex') tA = var.trees[0] # make a duplicate tree, as tA is used again below tg = TreeGram(tA.dupe()) tg.baseName = 'combineSplitSupports' tg.tree.node(8).label.myStyle = 'node upper right' tg.tree.node(10).label.myStyle = 'node right' tB = var.trees[1] tgB = TreeGram(tB) tgB.gY = -7.5 tg.grams.append(tgB) tA.makeSplitKeys() tB.makeSplitKeys() nodeForSKDict = {} for n in tB.iterInternalsNoRoot(): nodeForSKDict[n.br.splitKey] = n for n in tA.iterInternalsNoRoot(): theNode = nodeForSKDict.get(n.br.splitKey) if theNode: n.name += '/%s' % theNode.name tgX = TreeGram(tA, showNodeNums=False) tgX.tree.node(8).label.myStyle = 'node upper right' tgX.tree.node(10).label.myStyle = 'node right' tgX.gY = -15. tg.grams.append(tgX)
from gram import TreeGram read("((A,B)89,C,(D,E)95);") t = var.trees[0] tg = TreeGram(t) tg.baseName = 'minimal' tg.pdf()
from gram import TreeGram read('tinyTree.nex') t = var.trees[0] tg = TreeGram(t) tg.baseName = 'tinyIII' # styleDict is empty until you render(). tg.render() # Grab the leaf style ... st = tg.styleDict['leaf'] # ... and change it st.textShape = 'itshape' #tg.pdf() tg.svg()
from gram import TreeGram read("(((A, B), (C, D)));") t = var.trees[0] tg = TreeGram(t) tg.baseName = 'scaleBar' tg.grid(-1, -1, 3, 3) tg.setScaleBar(length=0.1, yOffset=-0.0) tg.pdf() tg.svg()
from gram import TreeGram read("((A,B)89,C,(D,E)95);") t = var.trees[0] tg = TreeGram(t) tg.font = 'palatino' tg.documentFontSize = 10 tg.baseName = 'minimal_palatino' tg.png() tg.svg()
from p4 import * read("((A,B)89,C,(D,E)95);") t = var.trees[0] n = t.node('A') n.name = r'Ab{\textcolor{blue}{cde}}fgh {\textcolor{blue}{\ding{110}}}' #n.name = r'Ab<tspan fill="blue">cde</tspan>fgh <tspan fill="blue"> ⬛</tspan>' #n.name = r'Ab<tspan fill="blue">cde</tspan>fgh <tspan fill="blue"> ■</tspan>' t.draw() from gram import TreeGram tg = TreeGram(t, scale=None, showNodeNums=False, widthToHeight=0.67) tg.latexUsePackages.append('pifont') tg.baseName = "multiBrackets" #tg.showTextBB=True #tg.showTextAnchor=True #tg.pdflatexOutputGoesToDevNull=False #tg.grid(0,0,4,4) g = tg.setBracket(t.node('D').nodeNum, 7, text="Bracket DE", rotated=True) g = tg.setBracket(t.node('B').nodeNum, 6, text="Bracket BCD", rotated=True) g.rightExtra = 0.7 g = tg.setBracket(2, 4, text="Bracket", rotated=False) tg.bracketsLineUp = False #tg.render() #tg.styleDict['bracket label'].textSize = 'tiny' tg.png() n.label.rawText = r'Ab<tspan fill="blue">cde</tspan>fgh <tspan fill="blue"> ⬛</tspan>' tg.svg()
from gram import TreeGram read('tinyTree.nex') t = var.trees[0] tg = TreeGram(t, showNodeNums=True) tg.baseName = 'tinyIV' tg.font = 'helvetica' if 1: # Make a new style, and put it in the # styleDict, with a name. from gram import GramText g = GramText("Xyx") g.textShape = 'itshape' g.textSize = 'small' g.color = 'white' g.draw = 'black' g.lineThickness = 'very thick' g.fill = 'blue!60' g.name = 'myleaf' g.anchor = 'west' tg.styleDict[g.name] = g # Apply the style to some of the leaves. for nNum in [1, 4, 5, 7]: # and one internal n = t.node(nNum) n.label.myStyle = 'myleaf' tg.png() tg.svg()
from gram import TreeGram tString = "(('TreeGram needs to', 'know how big this':0.05, 'text is':0.5), (Boojum, Snark):0.03);" t = func.readAndPop(tString) t.draw() tg = TreeGram(t) tg.font = 'helvetica' # for nNum in [2,3,4]: # n = t.node(nNum) # n.label.draw = True for nNum in [6,7]: n = t.node(nNum) n.label.textShape = 'itshape' brText = "in order to place this bracket" tg.setBracket(2,4, text=brText) tg.baseName = 'textHowBig' # tg.grid(0,0,5,4) tg.pdf() tg.svg()
from gram import TreeGram read("(((A, B, (C, D)'a node label'):0.01, E, F)'another node label', G);") t = var.trees[0] tg = TreeGram(t.dupe()) tg.baseName = 'overlapping' tgB = TreeGram(t.dupe()) tgB.fixTextOverlaps() tgB.gX = 6 tg.grams.append(tgB) #tg.png() tg.svgPxForCm = 50. tg.svg()
from gram import TreeGram tString = "(('TreeGram needs to', 'know how big this':0.05, 'text is':0.5), (Boojum, Snark):0.03);" t = func.readAndPop(tString) t.draw() tg = TreeGram(t) # for nNum in [2,3,4]: # n = t.node(nNum) # n.label.draw = True for nNum in [6, 7]: n = t.node(nNum) n.label.textShape = 'itshape' brText = "in order to place this bracket" tg.setBracket(2, 4, text=brText) tg.baseName = 'textHowBig' # tg.grid(0,0,5,4) tg.pdf() tg.svg()
from gram import TreeGram read('tinyTree.nex') t = var.trees[0] tg = TreeGram(t,showNodeNums=True) tg.baseName = 'tinyIV' tg.font = 'helvetica' if 1: # Make a new style, and put it in the # styleDict, with a name. from gram import GramText g = GramText("Xyx") g.textShape = 'itshape' g.textSize = 'small' g.color = 'white' g.draw = 'black' g.lineThickness = 'very thick' g.fill = 'blue!60' g.name = 'myleaf' g.anchor = 'west' tg.styleDict[g.name] = g # Apply the style to some of the leaves. for nNum in [1,4,5,7]: # and one internal n = t.node(nNum) n.label.myStyle = 'myleaf' tg.png() tg.svg()
from gram import TreeGram read('easyTreeA.nex') read('easyTreeB.nex') tA = var.trees[0] # make a duplicate tree, as tA is used again below tg = TreeGram(tA.dupe()) tg.baseName = 'combineSplitSupports' tg.tree.node(8).label.myStyle = 'node upper right' tg.tree.node(10).label.myStyle = 'node right' tB = var.trees[1] tgB = TreeGram(tB) tgB.gY = -7.5 tg.grams.append(tgB) tA.makeSplitKeys() tB.makeSplitKeys() nodeForSKDict = {} for n in tB.iterInternalsNoRoot(): nodeForSKDict[n.br.splitKey] = n for n in tA.iterInternalsNoRoot(): theNode = nodeForSKDict.get(n.br.splitKey) if theNode: n.name += '/%s' % theNode.name tgX = TreeGram(tA, showNodeNums=False) tgX.tree.node(8).label.myStyle = 'node upper right' tgX.tree.node(10).label.myStyle = 'node right' tgX.gY = -15. tg.grams.append(tgX)
from gram import TreeGram read("(((A, B, (C, D)'a node label'):0.01, E, F)'another node label', G);") t = var.trees[0] tg = TreeGram(t.dupe()) tg.baseName = 'overlapping' tgB = TreeGram(t.dupe()) tgB.fixTextOverlaps() tgB.gX = 6 tg.grams.append(tgB) #tg.png() tg.svgPxForCm = 50. tg.svg()
from gram import TreeGram read('((A, B), (C, (D, E)));') t = var.trees[0] t.draw() nB = t.node('B') nB.name = """synonym 1, another synonym, and a third synonym.""" nE = t.node('D') nE.name = """synonym 1, synonym 2, yet another synonym, and synonym 4""" tg = TreeGram(t, showNodeNums=False) tg.wrapLeafLabelsAt = 'comma' tg.baseName = 'wrapLeafLabelsAtComma' tg.png() # tg.svg() no workee
from gram import TreeGram read("((A,B)89,C,(D,E)96);") read("((H, I)73, (J, K)98, L);") t = var.trees[0] tg = TreeGram(t) tg.font = 'palatino' tg.documentFontSize = 10 tg.baseName = 'twoTrees' t = var.trees[1] tgB = TreeGram(t) tgB.baseName = 'doesntMatter' tgB.gX = 4. tg.grams.append(tgB) #tg.pdf() tg.svg()
from gram import TreeGram read("((A,B)89,C,(D,E)95);") t = var.trees[0] tg = TreeGram(t) tg.baseName = 'minimal' tg.png()
from gram import TreeGram read("((A,B)89,C,(D,E)95);") t = var.trees[0] tg = TreeGram(t) tg.font = 'cm' tg.baseName = 'minimal_cm' tg.png()
from gram import TreeGram read("tinyTree.nex") t = var.trees[0] tg = TreeGram(t) tg.baseName = 'brokenBranches' tg.setBrokenBranch(1) tg.setBrokenBranch(7) tg.png() tg.svg()