Guest User

my trashy dna pset6

a guest
Sep 13th, 2021
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import csv
  2. import sys
  3.  
  4. def main():
  5.  
  6. # Ensure correct usage
  7. if len(sys.argv) != 3:
  8. sys.exit("You should enter 2 arguments after the program's name")
  9. exit(1)
  10. dict_list = []
  11. # TODO: Read teams into memory from file
  12. with open(sys.argv[1], "r") as file:
  13. reader = csv.DictReader(file)
  14. for name in reader:
  15. name["AGATC"] = int(name["AGATC"])
  16. name["TTTTTTCT"] = int(name["TTTTTTCT"])
  17. name["AATG"] = int(name["AATG"])
  18. name["TCTAG"] = int(name["TCTAG"])
  19. name["GATA"] = int(name["GATA"])
  20. name["TATC"] = int(name["TATC"])
  21. name["GAAA"] = int(name["GAAA"])
  22. name["TCTG"] = int(name["TCTG"])
  23. dict_list.append(name)
  24.  
  25. with open(sys.argv[2], "r") as text:
  26. sequence = text.read()
  27.  
  28. c_1 = sequence.count("AGATC")
  29. c_2 = sequence.count("TTTTTTCT")
  30. c_3 = sequence.count("AATG")
  31. c_4 = sequence.count("TCTAG")
  32. c_5 = sequence.count("GATA")
  33. c_6 = sequence.count("TATC")
  34. c_7 = sequence.count("GAAA")
  35. c_8 = sequence.count("TCTG")
  36. max_counts = [c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8]
  37.  
  38. # Compare against data
  39. for i in range(len(dict_list)):
  40. matches = 0
  41. for j in range(1, len(reader.fieldnames)):
  42. if max_counts[j - 1] == int(dict_list[i][reader.fieldnames[j]]):
  43. matches += 1
  44. if matches == (len(reader.fieldnames) - 1):
  45. print(dict_list[i]['name'])
  46. exit(0)
  47. print("No match")
  48.  
  49. if __name__ == "__main__":
  50. main()
Advertisement
Add Comment
Please, Sign In to add comment