{\r
try\r
{\r
- sg.cs = (ColourSchemeI) cs.getClass().newInstance();\r
+ sg.cs = cs.getClass().newInstance();\r
} catch (Exception ex)\r
{\r
ex.printStackTrace();\r
throw new RuntimeException("The file provided does not match the T-Coffee scores file format");\r
}\r
\r
+ /*\r
+ * check that the score matrix matches the alignment dimensions\r
+ */\r
+ AlignmentI aln; \r
+ if( (aln=viewport.alignment) != null && (aln.getHeight() != file.getHeight() || aln.getWidth() != file.getWidth()) ) {\r
+ throw new RuntimeException("The scores matrix does not match the alignment dimensions");\r
+ }\r
+ \r
tcoffeeColour.setEnabled(true);\r
tcoffeeScoreFile = file;\r
\r
try {\r
URL urlScore = new URL(sScoreFile);\r
newAlignFrame.loadScoreFile(urlScore);\r
- //TODO check the scores matrix matches the MSA dimensions\r
\r
}\r
catch( Exception e ) {\r
}
FormatAdapter f = new FormatAdapter();
String output = f.formatSequences(format,
- (Alignment) viewport.alignment, // class cast exceptions will
+ viewport.alignment, // class cast exceptions will
// occur in the distant future
omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
{
try
{
- sg.cs = (ColourSchemeI) cs.getClass().newInstance();
+ sg.cs = cs.getClass().newInstance();
} catch (Exception ex)
{
}
try
{
TCoffeeScoreFile result = TCoffeeScoreFile.load(new File(sFilePath));
- if( result == null ) { throw new RuntimeException("The file provided does not match the T-Coffee scores file format"); }
+ if( result == null ) {
+ throw new RuntimeException("The file provided does not match the T-Coffee scores file format");
+ }
+
+ /*
+ * check that the score matrix matches the alignment dimensions
+ */
+ AlignmentI aln;
+ if( (aln=viewport.alignment) != null && (aln.getHeight() != result.getHeight() || aln.getWidth() != result.getWidth()) ) {
+ throw new RuntimeException("The scores matrix does not match the alignment dimensions");
+ }
- // TODO check that the loaded scores matches the current MSA 'dimension'
changeColour( new TCoffeeColourScheme(result) );
tcoffeeScoreFile = result;
tcoffeeColour.setEnabled(true);
* 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");
+ }
+ }
+
+
+
}
TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.fasta_aln"));
assertNull(result);
}
+
+ @Test
+ public void testHeightAndWidth() {
+ TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.score_ascii"));
+ assertNotNull(result);
+ assertEquals( 8, result.getHeight() );
+ assertEquals( 83, result.getWidth() );
+ }
@Test
public void testReadBlock( ) throws IOException {