joseleeph

Untitled

Dec 8th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. from sys import argv, exit
  2. import csv
  3. import re
  4. if len(argv) < 3:
  5. print("mising command-line argument")
  6. exit(1)
  7.  
  8. #pattern1 = re.compile(r'AGAT')
  9. #pattern2 = re.compile(r'AATG')
  10. #pattern3 = re.compile(r'TATC')
  11. # pattern = re.compile(r'contents[i:j]')
  12.  
  13.  
  14. with open(argv[1],"r") as file, open(argv[2],"r") as csvfile:
  15. count = 0
  16. contents = file.read()
  17. csvcontents = csv.reader(csvfile)
  18. header = next(csvcontents)
  19. data = [row for row in csvcontents]
  20.  
  21. i = 0
  22. j = 4
  23. while contents[i:j]:
  24. span = contents[i:j]
  25. repcount = 1
  26. while contents[i+4:j+4] == span:
  27. repcount += 1
  28. i += 4
  29. j += 4
  30. #if repcount != 0:
  31. if repcount > 1:
  32. print("span " + span + " repeats " + str(repcount) + " times")
  33. i += 4
  34. j += 4
  35. else:
  36. i += 4
  37. j += 4
  38.  
  39.  
  40. index = 0
  41. for headervalue in header:
  42. index += 1
  43. if headervalue == span:
  44. data = [row for row in contents]
  45. #if int(data[index]) == repcount:
  46. if data[index] == repcount:
  47. print("possible match is named " + data[0])
  48.  
  49. #with open(argv[2],"r") as csvfile:
  50. # csvcontents = csv.reader(csvfile)
  51. # header = next(csvcontents) # look up what next is doing again
  52. # print("seeing what the next() function does by assigning it to header")
  53. # print("printing header")
  54. # print(header) ## assign header into a list
  55.  
  56. # data = [row for row in csvcontents]
  57. # print("printing data[0]")
  58. # print(data[0])
  59. # row could be called anything... how does it know to print a row?
  60. # is it part of the csv reader() method?
  61.  
  62. # print("printing 1 line at a time")
  63. # i = 0
  64. # while i < len(data):
  65. # print(data[i])
  66. # i += 1
  67. # print("print(data[15][2]) prints: ")
  68. # print(int(data[15][2]))
  69.  
  70. # print("print(data[15][1]) prints: ")
  71. # print(int(data[15][1]))
  72.  
  73. # print("print(data[15][0]) prints: ")
  74. # print(str(data[15][0]))
  75.  
  76. #File "fcsvdna.py", line 70, in <module>
  77. # print(int(data[15][0]))
  78. # ValueError: invalid literal for int() with base 10: 'Neville'
  79.  
  80. #print("header[1] prints: ")
  81. #print(header[1])
  82.  
  83. #print("printing everything in the csv file: ")
  84. #print(data)
  85.  
Advertisement
Add Comment
Please, Sign In to add comment