Пример #1
0
  /**
   * Gets a sub-matrix for only those taxa in the collection (all of which should be present in this
   * matrix).
   *
   * @param taxonSubset
   * @return the new submatrix
   */
  public DistanceMatrix getSubmatrix(Collection<Taxon> taxonSubset) {
    double[][] newDistances = new double[taxonSubset.size()][taxonSubset.size()];
    int i = 0;
    for (Taxon taxonRow : taxonSubset) {

      int row = taxa.indexOf(taxonRow);
      if (row == -1) {
        throw new IllegalArgumentException(
            "The taxon, " + taxonRow.getName() + " is not found in this matrix");
      }

      int j = 0;
      for (Taxon taxonColumn : taxonSubset) {
        int column = taxa.indexOf(taxonColumn);
        if (column == -1) {
          throw new IllegalArgumentException(
              "The taxon, " + taxonColumn.getName() + " is not found in this matrix");
        }

        newDistances[i][j] = getDistance(row, column);
      }
      i++;
    }
    return new BasicDistanceMatrix(taxonSubset, newDistances);
  }
Пример #2
0
  /**
   * Gets the distance between 2 taxa
   *
   * @param taxonRow
   * @param taxonColumn
   * @return the distance
   */
  public double getDistance(Taxon taxonRow, Taxon taxonColumn) {
    int row = taxa.indexOf(taxonRow);
    if (row == -1) {
      throw new IllegalArgumentException(
          "The row taxon, " + taxonRow.getName() + " is not found in this matrix");
    }

    int column = taxa.indexOf(taxonColumn);
    if (column == -1) {
      throw new IllegalArgumentException(
          "The column taxon, " + taxonColumn.getName() + " is not found in this matrix");
    }

    return getDistance(row, column);
  }