Guest User

Untitled

a guest
Dec 20th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. from sys import argv, exit
  2. import csv
  3.  
  4. if len(argv) != 3:
  5.     print("Usage: python dna.py data.csv sequence.txt")
  6.     exit()
  7.  
  8. with open(argv[2]) as seqfile:
  9.     sequence = seqfile.readline().rstrip()
  10.  
  11. with open(argv[1], newline='') as csvfile:
  12.     database = csv.reader(csvfile)
  13.     # read the patterns from the first line
  14.     patterns = next(database)[1:]  # drop "name"
  15.  
  16.     # find the longest runs of each pattern
  17.     matches = []
  18.     for p in patterns:
  19.         i = 0
  20.         while p * (i + 1) in sequence:
  21.             i += 1
  22.         matches.append(f"{i}")
  23.  
  24.     # iterate the database looking for an ordered match
  25.     for row in database:
  26.         name = row.pop(0)
  27.         if row == matches:
  28.             print(name)
  29.             exit()
  30.  
  31. print("No match")
Advertisement
Add Comment
Please, Sign In to add comment