我有以下序列,我正在尝试选择最长的序列。我知道它是第一个序列,但是我如何告诉Python选择M(开始)和*(停止)之间距离最长的序列?
First= MATVEPETTPTPNPPTTEEEKTESNQEVANPEHYIKHPLQNRWALWFFKNDKSKTWQANLRLISKFDTVEDFWALYNHIQLSSNLMPGCDYSLFKDGIEPMWEDEKNKRGGRWLITLNKQQRRSDLDRFWLETLLCLIGESFDDYSDDVCGAVVNVRAKGDKIAIWTTECENREAVTHIGRVYKERLGLPPKIVIGYQSHADTATKSGSTTKNRFVV*
Second= WRLSNRKPPLLLIPRLQKRRKRNLIRRLLTQNTILNIPYRTDGHSGFLKMIKAKLGKQTCG*SPSLILLKTFGLCTTISSCLVI*CLAVTTHFLRMVLSLCGKMRKTNGEDDG*LH*TNSRDEVTSIAFG*RHFCALLENLLMTTVMMYVALLLMLELKVIR*QYGLLNVKTEKLLHI*GGYTRKG*DFLQR**LVISPTQTQLLRAAPPLKIGLLF
Third= GDCRTGNHPYS*SPDYRRGENGI*SGGC*PRTLY*TSPTEQMGTLVF*K**KQNLASKPAADLQV*YC*RLLGSVQPYPVV**FNAWL*LLTF*GWY*AYVGR*EKQTGRTMANYIEQTAETK*PRSLLARDTSVPYWRIF**LQ**CMWRCC*C*S*R**DSNMDY*M*KQRSCYTYREGIQGKVRTSSKDSDWLSVPRRHSY*ERLHH*K*VCCL
Fourth= LNNKPIFSGGAALSSCVCVGLITNHYLWRKS*PFLVYPPYMCNSFSVFTFSSPYCYLITFSSNINNSATYIITVVIKRFSNKAQKCL*PKAIEVTSSLLFVQCN*PSSSPFVFLIFPHRLNTILKK*VVTARH*ITRQLDMVVQSPKVFNSIKLGDQPQVCLPSFAFIIFKKPECPSVL*GMFNIVFWVSNLLIRFRFLLFCSRGIRSRGGFRFDSRH
Fifth= *TTNLFLVVEPLLVAVSAWD**PITIFGGSPNLSLYTLPICVTASLFSHSVVHIAILSPLALTLTTAPHTSSL*SSKDSPIRHRSVSSQKRSRSLRLCCLFNVISHRPPRLFFSSSHIGSIPSLKSE*SQPGIKLLDNWIWLYRAQKSSTVSNLEISRRFACQVLLLSFLKNQSAHLFCRGCLI*CSGLATS*LDSVFSSSVVGGLGVGVVSGSTVA
Sixth= KQQTYF*WWSRS**LCLRGTDNQSLSLEEVLTFPCIPSLYV*QLLCFHIQ*SILLSYHL*L*H*QQRHIHHHCSHQKILQ*GTEVSLAKSDRGHFVSAVCSM*LAIVLPVCFSHLPT*AQYHP*KVSSHSQALNY*TTGYGCTEPKSLQQYQTWRSAAGLLAKFCFYHF*KTRVPICSVGDV*YSVLG*QPPD*IPFSPLL*SGD*E*GWFPVRQSP
为了帮助您入门,这里有一些基本命令来获取您感兴趣的长度。我定义了一个函数来检查每个字符的第一个元素之间的长度。
First= 'MATVEPETTPTPNPPTTEEEKTESNQEVANPEHYIKHPLQNRWALWFFKNDKSKTWQANLRLISKFDTVEDFWALYNHIQLSSNLMPGCDYSLFKDGIEPMWEDEKNKRGGRWLITLNKQQRRSDLDRFWLETLLCLIGESFDDYSDDVCGAVVNVRAKGDKIAIWTTECENREAVTHIGRVYKERLGLPPKIVIGYQSHADTATKSGSTTKNRFVV*'
Second= 'WRLSNRKPPLLLIPRLQKRRKRNLIRRLLTQNTILNIPYRTDGHSGFLKMIKAKLGKQTCGSPSLILLKTFGLCTTISSCLVICLAVTTHFLRMVLSLCGKMRKTNGEDDGLHTNSRDEVTSIAFGRHFCALLENLLMTTVMMYVALLLMLELKVIRQYGLLNVKTEKLLHIGGYTRKGDFLQR**LVISPTQTQLLRAAPPLKIGLLF'
Third= 'GDCRTGNHPYSSPDYRRGENGISGGCPRTLYTSPTEQMGTLVFKKQNLASKPAADLQVYCRLLGSVQPYPVVFNAWLLLTFGWYAYVGREKQTGRTMANYIEQTAETKPRSLLARDTSVPYWRIFLQCMWRCCCS*R**DSNMDYMKQRSCYTYREGIQGKVRTSSKDSDWLSVPRRHSYERLHHK*VCCL'
Fourth= 'LNNKPIFSGGAALSSCVCVGLITNHYLWRKSPFLVYPPYMCNSFSVFTFSSPYCYLITFSSNINNSATYIITVVIKRFSNKAQKCLPKAIEVTSSLLFVQCNPSSSPFVFLIFPHRLNTILKKVVTARHITRQLDMVVQSPKVFNSIKLGDQPQVCLPSFAFIIFKKPECPSVLGMFNIVFWVSNLLIRFRFLLFCSRGIRSRGGFRFDSRH'
Fifth= '*TTNLFLVVEPLLVAVSAWD**PITIFGGSPNLSLYTLPICVTASLFSHSVVHIAILSPLALTLTTAPHTSSLSSKDSPIRHRSVSSQKRSRSLRLCCLFNVISHRPPRLFFSSSHIGSIPSLKSESQPGIKLLDNWIWLYRAQKSSTVSNLEISRRFACQVLLLSFLKNQSAHLFCRGCLICSGLATSLDSVFSSSVVGGLGVGVVSGSTVA'
Sixth= 'KQQTYF*WWSRS**LCLRGTDNQSLSLEEVLTFPCIPSLYVQLLCFHIQSILLSYHLLHQQRHIHHHCSHQKILQGTEVSLAKSDRGHFVSAVCSMLAIVLPVCFSHLPTAQYHPKVSSHSQALNYTTGYGCTEPKSLQQYQTWRSAAGLLAKFCFYHFKTRVPICSVGDVYSVLGQPPDIPFSPLLSGDE*GWFPVRQSP'
def sequence_length( string, char1, char2 ):
try:
return string.index(char2) - string.index(char1)
except ValueError:
return None
print( sequence_length( First, 'M', '*' ) )
print( sequence_length( Second, 'M', '*' ) )
print( sequence_length( Third, 'M', '*' ) )
print( sequence_length( Fourth, 'M', '*' ) )
print( sequence_length( Fifth, 'M', '*' ) )
print( sequence_length( Sixth, 'M', '*' ) )
返回:
217
135
98
None
None
-89
我是一名优秀的程序员,十分优秀!