Skip to content

Instantly share code, notes, and snippets.

@odanga94
Created May 9, 2017 08:00
Show Gist options
  • Save odanga94/7129364ecc0c815aebd409f7494ac040 to your computer and use it in GitHub Desktop.
Save odanga94/7129364ecc0c815aebd409f7494ac040 to your computer and use it in GitHub Desktop.
CodeAcademy Python project: DNA Analysis
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):
codons.append(dna[i:(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("There were %d codon matches in %s. Further investigation should be done") %(num_matches, dna_sample)
else:
print("There were only %d codon matches in %s. As the dna test clears this suspect of any allegations they can be freed") % (num_matches, dna_sample)
is_criminal('suspect1.txt')
is_criminal('suspect2.txt')
is_criminal('suspect3.txt')
@SurajKeshri1998
Copy link

Can you please send me the full ipython code of DNA matching?
surajkeshri.2020@gmail.com - this is my email id
send it as fast as possible please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment