package jalview.ext.forester;
+import jalview.datamodel.Sequence;
import jalview.math.MatrixI;
+import java.io.IOException;
+import java.io.Writer;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
import org.forester.evoinference.matrix.distance.DistanceMatrix;
+import org.forester.util.ForesterUtil;
+import org.forester.util.IllegalFormatUseException;
public class ForesterMatrix implements DistanceMatrix
{
- private MatrixI jalviewMatrix;
+ private final static NumberFormat PHYLIP_FORMATTER = new DecimalFormat(
+ "0.000000"); // straight from forester
+
+ private final MatrixI jalviewMatrix;
+
+ private final Sequence[] sequences;
- public ForesterMatrix(MatrixI jalviewInputMatrix)
+ private final double[][] values;
+
+ public ForesterMatrix(MatrixI jalviewInputMatrix,
+ Sequence[] matrixSequences)
{
this.jalviewMatrix = jalviewInputMatrix;
+ this.sequences = matrixSequences;
+
if (jalviewMatrix.width() != jalviewMatrix.height())
{
-
+ // some kind of warning?
}
+ values = new double[jalviewMatrix.width()][jalviewMatrix.height()];
+
}
@Override
@Override
public double[][] getValues()
{
- // TODO Auto-generated method stub
+
return null;
}
+ @Override
+ public void write(Writer w) throws IOException // directly copied from
+ // forester
+ {
+ w.write(" ");
+ w.write(getSize() + "");
+ w.write(ForesterUtil.LINE_SEPARATOR);
+ for (int row = 0; row < getSize(); ++row)
+ {
+ if (!ForesterUtil.isEmpty(getIdentifier(row)))
+ {
+ w.write(ForesterUtil.pad(getIdentifier(row), 10, ' ', false)
+ .toString());
+ w.write(' ');
+ w.write(' ');
+ }
+ else
+ {
+ throw new IllegalFormatUseException(
+ "Phylip format does not allow empty identifiers");
+ }
+ for (int col = 0; col < getSize(); ++col)
+ {
+ w.write(PHYLIP_FORMATTER.format(getValue(col, row)));
+ if (col < (getSize() - 1))
+ {
+ w.write(' ');
+ w.write(' ');
+ }
+ }
+ if (row < (getSize() - 1))
+ {
+ w.write(ForesterUtil.LINE_SEPARATOR);
+ }
+ }
+
+ }
+
+
}
\ No newline at end of file