代码:
n = 3
DNA-Sequence = { #dictionary of DNA
"Phenylalanine": ["UUU", "UUC"],
"Leucine": ["UUA", "CUU", "CUC", "CUA", "CUG", "UUG"],
"Isoleucine": ["AUU", "AUC", "AUA"],
"Methionine": "AUG",
"Valine": ["GUU", "GUC", "GUA", "GUG"],
"Serine": ["UCU", "UCC", "UCA", "UCG"],
"Proline": ["CCU", "CCC", "CCA", "CCG"],
"Threonine": ["ACU", "ACC", "ACA", "ACG"],
"Alanine": ["GCU", "GCC", "GCA", "GCG"],
"Tyrosine": ["UAU", "UAC"],
"Histidine": ["CAU", "CAC"],
"Glutamine": ["CAA", "CAG"],
"Asparagine": ["AAU", "AAC"],
"Lysine": ["AAA", "AAG"],
"Asparatic Acid": ["GAU", "GAC"],
"Glutamic Acid": ["GAA", "GAG"],
"Cysteine": ["UGU", "UGC"],
"Trytophan": "UGG",
"Arginine": ["CGU", "CGC", "CGA", "CGG", "AGG", "AGA"],
"Serine": ["AGU", "AGC"],
"Glycine": ["GGU", "GGC", "GGA", "GGG"]
}
lookup_dict = {k: key for key, values in DNA-Sequence.items() for k in values} #this is used to find the values in the dictionary using the inputDNA
inputDNA = input("Enter your DNA sequence: ")
inputDNA = inputDNA.upper()
print("Your DNA sequence is", inputDNA)
str(inputDNA)
RNA = inputDNA.replace('C', 'G') #this is me trying to convert DNA sequence to RNA
RNA = RNA.replace('A', "U") #this is me trying to convert DNA sequence to RNA
RNA = RNA.replace('T', 'A') #this is me trying to convert DNA sequence to RNA
print(RNA)
b = len(inputDNA)
if b % 3 == 0: #if the length of inputDNA is a multiple of 3
for k in (inputDNA[i:i + n] for i in range(0, len(inputDNA), n)):
for _, values in DNA-Sequence.items():
if k in values:
print(lookup_dict[k], end=" ")
break
else: #if the length of inputDNA is not a multiple of 3
print("I hate u")发生了什么:
Enter your DNA sequence: CCATAGCACGTT
Your DNA sequence is: CCATAGCACGTT
GGUAUGGUGGAA
Proline I hate u
Histidine I hate u我想要的是:
Enter your DNA sequence: CCATAGCACGTT
Your DNA sequence is: CCATAGCACGTT #this is because I need to convert DNA sequence to RNA but I am not sure of the formula and how to do it in python
GGUAUCGUGCAA
Your amino acids chain is: Glycine, Isoleucine, Valine, Glutamine为什么我要获得A的输出,以及如何将它修复成我想要的输出?我知道我不是在做RNA = RNA.replace('G', 'C'),但是当我这样做时,输出就变成了
Enter your DNA sequence: CAACAUGCU
Your DNA sequence is CAACAUGCU
A
Glutamine Histidine Alanine 或者一些类似的东西,但绝对不是,我不知道发生了什么。请帮帮忙?
发布于 2019-12-15 07:49:55
据我所见,您可以对遇到问题的替换进行以下操作;可以通过1次转换调用或2次依赖于您的首选项来完成:
a = input("Enter your DNA sequence: ")
a = a.upper()
print("Your DNA sequence is", a)
# RNA = a.translate(str.maketrans({'G': 'C', 'C': 'G'}))
# RNA = RNA.translate(str.maketrans({'A': 'U', 'T': 'A'}))
RNA = a.translate(str.maketrans({'G': 'C', 'C': 'G', 'A': 'U', 'T': 'A'}))
print(RNA)产出如下:
Enter your DNA sequence: CCATAGCACGTT
Your DNA sequence is CCATAGCACGTT
GGUAUCGUGCAA关于氨基酸的印刷:
b = len(RNA)
if b % 3 == 0: #if the length of inputDNA is a multiple of 3
for k in (RNA[i:i + n] for i in range(0, len(RNA), n)):
for kk, val in DNA_Sequence.items():
if k in val:
print(kk, end=" ")
break
else: #if the length of inputDNA is not a multiple of 3
print("I hate u")通知
该表不是DNA表,而是RNA (您有U),因此需要在循环中使用RNA,输出如下:
甘氨酸异亮氨酸谷氨酰胺
发布于 2019-12-15 07:52:38
我为另一个人写了一个熊猫解决方案:
import pandas as pd
df = pd.DataFrame(list(xdict.items()))
import re
def lookupKeys(df, key):
name = []
matches = re.findall(r'...', key)
for match in matches:
name.append(df[df[1].apply(lambda x: True if key in x else x) == True][0].reset_index()[0][0])
return name
lookupKeys(df, 'GGUAUCGUGCAA')
# ['Glycine', 'Isoleucine', 'Valine', 'Glutamine']发布于 2019-12-15 07:53:47
好的,有一些语法错误,但是让它启动并运行.
n = 3
xdict = {
"Phenylalanine": ["UUU", "UUC"],
"Leucine": ["UUA", "CUU", "CUC", "CUA", "CUG", "UUG"],
"Isoleucine": ["AUU", "AUC", "AUA"],
# Put the 'AUG' on brackets []
"Methionine": ["AUG"],
"Valine": ["GUU", "GUC", "GUA", "GUG"],
"Serine": ["UCU", "UCC", "UCA", "UCG"],
"Proline": ["CCU", "CCC", "CCA", "CCG"],
"Threonine": ["ACU", "ACC", "ACA", "ACG"],
"Alanine": ["GCU", "GCC", "GCA", "GCG"],
"Tyrosine": ["UAU", "UAC"],
"Histidine": ["CAU", "CAC"],
"Glutamine": ["CAA", "CAG"],
"Asparagine": ["AAU", "AAC"],
"Lysine": ["AAA", "AAG"],
"Asparatic Acid": ["GAU", "GAC"],
"Glutamic Acid": ["GAA", "GAG"],
"Cysteine": ["UGU", "UGC"],
"Trytophan": "UGG",
"Arginine": ["CGU", "CGC", "CGA", "CGG", "AGG", "AGA"],
"Serine": ["AGU", "AGC"],
"Glycine": ["GGU", "GGC", "GGA", "GGG"]
}
lookup_dict = {k: key for key, values in xdict.items() for k in values}
a = input("Enter your DNA sequence: ")
a = a.upper()
print("Your DNA sequence is", a)
str(a)
RNA = a.replace('C', 'G')
RNA = RNA.replace('A', "U")
RNA = RNA.replace('T', 'A')
print(RNA)
b = len(a)
# Introduced a new flag variable
val = ''
if b % 3 == 0:
# a replaced with RNA
for k in (RNA[i:i + n] for i in range(0, len(a), n)):
val += lookup_dict[k] + ' '
elif b % 3 != 0:
print("Try again.")
print('Name', val)你是通过'a‘循环的,但应该是RNA。阅读评论以了解其他变化..。
https://stackoverflow.com/questions/59341986
复制相似问题