RNAStruct replaced by RNAStructScoreManager. Why does webservice
[jabaws.git] / datamodel / compbio / data / sequence / RNAStructReader.java
index cfc83ff..7ebba4c 100644 (file)
-package compbio.data.sequence;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Scanner;
-import java.util.TreeSet;
-import java.util.regex.Pattern;
-
-import org.apache.log4j.Logger;
-
-import compbio.runner.structure.RNAalifold;
-
-// Utility class for reading alifold output
-
-public class RNAStructReader {
-
-       private static Logger log = Logger.getLogger(RNAStructReader.class);
-       
-       // Whitespace patterns
-       static String s = "[+\\s=]+";
-       static String bracket = "\\(|\\)|\\{|\\}|\\[|\\]";
-       static String notData = "[\\s=+]+";
-
-       // RNAOut data type patterns 
-       static String seqP = "[_\\-a-zA-Z]{2,}"; // Has to match --mis output aswell (not just ACGU_)
-       static String structP = "[\\.)({}\\[\\],]{2,}";
-       static String floatP = "-?\\d+\\.\\d*(e[+\\-]\\d+)?";
-       static String energyP = "-?[0-9]*\\.?[0-9]{2}";
-       static String freqP = "^-?\\d\\.\\d{6,}(e[+\\-]\\d+)?$";
-       
-       // alifold out line patterns
-       static String ps = "\\s*";
-       static String alignmentP = "^"+seqP+ps+"$";
-       static String stdStructP = "^"+structP+s+"\\("+ps+floatP+s+floatP+s+floatP+ps+"\\)"+ps+"$";
-       static String justStructP = "^"+structP+ps+"$";
-       static String stochBTStructP = "^"+structP+s+floatP+s+floatP+ps+"$";
-       static String PStructP = "^"+structP+s+"\\["+ps+floatP+ps+"\\]"+ps+"$";
-       static String centStructP = "^"+structP+s+floatP+ps+"\\{"+ps+floatP+s+floatP+ps+"\\}"+ps+"$";
-       static String MEAStructP = "^"+structP+s+"\\{"+ps+floatP+s+"MEA="+floatP+ps+"\\}"+ps+"$";
-       static String freeEnergyP = "^"+ps+"free energy of ensemble"+ps+"="+ps+floatP+ps+"kcal/mol"+ps+"$";
-       static String ensembleFreqP = "^"+ps+"frequency of mfe structure in ensemble "+floatP+ps+"$";
-
-       public static ScoreManager readRNAStructStream(InputStream stdout)
-                       throws IOException {
-               
-               String error = "Error in parsing alifold stdout file: ";
-               // The Lists required to construct a ScoreManager Using the new constructor
-               List<String> structs = new ArrayList<String>();
-               List<TreeSet<Score>> data = new ArrayList<TreeSet<Score>>();
-
-               // Allocate necessry data structures for creating Score objects
-               ArrayList<Float> scores = new ArrayList<Float>();
-
-               BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
-               // The first 2 lines of the alifold stdout file are always the same format
-               String fline = reader.readLine();
-               assert (Pattern.matches(AlifoldLine.alignment.regex, fline)) :
-                       error + "Sequence Alignment Expected";
-               structs.add(fline.trim());
-               data.add(newEmptyScore(AlifoldResult.alifoldSeq));
-               
-               fline = reader.readLine();
-               assert (Pattern.matches(AlifoldLine.stdStruct.regex, fline)) :
-                       error + "Consensus Structure and Energy Expected";
-               Scanner sc = new Scanner(fline);
-               structs.add(sc.next());
-               for (int i = 0; i < 3; i++) {
-                       scores.add(Float.parseFloat(sc.findInLine(floatP)));
-               }
-               data.add(newSetScore(AlifoldResult.alifold, scores));
-               
-               // Now the alifold stdout file formats diverge based on arguments
-               fline = reader.readLine();
-               String sline;
-               Scanner nsc = null;
-               while ( fline != null) {
-                       scores.clear();
-                       AlifoldLine ftype = identifyLine(fline);
-                       sline = reader.readLine(); // Look ahead
-                       sc = new Scanner(fline);
-                       if (sline != null) nsc = new Scanner(sline);
-
-                       if (ftype.equals(AlifoldLine.PStruct)) {
-                               // The -p or --MEA option is specified
-                               // The next line should always be frequency of mfe structure
-                               assert ( sline != null && Pattern.matches(AlifoldLine.ensembleFreq.regex, sline)) :
-                                       error + "Expected frequency of mfe structure";
-                               structs.add(sc.next());
-                               scores.add(Float.parseFloat(sc.findInLine(floatP)));
-                               scores.add(Float.parseFloat(nsc.findInLine(floatP)));
-                               data.add(newSetScore(AlifoldResult.alifoldP, scores));
-                               // Jump line
-                               sline = reader.readLine();
-                       }
-                       else if (ftype.equals(AlifoldLine.centStruct)) {
-                               structs.add(sc.next());
-                               for (int i = 0; i < 3; i++) {
-                                       scores.add(Float.parseFloat(sc.findInLine(floatP)));
-                               }
-                               data.add(newSetScore(AlifoldResult.alifoldCentroid, scores));
-                       }
-                       else if (ftype.equals(AlifoldLine.MEAStruct)) {
-                               structs.add(sc.next());
-                               for (int i = 0; i < 2; i++) {
-                                       scores.add(Float.parseFloat(sc.findInLine(floatP)));
-                               }
-                               data.add(newSetScore(AlifoldResult.alifoldMEA, scores));
-                       }
-                       else if (ftype.equals(AlifoldLine.justStruct)) {
-                               structs.add(sc.next());
-                               data.add(newEmptyScore(AlifoldResult.alifoldStochBT));
-                       }
-                       else if (ftype.equals(AlifoldLine.stochBTStruct)) {
-                               structs.add(sc.next());
-                               scores.add(sc.nextFloat());
-                               scores.add(sc.nextFloat());
-                               data.add(newSetScore(AlifoldResult.alifoldStochBT, scores));
-                       }
-                       else if (ftype.equals(AlifoldLine.freeEnergy)) {
-                               assert (sline != null 
-                                               && Pattern.matches(AlifoldLine.ensembleFreq.regex, sline)) :
-                                               error + "Found 'freeEnergy' line on its own";
-                               structs.add("Free energy of ensemble (kcal/mol) followed by "
-                                               + "frequency of mfe structure in ensemble");
-                               scores.add(Float.parseFloat(sc.findInLine(floatP)));
-                               scores.add(Float.parseFloat(nsc.findInLine(floatP)));
-                               data.add(newSetScore(AlifoldResult.alifoldMetadata, scores));
-                               // jump line
-                               sline = reader.readLine();
-                       }
-                       
-
-                       assert(!ftype.equals(AlifoldLine.ensembleFreq)) :
-                               error + "Wasn't expecting 'frequency of mfe structure'!";
-                       assert(!ftype.equals(AlifoldLine.stdStruct)) :
-                               error + "'Standard output' line at a place other than line 2!";
-                       assert(!ftype.equals(AlifoldLine.alignment)) :
-                               error + "Wasn't expecting an alignment sequence!";
-                       assert(!ftype.equals(AlifoldLine.OTHER)) :
-                               error + "Wasn't expecting this whatever it is: " + fline;
-                       if (Pattern.matches("^\\s*$", fline)) {
-                               log.warn("While parsing alifold stdout: A line is either empty or"
-                                               + " contains only whitespace");
-                       }
-                       
-                       fline = sline;
-               }
-                               
-               sc.close();
-               if (nsc != null) nsc.close();
-               
-               return new ScoreManager(new RNAStruct(structs, data));
-       }
-       
-       // Just for the purpose of creating nee TreeSet<Score> objects of length one
-       // for adding to a 'data' list to make a ScoreManager
-       private static TreeSet<Score> newSetScore(Enum<?> res, List<Float> scores) {
-               // first convert List<Float> to float[]
-               float[] scoresf = new float[scores.size()];
-               Float f;
-               for (int i = 0; i < scoresf.length; i++) {
-                       f = scores.get(i);
-                       scoresf[i] = ( f != null ? f : Float.NaN);
-               }
-               return new TreeSet<Score>(Arrays.asList(new Score(res, scoresf)));
-       }
-
-       // A method just for the purpose of neatly creating Almost Empty score objects
-       // that can't be null
-       public static TreeSet<Score> newEmptyScore(Enum<?> res) {
-               return new TreeSet<Score>(Arrays.asList(new Score(res, new float[0])));
-       }
-
-       public static ScoreManager readRNAStructStream(InputStream stdout, 
-                       InputStream alifold) throws IOException {
-               
-               // The Lists required to construct a ScoreManager Using the new constructor
-               List<String> structs;
-               List<TreeSet<Score>> data; 
-               
-               // Get a ScoreManager that takes the std output but ignores alifold.out (-p)
-               ScoreManager stdSM = readRNAStructStream(stdout);
-               
-               // Unpack this into the structs and data lists
-               structs = stdSM.asRNAStruct().getStructs();
-               data = stdSM.asRNAStruct().getData();
-               
-               // Now parse alifold.out
-               Scanner sc = new Scanner(alifold);
-               sc.useDelimiter("[\\s%]+");
-               
-               // jump two lines to the data 
-               sc.nextLine(); sc.nextLine();
-               
-               // Read the first, second and fourth columns. Ignoring everything else.
-               // Allocate necessry data structures for creating Score objects
-               ArrayList<Float> scores = new ArrayList<Float>();
-               List<Range> rangeHolder = new ArrayList<Range>();
-               String s = "null";
-               while (true) {
-                       s = sc.next();
-                       if (java.util.regex.Pattern.matches("^[\\.)(]{2,}$", s)) break;
-                       if (!sc.hasNextLine()) break;
-                       int t = sc.nextInt();
-                       rangeHolder.add(new Range(Integer.parseInt(s), t));
-                       sc.next();
-                       scores.add(sc.nextFloat());
-                       sc.nextLine();
-               }
-               sc.close();
-               
-               // Update the first ScoreHolder TreeSet<Score> element
-               assert (rangeHolder.size() == scores.size());
-               TreeSet<Score> sHolder = new TreeSet<Score>();
-               for (int i = 0; i < rangeHolder.size(); i++) {
-                       ArrayList<Float> singleS = new ArrayList<Float>(Arrays.asList(scores.get(i)));
-                       TreeSet<Range> singleR = new TreeSet<Range>(Arrays.asList(rangeHolder.get(i)));
-                       sHolder.add(new Score(AlifoldResult.alifoldSeq, singleS, singleR));
-               }
-               
-               data.set(0, sHolder);
-               
-               return new ScoreManager(new RNAStruct(structs, data));
-       }
-
-       private static RNAOut identify(String token) {
-               if (Pattern.matches(seqP, token)) {
-                       return RNAOut.SEQ;
-               } else if (Pattern.matches(structP, token)) {
-                       return RNAOut.STRUCT;
-               } else if (Pattern.matches(energyP, token)) {
-                       return RNAOut.ENERGY;
-               } else if (Pattern.matches(freqP, token)) {
-                       return RNAOut.FREQ;
-               }
-               
-               return RNAOut.OTHER;
-       }
-       
-       private static AlifoldLine identifyLine(String line) {
-               
-               for (AlifoldLine il : AlifoldLine.values()) {
-                       if (Pattern.matches(il.regex, line)) return il;
-               }
-               return AlifoldLine.OTHER;
-       }
-       
-       static enum AlifoldLine {
-               stdStruct (stdStructP),
-               justStruct (justStructP),
-               stochBTStruct (stochBTStructP),
-               PStruct (PStructP),
-               centStruct (centStructP),
-               MEAStruct (MEAStructP),
-               freeEnergy (freeEnergyP),
-               ensembleFreq (ensembleFreqP),
-               alignment (alignmentP), 
-               OTHER (".*");
-               
-               String regex;
-               AlifoldLine(String regex) { this.regex = regex; }
-
-       }
-       
-       //The types of data in an RNAalifold stdout file
-       static enum RNAOut {
-               SEQ, STRUCT, ENERGY, FREQ, OTHER
-       }
-
-       //Something to put in the Score objects of the alifold result which gives information
-       //about what kind of sequence it is holding in its String Id.
-       static enum AlifoldResult {
-               alifold, alifoldP, alifoldMEA, alifoldCentroid, alifoldStochBT, alifoldSeq, alifoldMetadata
-       }
-       
-       
-
-       // Print the full regex Strings for testing 
-       public static void main(String[] args) {
-               for (AlifoldLine l : AlifoldLine.values()) {
-                       System.out.println(l.toString() + ": " + l.regex.replace("^","").replace("$",""));
-               }
-       }
-       
-
-       
-}      
+package compbio.data.sequence;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.List;\r
+import java.util.Scanner;\r
+import java.util.TreeSet;\r
+import java.util.regex.Pattern;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.runner.structure.RNAalifold;\r
+\r
+// Utility class for reading alifold output\r
+\r
+public class RNAStructReader {\r
+\r
+       private static Logger log = Logger.getLogger(RNAStructReader.class);\r
+       \r
+       // Whitespace patterns\r
+       static String s = "[+\\s=]+";\r
+       static String bracket = "\\(|\\)|\\{|\\}|\\[|\\]";\r
+       static String notData = "[\\s=+]+";\r
+\r
+       // RNAOut data type patterns \r
+       static String seqP = "[_\\-a-zA-Z]{2,}"; // Has to match --mis output aswell (not just ACGU_)\r
+       static String structP = "[\\.)({}\\[\\],]{2,}";\r
+       static String floatP = "-?\\d+\\.\\d*(e[+\\-]\\d+)?";\r
+       static String energyP = "-?[0-9]*\\.?[0-9]{2}";\r
+       static String freqP = "^-?\\d\\.\\d{6,}(e[+\\-]\\d+)?$";\r
+       \r
+       // alifold out line patterns\r
+       static String ps = "\\s*";\r
+       static String alignmentP = "^"+seqP+ps+"$";\r
+       static String stdStructP = "^"+structP+s+"\\("+ps+floatP+s+floatP+s+floatP+ps+"\\)"+ps+"$";\r
+       static String justStructP = "^"+structP+ps+"$";\r
+       static String stochBTStructP = "^"+structP+s+floatP+s+floatP+ps+"$";\r
+       static String PStructP = "^"+structP+s+"\\["+ps+floatP+ps+"\\]"+ps+"$";\r
+       static String centStructP = "^"+structP+s+floatP+ps+"\\{"+ps+floatP+s+floatP+ps+"\\}"+ps+"$";\r
+       static String MEAStructP = "^"+structP+s+"\\{"+ps+floatP+s+"MEA="+floatP+ps+"\\}"+ps+"$";\r
+       static String freeEnergyP = "^"+ps+"free energy of ensemble"+ps+"="+ps+floatP+ps+"kcal/mol"+ps+"$";\r
+       static String ensembleFreqP = "^"+ps+"frequency of mfe structure in ensemble "+floatP+ps+"$";\r
+\r
+       public static RNAStructScoreManager readRNAStructStream(InputStream stdout)\r
+                       throws IOException {\r
+               \r
+               String error = "Error in parsing alifold stdout file: ";\r
+               // The Lists required to construct a ScoreManager Using the new constructor\r
+               List<String> structs = new ArrayList<String>();\r
+               List<TreeSet<Score>> data = new ArrayList<TreeSet<Score>>();\r
+\r
+               // Allocate necessry data structures for creating Score objects\r
+               ArrayList<Float> scores = new ArrayList<Float>();\r
+\r
+               BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));\r
+               // The first 2 lines of the alifold stdout file are always the same format\r
+               String fline = reader.readLine();\r
+               assert (Pattern.matches(AlifoldLine.alignment.regex, fline)) :\r
+                       error + "Sequence Alignment Expected";\r
+               structs.add(fline.trim());\r
+               data.add(newEmptyScore(AlifoldResult.alifoldSeq));\r
+               \r
+               fline = reader.readLine();\r
+               assert (Pattern.matches(AlifoldLine.stdStruct.regex, fline)) :\r
+                       error + "Consensus Structure and Energy Expected";\r
+               Scanner sc = new Scanner(fline);\r
+               structs.add(sc.next());\r
+               for (int i = 0; i < 3; i++) {\r
+                       scores.add(Float.parseFloat(sc.findInLine(floatP)));\r
+               }\r
+               data.add(newSetScore(AlifoldResult.alifold, scores));\r
+               \r
+               // Now the alifold stdout file formats diverge based on arguments\r
+               fline = reader.readLine();\r
+               String sline;\r
+               Scanner nsc = null;\r
+               while ( fline != null) {\r
+                       scores.clear();\r
+                       AlifoldLine ftype = identifyLine(fline);\r
+                       sline = reader.readLine(); // Look ahead\r
+                       sc = new Scanner(fline);\r
+                       if (sline != null) nsc = new Scanner(sline);\r
+\r
+                       if (ftype.equals(AlifoldLine.PStruct)) {\r
+                               // The -p or --MEA option is specified\r
+                               // The next line should always be frequency of mfe structure\r
+                               assert ( sline != null && Pattern.matches(AlifoldLine.ensembleFreq.regex, sline)) :\r
+                                       error + "Expected frequency of mfe structure";\r
+                               structs.add(sc.next());\r
+                               scores.add(Float.parseFloat(sc.findInLine(floatP)));\r
+                               scores.add(Float.parseFloat(nsc.findInLine(floatP)));\r
+                               data.add(newSetScore(AlifoldResult.alifoldP, scores));\r
+                               // Jump line\r
+                               sline = reader.readLine();\r
+                       }\r
+                       else if (ftype.equals(AlifoldLine.centStruct)) {\r
+                               structs.add(sc.next());\r
+                               for (int i = 0; i < 3; i++) {\r
+                                       scores.add(Float.parseFloat(sc.findInLine(floatP)));\r
+                               }\r
+                               data.add(newSetScore(AlifoldResult.alifoldCentroid, scores));\r
+                       }\r
+                       else if (ftype.equals(AlifoldLine.MEAStruct)) {\r
+                               structs.add(sc.next());\r
+                               for (int i = 0; i < 2; i++) {\r
+                                       scores.add(Float.parseFloat(sc.findInLine(floatP)));\r
+                               }\r
+                               data.add(newSetScore(AlifoldResult.alifoldMEA, scores));\r
+                       }\r
+                       else if (ftype.equals(AlifoldLine.justStruct)) {\r
+                               structs.add(sc.next());\r
+                               data.add(newEmptyScore(AlifoldResult.alifoldStochBT));\r
+                       }\r
+                       else if (ftype.equals(AlifoldLine.stochBTStruct)) {\r
+                               structs.add(sc.next());\r
+                               scores.add(sc.nextFloat());\r
+                               scores.add(sc.nextFloat());\r
+                               data.add(newSetScore(AlifoldResult.alifoldStochBT, scores));\r
+                       }\r
+                       else if (ftype.equals(AlifoldLine.freeEnergy)) {\r
+                               assert (sline != null \r
+                                               && Pattern.matches(AlifoldLine.ensembleFreq.regex, sline)) :\r
+                                               error + "Found 'freeEnergy' line on its own";\r
+                               structs.add("Free energy of ensemble (kcal/mol) followed by "\r
+                                               + "frequency of mfe structure in ensemble");\r
+                               scores.add(Float.parseFloat(sc.findInLine(floatP)));\r
+                               scores.add(Float.parseFloat(nsc.findInLine(floatP)));\r
+                               data.add(newSetScore(AlifoldResult.alifoldMetadata, scores));\r
+                               // jump line\r
+                               sline = reader.readLine();\r
+                       }\r
+                       \r
+\r
+                       assert(!ftype.equals(AlifoldLine.ensembleFreq)) :\r
+                               error + "Wasn't expecting 'frequency of mfe structure'!";\r
+                       assert(!ftype.equals(AlifoldLine.stdStruct)) :\r
+                               error + "'Standard output' line at a place other than line 2!";\r
+                       assert(!ftype.equals(AlifoldLine.alignment)) :\r
+                               error + "Wasn't expecting an alignment sequence!";\r
+                       assert(!ftype.equals(AlifoldLine.OTHER)) :\r
+                               error + "Wasn't expecting this whatever it is: " + fline;\r
+                       if (Pattern.matches("^\\s*$", fline)) {\r
+                               log.warn("While parsing alifold stdout: A line is either empty or"\r
+                                               + " contains only whitespace");\r
+                       }\r
+                       \r
+                       fline = sline;\r
+               }\r
+                               \r
+               sc.close();\r
+               if (nsc != null) nsc.close();\r
+               \r
+               return new RNAStructScoreManager(structs, data);\r
+       }\r
+       \r
+       // Just for the purpose of creating nee TreeSet<Score> objects of length one\r
+       // for adding to a 'data' list to make a ScoreManager\r
+       private static TreeSet<Score> newSetScore(Enum<?> res, List<Float> scores) {\r
+               // first convert List<Float> to float[]\r
+               float[] scoresf = new float[scores.size()];\r
+               Float f;\r
+               for (int i = 0; i < scoresf.length; i++) {\r
+                       f = scores.get(i);\r
+                       scoresf[i] = ( f != null ? f : Float.NaN);\r
+               }\r
+               return new TreeSet<Score>(Arrays.asList(new Score(res, scoresf)));\r
+       }\r
+\r
+       // A method just for the purpose of neatly creating Almost Empty score objects\r
+       // that can't be null\r
+       public static TreeSet<Score> newEmptyScore(Enum<?> res) {\r
+               return new TreeSet<Score>(Arrays.asList(new Score(res, new float[0])));\r
+       }\r
+\r
+       public static RNAStructScoreManager readRNAStructStream(InputStream stdout, \r
+                       InputStream alifold) throws IOException {\r
+               \r
+               // The Lists required to construct a ScoreManager Using the new constructor\r
+               List<String> structs;\r
+               List<TreeSet<Score>> data; \r
+               \r
+               // Get a ScoreManager that takes the std output but ignores alifold.out (-p)\r
+               RNAStructScoreManager stdSM = readRNAStructStream(stdout);\r
+               \r
+               // Unpack this into the structs and data lists\r
+               structs = stdSM.getStructs();\r
+               data = stdSM.getData();\r
+               \r
+               // Now parse alifold.out\r
+               Scanner sc = new Scanner(alifold);\r
+               sc.useDelimiter("[\\s%]+");\r
+               \r
+               // jump two lines to the data \r
+               sc.nextLine(); sc.nextLine();\r
+               \r
+               // Read the first, second and fourth columns. Ignoring everything else.\r
+               // Allocate necessry data structures for creating Score objects\r
+               ArrayList<Float> scores = new ArrayList<Float>();\r
+               List<Range> rangeHolder = new ArrayList<Range>();\r
+               String s = "null";\r
+               while (true) {\r
+                       s = sc.next();\r
+                       if (java.util.regex.Pattern.matches("^[\\.)(]{2,}$", s)) break;\r
+                       if (!sc.hasNextLine()) break;\r
+                       int t = sc.nextInt();\r
+                       rangeHolder.add(new Range(Integer.parseInt(s), t));\r
+                       sc.next();\r
+                       scores.add(sc.nextFloat());\r
+                       sc.nextLine();\r
+               }\r
+               sc.close();\r
+               \r
+               // Update the first ScoreHolder TreeSet<Score> element\r
+               assert (rangeHolder.size() == scores.size());\r
+               TreeSet<Score> sHolder = new TreeSet<Score>();\r
+               for (int i = 0; i < rangeHolder.size(); i++) {\r
+                       ArrayList<Float> singleS = new ArrayList<Float>(Arrays.asList(scores.get(i)));\r
+                       TreeSet<Range> singleR = new TreeSet<Range>(Arrays.asList(rangeHolder.get(i)));\r
+                       sHolder.add(new Score(AlifoldResult.alifoldSeq, singleS, singleR));\r
+               }\r
+               \r
+               data.set(0, sHolder);\r
+               \r
+               return new RNAStructScoreManager(structs, data);\r
+       }\r
+\r
+       private static RNAOut identify(String token) {\r
+               if (Pattern.matches(seqP, token)) {\r
+                       return RNAOut.SEQ;\r
+               } else if (Pattern.matches(structP, token)) {\r
+                       return RNAOut.STRUCT;\r
+               } else if (Pattern.matches(energyP, token)) {\r
+                       return RNAOut.ENERGY;\r
+               } else if (Pattern.matches(freqP, token)) {\r
+                       return RNAOut.FREQ;\r
+               }\r
+               \r
+               return RNAOut.OTHER;\r
+       }\r
+       \r
+       private static AlifoldLine identifyLine(String line) {\r
+               \r
+               for (AlifoldLine il : AlifoldLine.values()) {\r
+                       if (Pattern.matches(il.regex, line)) return il;\r
+               }\r
+               return AlifoldLine.OTHER;\r
+       }\r
+       \r
+       static enum AlifoldLine {\r
+               stdStruct (stdStructP),\r
+               justStruct (justStructP),\r
+               stochBTStruct (stochBTStructP),\r
+               PStruct (PStructP),\r
+               centStruct (centStructP),\r
+               MEAStruct (MEAStructP),\r
+               freeEnergy (freeEnergyP),\r
+               ensembleFreq (ensembleFreqP),\r
+               alignment (alignmentP), \r
+               OTHER (".*");\r
+               \r
+               String regex;\r
+               AlifoldLine(String regex) { this.regex = regex; }\r
+\r
+       }\r
+       \r
+       //The types of data in an RNAalifold stdout file\r
+       static enum RNAOut {\r
+               SEQ, STRUCT, ENERGY, FREQ, OTHER\r
+       }\r
+\r
+       //Something to put in the Score objects of the alifold result which gives information\r
+       //about what kind of sequence it is holding in its String Id.\r
+       static enum AlifoldResult {\r
+               alifold, alifoldP, alifoldMEA, alifoldCentroid, alifoldStochBT, alifoldSeq, alifoldMetadata\r
+       }\r
+       \r
+       \r
+\r
+       // Print the full regex Strings for testing \r
+       public static void main(String[] args) {\r
+               for (AlifoldLine l : AlifoldLine.values()) {\r
+                       System.out.println(l.toString() + ": " + l.regex.replace("^","").replace("$",""));\r
+               }\r
+       }\r
+       \r
+\r
+       \r
+}      \r