Python: Appending a to a list from a dictionary -


this going long don't know how else explain this.

so have 2 files reading in. first 1 has list of characters.the second file list of 3 characters , it's matching identifier character(separated tab).

with second file made dictionary 3 characters items , 1 character corresponding key. need take 3 characters @ time first list , compare dictionary. if there match need take corresponding key , append new list print out. if match '*' character need stop not continue comparing list dictionary.

i'm having trouble comparing , making new list using append function.

here part of first input file:

seq0 atggaagcgaggatgtga 

here part second:

auu     auc     aua     cuu     l guu     v uga     * 

here code far:

input = open("input.fasta", "r") codons = open("codons.txt", "r")  counts = 1 amino_acids = {}  lines in codons:         lines = lines.strip()         codon, acid = lines.split("\t")         amino_acids[codon] = acid         counts += 1  count = 1  line in input:         if count%2 == 0:                 line = line.upper()                 line = line.strip()                 line = line.replace(" ", "")                 line = line.replace("t", "u")                  import re                  if not re.match("^[aucg]*$", line):                         print "error!"                  if re.match("^[aucg]*$", line):                         mrna = len(line)/3                         first = 0                         last = 3                          while mrna != 0:                                 codon = line[first:last]                                 first += 3                                 last += 3                                 mrna -= 1                                 list = []                                  if codon == amino_acids[codon]:                                         list.append(acid)                                          if acid == "*":                                                 mrna = 0                                  acid in list:                                         print acid 

so want output this:

m    l       v    * 

but i'm not getting close this. please help!

the following purely untested code. check indentation, syntax , logic, should closer want.

import re  codons = open("codons.txt", "r") amino_acids = {} lines in codons:         lines = lines.strip()         codon, acid = lines.split("\t")         amino_acids[codon] = acid  input = open("input.fasta", "r") count = 0 list = [] line in input:     count += 1     if count%2 == 0:    #i.e. care lines         line = line.upper()         line = line.strip()          line = line.replace(" ", "")          line = line.replace("t", "u")          if not re.match("^[aucg]*$", line):                 print "error!"         else:             mrna = len(line)/3               first = 0               while mrna != 0:                   codon = line[first:first+3]                   first += 3                   mrna -= 1                   if codon in amino_acids:                       list.append(amino_acids[codon])                       if acid == "*":                           mrna = 0  acid in list:     print acid 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -