Skip to content

Commit

Permalink
#81 WIP checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
weka511 committed Jun 15, 2024
1 parent 633a0f6 commit 3cd48ff
Show file tree
Hide file tree
Showing 2 changed files with 308 additions and 258 deletions.
44 changes: 11 additions & 33 deletions BA9F.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright (C) 2020 Greenweaves Software Limited
# Copyright (C) 2020-2024 Greenweaves Software Limited
#
# This program 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 @@ -14,45 +14,23 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# BA9F Find the Shortest Non-Shared Substring of Two Strings

import argparse
from helpers import read_strings
''' BA9F Find the Shortest Non-Shared Substring of Two Strings'''

from argparse import ArgumentParser
from os.path import basename
from time import time
from snp import SuffixArray
import time
from numpy import argmin

def FindShortestNonShared(s,t):
m = len(s)
n = len(t)
print (m,n)
r0,p0,l0 = SuffixArray(s,auxiliary=True,padLCP=True)
for i in range(len(r0)):
print (f'{i:2d} {r0[i]:2d} {p0[i]:2d} {l0[i]:2d} {s[r0[i]:]}')
r1,p1,l1 = SuffixArray(t,auxiliary=True,padLCP=True)
for i in range(len(r1)):
print (f'{i:2d} {r1[i]:2d} {p1[i]:2d} {l1[i]:2d} {t[r1q[i]:]}')
#text = s + '$' + t + '#'
#r,p,l = SuffixArray(text,auxiliary=True,padLCP=True)
#Candidates = []
#Lengths = []
#previous = -1
#for i in range(len(r)):
#if r[i]<m:
#print (f'{i:2d} {r[i]:2d} {p[i]:2d} {l[i]:2d} {text[r[i]:]}')
#if i==previous+1:
#Candidates.append(i)
#Lengths.append(l[i])
#previous = i
#shortest = min(Lengths)
#locations = [Candidates[i] for i in range(len(Candidates)) if Lengths[i]==shortest]
#for i in locations:
#print (f'{i:2d} {r[i]:2d} {p[i]:2d} {l[i]:2d} {text[r[i]:]}')
a2 = SuffixArray(t)
return ''

if __name__=='__main__':
start = time.time()
parser = argparse.ArgumentParser('BA9D Find the Longest Repeat in a String')
start = time()
parser = ArgumentParser('BA9D Find the Longest Repeat in a String')
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')
Expand All @@ -75,7 +53,7 @@ def FindShortestNonShared(s,t):
with open(f'{os.path.basename(__file__).split(".")[0]}.txt','w') as f:
f.write(f'{Result}\n')

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

0 comments on commit 3cd48ff

Please sign in to comment.