Gramma improved
[jabaws.git] / datamodel / compbio / data / sequence / SequenceUtil.java
index 149e0e0..ddd1222 100644 (file)
@@ -25,6 +25,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;\r
 import java.io.OutputStreamWriter;\r
 import java.util.ArrayList;\r
+import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Scanner;\r
 import java.util.logging.Level;\r
@@ -302,13 +303,23 @@ public final class SequenceUtil {
        }\r
 \r
        /**\r
-        * Reader for JRonn horizontal file format >Foobar M G D T T A G 0.48 0.42\r
-        * 0.42 0.48 0.52 0.53 0.54 All values are tab delimited\r
+        * Reader for JRonn horizontal file format\r
+        * \r
+        * <pre>\r
+        * &gtFoobar M G D T T A G 0.48 0.42\r
+        * 0.42 0.48 0.52 0.53 0.54\r
+        * \r
+        * <pre>\r
+        * Where all values are tab delimited\r
         * \r
         * @param inStream\r
-        * @return\r
+        *            the InputStream connected to the JRonn output file\r
+        * @return List of {@link AnnotatedSequence} objects\r
         * @throws IOException\r
+        *             is thrown if the inStream has problems accessing the data\r
         * @throws UnknownFileFormatException\r
+        *             is thrown if the inStream represents an unknown source of\r
+        * data, i.e. not a JRonn output\r
         */\r
        public static List<AnnotatedSequence> readJRonn(final InputStream inStream)\r
                        throws IOException, UnknownFileFormatException {\r
@@ -402,7 +413,7 @@ public final class SequenceUtil {
         * @throws IOException\r
         * @throws UnknownFileFormatException\r
         */\r
-       public static List<MultiAnnotatedSequence<DisemblResultAnnot>> readDisembl(\r
+       static List<MultiAnnotatedSequence<DisemblResultAnnot>> readDisembl(\r
                        final InputStream input) throws IOException,\r
                        UnknownFileFormatException {\r
                Scanner scan = new Scanner(input);\r
@@ -421,9 +432,9 @@ public final class SequenceUtil {
                        String singleSeq = scan.next();\r
                        Scanner scansingle = new Scanner(singleSeq);\r
                        StringBuffer seqbuffer = new StringBuffer();\r
-                       List<Float> coils = new ArrayList<Float>();\r
-                       List<Float> rem = new ArrayList<Float>();\r
-                       List<Float> hotloops = new ArrayList<Float>();\r
+                       ArrayList<Float> coils = new ArrayList<Float>();\r
+                       ArrayList<Float> rem = new ArrayList<Float>();\r
+                       ArrayList<Float> hotloops = new ArrayList<Float>();\r
 \r
                        MultiAnnotatedSequence<DisemblResultAnnot> disemblRes = new MultiAnnotatedSequence<DisemblResultAnnot>(\r
                                        DisemblResultAnnot.class);\r
@@ -450,4 +461,40 @@ public final class SequenceUtil {
                return results;\r
        }\r
 \r
+       /**\r
+        * Read AACon result with no alignment files. This method leaves incoming\r
+        * the InputStream results open!\r
+        * \r
+        * @param results\r
+        *            output file of AAConservation\r
+        * @return Map with keys {@link Method} -> float[]\r
+        */\r
+       public static HashSet<Score> readAAConResults(InputStream results) {\r
+               if (results == null) {\r
+                       throw new NullPointerException(\r
+                                       "InputStream with results must be provided");\r
+               }\r
+               HashSet<Score> annotations = new HashSet<Score>();\r
+               Scanner sc = new Scanner(results);\r
+               sc.useDelimiter("#");\r
+               while (sc.hasNext()) {\r
+                       String line = sc.next();\r
+                       int spacePos = line.indexOf(" ");\r
+                       assert spacePos > 0 : "Space is expected as delimited between method "\r
+                                       + "name and values!";\r
+                       String methodLine = line.substring(0, spacePos);\r
+                       Method method = Method.getMethod(methodLine);\r
+                       assert method != null : "Method " + methodLine\r
+                                       + " is not recognized! ";\r
+                       Scanner valuesScanner = new Scanner(line.substring(spacePos));\r
+                       ArrayList<Float> values = new ArrayList<Float>();\r
+                       while (valuesScanner.hasNextDouble()) {\r
+                               Double value = valuesScanner.nextDouble();\r
+                               values.add(value.floatValue());\r
+                       }\r
+                       annotations.add(new Score(method, values));\r
+               }\r
+               return annotations;\r
+       }\r
+\r
 }\r