为什么python发出错误说这是一个文件夹?

时间:2017-11-05 16:27:47

标签: python-2.7 biopython

我正在开发一个程序,其中一个功能是根据ID整理一个fasta文件。该功能描述为:

def sorting_files(output,my_fasta_file, sample_name):
    #to sort the fasta file that contain all the genes 
    my_file=open(my_fasta_file)
    input_handle=(my_file,'rU')
    fasta_file=SeqIO.parse(input_handle, 'fasta')
    sorted_fasta_file=(record for record in sorted(fasta_file, key=lambda x : x.id))
    sorted_file=SeqIO.write(sorted_fasta_file, output + 'sorted_' + sample_name +'.fa', 'fasta')
    return sorted_file 

然后我从main调用函数:

      #to sort the fasta file
   def main():    
        folders=sorted(glob.glob(opts.input_file +'/*_velvet'))         
        for folder in folders:
            my_fasta_file=glob.glob(folder +'/H*.fa')
            print my_fasta_file
            #sys.exit()
            sorted_file=sorting_files(my_fasta_file,output,sample_name)
            print 'The fasta file has been sorted, hoooray!'
    main()

When it prints my_fasta_file it prints:

['/home/path_to_file/velvet_file/sample_name_velvet/sample_name.fa']

但是我收到以下错误消息:

File "model.py", line 82, in sorting_files
    my_file=open(my_fasta_file)
IOError: [Errno 21] Is a directory: '/home/path_to_files/velvet_file/sample-name_velvet/'

我无法弄清楚错误的位置。任何有关这方面的帮助将受到高度赞赏。 谢谢,

1 个答案:

答案 0 :(得分:1)

我认为您的代码中的错误会带有您的参数的顺序。

def sorting_files(output,my_fasta_file, sample_name):
    ...
sorted_file=sorting_files(my_fasta_file,output,sample_name)

你将output置于my_fasta_file应该去的地方和版面。我不知道您的代码中output是什么,但我的猜测是,它是目录'/home/path_to_files/velvet_file/sample-name_velvet/'