public Tuple <double, int, int[]> Compute_mHG(mHGCorrectionType correctionType, ConfigParams Conf) { lock (locker) { _mHG = mHGJumper.minimumHypergeometric(InducedLabledVector, -1, -1, correctionType); Conf.mHGlist.Add(new Tuple <double, int>(mHG.Item1, Interlocked.Increment(ref Conf.computedMHGs))); } return(_mHG); }
public static Tuple <double, int, int[]> minimumHypergeometric(bool[] binVec, int tN = -1, int tB = -1, mHGCorrectionType correctMultiHypothesis = mHGCorrectionType.Exact) { var N = tN > 0 ? tN : binVec.Length; var K = tB > 0 ? tB : binVec.Sum(val => val ? 1 : 0); var B = tB > 0 ? tB : binVec.Sum(val => !val ? 1 : 0); var currHGT = 1.0; var mHGT = 1.1; var currIndex = 0; var k = 0; //OptDistVec is a vector that counts for each '1' in the binary vector the minimum number of 1's needed directly after it for a significant p-value var OptDistVec = new int[Ones + 1]; for (var i = 0; i < Ones + 1; i++) { OptDistVec[i] = Ones; // default max step size (int.maxvalue) } for (var i = 0; i < Ones + 1; i++) { if (HGTmat[1, i] <= optHGT.Value) { OptDistVec[0] = Math.Min(OptDistVec[0], i); } } for (var n = 0; n < binVec.Length; n++) { if (binVec[n]) { k++; currHGT = HGTmat[n - k + 1, k]; //currHGT = ScoreMap[currHG]; if (currHGT < mHGT) { currIndex = n; mHGT = currHGT; } //check distance to optimum if (optHGT.HasValue && optHGT <= currHGT) { for (var i = k; i < Ones + 1; i++) { if (HGTmat[n - k + 1, i] <= optHGT.Value) { OptDistVec[k] = Math.Min(OptDistVec[k], i - k); } } } else { optHGT = currHGT; Console.WriteLine("new mHG OPT={0}", optHGT); } } } //for (var i = 0; i < Ones; i++) if(OptDistVec[i] > Ones) OptDistVec[i] = 1; //this happens when we cannot fulfil the required number of ones at this threshold. double pval = -1; switch (correctMultiHypothesis) { case mHGCorrectionType.Exact: pval = ScoreMap[mHGT]; break; case mHGCorrectionType.None: pval = mHGT; break; case mHGCorrectionType.Bonferroni: pval = mHGT * N; break; case mHGCorrectionType.Lipson: pval = mHGT * B; break; } return(new Tuple <double, int, int[]>(pval, currIndex + 1, OptDistVec)); }