def getSplicesCount(self, chrom="", rmin="", rmax="", restrict="", distinct=False):
""" returns the number of row in the splices table.
"""
+ # TODO: if the rds type is DNA should this just return zero?
return self.getTableEntryCount("splices", chrom, rmin, rmax, restrict, distinct, startField="startL")
destinationEntries.append((row["readID"], row["chrom"], int(row["startL"]), int(row["stopL"]), int(row["startR"]), int(row["stopR"]), row["sense"],
row["weight"], row["flag"], row["mismatch"]))
- self.memcon.executemany("insert into splices(ID, readID, chrom, startL, stopL, startR, stopR, sense, weight, flag, mismatch) values (NULL,?,?,?,?,?,?,?,?)", destinationEntries)
+ self.memcon.executemany("insert into splices(ID, readID, chrom, startL, stopL, startR, stopR, sense, weight, flag, mismatch) values (NULL,?,?,?,?,?,?,?,?,?,?)", destinationEntries)
doCache = False
cachePages = -1
+ mockRDS = None
if doControl:
print "\ncontrol:"
mockRDS = ReadDataset.ReadDataset(mockfile, verbose=True, cache=doCache)
mockRDSsize = len(mockRDS) / 1000000.
controlSampleString = "\t%s (%.1f M reads)" % (mockfile, mockRDSsize)
else:
+ mockRDSsize = 0
controlSampleString = " none"
hitRDSsize = len(hitRDS) / 1000000.
hitChromList = hitRDS.getChromosomes()
if doControl:
mockChromList = mockRDS.getChromosomes()
+ else:
+ mockChromList = []
+ mockSampleSize = 0
+ hitSampleSize = 0
if normalize:
if doControl:
mockSampleSize = mockRDSsize
continue
#now do background swapping the two samples around
- 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)
+ 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)
+ print headline
+ shiftModeValue = writeRegionsToFile(outfile, outregions, doPvalue, p, poissonmean, reportshift, shiftValue)
footer = getFooter(statistics, doDirectionality, doRevBackground, shiftValue, reportshift, shiftModeValue)
print footer
def getFoldRatio(rds, chrom, start, stop, doControl, useMulti, normalize, sampleSize, sumAll, minRatio):
- if doControl:
+ if doControl and rds is not None:
foldRatio = getFoldRatioFromRDS(rds, chrom, start, stop, useMulti, normalize, sampleSize, sumAll)
else:
foldRatio = minRatio
regionWeights.append(int(sumAll))
if sumAll >= minHits and numStarts > minRatio and (regionStop - regionStart) > readlen:
sumMulti = 0.
- #first pass uses getFoldRatio on mockRDS as there may not be control
- foldRatio = getFoldRatioFromRDS(referenceRDS, chrom, regionStart, regionStop, useMulti, normalizeToRPM, referenceSampleSize, sumAll)
+ foldRatio = getFoldRatio(referenceRDS, chrom, regionStart, regionStop, doControl, useMulti, normalizeToRPM, referenceSampleSize, sumAll, minRatio)
if foldRatio >= minRatio:
# first pass, with absolute numbers
peak = findPeak(currentReadList, regionStart, regionStop - regionStart, readlen, doWeight=True, leftPlus=doDirectionality, shift=shiftValue)
pValue *= poissonmean
pValue /= i+1
- outputList.append("%1.2f" % pValue)
+ outputList.append("%1.2g" % pValue)
outline = string.join(outputList, "\t")
print outline