Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F1-recombination.ipynb running error #2

Open
virologist opened this issue Nov 13, 2019 · 0 comments
Open

F1-recombination.ipynb running error #2

virologist opened this issue Nov 13, 2019 · 0 comments

Comments

@virologist
Copy link

Hi, there
I am trying to repeat the figure generated by F1-recombination.ipynb and generate my tangle tree by baltic. I met an error which indicates

def euclidean((x1,y1,x2,y2):
^
SyntaxError: invalid syntax

Here is the code I run. The baltic.py was obtained from the evogytis.

import imp
bt = imp.load_source('baltic', 'E:/Bio/Jupyter/baltic/baltic.py')
from glob import glob
from collections import defaultdict
import re
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import matplotlib as mpl
import pickle
%matplotlib inline
import random
from pprint import pprint

treefiles = glob('E:/Bio/Jupyter/siv-cst/RAxML_bestTree*')
treefiles.sort(key=lambda x: int(x.split('_')[-2]))
def make_bt_tree(treefile):
t = bt.tree()
bt.make_tree(open(treefile, 'r').readlines()[0].strip(), t)
t.treeStats() ## initial traversal, checks for stats
t.sortBranches() ## traverses tree, sorts branches, draws tree
return t
trees = { i:make_bt_tree(treefile) for i,treefile in enumerate(treefiles)}

After this step, I got the same results as yours.

Tree height: 4.249024
Tree length: 27.026251
Numbers of objects in tree: 124 (61 nodes and 63 leaves)
...................

However, when I move to the next step I met this error. I didn't modify any code of this cell.

def euclidean((x1,y1),(x2,y2)):
return ((float(x2)-float(x1))**2+(float(y1)-float(y2))**2)**0.5
def sum_tip_distances(tree1,tree2):
tree1_tips = { k.numName: k for k in tree1.Objects if k.branchType=='leaf' }
tree2_tips = { k.numName: k for k in tree2.Objects if k.branchType=='leaf' }
shared_tips = set(tree1_tips.keys()).intersection(set(tree2_tips.keys()))
total_dist = 0.0
for t in shared_tips:
total_dist += euclidean( (tree1_tips[t].x, tree1_tips[t].y), (tree2_tips[t].x, tree2_tips[t].y) )
return total_dist
def untangle(tree1, tree2):
current_distance = sum_tip_distances(tree1, tree2)
for n in sorted(tree2.nodes,key=lambda x: -x.height):
if n.parent=='Root':
continue
n.rotate()
tree2.drawTree()
new_distance = sum_tip_distances(tree1, tree2)
if new_distance <= current_distance:
current_distance = new_distance
continue
else:
n.rotate()
tree2.drawTree()
for i in range(1,len(trees)):
untangle(trees[i-1], trees[i])

Could you please help me figure it out?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant