Last active
October 18, 2016 17:03
-
-
Save rosiecakes/c2e81483f1f22081b448b1799c6f70cb to your computer and use it in GitHub Desktop.
Cute codecademy challenge
This file contains 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
sample = ['GTA','GGG','CAC'] | |
def read_dna(dna_file): | |
dna_data = '' | |
with open(dna_file, 'r') as f: | |
for line in f: | |
dna_data += line | |
return dna_data | |
def dna_codons(dna): | |
codons = [] | |
for i in range(0, len(dna), 3): | |
if i + 3 >= len(dna): | |
break | |
codons.append(dna[i] + dna[i+2] + dna[i+3]) | |
return codons | |
def match_dna(dna): | |
matches = 0 | |
for codon in dna: | |
if codon in sample: | |
matches += 1 | |
return matches | |
def is_criminal(dna_sample): | |
dna_data = read_dna(dna_sample) | |
codons = dna_codons(dna_data) | |
num_matches = match_dna(codons) | |
if num_matches >= 3: | |
print('Matches: {}'.format(num_matches) + '\n' + 'Suspect: Continue investigation'.format(num_matches)) | |
else: | |
print('Matches: {}'.format(num_matches) + '\n' + 'Suspect: Set free') | |
is_criminal("suspect1.txt") | |
is_criminal("suspect2.txt") | |
is_criminal("suspect3.txt") |
This file contains 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
ATCGAAAGCACAATCATGCATCGTGCCAGTGTGTTCGTGTCATCTAGGACGGGGCCATAGGATATATAATTCAATTAAGAATACCTTATACTACTGTCCCCTGTGGTTCGAAGGGGAACTATTTCGTGGGGCGAGCCCACACCGTCTCTTCTGCGGAAGACTTAACACGTTAGGGAGGTGGAATAGTTTCGAACGATGGTTATTAATCGTGATAACGGAACGCTGTCTGGAGGATGAGTCTGACGGTGTGTGACTCGATCAGTCACTCGCTATTCGAACTGCGCGAAAGATCCCAGCGCT |
This file contains 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
TCGCATAAGTACAGTAGATCCTCCCCGCGCATCCTATTTATTAAGTTAATTCTACAGCAATACGATCATATGCGGATCCGCAGTGGCCGGTAGACACACCATGCACTTGATTCCGAGGCCTGTCCCGATATATGAACCCAAACTAGAGCGAGGCTGTTGACGTTTGGAGTTGAAAAAATCTATTATACCAATCGGCTTCAACGTGCTCCACGGCAGGCGCCTGACGAGAGGCCCACACCGAGGAAGTAGACTGTTGCACGTTGAGGATAGCGCTAGCTAACAAAGACGCCTGCTACAACA |
This file contains 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
TCGCATAAGTACAGTAGATCCTCCCCGCGCATCCTATTTATTAAGTTAATTCTACAGCAATACGATCATATGCGGATCCGCAGTGGCCGGTAGACACACCATGCACTTGATTCCGAGGCCTGTCCCGATATATGAACCCAAACTAGAGCGAGGCTGTTGACGTTTGGAGTTGAAAAAATCTATTATACCAATCGGCTTCAACGTGCTCCACGGCAGGCGCCTGACGAGAGGCCCACACCGAGGAAGTAGACTGTTGCACGTTGAGGATAGCGCTAGCTAACAAAGACGCCTGCTACAACA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment