public int minkeys() {
   // if node is the root, minkey is 1
   if (getParent() == null) {
     return 1;
   } else {
     return (int) (Math.ceil(degree / 2.0) - 1);
   }
 }
Esempio n. 2
0
  public static void main(String[] args) {
    double a = -191.635;
    double b = 43.74;
    int c = 16, d = 45;

    System.out.printf("The absolute value " + "of %.3f is %.3f%n", a, abs(a));

    System.out.printf("The ceiling of " + "%.2f is %.0f%n", b, Math.ceil(b));

    System.out.printf("The floor of " + "%.2f is %.0f%n", b, Math.floor(b));

    System.out.printf("The rint of %.2f " + "is %.0f%n", b, Math.rint(b));

    System.out.printf("The max of %d and " + "%d is %d%n", c, d, Math.max(c, d));

    System.out.printf("The min of of %d " + "and %d is %d%n", c, d, Math.min(c, d));
  }
Esempio n. 3
0
  /**
   * Makes genotype AB calls. <code>genotypeCalling</code> determines which loci are genotype AB
   * (heterozygous) based on A and B allelesl signal of the normal sample.
   *
   * @param p probe set intensity data
   */
  private void genotypeCalling(ProbeSetIntensityData[] p) throws IOException {

    int numGenotypingProbeSet = 0;
    double meanPmA = 0;
    double meanPmB = 0;

    for (int i = 0; i < p.length; i++) {
      if (p[i].probeSetType == FusionGeneChipProbeSetType.GenotypingProbeSetType) {
        meanPmA += (p[i].pmA == 0 ? 0 : log2(p[i].pmA));
        meanPmB += (p[i].pmB == 0 ? 0 : log2(p[i].pmB));
        numGenotypingProbeSet++;
      }
    }

    meanPmA = meanPmA / numGenotypingProbeSet;
    meanPmB = meanPmB / numGenotypingProbeSet;

    double k = meanPmB / meanPmA;

    class DistanceToLine implements Comparable<DistanceToLine> {
      public Double dist;
      public int index;

      public boolean equals(DistanceToLine d) {
        return (dist == d.dist);
      }

      public int compareTo(DistanceToLine d) {
        return dist.compareTo(d.dist);
      }
    }

    DistanceToLine[] s = new DistanceToLine[numGenotypingProbeSet];
    int j = 0;
    for (int i = 0; i < p.length; i++) {
      if (p[i].probeSetType == FusionGeneChipProbeSetType.GenotypingProbeSetType) {
        s[j] = new DistanceToLine();
        s[j].dist = Math.abs(log2(p[i].pmB) - k * log2(p[i].pmA));
        s[j].index = i;
        j++;
      }
    }

    Arrays.sort(s);
    //  Add for testing
    //         BufferedWriter genotypeCallingFile = null;
    // try {
    //   genotypeCallingFile = new BufferedWriter(new FileWriter("genoTypeCalling_s_dist.csv"),
    // 30*1024*1024);
    //
    //   for (int i = 0; i < numGenotypingProbeSet; i ++) {
    //       String entry = s[i].dist + "," + s[i].index;
    //       genotypeCallingFile.write(entry.toCharArray());
    //        genotypeCallingFile.newLine();
    //   }
    //
    //   } finally {
    //       if (genotypeCallingFile != null) {
    //           genotypeCallingFile.close();
    //       }
    // }
    ////
    for (int i = 0; i < Math.ceil(numGenotypingProbeSet * 0.20); i++) {

      p[s[i].index].isGenotypeAB = true;
    }

    // 	BufferedWriter genotypeCallingFile = null;
    // 	try {
    //             genotypeCallingFile = new BufferedWriter(new
    // FileWriter("genoTypeCallingData.csv"), 30*1024*1024);

    // 	    for (int i = 0; i < p.length; i ++) {
    // 		if (p[i].probeSetType == FusionGeneChipProbeSetType.GenotypingProbeSetType) {
    // 		    String entry = (p[i].pmA == 0 ? 0:log2(p[i].pmA)) + "," + (p[i].pmB == 0 ?
    // 0:log2(p[i].pmB))
    // 			+ "," + (p[i].isGenotypeAB? 1:0);
    // 		    genotypeCallingFile.write(entry.toCharArray());
    // 		    genotypeCallingFile.newLine();
    // 		}
    // 	    }

    // 	} finally {
    // 	    if (genotypeCallingFile != null) {
    //                 genotypeCallingFile.close();
    //             }
    //         }

  }
Esempio n. 4
0
 public int getW_mls() {
   return (int) (Math.ceil(w * mlsPerMm));
 }
  public int insertionRedistribute() {
    // get val and ptr from newly created node
    int val = this.getNext().getKey(1);
    Node ptr = this.getNext().getPtr(1);

    boolean stop = false;
    int p = 1;
    while (p <= this.getLast() && !stop) {

      stop = this.getKey(p) > this.getNext().getKey(1);
      if (!stop) {
        p++;
      }
    }

    // create two arrays to store keys and ptrs
    int size = this.getLast() + this.getNext().getLast() + 1;
    int[] allKeys = new int[size];
    Node[] allPtrs = new Node[size];

    // store keys and ptrs of current node at position 1 to p-1 into array
    allPtrs[0] = this.getPtr(0);
    for (int k = 1; k < p; k++) {
      allKeys[k] = this.getKey(k);
      allPtrs[k] = this.getPtr(k);
    }

    // store first key and ptr of next node
    allKeys[p] = val;
    allPtrs[p] = ptr;

    // store keys and ptrs of current node at position p to lastindex into array
    for (int k = p; k <= this.getLast(); k++) {
      allKeys[k + 1] = this.getKey(k);
      allPtrs[k + 1] = this.getPtr(k);
    }

    // decide middle position and new size for current and next node
    int middle = (int) Math.ceil((size) / 2.0);
    int newSize = middle - 1;
    int newSizeNext = size - 1 - middle;

    // reset lastindex of current node and store keys and ptrs into current node
    this.lastindex = newSize;
    this.ptrs[0] = allPtrs[0];
    this.ptrs[0].setParent(new Reference(this, 0, false));
    for (int k = 1; k <= this.getLast(); k++) {
      this.keys[k] = allKeys[k];
      this.ptrs[k] = allPtrs[k];
      this.ptrs[k].setParent(new Reference(this, k, false));
    }

    // reset lastindex of next node and store keys and ptrs into next node
    this.getNext().lastindex = newSizeNext;
    this.getNext().ptrs[0] = allPtrs[middle];
    this.getNext().ptrs[0].setParent(new Reference(this.getNext(), 0, false));
    for (int k = 1; k <= this.getNext().getLast(); k++) {
      this.getNext().keys[k] = allKeys[middle + k];
      this.getNext().ptrs[k] = allPtrs[middle + k];
      this.getNext().ptrs[k].setParent(new Reference(this.getNext(), k, false));
    }

    // return value to be updated in the parent
    return allKeys[middle];
  }
  public int deletionRedistribute() {
    // decide middle position and new size of current and next node
    int size = this.getLast() + this.getNext().getLast() + 2;
    int middle = (int) Math.ceil(size / 2.0);
    int newSize = middle - 1;
    int newSizeNext = size - 1 - middle;

    // get special key and val to be inserted into array
    int val = this.getNext().getParent().getNode().getKey(this.getNext().getParent().getIndex());
    Node ptr = this.getNext().getPtr(0);

    // create two arrays to store keys and ptrs
    int[] allKeys = new int[size];
    Node[] allPtrs = new Node[size];

    // store keys and ptrs from current node
    allPtrs[0] = this.getPtr(0);
    for (int k = 1; k <= this.getLast(); k++) {
      allKeys[k] = this.getKey(k);
      allPtrs[k] = this.getPtr(k);
    }

    // insert special key and ptr
    allKeys[this.getLast() + 1] = val;
    allPtrs[this.getLast() + 1] = ptr;

    // store keys and ptrs from next node
    for (int k = 1; k <= this.getNext().getLast(); k++) {
      allKeys[this.getLast() + 1 + k] = this.getNext().getKey(k);
      allPtrs[this.getLast() + 1 + k] = this.getNext().getPtr(k);
    }

    // update lastindex of current and next node
    this.lastindex = newSize;
    this.getNext().lastindex = newSizeNext;

    // update keys and ptrs in current node
    this.ptrs[0] = allPtrs[0];
    this.ptrs[0].setParent(new Reference(this, 0, false));
    for (int k = 1; k <= this.getLast(); k++) {
      this.keys[k] = allKeys[k];
      this.ptrs[k] = allPtrs[k];
      this.ptrs[k].setParent(new Reference(this, k, false));
    }

    // update parent
    this.getNext().getParent().getNode().keys[this.getNext().getParent().getIndex()] =
        allKeys[middle];

    // update keys and ptrs in next node
    this.getNext().ptrs[0] = allPtrs[middle];
    this.getNext().ptrs[0].setParent(new Reference(this.getNext(), 0, false));
    for (int k = 1; k <= this.getNext().getLast(); k++) {
      this.getNext().keys[k] = allKeys[middle + k];
      this.getNext().ptrs[k] = allPtrs[middle + k];
      this.getNext().ptrs[k].setParent(new Reference(this.getNext(), k, false));
    }

    // return value to be updated in the parent
    return this.getKey(middle);
  }