示例#1
0
  public static BSTree createTree(Protein[] p) {
    int l = p.length;

    BSTree[] protree = new BSTree[l];

    for (int i = 0; i < l; ++i) protree[i] = p[i].treeify();

    while (l > 0) {
      System.out.println(l + " generalized leaf node" + (l > 1 ? "s" : "") + " left.");

      System.out.println(prettyPrint(protree));

      if (l == 1) break;

      int maxReward = Integer.MIN_VALUE;
      int maxPos = -1;
      Protein maxCestor = null;

      for (int i = 0; i < l - 1; ++i) {
        Protein thisCestor =
            ((Protein) (protree[i].root().data()))
                .findMLAncestor((Protein) (protree[i + 1].root().data()));
        int thisReward = thisCestor.weight();

        if (maxReward < thisReward) {
          maxReward = thisReward;
          maxPos = i;
          maxCestor = thisCestor;
        }
      }

      // System.out.println ("We're joining \"" + ((Protein)(protree[maxPos].root().data())).desc()
      // + "\"(" + maxPos + ") and \"" + ((Protein)(protree[maxPos+1].root().data())).desc() + "\"("
      // + (maxPos + 1) + ") with a reward of " + maxReward + ".");

      BSTree[] protree_new = new BSTree[l - 1];

      BSTree tree_merged =
          maxCestor.treeify().merge(protree[maxPos], protree[maxPos + 1], maxReward);

      for (int i = 0; i < l - 1; ++i) {
        protree_new[i] = (i < maxPos ? protree[i] : i == maxPos ? tree_merged : protree[i + 1]);
      }

      protree = protree_new;

      // System.out.println ("Suddenly, " + (l-1) + " element" + (l-1==1?" is":"s are") + " left.");

      --l;
    }

    return protree[0];
  }
 public static IProtein processProtein(final String line) {
   String peptide = XMLUtil.extractAttribute(line, "protein_descr");
   if (peptide == null) throw new IllegalArgumentException("bad line " + line);
   return Protein.getProtein(peptide, "", "", null);
 }