Moving a method from AACon to SequenceUtil
[jabaws.git] / datamodel / compbio / data / sequence / SequenceUtil.java
index 20628a1..f061ac7 100644 (file)
@@ -483,7 +483,8 @@ public final class SequenceUtil {
                        assert spacePos > 0 : "Space is expected as delimited between method "\r
                                        + "name and values!";\r
                        String methodLine = line.substring(0, spacePos);\r
-                       ConservationMethod method = ConservationMethod.getMethod(methodLine);\r
+                       ConservationMethod method = ConservationMethod\r
+                                       .getMethod(methodLine);\r
                        assert method != null : "Method " + methodLine\r
                                        + " is not recognized! ";\r
                        Scanner valuesScanner = new Scanner(line.substring(spacePos));\r
@@ -497,4 +498,37 @@ public final class SequenceUtil {
                return annotations;\r
        }\r
 \r
+       /**\r
+        * Reads and parses Fasta or Clustal formatted file into a list of\r
+        * FastaSequence objects\r
+        * \r
+        * @param inFilePath\r
+        *            the path to the input file\r
+        * @throws IOException\r
+        *             if the file denoted by inFilePath cannot be read\r
+        * @throws UnknownFileFormatException\r
+        *             if the inFilePath points to the file which format cannot be\r
+        *             recognised\r
+        * @return the List of FastaSequence objects\r
+        * \r
+        */\r
+       public static List<FastaSequence> openInputStream(String inFilePath)\r
+                       throws IOException, UnknownFileFormatException {\r
+\r
+               // This stream gets closed in isValidClustalFile method\r
+               InputStream inStrForValidation = new FileInputStream(inFilePath);\r
+               // This stream is closed in the calling methods\r
+               InputStream inStr = new FileInputStream(inFilePath);\r
+               List<FastaSequence> fastaSeqs = null;\r
+               if (ClustalAlignmentUtil.isValidClustalFile(inStrForValidation)) {\r
+                       Alignment al = ClustalAlignmentUtil.readClustalFile(inStr);\r
+                       // alignment cannot be null see\r
+                       // ClustalAlignmentUtil.readClustalFile(inStr);\r
+                       fastaSeqs = al.getSequences();\r
+               } else {\r
+                       fastaSeqs = SequenceUtil.readFasta(inStr);\r
+               }\r
+               return fastaSeqs;\r
+       }\r
+\r
 }\r