joseleeph

Untitled

Dec 1st, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 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("small.csv", "r") as file:
  11. #with open(sequences/"1.txt", "r") as f:
  12. #with open(argv[1], "r") as f:
  13. #contents = f.read()
  14. #matches = pattern2.finditer(contents)
  15. #for match in matches:
  16. #print(match)
  17. #with open(argv[1], "r") as f:
  18. #contents = f.read()
  19. #matches = pattern3.finditer(contents)
  20. #for match in matches:
  21. #print(match)
  22.  
  23. #print("Here is a list of all the times the string TATC occurs")
  24. with open(argv[1], "r") as f:
  25. count = 0
  26. contents = f.read()
  27. print("contents prints: ")
  28. print(contents)
  29. #print(contents[0:4])
  30. i = 0
  31. j = i + 4
  32. while contents[i:j]: # will read contents until end of file
  33. span = contents[i:j]
  34. #count = 0
  35. #sample output for this count
  36.  
  37. #span GAAA reapeats 0 consecutive times
  38. #span GGAG reapeats 0 consecutive times
  39. #span GGAT reapeats 0 consecutive times
  40.  
  41. while contents[i+4:j+4] == span:
  42. count += 1
  43. #print("span reapeats " + str(count) + " times" )
  44. i += 4
  45. j += 4
  46. #count = 0 # resetting count to 0 as suggested
  47.  
  48. #sample output for this count
  49.  
  50. #span GAAA reapeats 0 consecutive times
  51. #span GGAG reapeats 0 consecutive times
  52. #span GGAT reapeats 0 consecutive times
  53. #count = 0
  54. #count +=1
  55. i += 4
  56. j += 4
  57. print("span " + span + " reapeats " + str(count) + " consecutive times" )
  58. #count = 0
  59. #count = 0 sample output remains unchanged
  60. #print("span " + span + " reapeats " + str(count) + " consecutive times" )
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment