1 package jalview.ext.forester;
3 import jalview.datamodel.Sequence;
4 import jalview.math.MatrixI;
6 import java.io.IOException;
8 import java.text.DecimalFormat;
9 import java.text.NumberFormat;
11 import org.forester.evoinference.matrix.distance.DistanceMatrix;
12 import org.forester.util.ForesterUtil;
13 import org.forester.util.IllegalFormatUseException;
15 public class ForesterMatrix implements DistanceMatrix
17 private final static NumberFormat PHYLIP_FORMATTER = new DecimalFormat(
18 "0.000000"); // straight from forester
20 private final MatrixI jalviewMatrix;
22 private final Sequence[] sequences;
24 private final double[][] values;
26 public ForesterMatrix(MatrixI jalviewInputMatrix,
27 Sequence[] matrixSequences)
29 this.jalviewMatrix = jalviewInputMatrix;
30 this.sequences = matrixSequences;
32 if (jalviewMatrix.width() != jalviewMatrix.height())
34 // some kind of warning?
37 values = new double[jalviewMatrix.width()][jalviewMatrix.height()];
42 public String getIdentifier(int i)
44 // TODO Auto-generated method stub
49 public int getIndex(String identifier)
57 return jalviewMatrix.width();
61 public double getValue(int col, int row)
63 return jalviewMatrix.getValue(row, col);
67 public void setIdentifier(int i, String identifier)
69 // TODO Auto-generated method stub
74 public void setValue(int col, int row, double distance)
76 jalviewMatrix.setValue(row, col, distance);
81 public StringBuffer toStringBuffer(Format format)
83 // TODO Auto-generated method stub
88 public double[][] getValues()
95 public void write(Writer w) throws IOException // directly copied from
99 w.write(getSize() + "");
100 w.write(ForesterUtil.LINE_SEPARATOR);
101 for (int row = 0; row < getSize(); ++row)
103 if (!ForesterUtil.isEmpty(getIdentifier(row)))
105 w.write(ForesterUtil.pad(getIdentifier(row), 10, ' ', false)
112 throw new IllegalFormatUseException(
113 "Phylip format does not allow empty identifiers");
115 for (int col = 0; col < getSize(); ++col)
117 w.write(PHYLIP_FORMATTER.format(getValue(col, row)));
118 if (col < (getSize() - 1))
124 if (row < (getSize() - 1))
126 w.write(ForesterUtil.LINE_SEPARATOR);