* insertion order.
*/
LinkedHashMap<String,StringBuilder> scores = new LinkedHashMap<String,StringBuilder>();
-
+
+ Integer fWidth;
/**
* Parse the specified file.
}
/**
+ * @return The 'height' of the score matrix i.e. the numbers of score rows that should matches
+ * the number of sequences in the alignment
+ */
+ public int getHeight() {
+ // the last entry will always be the 'global' alingment consensus scores, so it is removed
+ // from the 'height' count to make this value compatible with the number of sequences in the MSA
+ return scores != null && scores.size() > 0 ? scores.size()-1 : 0;
+ }
+
+ /**
+ * @return The 'width' of the score matrix i.e. the number of columns.
+ * Since teh score value are supposd to be calculated for an 'aligned' MSA, all the entries
+ * have to have the same width.
+ */
+ public int getWidth() {
+ return fWidth != null ? fWidth : 0;
+ }
+
+ /**
* The default constructor is marked as {@code protected} since this class is meant to created
* through the {@link #load(File)} or {@link #load(Reader)} factory methods
*/
for( Map.Entry<String,String> entry : block.items.entrySet() ) {
StringBuilder scoreStringBuilder = scores.get(entry.getKey());
if( scoreStringBuilder == null ) {
- throw new RuntimeException(String.format("Invalid T-Coffee score file. Sequence ID '%s' is not declared in header section", entry.getKey()));
+ throw new RuntimeException(String.format("Invalid T-Coffee score file: Sequence ID '%s' is not declared in header section", entry.getKey()));
}
scoreStringBuilder.append( entry.getValue() );
}
-
}
+ /*
+ * verify that all rows have the same width
+ */
+ for( StringBuilder str : scores.values() ) {
+ if( fWidth == null ) {
+ fWidth = str.length();
+ }
+ else if( fWidth != str.length() ) {
+ throw new RuntimeException("Invalid T-Coffee score file: All the score sequences must have the same length");
+ }
+ }
+
+
+
}