gpt4 book ai didi

python - 删除行更改(换行符)

转载 作者:太空宇宙 更新时间:2023-11-03 15:38:34 25 4
gpt4 key购买 nike

我想从 NCBI 数据库中找到的序列中删除行更改。例如:https://www.ncbi.nlm.nih.gov/protein/148744825?report=fasta

我的目标是直接从网页复制,以便进行输入并获得一行来正确处理序列。到目前为止,我必须使用记事本并手动删除所有空格(这真的很烦人)。

我尝试过很多事情:

s = s.replace('\n', '')
s = s.strip()
s = ''.join(s.split())

他们都不适合我。也许问题是我如何进行输入。

提前谢谢您。

最佳答案

这有效:

s='''MATLKEKLIAPVAEEETRIPNNKITVVGVGQVGMACAISILGKSLTDELALVDVLEDKLKGEMMDLQHGS
LFLQTPKIVADKDYSVTANSKIVVVTAGVRQQEGESRLNLVQRNVNVFKFIIPQIVKYSPDCIIIVVSNP
VDILTYVTWKLSGLPKHRVIGSGCNLDSARFRYLMAEKLGIHPSSCHGWILGEHGDSSVAVWSGVNVAGV
SLQELNPEMGTDNDSENWKEVHKMVVESAYEVIKLKGYTNWAIGLSVADLIESMLKNLSRIHPVSTMVKG
MYGIENEVFLSLPCILNARGLTSVINQKLKDEEVAQLKKSADTLWGIQKDLKDL'''

s
Out[69]: 'MATLKEKLIAPVAEEETRIPNNKITVVGVGQVGMACAISILGKSLTDELALVDVLEDKLKGEMMDLQHGS\nLFLQTPKIVADKDYSVTANSKIVVVTAGVRQQEGESRLNLVQRNVNVFKFIIPQIVKYSPDCIIIVVSNP\nVDILTYVTWKLSGLPKHRVIGSGCNLDSARFRYLMAEKLGIHPSSCHGWILGEHGDSSVAVWSGVNVAGV\nSLQELNPEMGTDNDSENWKEVHKMVVESAYEVIKLKGYTNWAIGLSVADLIESMLKNLSRIHPVSTMVKG\nMYGIENEVFLSLPCILNARGLTSVINQKLKDEEVAQLKKSADTLWGIQKDLKDL'

s.split()
Out[70]:
['MATLKEKLIAPVAEEETRIPNNKITVVGVGQVGMACAISILGKSLTDELALVDVLEDKLKGEMMDLQHGS',
'LFLQTPKIVADKDYSVTANSKIVVVTAGVRQQEGESRLNLVQRNVNVFKFIIPQIVKYSPDCIIIVVSNP',
'VDILTYVTWKLSGLPKHRVIGSGCNLDSARFRYLMAEKLGIHPSSCHGWILGEHGDSSVAVWSGVNVAGV',
'SLQELNPEMGTDNDSENWKEVHKMVVESAYEVIKLKGYTNWAIGLSVADLIESMLKNLSRIHPVSTMVKG',
'MYGIENEVFLSLPCILNARGLTSVINQKLKDEEVAQLKKSADTLWGIQKDLKDL']

''.join(s.split())
Out[71]: 'MATLKEKLIAPVAEEETRIPNNKITVVGVGQVGMACAISILGKSLTDELALVDVLEDKLKGEMMDLQHGSLFLQTPKIVADKDYSVTANSKIVVVTAGVRQQEGESRLNLVQRNVNVFKFIIPQIVKYSPDCIIIVVSNPVDILTYVTWKLSGLPKHRVIGSGCNLDSARFRYLMAEKLGIHPSSCHGWILGEHGDSSVAVWSGVNVAGVSLQELNPEMGTDNDSENWKEVHKMVVESAYEVIKLKGYTNWAIGLSVADLIESMLKNLSRIHPVSTMVKGMYGIENEVFLSLPCILNARGLTSVINQKLKDEEVAQLKKSADTLWGIQKDLKDL'

不确定您的问题是什么。投票结束。

关于python - 删除行更改(换行符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42333550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com