joseleeph

Untitled

Dec 2nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 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.  
  7. pattern1 = re.compile(r'AGAT')
  8. pattern2 = re.compile(r'AATG')
  9. pattern3 = re.compile(r'TATC')
  10. with open(argv[1],"r") as file:
  11.  
  12. contents = file.read()
  13. i = 0
  14. j = 4
  15. while contents[i:j]:
  16. #this works.... save it... prints one string of 4 per line
  17. print(contents[i:j])
  18. i += 4
  19. #j += 4
  20.  
  21. while contents[i:j]:
  22. if contents[i:j] == contents[i+4:j+4]:
  23. index = 1
  24. count = 1
  25. while contents[i:j] == contents[i+4*index:j+4*index]:
  26. i += 1
  27. j += 1
  28. count += 1
  29. index += 1
  30. print(str(contents[i:j]) + " count is: " + count)
  31.  
  32. matchcount = 0
  33. i = 0
  34. j = 4
  35. while contents[i:j]:
  36. pattern = contents[i:j] #pattern = re.compile(pattern?)
  37. if pattern == contents[i+4:j+4]:
  38. #matches = pattern.finditer(contents)
  39. #matches = pattern.finditer(f'contents')
  40. mcount = 1
  41. for match in matches:
  42. #print(match)
  43. mcount += 1
  44.  
  45. i += 1
  46. j += 1
  47.  
  48.  
  49. print("printing count, the number of times that pattern1 appears in the file, should return 5")
  50. print(mcount)
  51. print("mind you, these are not consecutive matches")
Advertisement
Add Comment
Please, Sign In to add comment