Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import sys
- def main():
- # Ensure correct usage
- if len(sys.argv) != 3:
- sys.exit("You should enter 2 arguments after the program's name")
- exit(1)
- dict_list = []
- # TODO: Read teams into memory from file
- with open(sys.argv[1], "r") as file:
- reader = csv.DictReader(file)
- for name in reader:
- name["AGATC"] = int(name["AGATC"])
- name["TTTTTTCT"] = int(name["TTTTTTCT"])
- name["AATG"] = int(name["AATG"])
- name["TCTAG"] = int(name["TCTAG"])
- name["GATA"] = int(name["GATA"])
- name["TATC"] = int(name["TATC"])
- name["GAAA"] = int(name["GAAA"])
- name["TCTG"] = int(name["TCTG"])
- dict_list.append(name)
- with open(sys.argv[2], "r") as text:
- sequence = text.read()
- c_1 = sequence.count("AGATC")
- c_2 = sequence.count("TTTTTTCT")
- c_3 = sequence.count("AATG")
- c_4 = sequence.count("TCTAG")
- c_5 = sequence.count("GATA")
- c_6 = sequence.count("TATC")
- c_7 = sequence.count("GAAA")
- c_8 = sequence.count("TCTG")
- max_counts = [c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8]
- # Compare against data
- for i in range(len(dict_list)):
- matches = 0
- for j in range(1, len(reader.fieldnames)):
- if max_counts[j - 1] == int(dict_list[i][reader.fieldnames[j]]):
- matches += 1
- if matches == (len(reader.fieldnames) - 1):
- print(dict_list[i]['name'])
- exit(0)
- print("No match")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment