More work on AAConWS not finished yet!
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 24 Nov 2010 12:43:52 +0000 (12:43 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 24 Nov 2010 12:43:52 +0000 (12:43 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3376 e3abac25-378b-4346-85de-24260fe3988d

datamodel/compbio/data/sequence/AnnotatedSequence.java
datamodel/compbio/data/sequence/FastaSequence.java
datamodel/compbio/data/sequence/MultiAnnotatedSequence.java
datamodel/compbio/data/sequence/SequenceUtil.java

index 5d09534..65dbce9 100644 (file)
@@ -4,53 +4,58 @@ import java.util.Arrays;
 \r
 public class AnnotatedSequence extends FastaSequence {\r
 \r
-    private final float[] annotation;\r
-\r
-    public AnnotatedSequence(String id, String sequence, float[] annotation) {\r
-       super(id, sequence);\r
-       this.annotation = annotation;\r
-       if (annotation == null || annotation.length != sequence.length()) {\r
-           throw new IllegalArgumentException("The length of the annotation ("\r
-                   + ((annotation != null) ? annotation.length : "0")\r
-                   + ") does not match the length of the sequence ("\r
-                   + sequence.length() + ")!");\r
+       private float[] annotation;\r
+\r
+       private AnnotatedSequence() {\r
+               super();\r
+               // JAXB default constructor\r
+       }\r
+\r
+       public AnnotatedSequence(String id, String sequence, float[] annotation) {\r
+               super(id, sequence);\r
+               this.annotation = annotation;\r
+               if (annotation == null || annotation.length != sequence.length()) {\r
+                       throw new IllegalArgumentException("The length of the annotation ("\r
+                                       + ((annotation != null) ? annotation.length : "0")\r
+                                       + ") does not match the length of the sequence ("\r
+                                       + sequence.length() + ")!");\r
+               }\r
+       }\r
+\r
+       public AnnotatedSequence(FastaSequence fsequence, float[] annotation) {\r
+               this(fsequence.getId(), fsequence.getSequence(), annotation);\r
+       }\r
+\r
+       public float[] getAnnotation() {\r
+               return annotation;\r
+       }\r
+\r
+       @Override\r
+       public int hashCode() {\r
+               final int prime = 7;\r
+               int result = super.hashCode();\r
+               result = prime * result + Arrays.hashCode(annotation);\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public boolean equals(Object obj) {\r
+               if (this == obj)\r
+                       return true;\r
+               if (!super.equals(obj))\r
+                       return false;\r
+               if (getClass() != obj.getClass())\r
+                       return false;\r
+               AnnotatedSequence other = (AnnotatedSequence) obj;\r
+               if (!Arrays.equals(annotation, other.annotation))\r
+                       return false;\r
+               return true;\r
+       }\r
+\r
+       @Override\r
+       public String toString() {\r
+               return super.toString() + "Annotation:\n "\r
+                               + Arrays.toString(annotation) + "\n";\r
        }\r
-    }\r
-\r
-    public AnnotatedSequence(FastaSequence fsequence, float[] annotation) {\r
-       this(fsequence.getId(), fsequence.getSequence(), annotation);\r
-    }\r
-\r
-    public float[] getAnnotation() {\r
-       return annotation;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-       final int prime = 7;\r
-       int result = super.hashCode();\r
-       result = prime * result + Arrays.hashCode(annotation);\r
-       return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-       if (this == obj)\r
-           return true;\r
-       if (!super.equals(obj))\r
-           return false;\r
-       if (getClass() != obj.getClass())\r
-           return false;\r
-       AnnotatedSequence other = (AnnotatedSequence) obj;\r
-       if (!Arrays.equals(annotation, other.annotation))\r
-           return false;\r
-       return true;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-       return super.toString() + "Annotation:\n "\r
-               + Arrays.toString(annotation) + "\n";\r
-    }\r
 \r
 }\r
index 1da5900..a5c92c1 100644 (file)
@@ -50,7 +50,7 @@ public class FastaSequence {
         */\r
        private String sequence;\r
 \r
-       private FastaSequence() {\r
+       FastaSequence() {\r
                // Default constructor for JaxB\r
        }\r
 \r
index 1a889e3..d5942b3 100644 (file)
@@ -1,9 +1,13 @@
 package compbio.data.sequence;\r
 \r
+import java.util.ArrayList;\r
 import java.util.EnumMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+\r
 import compbio.util.annotation.NotThreadSafe;\r
 \r
 /**\r
@@ -15,15 +19,20 @@ import compbio.util.annotation.NotThreadSafe;
  *            enum type\r
  */\r
 @NotThreadSafe\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
 public class MultiAnnotatedSequence<T extends Enum<T>> {\r
 \r
-       private final Map<T, List<Float>> annotations;\r
+       private EnumMap<T, ArrayList<Float>> annotations;\r
+\r
+       MultiAnnotatedSequence() {\r
+               // default constructor for JAXB\r
+       }\r
 \r
        public MultiAnnotatedSequence(Class<T> enumeration) {\r
-               this.annotations = new EnumMap<T, List<Float>>(enumeration);\r
+               this.annotations = new EnumMap<T, ArrayList<Float>>(enumeration);\r
        }\r
 \r
-       public void addAnnotation(T type, List<Float> annotation) {\r
+       public void addAnnotation(T type, ArrayList<Float> annotation) {\r
                assert type != null : "Type is expected";\r
                assert annotation != null : "Not empty value is expected!";\r
                if (!annotations.isEmpty()) {\r
@@ -66,7 +75,7 @@ public class MultiAnnotatedSequence<T extends Enum<T>> {
        @Override\r
        public String toString() {\r
                String value = "";\r
-               for (Map.Entry<T, List<Float>> annt : annotations.entrySet()) {\r
+               for (Map.Entry<T, ArrayList<Float>> annt : annotations.entrySet()) {\r
                        value += annt.getKey() + " ";\r
                        value += annt.getValue() + "\n";\r
                }\r
index 149e0e0..5946e78 100644 (file)
@@ -31,6 +31,8 @@ import java.util.logging.Level;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
+import compbio.conservation.Method;\r
+\r
 /**\r
  * Utility class for operations on sequences\r
  * \r
@@ -421,9 +423,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 +452,41 @@ 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 {@link MultiAnnotatedSequence}\r
+        */\r
+       public static MultiAnnotatedSequence<Method> readResults(InputStream results) {\r
+               if (results == null) {\r
+                       throw new NullPointerException(\r
+                                       "InputStream with results must be provided");\r
+               }\r
+               MultiAnnotatedSequence<Method> annotations = new MultiAnnotatedSequence<Method>(\r
+                               Method.class);\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.addAnnotation(method, values);\r
+               }\r
+               return annotations;\r
+       }\r
+\r
 }\r