Skip to content

Commit

Permalink
weka511#109 continued
Browse files Browse the repository at this point in the history
  • Loading branch information
weka511 committed Feb 24, 2023
1 parent be46b59 commit 3893e9a
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 79 deletions.
9 changes: 5 additions & 4 deletions BA5I.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand All @@ -19,10 +21,9 @@

if __name__=='__main__':
from helpers import create_strings

strings = create_strings('ba5i',ext=1)
d,s1,t1 = overlap_assignment(strings[0],strings[1])
d,s1,t1 = overlap_assignment(strings[0],strings[1])
print ('{0}'.format(d))
print (s1)
print (t1)

print (t1)
8 changes: 5 additions & 3 deletions BA5J.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand All @@ -22,14 +24,14 @@ def ba5j(s,t):
return score,''.join(s1),''.join(t1)

if __name__=='__main__':
from helpers import create_strings
from helpers import create_strings

strings = create_strings('ba5j',ext=7)
score,s,t=ba5j(strings[0],strings[1])
print (score)
print (s)
print (t)
print (t)
with open('ba5j.txt','w') as o:
o.write('{0}\n'.format(score))
o.write('{0}\n'.format(s))
o.write('{0}\n'.format(t))
o.write('{0}\n'.format(t))
14 changes: 8 additions & 6 deletions BA5K.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019-2020 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -28,26 +30,26 @@
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:
print (FindMiddleEdge('PLEASANTLY','MEASNLY'))
# (4, 3) (5, 4)
if args.extra:

if args.extra:
Input,Expected = read_strings(f'data/middle_edge.txt',init=0)
((i,j),(k,l)) = FindMiddleEdge(Input[0],Input[1])
print (f'Calculated: (({i},{j}),({k},{l}))')
print (f'Expected {Expected[0]}')
# Expect (512,510)(513,511)

if args.rosalind:
Input = read_strings(f'data/rosalind_{os.path.basename(__file__).split(".")[0]}.txt')
((i,j),(k,l)) = FindMiddleEdge(Input[0],Input[1])
print (f'({i},{j}) ({k},{l})')
with open(f'{os.path.basename(__file__).split(".")[0]}.txt','w') as f:
f.write(f'({i},{j}) ({k},{l})\n')

elapsed = time.time() - start
minutes = int(elapsed/60)
seconds = elapsed - 60*minutes
print (f'Elapsed Time {minutes} m {seconds:.2f} s')
print (f'Elapsed Time {minutes} m {seconds:.2f} s')
32 changes: 17 additions & 15 deletions BA5L.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019-2020 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -34,21 +36,21 @@
def alignUsingLinearSpace(v,w,
replace_score = substitution_matrices.load("BLOSUM62"),
indel_cost = 5):

def isRightOrDownRight(midEdge):
return midEdge==RIGHT or midEdge==DOWNRIGHT

def isDownOrDownRight(midEdge):
return midEdge==DOWN or midEdge==DOWNRIGHT

# MiddleNodeAndEdge
#
# An adapter which replaces MiddleNode and MiddleEdge in the pseudocode, and calls FindMiddleEdge
def MiddleNodeAndEdge(top, bottom, left, right):
((i1,j1),(i2,j2)) = FindMiddleEdge(v[top:bottom],w[left:right],replace_score=replace_score,indel_cost=indel_cost)
direction = RIGHT if i1==i2 else DOWN if j1==j2 else DOWNRIGHT
return j1,direction

# LinearSpaceAlignment
#
# Find longest path between a substring of v[top] v[bottom-1]
Expand All @@ -58,29 +60,29 @@ def MiddleNodeAndEdge(top, bottom, left, right):
# bottom
# left
# right

def LinearSpaceAlignment(top, bottom, left, right):
if left==right:
return indel_cost*(bottom - top)
if top==bottom:
return indel_cost*(right-left)
middle = (left + right)//2
midNode,midEdge = MiddleNodeAndEdge(top, bottom, left, right)

LinearSpaceAlignment(top, midNode, left, middle)
# output midEdge
if isRightOrDownRight(midEdge):
middle += 1
if isDownOrDownRight(midEdge):
midNode+= 1
LinearSpaceAlignment(midNode, bottom, middle, right)
LinearSpaceAlignment(midNode, bottom, middle, right)

RIGHT = 0
DOWN = 1
DOWNRIGHT = 2
LinearSpaceAlignment(0,len(v)+1,0,len(w)+1)


if __name__=='__main__':
start = time.time()
parser = argparse.ArgumentParser('BA5L.py Align Two Strings Using Linear Space')
Expand All @@ -90,20 +92,20 @@ def LinearSpaceAlignment(top, bottom, left, right):
args = parser.parse_args()
if args.sample:
print (alignUsingLinearSpace('PLEASANTLY','MEANLY'))

if args.extra:
Input,Expected = read_strings(f'data/linear_space_alignment.txt',init=0)
print (alignUsingLinearSpace(Input[0],Input[1]))

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

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

elapsed = time.time() - start
minutes = int(elapsed/60)
seconds = elapsed - 60*minutes
seconds = elapsed - 60*minutes
15 changes: 8 additions & 7 deletions BA5M.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand All @@ -13,33 +15,32 @@
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>

# BA5M.py Find a Highest-Scoring Multiple Sequence Alignment
# BA5M.py Find a Highest-Scoring Multiple Sequence Alignment

from align import FindHighestScoringMultipleSequenceAlignment




if __name__=='__main__':
from helpers import create_strings
from helpers import create_strings
s,u,v,w = FindHighestScoringMultipleSequenceAlignment('ATATCCG','TCCGA','ATGTACTG')
print (s)
print (u)
print (v)
print (w)

s1,u1,v1,w1 = FindHighestScoringMultipleSequenceAlignment('TGTTTAAAAATGTCCGCAACCATTTC',
'GATATAAAACAGGGATAACTGCAATGG',
'CCTGCTACTTTATGCCGTCTCCATATGCG')
print (s1)
print (u1)
print (v1)
print (w1)
print (w1)

ss=create_strings(ext=3)
s2,u2,v2,w2 = FindHighestScoringMultipleSequenceAlignment(ss[0],ss[1],ss[2])
print (s2)
print (u2)
print (v2)
print (w2)

print (w2)
6 changes: 4 additions & 2 deletions BA6A.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019-2021 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -43,8 +45,8 @@ def f(p):
for permutation in GreedySorting(get_permutation(Input[0]),signed=True):
print (format(permutation))
f.write(f'{format(permutation)}\n')

elapsed = time.time() - start
minutes = int(elapsed/60)
seconds = elapsed - 60*minutes
print (f'Elapsed Time {minutes} m {seconds:.2f} s')
print (f'Elapsed Time {minutes} m {seconds:.2f} s')
12 changes: 7 additions & 5 deletions BA6B.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019-2021 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand All @@ -13,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
# BA6B Compute the Number of Breakpoints in a Permutation
# BA6B Compute the Number of Breakpoints in a Permutation

import argparse
import os
Expand All @@ -29,15 +31,15 @@
parser.add_argument('--sample', default=False, action='store_true', help='process sample dataset')
parser.add_argument('--rosalind', default=False, action='store_true', help='process Rosalind dataset')
args = parser.parse_args()
if args.sample:
if args.sample:
print (getBreakPoints([+3, +4, +5, -12, -8, -7, -6, +1, +2, +10, +9, -11, +13, +14]))

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

elapsed = time.time() - start
minutes = int(elapsed/60)
seconds = elapsed - 60*minutes
print (f'Elapsed Time {minutes} m {seconds:.2f} s')
print (f'Elapsed Time {minutes} m {seconds:.2f} s')
12 changes: 7 additions & 5 deletions BA6C.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019-2021 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -35,9 +37,9 @@ def parse_permutations(text):
depth -= 1
i1 = i
Permutations.append([int(j) for j in text[i0+1:i1-1].split()])

return Permutations

if __name__=='__main__':

start = time.time()
Expand All @@ -48,7 +50,7 @@ def parse_permutations(text):
if args.sample:
print (d2break([[+1, +2, +3, +4, +5, +6]],
[[+1, -3, -6, -5],[+2, -4]]))

if args.rosalind:
Input = read_strings(f'data/rosalind_{os.path.basename(__file__).split(".")[0]}.txt')
Perms = [parse_permutations(i) for i in Input]
Expand All @@ -57,5 +59,5 @@ def parse_permutations(text):
elapsed = time.time() - start
minutes = int(elapsed/60)
seconds = elapsed - 60*minutes
print (f'Elapsed Time {minutes} m {seconds:.2f} s')
print (f'Elapsed Time {minutes} m {seconds:.2f} s')

13 changes: 7 additions & 6 deletions BA6D.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019-2021 Greenweaves Software Limited

# This is free software: you can redistribute it and/or modify
Expand All @@ -13,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

# BA6D Find a Shortest Transformation of One Genome into Another by 2-Breaks
# BA6D Find a Shortest Transformation of One Genome into Another by 2-Breaks

import argparse
import os
Expand All @@ -39,7 +41,7 @@ def get2_breaks(Configuration):
i1,j1 = Configuration[l]
result.append((i0,j0,i1,j1))
return result

def FindShortestTransformationCycles(s,t):
assert sorted(s)== sorted(t)
ColouredS = ColouredEdges(s)
Expand All @@ -61,7 +63,7 @@ def FindShortestTransformationCycles(s,t):
Config,score,path = leader_board[0]
if score==0:
return path,Blacks

return FindShortestTransformationCycles(ChromosomeToCycle(s),ChromosomeToCycle(t))

def CycleToChromosome1(Blacks,Coloured):
Expand Down Expand Up @@ -89,7 +91,7 @@ def CycleToChromosome1(Blacks,Coloured):
#print (len(paths))
for Coloured in paths:
#print (Coloured)
print (CycleToChromosome1(Blacks,Coloured))
print (CycleToChromosome1(Blacks,Coloured))



Expand All @@ -105,5 +107,4 @@ def CycleToChromosome1(Blacks,Coloured):
elapsed = time.time() - start
minutes = int(elapsed/60)
seconds = elapsed - 60*minutes
print (f'Elapsed Time {minutes} m {seconds:.2f} s')

print (f'Elapsed Time {minutes} m {seconds:.2f} s')
4 changes: 3 additions & 1 deletion BA6F.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright (C) 2019 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
Expand All @@ -18,4 +20,4 @@
from fragile import ChromosomeToCycle

if __name__=='__main__':
print (ChromosomeToCycle([-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, -49, -50, +51, +52, -53, +54, +55, +56, -57, +58, -59, -60, -61, -62, +63, +64, +65, +66, +67, +68]))
print (ChromosomeToCycle([-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, -49, -50, +51, +52, -53, +54, +55, +56, -57, +58, -59, -60, -61, -62, +63, +64, +65, +66, +67, +68]))
Loading

0 comments on commit 3893e9a

Please sign in to comment.