public void scan() {
   // in the future this may call other scanOnChr to split the effort up more
   long tests = 0;
   int bestSite = -1, countSig = 0;
   double bestP = 2;
   for (int i = 0; i < refAlignment.getSiteCount(); i += step) {
     //   if(i%10000==0) System.out.println("scanChromosome
     // chr:"+refAlignment.getChr()+"+site:"+i+" with Chr:"+refAlignment.getChr()+"
     // test:"+tests);
     if (Math.abs(refAlignment.getPositionInLocus(i) - blockPosition) < blockWindow) continue;
     OpenBitSet mj = refAlignment.getSiteBitsNoClone(i, 0);
     OpenBitSet mn = refAlignment.getSiteBitsNoClone(i, 1);
     if (mn.lastCalculatedCardinality() > 4) {
       double p = TagCallerAgainstAnchorMT.testSites(obsymj, mj, mn, binomFunc);
       if (p < bestP) {
         bestP = p;
         bestSite = i;
       }
       if (p < sigThreshold) {
         countSig++;
         if (minSigPos == -1) minSigPos = refAlignment.getPositionInLocus(i);
         maxSigPos = refAlignment.getPositionInLocus(i);
       }
     }
     tests++;
   }
   int chr = Integer.parseInt(refAlignment.getLocus(bestSite).getChromosomeName());
   double[] result = {chr, bestSite, refAlignment.getPositionInLocus(bestSite), bestP, countSig};
   //  if(bestP<0.000001) System.out.println(Arrays.toString(result));
   resultReport[resultIndex] = result;
 }
    public double testSiteSimple(OpenBitSet dA1, OpenBitSet dA2, OpenBitSet dT, OpenBitSet dF) {
      double result = 1;
      int cntIA1 = 0, cntIA2 = 0;
      cntIA1 = (int) OpenBitSet.intersectionCount(dT, dA1);
      cntIA2 = (int) OpenBitSet.intersectionCount(dT, dA2);

      int sum = cntIA1 + cntIA2;
      if (sum > 0) {
        if (cntIA1 < cntIA2) result = (double) cntIA1 / sum;
        else result = (double) cntIA2 / sum;
      }
      /*
      		if (result < 0.0001) {
      			int cA1 = (int)dA1.lastCalculatedCardinality();
      			int cA2 = (int)dA2.lastCalculatedCardinality();
      			int cT = (int)dT.lastCalculatedCardinality();
      			int cF = (int)dF.lastCalculatedCardinality();
      			int cntIA1F = (int)OpenBitSet.intersectionCount(dF, dA1);
      			int cntIA2F = (int)OpenBitSet.intersectionCount(dF, dA2);
      			System.out.println(cntIA1 + "\t" + cntIA2 + "\t" + sum +"\t"+cA1+"\t"+cA2+"\t"+cT+"\t"+cF+"\t"+cntIA1F+"\t"+cntIA2F);
      		}
      *
      */
      return result;
    }
 public boolean checkAnchorSegregationInFamilies(
     OpenBitSet familiesMark, OpenBitSet dA1, OpenBitSet dA2, int familySize) {
   int cntA1 = (int) OpenBitSet.intersectionCount(familiesMark, dA1);
   int cntA2 = (int) OpenBitSet.intersectionCount(familiesMark, dA2);
   if (cntA1 > cntA2) {
     int temp = cntA1;
     cntA1 = cntA2;
     cntA2 = temp;
   }
   int sum = cntA1 + cntA2;
   double rate = (double) cntA1 / sum;
   if (rate < 0.2) return false; // check segregation
   // if ((double)sum/familySize < 0.8) return false; //check missing data
   return true;
 }
 public double testSiteBio(OpenBitSet dA1, OpenBitSet dA2, OpenBitSet dT, OpenBitSet dF) {
   double result = 1, minorP = 1;
   int cntIA1 = 0, cntIA2 = 0, cntIA1T = 0, cntIA2T = 0, cntIA1F = 0, cntIA2F = 0;
   cntIA1T = (int) OpenBitSet.intersectionCount(dT, dA1);
   cntIA2T = (int) OpenBitSet.intersectionCount(dT, dA2);
   cntIA1F = (int) OpenBitSet.intersectionCount(dF, dA1);
   cntIA2F = (int) OpenBitSet.intersectionCount(dF, dA2);
   int sumTag = cntIA1T + cntIA2T;
   if (sumTag == 0) return result;
   int sumAnchor = cntIA1F + cntIA2F;
   if (cntIA1T < cntIA2T) {
     minorP = (double) cntIA1F / sumAnchor;
   } else {
     minorP = (double) cntIA2F / sumAnchor;
   }
   Binomial binomFunc = new Binomial(5, 0.5, new RandomJava());
   binomFunc.setNandP(sumTag, minorP);
   try {
     result = (cntIA1T < cntIA2T) ? binomFunc.cdf(cntIA1T) : binomFunc.cdf(cntIA2T);
   } catch (Exception e) {
     System.out.println(e.toString());
   }
   return result;
 }