Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from nwck_class_3 import Newick_Tree
class Parsimony:
def __init__(self,tree,sequences,alphabet,length):
self.sequences=sequences
self.seq=dict()
self.costV=dict()
self.cost=dict()
self.tree=tree
self.alphabet=alphabet
self.N=length
for taxon in tree.labels.keys():
self.seq[tree.labels[taxon]]=self.sequences[taxon]
for i in range(self.N):
self.costV[(tree.labels[taxon],i,sequences[taxon][i])]=0
self.cost[(tree.labels[taxon],i)]=0
self.sankoff()
def sankoff(self,base=None):
if not base:
base=self.tree.root
if len(self.tree.dtree[base])==0:
return
for v in self.tree.dtree[base]:
self.sankoff(v)
for i in range(self.N):
for c in self.alphabet:
m=0
for v in self.tree.dtree[base]:
if (v,i,c) in self.costV:
m=m+min(self.costV[(v,i,c)],self.cost[(v,i)]+1)
else:
m=m+self.cost[(v,i)]+1
self.costV[(base,i,c)]=m
self.cost[(base,i)]=min([self.costV[(base,i,c)] for c in self.alphabet])
return
def score(self):
return sum([self.costV[(self.tree.root,i,self.sequences[self.tree.taxa[self.tree.node_to_taxon[self.tree.root]]][i])] for i in range(self.N)])