in Education by
How can I return the list in alphabets? I have sequence translator, and a python code that reads both dna and protein sequence. The code reads the dna sequence and translate it to protein sequence, reads the protein sequence, compares it with the translated protein sequence and prints out a list of the protein sequence that exist in the read protein sequence. How can I print a list of the protein that exist in both of them? def translate_codon(cod): """Translates a codon into an aminoacid using an internal dictionary with the standard genetic code.""" tc = {"GCT":"A", "GCC":"A", "GCA":"A", "GCG":"A", "TGT":"C", "TGC":"C", "GAT":"D", "GAC":"D", "GAA":"E", "GAG":"E", "TTT":"F", "TTC":"F", "GGT":"G", "GGC":"G", "GGA":"G", "GGG":"G", "CAT":"H", "CAC":"H", "ATA":"I", "ATT":"I", "ATC":"I", "AAA":"K", "AAG":"K", "TTA":"L", "TTG":"L", "CTT":"L", "CTC":"L", "CTA":"L", "CTG":"L", "ATG":"M", "AAT":"N", "AAC":"N", "CCT":"P", "CCC":"P", "CCA":"P", "CCG":"P", "CAA":"Q", "CAG":"Q", "CGT":"R", "CGC":"R", "CGA":"R", "CGG":"R", "AGA":"R", "AGG":"R", "TCT":"S", "TCC":"S", "TCA":"S", "TCG":"S", "AGT":"S", "AGC":"S", "ACT":"T", "ACC":"T", "ACA":"T", "ACG":"T", "GTT":"V", "GTC":"V", "GTA":"V", "GTG":"V", "TGG":"W", "TAT":"Y", "TAC":"Y", "TAA":"_", "TAG":"_", "TGA":"_"} if cod in tc: return tc[cod] else: return '-1' def seq_prot(dna_seq, ab): seqm = dna_seq.upper() prot = ab.upper() seq_aa = '' for pos in range(0, len(seqm)-2,3): cod = seqm[pos:pos+3] seq_aa += translate_codon(cod) for p in seq_aa: if p in prot: seq_aa[p] += 1 else: seq_aa = p return seq_aa dna_seq = "ACCCCTGTGACATACCTTTATGTTGCCTCGGCGGATCAGCCCGCGCCCC" ab = 'TLYPAP' print("The protein sequence are :",seq_prot(dna_seq, ab)) The protein sequence are : TYPP JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You're code is broken as it treats seq_aa as if it's both a str and a dict. Let's add an actual dictionary to collect your results: def seq_prot(dna_seq, ab): sequence = dna_seq.upper() protein = ab.upper() matches = {} for position in range(0, len(sequence), 3): codon = sequence[position: position + 3] aa = translate_codon(codon) if aa in protein: if aa in matches: matches[aa] += 1 else: matches[aa] = 1 return matches dna_seq = "ACCCCTGTGACATACCTTTATGTTGCCTCGGCGGATCAGCCCGCGCCCC" ab = 'TLYPAP' print("The protein sequence matches are :", seq_prot(dna_seq, ab)) OUTPUT The protein sequence matches are : {'T': 2, 'P': 3, 'Y': 2, 'L': 1, 'A': 3} From which you can extract proteins by using .keys() on the returned dict. If you want the letters multiplied by the values, you can use multiply (*) as a repetition operator. However, any sense of order has been lost--we're just dealing with existence. If you want to preserve order, we have to go about it differently.

Related questions

0 votes
    The data are kept in a list whose elements are dictionaries, where each dictionary contains the data for a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have list1 of a certain length and list2 of a certain length. Let's say: list1 = [32, 345, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    HOW DO I SORT THIS BY BIRTHYEAR IN ASCENDING ORDER? I'm distance learning student and have no help. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    I have the following code: import os import csv listing = os.listdir('/directory/my/files/are/in' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    When I executes my python program it shows the error TypeError: 'list' object is not callable. In these two lines ... ))).append(words) Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Milk protein is called as - 1. Milkein 2. Casein 3. Malkein 4. Kazien...
asked May 5, 2021 in General by JackTerrance
0 votes
    Bitmaps can be combined with regular B+-tree indices for relations where a few attribute values are ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Which of these interface handle sequences? (a) Set (b) List (c) Comparator (d) Collection The question ... Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of the following operator is used to create integer sequences? (a) : (b) ; (c) - (d) ~ I ... Getting Started of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which of the following takes a dict of dicts or a dict of array-like sequences and returns a DataFrame ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    To create sequences of numbers, NumPy provides a function __________ analogous to range that returns arrays instead ... answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    Which of these interface handle sequences? (a) Set (b) List (c) Comparator (d) Collection The ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    I am writing a program for school project in C which compares the values of two arrays and gives specific ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
...