Skip to content

Commit

Permalink
#46 Started work on qrtd
Browse files Browse the repository at this point in the history
  • Loading branch information
weka511 committed Nov 11, 2020
1 parent 7b147e4 commit 4ad6429
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ NB: functions generally use zero based indexing; [Rosalind](http://rosalind.info
| ---- | --------------- | ------------------------------------------------|
|alph|alph.py|[Alignment-Based Phylogeny](http://rosalind.info/problems/alph/) WIP|
|chbp|chbp.py phylogeny.py|[Character-Based Phylogeny](http://rosalind.info/problems/chbp/) WIP|
|cntq|chtq.py |[Counting Quartets](http://rosalind.info/problems/cntq/) WIP|
|cntq|chtq.py |[Counting Quartets](http://rosalind.info/problems/cntq/)|
|cset|cset.py|[Fixing an Inconsistent Character Set](http://rosalind.info/problems/cset/) WIP|
|cstr|cstr.py phylogeny.py|[Creating a Character Table from Genetic Strings](http://rosalind.info/problems/cstr/)|
|ctbl|ctbl.py phylogeny.py|[Creating a Character Table](http://rosalind.info/problems/ctbl/) |
Expand Down
5 changes: 2 additions & 3 deletions phylogeny.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def ds(adj1,adj2):

n = len(species)
seiceps = {species[i]:i for i in range(n)}
tree1 = replace_leaves(create_adj(parse(newick1,start=n)))
tree2 = replace_leaves(create_adj(parse(newick2,start=n)))

return ds(tree1,tree2)
return ds(replace_leaves(create_adj(parse(newick1,start=n))),
replace_leaves(create_adj(parse(newick2,start=n))))
44 changes: 32 additions & 12 deletions qrtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,52 @@
import argparse
import os
import time
from helpers import read_strings
from helpers import read_strings
from phylogeny import create_adj, parse

def qrtd(species,newick1,newick2):

def q(n):
return (n*(n-1)*(n-2)*(n-3))/(4*3*2*1)

def replace_leaves(adj):
return {parent:sorted([seiceps[child] if child in seiceps else child for child in children]) for parent,children in adj.items() }

def dq(T1,T2):
return q(count_leaves(T1)) + q(count_leaves(T2)) -2 * shared_quartets(T1,T2)

def count_leaves(adj):
return sum([1 for children in adj.values() for child in children if child<n])

def shared_quartets(T1,T2):
return 0

n = len(species)
seiceps = {species[i]:i for i in range(n)}
tree1 = replace_leaves(create_adj(parse(newick1,start=n)))
tree2 = replace_leaves(create_adj(parse(newick2,start=n)))
return dq(tree1,tree2)


if __name__=='__main__':
start = time.time()
parser = argparse.ArgumentParser('....')
parser.add_argument('--sample', default=False, action='store_true', help='process sample dataset')
parser.add_argument('--extra', default=False, action='store_true', help='process extra dataset')
parser.add_argument('--rosalind', default=False, action='store_true', help='process Rosalind dataset')
args = parser.parse_args()
if args.sample:
pass
print(qrtd(
'A B C D E'.split(),
'(A,C,((B,D),E));',
'(C,(B,D),(A,E));'
))


if args.extra:
Input,Expected = read_strings('data/....txt',init=0)
...

if args.rosalind:
Input = read_strings(f'data/rosalind_{os.path.basename(__file__).split(".")[0]}.txt')

Result = None
Result = qrtd(Input[0].split(), Input[1], Input[2])
print (Result)
with open(f'{os.path.basename(__file__).split(".")[0]}.txt','w') as f:
for line in Result:
f.write(f'{line}\n')
f.write(f'{Result}\n')

elapsed = time.time() - start
minutes = int(elapsed/60)
Expand Down

0 comments on commit 4ad6429

Please sign in to comment.