def do_pred_bam(self, inpath_bam, outpath_npy): if os.stat(inpath_bam).st_size != 0: pre, ext = os.path.splitext(inpath_bam) temp_fasta = "{}.fasta".format(pre) # create the file upfront, so pysam can open it with open(temp_fasta, 'w') as fp: pass pysam.fasta("-@", str(self.cores - 1), inpath_bam, save_stdout=temp_fasta) self.do_pred_fasta(temp_fasta, outpath_npy) else: np.save(outpath_npy, np.empty(0))
def get_mapped_fasta(self, inpath, outpath, single=False): # set output in both pysam wrapper and samtools argument list outpath_fasta_1 = outpath + "_1.fasta" # create the file upfront, so pysam can open it with open(outpath_fasta_1, 'w') as fp: pass if single: pysam.fasta("-G 4", "-@", self.c_threads, inpath, save_stdout=outpath_fasta_1) return outpath_fasta_1, "" else: pysam.fasta("-NG 12", "-f 64", "-@", self.c_threads, inpath, save_stdout=outpath_fasta_1) outpath_fasta_2 = outpath + "_2.fasta" # create the file upfront, so pysam can open it with open(outpath_fasta_2, 'w') as fp: pass pysam.fasta("-NG 12", "-f 128", "-@", self.c_threads, inpath, save_stdout=outpath_fasta_2) return outpath_fasta_1, outpath_fasta_2
def setUpClass(cls): # convert bam to reads pysam.fasta(cls.__reads_bam__, save_stdout=cls.__reads_fasta__.name)