diff --git a/BA5L.py b/BA5L.py index ee6e81e..9f73fd3 100644 --- a/BA5L.py +++ b/BA5L.py @@ -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 @@ -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 +# along with this program. If not, see # 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 # @@ -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] @@ -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'))