2017-08-09 30 views
-1

私はsamファイルをbamファイルに変換し、それをソートしてPythonでインデックスするクラスの関数を書いています(これはbashで実現するのは簡単ですが、もっと)。Popen samtoolsが実行されていません

すでに定義されているディレクトリ(cwd)に、クラスの別の関数によってsamファイルが生成されています。

def sam2bam(self): 
    """ 
    return a sorted and index bam file in the working directory 
    """ 


    if str(self.fq)[7:9] == '24': 
     # create bam 
     comnd = "samtools view -bS " + str(self.fq)[0:10] + ".sam > " + str(self.fq)[0:10] + ".bam" 

     print("Converting sam to bam ... (executed command: {})\n".format(comnd)) 
     comnd_input = shlex.split(comnd) 

     with open((str(self.fq)[0:10] + '.bam'), 'w') as f: 
      Popen(comnd_input, stdout = f, stderr = PIPE, cwd = 'G24/' + str(self.fq)) 


     # sort bam  
     comnd2 = "samtools sort " + str(self.fq)[0:10] + ".bam -o " + str(self.fq)[0:10] + ".sorted.bam" 
     print('Sorting bam ... (executed command: {}\n)'.format(comnd2)) 

     comnd_input2 = shlex.split(comnd2) 
     with open((str(self.fq)[0:10] + 'sorted.bam'), 'w') as f_sort: 
      Popen(comnd_input2, stdout = f_sort, stderr = PIPE, cwd = 'G24/' + str(self.fq)) 

     # index bam 
     comnd3 = "samtools index " + str(self.fq)[0:10] + ".sorted.bam" 
     print('Indexing bam ... (executed command: {}\n)'.format(comnd3)) 

     comnd_input3 = shlex.split(comnd3) 

     with open((str(self.fq)[0:10] + 'sorted.bam'), 'w') as f_index: 
      Popen(comnd_input3, stdout = f_index, stderr = PIPE, cwd = 'G24/' + str(self.fq)) 

しかし、何も

を出てきた私が試した:どちらか

Popen(comnd_input, stdout = PIPE, stderr = PIPE, cwd = 'G24/' + str(self.fq)) 

まだ何もここで

はコードです。変数として保存し、.communicate()、何もしません。

私は何が間違っているのか分かりません。

おかげで、

XPの

答えて

0

は、それが原因で '>' リダイレクトであるhere.

を参照してください。コードを次のように変更しました。

Popen(comnd, stdout = PIPE, stderr = PIPE, shell = True, cwd = 'G14/' + str(self.fq)) 

関連する問題