X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fio%2FTCoffeeScoreFile.java;h=2de4573125b1c52000033e2a93b8d9e35af3977b;hb=1379350f04bc63ca05bd428afb86717c4764755d;hp=7a3f2d9deaae376cd55d360b1f3eb8a4e7437095;hpb=b3f065b1e4604502ef60a0d5c83ac43f07ccec0f;p=jalview.git diff --git a/src/jalview/io/TCoffeeScoreFile.java b/src/jalview/io/TCoffeeScoreFile.java index 7a3f2d9..2de4573 100644 --- a/src/jalview/io/TCoffeeScoreFile.java +++ b/src/jalview/io/TCoffeeScoreFile.java @@ -75,7 +75,8 @@ public class TCoffeeScoreFile { * insertion order. */ LinkedHashMap scores = new LinkedHashMap(); - + + Integer fWidth; /** * Parse the specified file. @@ -110,6 +111,25 @@ public class TCoffeeScoreFile { } /** + * @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 */ @@ -190,14 +210,27 @@ public class TCoffeeScoreFile { for( Map.Entry 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"); + } + } + + + }