Skip to content

Instantly share code, notes, and snippets.

@moqdm
Last active September 6, 2021 13:30
Show Gist options
  • Save moqdm/1a76fcf11fda750c08e84930fe2daedd to your computer and use it in GitHub Desktop.
Save moqdm/1a76fcf11fda750c08e84930fe2daedd to your computer and use it in GitHub Desktop.
it's my PSet 6: DNA solution... *Please just take a look if you couldn't solve it ... Thank you πŸ™‚ #cs50
import csv
import sys
import re
if len(sys.argv) != 3:
print("Usage: python dna.py data.csv sequence.txt")
# Read DNA sequence
with open(sys.argv[2], "r") as txt:
dna = txt.read(-1)
# Open CSV file
with open(sys.argv[1], "r") as data:
# Open CSV to get the key
read = csv.DictReader(data)
for row in read:
i = list(row)
break
i = i[1:]
s = {}
for STR in i:
result = re.findall(f"(?:{STR})+", dna)
if result:
s[STR] = str(int(len(max(result)) / len(STR)))
# Searching to find and result
with open(sys.argv[1], "r") as data:
read = csv.DictReader(data)
for row in read:
a = dict(row)
del a["name"]
if a == s:
print(row["name"])
break
# End :)
else:
print("No match")
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment