\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
*/\r
private String sequence;\r
\r
- private FastaSequence() {\r
+ FastaSequence() {\r
// Default constructor for JaxB\r
}\r
\r
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
* 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
@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
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
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
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