【发布时间】:2019-10-16 09:26:05
【问题描述】:
我有一个生物信息学课程的作业,该课程要求 python 脚本对包含多个蛋白质序列的 FASTA 文件执行以下操作:
-打开用户输入指定的.fasta文件
-打印标题行(即以“>”开头的行)
-打印前10个氨基酸并在同一行,报告序列中氨基酸的数量
经过几个小时的尝试,我只设法为第一个序列打印了标题行和前 10 个氨基酸。我编写的 for 循环似乎并没有超出此范围(如果这是垃圾,请道歉,我是一个完整的初学者!)
input_file = open(input("\nPlease enter the name of a FASTA file (inlcuding the .fasta extension): "))
# Opens the file specified by the user
for line in input_file:
line = line.rstrip()
if line[0] == ">":
header = line
print("\nHeader:", header) # prints the header line
no_lines_searched = 0 # To stop loop after first line of sequence when printing first 10 AAs
for i in input_file:
if ">" not in i and no_lines_searched < 1:
print("First ten amino acid residues: ", i[0:10], "# Amino acids: ") # Prints the first 10 AAs
no_lines_searched = no_lines_searched+1 # To stop loop after first line of sequence
我试图变得聪明并设计第二个循环,使其返回序列的前 10 个氨基酸,然后停止,直到遇到另一个序列(用“>”表示)。
然后我打算使用占位符 %s 以某种方式计算文件中每个序列的总序列长度,但似乎无法超越这一点!
我得到的输出如下:
Header: >sp|P03378|ENV_HV1A2 Envelope glycoprotein gp160 OS=Human immunodeficiency virus type 1 group M subtype B (isolate ARV2/SF2) GN=env PE=3 SV=1
First ten amino acid residues: MKVKGTRRNY # Amino acids:
任何帮助将不胜感激!
【问题讨论】: