Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv, exit
- import csv
- if len(argv) != 3:
- print("Usage: python dna.py data.csv sequence.txt")
- exit()
- with open(argv[2]) as seqfile:
- sequence = seqfile.readline().rstrip()
- with open(argv[1], newline='') as csvfile:
- database = csv.reader(csvfile)
- # read the patterns from the first line
- patterns = next(database)[1:] # drop "name"
- # find the longest runs of each pattern
- matches = []
- for p in patterns:
- i = 0
- while p * (i + 1) in sequence:
- i += 1
- matches.append(f"{i}")
- # iterate the database looking for an ordered match
- for row in database:
- name = row.pop(0)
- if row == matches:
- print(name)
- exit()
- print("No match")
Advertisement
Add Comment
Please, Sign In to add comment