首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Python分离到mRNA可读区域以获得分离的蛋白质

使用Python分离到mRNA可读区域以获得分离的蛋白质
EN

Stack Overflow用户
提问于 2021-07-02 14:00:07
回答 1查看 127关注 0票数 1

我正在尝试创建一个程序来执行以下操作:

  • 输入可以是DNA序列(反义或正义)或mRNA
  • DNA序列,获得互补的mRNA序列。

该程序将查找并打印mRNA序列的可读区域,并将这些区域转换为氨基酸序列。

问题是,我忘记分离可读区域,因此可读区都在一起,AA序列也是如此。什么是最好的方式将他们分开,并提出结果?

代码语言:javascript
复制
#DNA->RNA->Protein

print ('Are you using a DNA ou RNA string?')
RNAS= 'RNA'
Resp=input().upper()
if "DNA" in Resp: #convert DNA to RNA
    print('Is the strand sense or antisense? Meaning, from 5 to 3 or from 3 to 5?')
    Resp2= input().upper()
    if "ANTISENSE" in Resp2: #reverse
        print ('Please input the string')
        DNAs=input().upper()
        RNAs = DNAs.replace('A', 'u').replace('T', 'a').replace('C', 'g').replace('G', 'c').upper()[::-1]
        print ('The complementar RNA strand is:')
        print (RNAs)
    else:
        print ('Please input the string')
        DNAs=input().upper()
        RNAs = DNAs.replace('A', 'u').replace('T', 'a').replace('C', 'g').replace('G', 'c').upper()
        print ('The complementar RNA strand is:')
        print (RNAs)
if "RNA" in Resp:
    print ('Please input the string')
    RNAs=input().upper()

# search for readable regions
def readable(seq, n):
    for i in range(0, len(seq), n):
        yield seq[i:i+n]

def method(seq, start=['AUG'], stop=['UAA','UAG','UGA']):
    response = ''
    started = False
    for x in readable(seq, 3):
        if x in start:
            started = True
        if x in stop:
             started=False
        if started:
            response += x
                
    yield response

for result in method(RNAs):
    b=result
print (' ')
print ('The readable part of the RNA is:')
print(result)

def translate(seq): #translate the readable region
      
    table = {
        'AUA':'I', 'AUC':'I', 'AUU':'I', 'AUG':'M',
        'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACU':'T',
        'AAC':'N', 'AAU':'N', 'AAA':'K', 'AAG':'K',
        'AGC':'S', 'AGU':'S', 'AGA':'R', 'AGG':'R',                 
        'CUA':'L', 'CUC':'L', 'CUG':'L', 'CUU':'L',
        'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCU':'P',
        'CAC':'H', 'CAU':'H', 'CAA':'Q', 'CAG':'Q',
        'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGU':'R',
        'GUA':'V', 'GUC':'V', 'GUG':'V', 'GUU':'V',
        'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCU':'A',
        'GAC':'D', 'GAU':'D', 'GAA':'E', 'GAG':'E',
        'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGU':'G',
        'UCA':'S', 'UCC':'S', 'UCG':'S', 'UCU':'S',
        'UUC':'F', 'UUU':'F', 'UUA':'L', 'UUG':'L',
        'UAC':'Y', 'UAU':'Y', 'UGG':'W', 'UGU':'C',
        'UGC':'C'}
    protein =""
    if len(b)%3 == 0:
  
        for i in range(0, len(seq), 3):
            codon = seq[i:i + 3]
            protein+= table[codon]
    return protein
p = translate(b)
print (' ')
print ('The aa sequence is:')
print (p)
print('')
print('')
print ('Ready to close programm? Yes or no')

Close=input().lower
if "yes" in Close:
    print('Bye')

编辑:

代码语言:javascript
复制
def method(seq, start=['AUG'], stop=['UAA','UAG','UGA']):
    response = ''
    started = False
    for x in readable(seq, 3):
        if x in start:
            started = True
            response += ' '
        if x in stop:
            started=False
        if started:
            response += x
                
    yield response

for result in method(RNAs):
    b=result
print (' ')
print ('The readable part of the RNA is:')
print(result)
print (' ')
print ('Considering a minimum of 30 nucleotides, the readable part of the RNA is:')
f=result.split()
readable_regions=[x for x in f if len(x)>=int(30)] #readable regions
EN

回答 1

Stack Overflow用户

发布于 2021-07-02 21:32:12

只解决了最初的问题,还没有优化变化。

代码语言:javascript
复制
print ('Are you using a DNA ou RNA string?')
RNAS= 'RNA'
Resp=input().upper()
if "DNA" in Resp: #convert DNA to RNA
    print('Is the strand sense or antisense? Meaning, from 5 to 3 or from 3 to 5?')
    Resp2= input().upper()
    if "ANTISENSE" in Resp2: #reverse
        print ('Please input the string')
        DNAs=input().upper()
        RNAs = DNAs.replace('A', 'u').replace('T', 'a').replace('C', 'g').replace('G', 'c').upper()[::-1]
        print (' ')
        print ('The complementar RNA strand is:')
        print (RNAs)
    else:
        print ('Please input the string')
        DNAs=input().upper()
        RNAs = DNAs.replace('A', 'u').replace('T', 'a').replace('C', 'g').replace('G', 'c').upper()
        print (' ')
        print ('The complementar RNA strand is:')
        print (RNAs)
if "RNA" in Resp:
    print ('Please input the string')
    RNAs=input().upper()

# search for readable regions
def readable(seq, n):
    for i in range(0, len(seq), n):
        yield seq[i:i+n]

def method(seq, start=['AUG'], stop=['UAA','UAG','UGA']):
    response = ''
    started = False
    for x in readable(seq, 3):
        if x in start:
            started = True
            response += '   '
        if x in stop:
            started=False
        if started:
            response += x
                
    yield response

for result in method(RNAs):
    b=result
print (' ')
print ('The readable part of the RNA is:')
print(result)
print (' ')
print ('Considering a minimum of 30 nucleotides, the readable part of the RNA is:')
f=result.split()
readable_regionslist=[x for x in f if len(x)>=int(30)] #readable regions
separator = '   '
readable_regions=(separator.join(readable_regionslist))
print(readable_regions)


def translate(seq): #translate the readable regions
    table = {
        'AUA':'I', 'AUC':'I', 'AUU':'I', 'AUG':'M',
        'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACU':'T',
        'AAC':'N', 'AAU':'N', 'AAA':'K', 'AAG':'K',
        'AGC':'S', 'AGU':'S', 'AGA':'R', 'AGG':'R',                 
        'CUA':'L', 'CUC':'L', 'CUG':'L', 'CUU':'L',
        'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCU':'P',
        'CAC':'H', 'CAU':'H', 'CAA':'Q', 'CAG':'Q',
        'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGU':'R',
        'GUA':'V', 'GUC':'V', 'GUG':'V', 'GUU':'V',
        'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCU':'A',
        'GAC':'D', 'GAU':'D', 'GAA':'E', 'GAG':'E',
        'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGU':'G',
        'UCA':'S', 'UCC':'S', 'UCG':'S', 'UCU':'S',
        'UUC':'F', 'UUU':'F', 'UUA':'L', 'UUG':'L',
        'UAC':'Y', 'UAU':'Y', 'UGG':'W', 'UGU':'C',
        'UGC':'C', '   ':'   '}
    protein =""
    if len(b)%3 == 0:
  
        for i in range(0, len(seq), 3):
            codon = seq[i:i + 3]
            protein+= table[codon]
    return protein
p = translate(b)


p = translate(readable_regions)
print (' ')
print ('The aa sequence is:')
print (p)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68226498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档