X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FTCoffeeScoreFile.java;h=7a3f2d9deaae376cd55d360b1f3eb8a4e7437095;hb=b3f065b1e4604502ef60a0d5c83ac43f07ccec0f;hp=df009865cd405e68a66060ea5bb4eb88ea0b1afc;hpb=9d63632f20b8c8c2961601b0ab22ecea92059240;p=jalview.git diff --git a/src/jalview/io/TCoffeeScoreFile.java b/src/jalview/io/TCoffeeScoreFile.java index df00986..7a3f2d9 100644 --- a/src/jalview/io/TCoffeeScoreFile.java +++ b/src/jalview/io/TCoffeeScoreFile.java @@ -78,6 +78,44 @@ public class TCoffeeScoreFile { /** + * Parse the specified file. + * + * @param file The file to be parsed + */ + public static TCoffeeScoreFile load(File file) { + try { + return load(new FileReader(file)); + } + catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + /** + * Parse the provided reader for the T-Coffee scores file format + * + * @param reader + */ + public static TCoffeeScoreFile load(Reader reader) { + + try { + BufferedReader in = (BufferedReader) (reader instanceof BufferedReader ? reader : new BufferedReader(reader)); + TCoffeeScoreFile result = new TCoffeeScoreFile(); + result.doParsing(in); + return result.header != null && result.scores != null ? result : null; + } + catch( Exception e) { + throw new RuntimeException(e); + } + } + + /** + * 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 + */ + protected TCoffeeScoreFile() { } + + /** * Get the string of score values for the specified seqeunce ID. * @param id The sequence ID * @return The scores as a string of values e.g. {@code 99999987-------432}. @@ -122,43 +160,17 @@ public class TCoffeeScoreFile { return result; } - /** - * Parse the specified file. - * - * @param file The file to be parsed - */ - public void parse(File file) { - try { - parse(new FileReader(file)); - } - catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - - /** - * Parse the provided reader for the T-Coffee scores file format - * - * @param reader - */ - public void parse(Reader reader) { - try { - BufferedReader in = (BufferedReader) (reader instanceof BufferedReader ? reader : new BufferedReader(reader)); - doParsing(in); - } - catch( Exception e) { - throw new RuntimeException(e); - } - } - private void doParsing(BufferedReader in) throws IOException { /* * read the header */ header = readHeader(in); + + if( header == null ) { return; } + /* * initilize the structure */