Last active
September 6, 2021 13:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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