第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在找到值后立即跳過(guò)字符串搜索到索引?Python

如何在找到值后立即跳過(guò)字符串搜索到索引?Python

慕田峪9158850 2021-06-30 13:55:49
我的程序現(xiàn)在有兩個(gè)功能。get_orf(dna)它需要一個(gè)名為 dna 的字符串作為輸入。如果字符串以起始密碼子“ATG”開(kāi)頭,則以get_orf3 的倍數(shù)搜索任何終止密碼子。如果找到其中之一,則返回 ORF('ATG' 和直到終止密碼子的序列)。orf_List = []stopCodons = ["TAG", "TAA", "TGA"]def get_orf(dna):    #checks to see if the first three amino acids are ATG    if dna[:3] == "ATG":        #if the first three are amino acids,         #it checks the dna string in multiples of 3 uisng the range fucntion        for k in range(0, len(dna), 3):            #checking for stop codons in the dna string            if any(s in dna[k:k+3] for s in stopCodons):                #if a stop codon is found, it returns it                return dna[0:k]        #prints No Orf if there are no stop codons found        else:            print("No ORF.")    #prints No Orf if the dna does not start with ATG    else:        print("No ATG IN BEGINNING.")并且one_frame(dna)采用一個(gè)DNA串作為輸入。one_frame以三的倍數(shù)從左到右搜索該字符串。當(dāng)它遇到一個(gè)起始密碼子“ATG”時(shí),它會(huì)調(diào)用get_orf從該起始密碼子開(kāi)始(直到結(jié)束)的字符串片段以返回一個(gè) ORF。該 ORF 被添加到一個(gè) ORF 列表中,然后該函數(shù)在DNA 串到我們剛找到的 ORF 之后的點(diǎn),并開(kāi)始尋找下一個(gè) ORF。重復(fù)這個(gè)過(guò)程,直到我們遍歷了整個(gè) DNA 串。def one_frame(dna):    i = 0    while i < len(dna):        for i in range(0, len(dna), 3):            if "ATG" in dna[i:i+3]:                newOrf = get_orf(dna[i:])                orf_List.append(newOrf)            #i don't know how to skip ahead    print(orf_List)     return(orf_List)當(dāng)我調(diào)用 時(shí)one_frame("ATGCCCATGCCCCCCTAG"),我無(wú)法弄清楚如何向前跳到找到的 ORF 的最后一個(gè)索引,以便我可以繼續(xù)我的搜索。有什么幫助嗎?使用此代碼,它會(huì)打印出“ATGCCCATGCCCCCCTAG”和“ATGCCCCCCTAG”。較小的不應(yīng)打印,因?yàn)樗谳^大的內(nèi)部。
查看完整描述

1 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

我建議您擺脫for循環(huán)one_frame并將其實(shí)現(xiàn)為while循環(huán)(看起來(lái)您已經(jīng)嘗試過(guò))。


然后您可以手動(dòng)控制i值并將找到的 ORF 的長(zhǎng)度添加到它以向前跳過(guò)。


def one_frame(dna):

    orf_list = []

    i = 0

    while i < len(dna):

        if "ATG" == dna[i:i+3]:

            new_orf = get_orf(dna[i:])

            if new_orf:

                orf_list.append(new_orf)

                i += len(new_orf)

                continue

        i += 3


    print(orf_list)

    return(orf_list)


查看完整回答
反對(duì) 回復(fù) 2021-07-06
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)