Jan-07-2019, 10:01 PM
Dear all,
I am new to python programming. I wrote a code, but this code works partially. So what I basically did is writing a dictionary with keys and values. Then writing code to read a file and append all the values from the dictionary that are equivalent to the sequences present in the file.
This works and then I wrote a code to multiply all the values of the list and printing the answers. But this is where I get stuck.
Can someone help me to improve my code so that the end result can be printed?
VFHL
YKDTT
RTKT
RMLMIDYVCFQ
DKGTPMAEQTY
Then I tried to multiply all the list elements together and I expected to get something like this:
96, 128, 192, 13824, 32768
But my code doesn't work. I tried it like this:
Please help mee!!
I am new to python programming. I wrote a code, but this code works partially. So what I basically did is writing a dictionary with keys and values. Then writing code to read a file and append all the values from the dictionary that are equivalent to the sequences present in the file.
This works and then I wrote a code to multiply all the values of the list and printing the answers. But this is where I get stuck.
Can someone help me to improve my code so that the end result can be printed?
aa_code = { 'A': 4, 'C': 2, 'D': 2, 'E': 2, 'F': 2, 'G': 4, 'H': 2, 'I': 3, 'K': 2, 'L': 6, 'M': 1, 'N': 2, 'P': 4, 'Q': 2, 'R': 6, 'S': 6, 'T': 4, 'V': 4, 'W': 1, 'Y': 2, }# this is the dict
from Bio import SeqIO for protein_seq in SeqIO.parse("protein.fasta","fasta"): for i in list(protein_seq): combinations = list() for value in list(protein_seq): combinations.append(aa_code[value]) print(combinations)# this is the code to get values from the dictionary equivalent to sequence in protein fileanswers were:
Output:[4, 2, 2, 6]
[2, 2, 2, 4, 4]
[6, 4, 2, 4]
[6, 1, 6, 1, 3, 2, 2, 4, 2, 2, 2]
[2, 2, 4, 4, 4, 1, 4, 2, 2, 4, 2]
These answers were right as protein sequences were something like this:VFHL
YKDTT
RTKT
RMLMIDYVCFQ
DKGTPMAEQTY
Then I tried to multiply all the list elements together and I expected to get something like this:
96, 128, 192, 13824, 32768
But my code doesn't work. I tried it like this:
import functools from Bio import SeqIO for protein_seq in SeqIO.parse("protein.fasta","fasta"): for i in list(protein_seq): combinations = list() for value in list(protein_seq): combinations.append(aa_code[value]) print(list(combinations)) for i in list(combinations): new_value = list() print(functools.reduce(lambda a,b: a*b,(list(combinations[new_value])So I imported functools so that I can use the functool to reduce or multiply all the elements in the lists. But I am getting error Because my code is not able to recruit all the lists from the list(combinations).
Please help mee!!