为什么我不能在 python 中将 DNA 转化为 mRNA?
Why can't I convert DNA to mRNA in python?
代码:
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
或者类似的东西,但绝对 不是 我会发生什么。请帮忙?
据我所知,您可以在遇到问题的地方进行以下更换;可以通过 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")
通知
table 不是 DNA table 而是 RNA(你有 U
)因此你需要在循环中使用 RNA
并且输出是:
Glycine Isoleucine Valine Glutamine
我为另一个人写了一个 pandas 解决方案:
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']
好的,有一些语法错误,但已经解决了 运行...
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
。
阅读评论以了解其他更改...
代码:
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
或者类似的东西,但绝对 不是 我会发生什么。请帮忙?
据我所知,您可以在遇到问题的地方进行以下更换;可以通过 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")
通知
table 不是 DNA table 而是 RNA(你有 U
)因此你需要在循环中使用 RNA
并且输出是:
Glycine Isoleucine Valine Glutamine
我为另一个人写了一个 pandas 解决方案:
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']
好的,有一些语法错误,但已经解决了 运行...
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
。
阅读评论以了解其他更改...