Code Monkey home page Code Monkey logo

Comments (3)

evogytis avatar evogytis commented on June 8, 2024

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.

virologist avatar virologist commented on June 8, 2024

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.

evogytis avatar evogytis commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.