import sys,os,time
import multiprocessing as mp
bamfile = sys.argv[1]
#desDir = '/public0/nong/tcga_luad/bedgraph_test'
desDir = sys.argv[2]
os.system('mkdir -p ' + desDir)
bams = open(bamfile,'r').read().strip().split('\n')
cmd_filter = 'python3 '+ os.path.join(os.path.dirname(sys.argv[0]), '2.1_filter_chr.py')
def genomceCoverage(bam, outdir):
bamname = os.path.basename(bam)
graph = os.path.join(outdir,bamname ) + '.bedgraph'
cmd = 'genomeCoverageBed -bg -ibam '+bam + ' -g /public0/nong/source/hg38.chrom.chr.sizes -split | ' + cmd_filter + ' >' + graph
print(cmd)
os.system(cmd)
pool = mp.Pool(8) #多线程, 以及线程数!
for bam in bams:
t = pool.apply_async(genomceCoverage, (bam, desDir))
pool.close()
pool.join()
网友评论