joseleeph

Untitled

Dec 1st, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. from sys import argv, exit
  2. import re
  3. if len(argv) < 2:
  4. print("mising command-line argument")
  5. exit(1)
  6. pattern1 = re.compile(r'AGAT')
  7. pattern2 = re.compile(r'AATG')
  8. pattern3 = re.compile(r'TATC')
  9. with open(argv[1], "r") as f:
  10. count = 0
  11. contents = f.read()
  12. print(contents)
  13. print(contents[0:4])
  14. i = 0
  15. j = i + 4
  16. while contents[i:j]: # will read contents until end of file
  17. span = contents[i:j] # initially set span to contents 1-4
  18. while contents[i+4:j+4] == span: # while the following 4 characters are equal to the characters in span
  19. #while span[i+4:j+4] == span[i:j]:
  20. count += 1 # increment count
  21. print("span " + span + "repeats " + str(count) + " times" )
  22. i += 1
  23. j += 1
  24. i += 1
  25. j += 1
  26. #The bug as stated in your other
  27. #similar post is that i and j are only
  28. #incremented inside your inner loop on
  29. #condition you find a match. So if no match,
  30. #your outer loop keeps checking the same
  31. #part of contents[i][j] over and over
Advertisement
Add Comment
Please, Sign In to add comment