Guest User

Untitled

a guest
Mar 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. def FasterSymbolArray(Genome, symbol):
  2. array = {}
  3. n = len(Genome)
  4. ExtendedGenome = Genome + Genome[0:n//2]
  5.  
  6. # look at the first half of Genome to compute first array value
  7. array[0] = PatternCount(symbol, Genome[0:n//2])
  8.  
  9. for i in range(1, n):
  10. # start by setting the current array value equal to the previous array value
  11. array[i] = array[i-1]
  12.  
  13. # the current array value can differ from the previous array value by at most 1
  14. if ExtendedGenome[i-1] == symbol:
  15. array[i] = array[i]-1
  16. if ExtendedGenome[i+(n//2)-1] == symbol:
  17. array[i] = array[i]+1
  18. return array
  19.  
  20. def PatternCount(Pattern, Text):
  21. count = 0
  22. for i in range(len(Text)-len(Pattern)+1):
  23. if Text[i:i+len(Pattern)] == Pattern:
  24. count = count+1
  25. return count
Add Comment
Please, Sign In to add comment