-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathBA7G.py
48 lines (36 loc) · 1.59 KB
/
BA7G.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# Copyright (C) 2017-2023 Greenweaves Software Pty Ltd
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>
''' BA7G Adapt SmallParsimony to Unrooted Trees http://rosalind.info/problems/ba7g/'''
from rosalind import LabeledTree
from phylogeny import SmallParsimony, AdaptSmallParsimonyToUnrootedTrees
from BA7F import print_assignments
if __name__=='__main__':
def parse(input):
N=-1
lines=[]
for line in input:
if N==-1:
N=int(line.strip())
else:
lines.append(line.strip())
return N,LabeledTree.parse(N,lines,bidirectional=True)
with open('c:/Users/Weka/Downloads/rosalind_ba7g(3).txt') as f:
N,T=parse(f)
a,b,root,T1= AdaptSmallParsimonyToUnrootedTrees(N,T)
score,assignments=SmallParsimony(T1)
# This is the fixup at the end of processing
assignments.unlink(root,b)
assignments.unlink(root,a)
assignments.link(a,b)
print (score)
print_assignments(assignments)