1 package compbio.data.sequence;
\r
3 import java.io.BufferedWriter;
\r
4 import java.io.IOException;
\r
5 import java.io.OutputStream;
\r
6 import java.io.OutputStreamWriter;
\r
7 import java.text.NumberFormat;
\r
8 import java.util.ArrayList;
\r
9 import java.util.Arrays;
\r
10 import java.util.List;
\r
11 import java.util.Locale;
\r
12 import java.util.Set;
\r
14 import javax.xml.bind.annotation.XmlAccessType;
\r
15 import javax.xml.bind.annotation.XmlAccessorType;
\r
17 import compbio.util.annotation.Immutable;
\r
20 * A value class for AACon annotation results storage. The objects of this type
\r
26 @XmlAccessorType(XmlAccessType.FIELD)
\r
28 public class Score {
\r
30 static final NumberFormat NUMBER_FORMAT = NumberFormat
\r
31 .getNumberInstance(Locale.UK);
\r
33 NUMBER_FORMAT.setGroupingUsed(false);
\r
34 NUMBER_FORMAT.setMaximumFractionDigits(3);
\r
37 private ConservationMethod method;
\r
39 private List<Float> scores;
\r
42 // JaXB default constructor
\r
46 * Instantiate the Score
\r
49 * the ConservationMethod with which {@code scores} were
\r
52 * the actual conservation values for each column of the
\r
55 public Score(ConservationMethod method, List<Float> scores) {
\r
56 this.method = method;
\r
57 this.scores = new ArrayList<Float>(scores);
\r
61 * Returns the ConservationMethod
\r
63 * @return the ConservationMethod
\r
65 public ConservationMethod getMethod() {
\r
70 * The column scores for the alignment
\r
72 * @return the column scores for the alignment
\r
74 public List<Float> getScores() {
\r
79 public String toString() {
\r
80 return "Score [method=" + method + ", scores=" + scores + "]";
\r
84 public int hashCode() {
\r
85 final int prime = 31;
\r
87 result = prime * result + ((method == null) ? 0 : method.hashCode());
\r
88 result = prime * result + ((scores == null) ? 0 : scores.hashCode());
\r
93 * TODO test ! (non-Javadoc)
\r
95 * @see java.lang.Object#equals(java.lang.Object)
\r
98 public boolean equals(Object obj) {
\r
103 if (getClass() != obj.getClass())
\r
105 Score other = (Score) obj;
\r
106 if (method != other.method)
\r
108 if (scores == other.scores) {
\r
111 if (scores == null) {
\r
114 if (!Arrays.deepEquals(scores.toArray(), other.scores.toArray()))
\r
120 * Outputs the List of Score objects into the Output stream. The output
\r
121 * format is as follows:
\r
125 * #MethodName <space separated list of values>
\r
129 * #KABAT 0.2 0.3 0.2 0 0.645 0.333 1 1 0 0
\r
130 * #SMERFS 0.645 0.333 1 1 0 0 0.2 0.3 0.2 0
\r
134 * The maximum precision for values is 3 digits, but can be less.
\r
137 * the list of scores to output
\r
139 * the stream to output the data to
\r
140 * @throws IOException
\r
141 * if the OutputStream cannot be written into
\r
142 * @throws NullPointerException
\r
143 * if the output stream is null
\r
145 public static void write(Set<Score> scores, OutputStream output)
\r
146 throws IOException {
\r
147 if (output == null) {
\r
148 throw new NullPointerException("OutputStream must be provided!");
\r
150 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
\r
152 for (Score score : scores) {
\r
153 writer.write("#" + score.method + " ");
\r
154 for (Float scoreVal : score.getScores()) {
\r
155 writer.write(NUMBER_FORMAT.format(scoreVal) + " ");
\r
157 writer.write("\n");
\r