Getting a weird output for DNA Analysis project


#1

I do not see an error so I thought some more eyes could help. Please let me know if you see anything odd within the code that may mess with it.

My output should have a separate analysis for each suspect.txt but only 1 line is given.

of codon matches: 6. DNA Profile matches. Continue investigations.

is the output given.



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 ("# of codon matches: %s. DNA profile matches. Continue Investigation.") % (num_matches)
  else: ("# of codon matches: %s. DNA profile does not match. This suspect may be freed.")

is_criminal("suspect1.txt")
is_criminal("suspect2.txt")
is_criminal("suspect3.txt")


Thanks guys!


#2

I’ll look at it right now.


#3

Please post the URL to this project. Thanks.


#4

Thanks for the reply, I see people leave their posts without answering you constantly. I solved my problem I am sorry for not closing this or whatever the way to mark this as solved is on here.


#5

https://www.codecademy.com/courses/learn-python/projects/dna


#6