Advertisement
Guest User

cs50 dna

a guest
Sep 23rd, 2021
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import csv
  2. import sys
  3. import random
  4. import re
  5.  
  6. # Ensure correct argv line
  7.  
  8. if len(sys.argv)!= 3:
  9.     print("Error !")
  10.     sys.exit(1)
  11.  
  12. with open(sys.argv[1]) as file:
  13.     reader = csv.DictReader(file)
  14.     sequences = next(reader)
  15.    
  16. with open (sys.argv[2]) as dnafile:
  17.     dna = csv.reader(dnafile)
  18.     for row in dnafile:
  19.         dnalist = row
  20.    
  21. DNA = dnalist[0]
  22. dict_seq = {}
  23.  
  24.  
  25. search_re = re.compile('(?:' + STR + ')+')
  26. print(max((len(seq) for seq in search_re.findall(dna)), default=0) // len(STR))
  27.  
  28.  
  29. with open(sys.argv[1]) as file:
  30.     reader = csv.DictReader(file)
  31.     for row in reader:
  32.         match = 0
  33.         for DNA in dict_seq:
  34.             if dict_seq[DNA] == int(row[DNA]):
  35.                 match += 1
  36.         if match == len(dict_seq):
  37.             print(row['name'])
  38.             exit()
  39.     #otherwise, no match
  40.     print("No match")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement