JAL-2795 removed now unneeded values variable in ForesterMatrix
[jalview.git] / src / jalview / ext / forester / ForesterMatrix.java
1 package jalview.ext.forester;
2
3 import jalview.datamodel.Sequence;
4 import jalview.math.MatrixI;
5
6 import java.io.IOException;
7 import java.io.Writer;
8 import java.text.DecimalFormat;
9 import java.text.NumberFormat;
10
11 import org.forester.evoinference.matrix.distance.DistanceMatrix;
12 import org.forester.util.ForesterUtil;
13 import org.forester.util.IllegalFormatUseException;
14
15 public class ForesterMatrix implements DistanceMatrix
16 {
17   private final static NumberFormat PHYLIP_FORMATTER = new DecimalFormat(
18           "0.000000"); // straight from forester
19
20   private final MatrixI jalviewMatrix;
21
22   private Sequence[] sequences;
23
24
25   private String[] identifiers;
26
27   public ForesterMatrix(MatrixI jalviewInputMatrix,
28           Sequence[] matrixSequences)
29   {
30     this.jalviewMatrix = jalviewInputMatrix;
31     this.sequences = matrixSequences;
32
33
34     if (jalviewMatrix.width() != jalviewMatrix.height())
35     {
36       // some kind of warning?
37     }
38
39   }
40
41   public ForesterMatrix(MatrixI jalviewInputMatrix,
42           String[] matrixIdentifiers)
43   {
44     this.jalviewMatrix = jalviewInputMatrix;
45     this.identifiers = matrixIdentifiers;
46
47
48     if (jalviewMatrix.width() != jalviewMatrix.height())
49     {
50       // some kind of warning?
51     }
52
53
54   }
55
56   @Override
57   public String getIdentifier(int i)
58   {
59     // TODO Auto-generated method stub
60     return null;
61   }
62
63   @Override
64   public int getIndex(String identifier)
65   {
66     return 0;
67   }
68
69   @Override
70   public int getSize()
71   {
72     return jalviewMatrix.width();
73   }
74
75   @Override
76   public double getValue(int col, int row)
77   {
78     return jalviewMatrix.getValue(row, col);
79   }
80
81   @Override
82   public void setIdentifier(int i, String identifier)
83   {
84     // TODO Auto-generated method stub
85
86   }
87
88   @Override
89   public void setValue(int col, int row, double distance)
90   {
91     jalviewMatrix.setValue(row, col, distance);
92
93   }
94
95   @Override
96   public StringBuffer toStringBuffer(Format format)
97   {
98     // TODO Auto-generated method stub
99     return null;
100   }
101
102   @Override
103   public double[][] getValues()
104   {
105     return jalviewMatrix.getValues();
106   }
107
108   @Override
109   public void write(Writer w) throws IOException // directly copied from
110                                                  // forester
111   {
112     w.write("    ");
113     w.write(getSize() + "");
114     w.write(ForesterUtil.LINE_SEPARATOR);
115     for (int row = 0; row < getSize(); ++row)
116     {
117       if (!ForesterUtil.isEmpty(getIdentifier(row)))
118       {
119         w.write(ForesterUtil.pad(getIdentifier(row), 10, ' ', false)
120                 .toString());
121         w.write(' ');
122         w.write(' ');
123       }
124       else
125       {
126         throw new IllegalFormatUseException(
127                 "Phylip format does not allow empty identifiers");
128       }
129       for (int col = 0; col < getSize(); ++col)
130       {
131         w.write(PHYLIP_FORMATTER.format(getValue(col, row)));
132         if (col < (getSize() - 1))
133         {
134           w.write(' ');
135           w.write(' ');
136         }
137       }
138       if (row < (getSize() - 1))
139       {
140         w.write(ForesterUtil.LINE_SEPARATOR);
141       }
142     }
143
144   }
145
146
147 }