去除rdhA.faa序列中的换行符,序列名称除外,并将文件另存为rdhA.faa2
python脚本:
input_file = "rdhA.faa"
output_file = "rdhA.faa2"
with open(input_file, "r") as infile, open(output_file, "w") as outfile:
sequence = ""
for line in infile:
if line.startswith(">"):
# 如果是序列名称行,先写入之前的序列(如果有的话)
if sequence:
outfile.write(sequence + "\n")
sequence = ""
# 写入序列名称
outfile.write(line)
else:
# 如果是序列行,去除换行符并拼接到当前序列
sequence += line.strip()
# 处理最后一条序列
if sequence:
outfile.write(sequence + "\n")
# 输出完成的消息
print(f"处理完成。请查看文件:{output_file}")