Skip to content

Commit

Permalink
#29 converted to standard form
Browse files Browse the repository at this point in the history
  • Loading branch information
weka511 committed Nov 25, 2020
1 parent 53b15f2 commit cfdc1d4
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions BA5L.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 Greenweaves Software Limited
# Copyright (C) 2019-2020 Greenweaves Software Limited
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -11,12 +11,16 @@
# 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/>
# along with this program. If not, see <http://www.gnu.org/licenses/>

# BA5L.py Align Two Strings Using Linear Space

from align import FindMiddleEdge
from Bio.SubsMat.MatrixInfo import blosum62
import argparse
import os
import time
from helpers import read_strings
from align import FindMiddleEdge
from Bio.Align import substitution_matrices

# alignUsingLinearSpace
#
Expand All @@ -25,7 +29,7 @@
# Inputs: v
# w

def alignUsingLinearSpace(v,w,replace_score=blosum62,indel_cost=5):
def alignUsingLinearSpace(v,w,replace_score=substitution_matrices.load("BLOSUM62"),indel_cost=5):
# LinearSpaceAlignment
#
# Find longest path between a substring of v[top] v[bottom-1]
Expand Down Expand Up @@ -71,7 +75,36 @@ def LinearSpaceAlignment(top, bottom, left, right):
DOWN = 1
DOWNRIGHT = 2
LinearSpaceAlignment(0,len(v),0,len(w))


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('--rosalind', default=False, action='store_true', help='process Rosalind dataset')
args = parser.parse_args()
if args.sample:
score,s1,t1 = alignUsingLinearSpace('PLEASANTLY','MEANLY')
print (score)
print (s1)
print (t1)

if args.rosalind:
Input = read_strings(f'data/rosalind_{os.path.basename(__file__).split(".")[0]}.txt')
fasta = FastaContent(Input)
_,s = fasta[0]
_,t = fasta[1]
score,s1,t1 = alignUsingLinearSpace(s,t)

with open(f'{os.path.basename(__file__).split(".")[0]}.txt','w') as f:
f.write(f'{score}\n')
f.write(f'{s1}\n')
f.write(f'{t1}\n')

elapsed = time.time() - start
minutes = int(elapsed/60)
seconds = elapsed - 60*minutes
print (f'Elapsed Time {minutes} m {seconds:.2f} s')

if __name__=='__main__':
from helpers import create_strings
print (alignUsingLinearSpace('PLEASANTLY','MEANLY'))
Expand Down

0 comments on commit cfdc1d4

Please sign in to comment.