Example #1
0
 /** Get node indexed by this string */
 public AcgtTree get(String bases) {
   if (bases.isEmpty()) return this;
   char base = bases.charAt(0);
   AcgtTree node = get(base);
   if (node == null) return null;
   return node.get(bases.substring(1));
 }
Example #2
0
 protected void pAll(int thresholdCount, List<Double> ps) {
   for (int i = 0; i < nodes.length; i++) {
     AcgtTree node = nodes[i];
     double p[] = p();
     if (node != null) {
       if (counts[i] >= thresholdCount) ps.add(p[i]);
       node.pAll(thresholdCount, ps);
     }
   }
 }
Example #3
0
  public void add(String sequence) {
    if ((sequence == null) || sequence.isEmpty()) {
      totalCount++;
      return;
    }

    // Count for this node
    char base = sequence.charAt(0);
    inc(base);
    AcgtTree node = getOrCreate(base);

    // Recurse into tree
    node.add(sequence.substring(1));
  }
Example #4
0
  /** Find node names that are within the thresholds */
  public List<String> findNodeNames(
      double thresholdEntropy, double thresholdP, int thresholdCount) {
    ArrayList<String> names = new ArrayList<String>();
    if (getTotalCount() == 0) return names;

    double p[] = p();
    for (int idx = 0; idx < 4; idx++) {
      AcgtTree n = nodes[idx];
      if (n != null) {
        if (((parent == null)
                || (parent.entropy() <= thresholdEntropy)) // Parent's entropy is low enough?
            && (p[idx] >= thresholdP) // Probability is high enough?
            && (counts[idx] >= thresholdCount) // Do we have enough counts?
        ) {
          names.add(n.name);
        }

        names.addAll(n.findNodeNames(thresholdEntropy, thresholdP, thresholdCount));
      }
    }

    return names;
  }
Example #5
0
  public String toString(
      String tabs, double thresholdEntropy, double thresholdP, int thresholdCount) {
    if (getTotalCount() == 0) return "";

    StringBuilder sb = new StringBuilder();
    double p[] = p();
    for (int idx = 0; idx < 4; idx++) {
      char base = BASES[idx];
      AcgtTree n = nodes[idx];
      if (n != null) {
        sb.append(
            String.format(
                "%s%s%s: %d\te:%4.3f\tp:%4.2f\n",
                tabs, name, base, counts[idx], n.entropy(), p[idx]));

        if (((n.entropy() <= thresholdEntropy) || (p[idx] >= thresholdP)) //
            && (counts[idx] >= thresholdCount) //
        ) {
          Gpr.debug(
              "Name:"
                  + n.name
                  + "\tIdx:"
                  + +idx
                  + "\tEntropy: "
                  + n.entropy()
                  + "\tP:"
                  + p[idx]
                  + "\tCount:"
                  + counts[idx]);
          sb.append(n.toString(tabs + "\t", thresholdEntropy, thresholdP, thresholdCount));
        }
      }
    }

    return sb.toString();
  }
Example #6
0
 void entropyAll(int thresholdCount, ArrayList<Double> entropies) {
   if (totalCount >= thresholdCount) entropies.add(entropy());
   for (AcgtTree node : nodes) if (node != null) node.entropyAll(thresholdCount, entropies);
 }