import java.io.OutputStream;\r
import java.io.OutputStreamWriter;\r
import java.text.NumberFormat;\r
+import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.List;\r
import java.util.Locale;\r
\r
import compbio.util.annotation.Immutable;\r
\r
+/**\r
+ * A value class for AACon annotation results storage\r
+ * \r
+ * @author pvtroshin\r
+ * \r
+ */\r
@XmlAccessorType(XmlAccessType.FIELD)\r
@Immutable\r
public class Score {\r
\r
- public static final NumberFormat NUMBER_FORMAT = NumberFormat\r
+ static final NumberFormat NUMBER_FORMAT = NumberFormat\r
.getNumberInstance(Locale.UK);\r
static {\r
NUMBER_FORMAT.setGroupingUsed(false);\r
// JaXB default constructor\r
}\r
\r
+ /**\r
+ * Instantiate the Score\r
+ * \r
+ * @param method\r
+ * the ConservationMethod with which {@code scores} were\r
+ * calculated\r
+ * @param scores\r
+ * the actual conservation values for each column of the\r
+ * alignment\r
+ */\r
public Score(ConservationMethod method, List<Float> scores) {\r
this.method = method;\r
- this.scores = scores;\r
+ this.scores = new ArrayList<Float>(scores);\r
}\r
\r
+ /**\r
+ * Returns the ConservationMethod\r
+ * \r
+ * @return the ConservationMethod\r
+ */\r
public ConservationMethod getMethod() {\r
return method;\r
}\r
\r
+ /**\r
+ * The column scores for the alignment\r
+ * \r
+ * @return the column scores for the alignment\r
+ */\r
public List<Float> getScores() {\r
return scores;\r
}\r
return true;\r
}\r
\r
+ /**\r
+ * Outputs the List of Score objects into the Output stream. The output\r
+ * format is as follows:\r
+ * \r
+ * <pre>\r
+ * #MethodName <space separated list of values>\r
+ * \r
+ * For example:\r
+ * \r
+ * #KABAT 0.2 0.3 0.2 0 0.645 0.333 1 1 0 0\r
+ * #SMERFS 0.645 0.333 1 1 0 0 0.2 0.3 0.2 0\r
+ * </pre>\r
+ * \r
+ * The maximum precision for values is 3 digits, but can be less.\r
+ * \r
+ * @param scores\r
+ * the list of scores to output\r
+ * @param output\r
+ * the stream to output the data to\r
+ * @throws IOException\r
+ * if the OutputStream cannot be written into\r
+ * @throws NullPointerException\r
+ * if the output stream is null\r
+ */\r
public static void write(Set<Score> scores, OutputStream output)\r
throws IOException {\r
+ if (output == null) {\r
+ throw new NullPointerException("OutputStream must be provided!");\r
+ }\r
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
output));\r
for (Score score : scores) {\r