예제 #1
0
def multiWellington(regions, reads, **kwargs):
    p = mp.Pool(CPUs)
    for i in progress.bar(regions):
        if clargs.one_dimension:
            fp = footprinting.wellington1D(i, reads, **kwargs)
        else:
            fp = footprinting.wellington(i, reads, **kwargs)
        p.apply_async(fp, callback=writetodisk)
        # Hold here while the queue is bigger than the number of reads we're happy to store in memory
        while p._taskqueue.qsize() > max_regions_cached_in_memory:
            pass
    p.close()
    puts_err("Waiting for the last {0} jobs to finish...".format(max_regions_cached_in_memory))
    p.join()
def multiWellington(regions,reads,**kwargs):
    p = mp.Pool(CPUs)
    for i in progress.bar(regions):
        if clargs.one_dimension:
            fp = footprinting.wellington1D(i,reads,**kwargs)
        else:
            fp = footprinting.wellington(i,reads,**kwargs)
        p.apply_async(fp,callback = writetodisk)
        #Hold here while the queue is bigger than the number of reads we're happy to store in memory
        while p._taskqueue.qsize() > max_regions_cached_in_memory:
            pass
    p.close()
    puts_err("Waiting for the last {0} jobs to finish...".format(max_regions_cached_in_memory))
    p.join()
예제 #3
0
#Call footprints
import sys
import pyDNase
import pyDNase.footprinting as fp

if (sys.argv[5] == 'singleEnd'):
    regions = pyDNase.GenomicIntervalSet(sys.argv[1])
    reads = pyDNase.BAMHandler(sys.argv[2])
    f = len(regions) - 1
    for x in range(f):
        footprinter = fp.wellington1D(regions[x], reads)
        footprints = footprinter.footprints(withCutoff=int(sys.argv[4]))
        with open(sys.argv[3], "a") as bedout:
            bedout.write(str(footprints))
else:
    regions = pyDNase.GenomicIntervalSet(sys.argv[1])
    reads = pyDNase.BAMHandler(sys.argv[2])
    f = len(regions) - 1
    for x in range(f):
        footprinter = fp.wellington(regions[x], reads)
        footprints = footprinter.footprints(withCutoff=int(sys.argv[4]))
        with open(sys.argv[3], "a") as bedout:
            bedout.write(str(footprints))
예제 #4
0
#Call footprints
import sys
import pyDNase
import pyDNase.footprinting as fp

if(sys.argv[5] == 'singleEnd'):
	regions = pyDNase.GenomicIntervalSet(sys.argv[1])
	reads = pyDNase.BAMHandler(sys.argv[2])
	f=len(regions)-1
	for x in range(f):
	  footprinter = fp.wellington1D(regions[x],reads)
	  footprints = footprinter.footprints(withCutoff=int(sys.argv[4]))
	  with open(sys.argv[3],"a") as bedout:
	    bedout.write(str(footprints))
else:
	regions = pyDNase.GenomicIntervalSet(sys.argv[1])
	reads = pyDNase.BAMHandler(sys.argv[2])
	f=len(regions)-1
	for x in range(f):
	  footprinter = fp.wellington(regions[x],reads)
	  footprints = footprinter.footprints(withCutoff=int(sys.argv[4]))
	  with open(sys.argv[3],"a") as bedout:
	    bedout.write(str(footprints))	
예제 #5
0
wigout = open(os.path.join(args.outputdir,args.output_prefix+".wig"),"w")
fdrout = open(os.path.join(args.outputdir,args.output_prefix+".FDR.{0}.bed".format(args.FDR_cutoff)),"w")

#Required for UCSC upload
print >> wigout, "track type=wiggle_0"

#Iterate in chromosome, basepair order
orderedbychr = [item for sublist in sorted(regions.intervals.values()) 
                for item in sorted(sublist, key=lambda peak: peak.startbp)]
#puts("Calculating footprints...")
#for each in progress.bar(orderedbychr):
    #Calculate footprint scores (1D or 2D)
    #TODO: put args here.
for each in orderedbychr:
    if args.one_dimension:
        fp = footprinting.wellington1D(each, reads, shoulder_sizes=args.shoulder_sizes,
                                       footprint_sizes=args.footprint_sizes, bonferroni=args.bonferroni)
    else:
        fp = footprinting.wellington(each, reads, shoulder_sizes=args.shoulder_sizes,
                                     footprint_sizes=args.footprint_sizes, bonferroni=args.bonferroni)

    #Write fpscores to WIG
    print >> wigout, "fixedStep\tchrom="+str(fp.interval.chromosome)+"\tstart="+ str(fp.interval.startbp)+"\tstep=1"
    for i in fp.scores:
        print >> wigout, i

    #FDR footprints
    fdr = percentile(np.concatenate([fp.calculate(reads, FDR=True, shoulder_sizes=args.shoulder_sizes,
                                                  footprint_sizes=args.footprint_sizes, bonferroni=args.bonferroni)[0]
                                     for i in range(args.FDR_iterations)]).tolist(),args.FDR_cutoff)
###    print fdr
    if fdr < args.FDR_limit: