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

Running error when run austechia.ipynb #4

Closed
virologist opened this issue Nov 7, 2019 · 3 comments
Closed

Running error when run austechia.ipynb #4

virologist opened this issue Nov 7, 2019 · 3 comments

Comments

@virologist
Copy link

Hi, there

I meet an error when I am running the austechia.ipynb.
The error showing like this:
Tangled chains (sequential tanglegrams)
 address=r'https://raw.githubusercontent.com/evogytis/fluB/master/data/mcc%%20trees/InfB_%st_ALLs1.mcc.tre'%(segment) ## address of example tree

Thanks

@evogytis
Copy link
Owner

evogytis commented Nov 8, 2019

Could you paste the actual error message? That bit of code runs fine for me in both Python 2.7 and Python 3. Were edits made to the code that precedes the cell that loads the trees?

@virologist
Copy link
Author

Thank you very much for your response. I rerun this script and I made it.
I am learning baltic now. My purpose is repeating the published data to make a phylogenetic-incongruence tree and then make my own incongruence tree.
However, when I was trying to run another baltic script and failed in one step. I think their trees were generated from IQ-tree. Here is the code I obtain and have a slightly modified. This baltic.py was obtained from here.

from glob import glob
import imp
bt = imp.load_source('baltic', 'E:/Bio/Jupyter/phylogenetic-incongruence-master/baltic.py')
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/phylogenetic-incongruence-master/*.nwk')
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)}

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])

Then I meet an error.

File "", line 1
def euclidean((x1,y1),(x2,y2)):
^
SyntaxError: invalid syntax

Could you please take a look and help me figure it out?
Again, Thank you.

@evogytis
Copy link
Owner

The error you're getting is a Python syntax error, so nothing to do with baltic. It threw a similar error for me but I removed the nested parentheses in the euclidean function so now it says def euclidean(x1, y1, x2, y2) and doesn't throw the error near there. Not sure if that will solve it for you or not, but I'm closing this issue because the source of the problem isn't baltic.

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

2 participants