分段Fau

2024-06-25 05:39:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在UNIX机器上使用python2.4.4(旧机器,对此无能为力)。我对python/编程非常陌生,以前从未使用过UNIX机器。这就是我要做的:

  1. 从FASTA文件(蛋白质+核苷酸)中提取一个序列到临时文本文件。在
  2. 将这个临时文件交给一个名为“threader”的程序
  3. 附加threader的输出(调用临时结果输出)到一个名为结果。输出在
  4. 删除临时文件。在
  5. 移除临时结果输出文件。在
  6. 重复使用下一个FASTA序列。在

以下是我目前为止的代码:

import os
from itertools import groupby

input_file = open('controls.txt', 'r')
output_file = open('results.out', 'a')

def fasta_parser(fasta_name):
input = fasta_name
parse = (x[1] for x in groupby(input, lambda line: line[0] == ">"))
for header in parse:
    header = header.next()[0:].strip()
    seq = "\n".join(s.strip() for s in parse.next())
    yield (header, '\n', seq)

parsedfile = fasta_parser(input_file)

mylist = list(parsedfile)

index = 0

while index < len(mylist): 
    temp_file = open('temp.txt', 'a+')
    temp_file.write(' '.join(mylist[index]))    
    os.system('threader' + ' temp.txt' + ' tempresult.out' + ' structures.txt')
    os.remove('temp.txt')
    f = open('tempresult.out', 'r')
    data = str(f.read())
    output_file.write(data)   
    os.remove('tempresult.out')
    index +=1


output_file.close()
temp_file.close()
input_file.close()

当我运行这个脚本时,我得到错误'分段错误'。据我所知,这是因为我搞乱了我不该搞乱的记忆(???)。我想这和临时文件有关,但我不知道该怎么解决这个问题。在

任何帮助都将不胜感激!在

谢谢!在

更新1: Threader可以像这样多次使用同一序列:

^{pr2}$

更新2:如果其他人得到这个错误。我忘了关门温度文本在调用threader程序之前。在


Tags: txt机器inputoutputindexparseos序列