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
21 private Sequence[] sequences;
27 private final double[][] values;
29 private String[] identifiers;
31 public ForesterMatrix(MatrixI jalviewInputMatrix,
32 Sequence[] matrixSequences)
34 width = jalviewInputMatrix.width();
35 height = jalviewInputMatrix.height();
36 values = new double[width][height];
38 this.sequences = matrixSequences;
43 // some kind of warning?
52 public String getIdentifier(int i)
54 // TODO Auto-generated method stub
59 public int getIndex(String identifier)
71 public double getValue(int col, int row)
73 return values[row][col];
77 public void setIdentifier(int i, String identifier)
79 // TODO Auto-generated method stub
84 public void setValue(int col, int row, double distance)
86 values[row][col] = distance;
91 public StringBuffer toStringBuffer(Format format)
93 // TODO Auto-generated method stub
98 public double[][] getValues()
105 public void write(Writer w) throws IOException // directly copied from
109 w.write(getSize() + "");
110 w.write(ForesterUtil.LINE_SEPARATOR);
111 for (int row = 0; row < getSize(); ++row)
113 if (!ForesterUtil.isEmpty(getIdentifier(row)))
115 w.write(ForesterUtil.pad(getIdentifier(row), 10, ' ', false)
122 throw new IllegalFormatUseException(
123 "Phylip format does not allow empty identifiers");
125 for (int col = 0; col < getSize(); ++col)
127 w.write(PHYLIP_FORMATTER.format(getValue(col, row)));
128 if (col < (getSize() - 1))
134 if (row < (getSize() - 1))
136 w.write(ForesterUtil.LINE_SEPARATOR);