- mockSampleSize = 0
- hitSampleSize = 0
- if normalize:
- if doControl:
- mockSampleSize = mockRDSsize
-
- hitSampleSize = hitRDSsize
-
- hitChromList.sort()
-
- for chromosome in hitChromList:
- if doNotProcessChromosome(chromosome, doControl, mockChromList):
- continue
-
- print "chromosome %s" % (chromosome)
- hitDict = hitRDS.getReadsDict(fullChrom=True, chrom=chromosome, flag=withFlag, withWeight=True,
- doMulti=useMulti, findallOptimize=True, strand=stranded,
- combine5p=combine5p)
- maxCoord = hitRDS.getMaxCoordinate(chromosome, doMulti=useMulti)
- if shiftValue == "learn":
- shiftValue = learnShift(hitDict, hitSampleSize, mockRDS, chromosome, doControl, useMulti, normalize,
- mockSampleSize, minRatio, maxSpacing, maxCoord, stringency, readlen, minHits,
- logfilename, outfile, outfilename)
-
- regionStats, allRegionWeights, outregions = locateRegions(hitRDS, hitSampleSize, mockRDS, mockSampleSize,
- chromosome, useMulti, normalize, maxSpacing,
- doDirectionality, doTrim, minHits, minRatio,
- readlen, shiftValue, minPeak, minPlusRatio,
- maxPlusRatio, leftPlusRatio, listPeak, noMulti,
- doControl, factor, trimValue, outputRegionList=True)
-
- statistics["index"] += regionStats["index"]
- statistics["total"] += regionStats["total"]
- statistics["failed"] += regionStats["failed"]
- if not doRevBackground:
- if doPvalue:
- p, poissonmean = calculatePValue(allRegionWeights)
-
- print headline
- shiftModeValue = writeRegionsToFile(outfile, outregions, doPvalue, p, poissonmean, reportshift, shiftValue)
- continue
-
- #now do background swapping the two samples around
- if mockRDS is not None:
- print "calculating background..."
- backgroundTrimValue = 1/20.
- backgroundRegionStats, backgroundRegionWeights = locateRegions(mockRDS, mockSampleSize, hitRDS, hitSampleSize,
- chromosome, useMulti, normalize, maxSpacing,
- doDirectionality, doTrim, minHits, minRatio,
- readlen, shiftValue, minPeak, minPlusRatio,
- maxPlusRatio, leftPlusRatio, listPeak, noMulti,
- doControl, factor, backgroundTrimValue)
-
- statistics["mIndex"] += backgroundRegionStats["index"]
- statistics["mTotal"] += backgroundRegionStats["total"]
- statistics["failed"] += backgroundRegionStats["failed"]
- print statistics["mIndex"], statistics["mTotal"]
- if doPvalue:
- if pValueType == "self":
- p, poissonmean = calculatePValue(allRegionWeights)
- else:
- p, poissonmean = calculatePValue(backgroundRegionWeights)
-
- print headline
- shiftModeValue = writeRegionsToFile(outfile, outregions, doPvalue, p, poissonmean, reportshift, shiftValue)
-
- footer = getFooter(statistics, doDirectionality, doRevBackground, shiftValue, reportshift, shiftModeValue)
- print footer
- outfile.write(footer)
- outfile.close()