Advertisement
joseleeph

Untitled

Dec 9th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 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. #INSTRUCTIONS
  9.  
  10. #1. Read the sequence file into a string (you've got this).
  11.  
  12. #2. Open the csv file and get each sub string ("AGATC", "TCTG", etc) from the first row into a list (you've essentially done this too).
  13.  
  14. #3. For each item in the list of sub strings, look through the sequence you read in step 1 and see what the longest sequential run is. Store this number in a list so you have the longest runs of all sub strings.
  15.  
  16. #4. Iterate through the rest of the CSV file, comparing the numbers in each row to the list of numbers you created in step 3. When all numbers match, the name from this row is the one to print.
  17.  
  18.  
  19. with open(argv[1],"r") as file, open(argv[2],"r") as csvfile:
  20. count = 0
  21. contents = file.read() #1. Read the sequence file into a string (you've got this).
  22. csvcontents = csv.reader(csvfile)
  23. #2. Open the csv file and get each sub string
  24. #("AGATC", "TCTG", etc) from the first row
  25. #into a list (you've essentially done this too).
  26. header = next(csvcontents)
  27. print("header prints: ")
  28. print(header)
  29. print("header[1] prints: ")
  30. print(header[1])
  31. print("header[0] prints: ")
  32. print(header[0])
  33. stringcompare = [] # an empty list to store the values of header
  34. #charcount = 0
  35. print("appending the stringcompare[] list with every element in header")
  36. for i in header:
  37. stringcompare.append(i) # appending works!
  38. print("every element of stringcompare[] list prints: ")
  39. for s in stringcompare:
  40. print(s)
  41.  
  42. #3. For each item in the list of sub strings,
  43. #look through the sequence you read
  44. #in step 1 and see what the longest
  45. #sequential run is. Store this number
  46. #in a list so you have the longest runs of all sub strings.
  47.  
  48. sublist = []
  49. for item in stringcompare:
  50. charcount = len(item)
  51. index = 0
  52. #print("item " + item + " is " + str(charcount) + " long")
  53. longest = 0
  54. if charcount > longest:
  55. longest = charcount
  56.  
  57. index = 0
  58. while contents[index:charcount]:
  59. span = contents[index:charcount]
  60. repcount = 1
  61. while contents[index + charcount: charcount + charcount] == span:
  62. repcount += 1
  63.  
  64.  
  65. #Store this number
  66. #in a list so you
  67. #have the longest runs of all sub strings. ... why where?
  68.  
  69. index += charcount
  70. charcount += charcount
  71. sublist.append(repcount) # is this what is meant?
  72.  
  73. print("stringcompare prints: ")
  74. print(stringcompare)
  75. #4. Iterate through the rest of the CSV file,
  76. #comparing the numbers in each row to the list
  77. #of numbers you created in step 3.
  78. #When all numbers match, the name
  79. #from this row is the one to print.
  80. for i in header:
  81. n = 0
  82. print("header[" + n + "] prints:")
  83. print(i)
  84. n += 1
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement