Comments (3)
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?
from baltic.
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.
from baltic.
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.
from baltic.
Related Issues (20)
- Write basic unit tests
- Set up continuous integration HOT 1
- Add magic methods to baltic classes
- Set up sphinx for auto-documentation of classes and functions from docstrings
- Adding extra elements on tree plots HOT 8
- Booleans as values of traits dict incorrectly output to string. HOT 1
- loadJSON translation needs to be accessing `node_attrs` within traits instead of traits directly
- loadJSON needs to be updated for the new nextstrain json format HOT 2
- Export back to NextStrain JSON HOT 3
- AttributeError: 'NoneType' object has no attribute 'traverse_tree' HOT 2
- TypeError: unsupported operand type(s) for -: 'function' and 'int' HOT 2
- Add exports HOT 2
- No way of adding text to circular tree. HOT 2
- Unicode Errors
- Take singleton as a baltic tree object
- commonAncestor returns wrong node when MRCA is root of tree HOT 1
- Tree regex tricky to use HOT 1
- Ascending branch sort? HOT 4
- Typo in assertion that checks if new coordinates were computed by the drawTree function HOT 1
- Unable to extract assigned color, clade id, and leaf id into tsv/dataframe HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baltic.