我为一个生物信息学类分配了一个任务,它要求一个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:
任何帮助都将不胜感激!你知道吗
今天花了大部分时间在这个问题上,我回答了自己的问题。我完全错了。以下是我用来实现目标的代码:
输出结果如下:
相关问题 更多 >
编程相关推荐