Javadoc fixes
[jabaws.git] / datamodel / compbio / data / sequence / FastaReader.java
index ed91e93..1641d34 100644 (file)
@@ -19,6 +19,7 @@ package compbio.data.sequence;
 \r
 import java.io.File;\r
 import java.io.FileNotFoundException;\r
+import java.io.InputStream;\r
 import java.util.Iterator;\r
 import java.util.Scanner;\r
 \r
@@ -70,7 +71,7 @@ public class FastaReader implements Iterator<FastaSequence> {
        /**\r
         * Header data can contain non-ASCII symbols and read in UTF8\r
         * \r
-        * @param input\r
+        * @param inputFile\r
         *            the file containing the list of FASTA formatted sequences to\r
         *            read from\r
         * @throws FileNotFoundException\r
@@ -92,6 +93,19 @@ public class FastaReader implements Iterator<FastaSequence> {
                        }\r
                });\r
        }\r
+\r
+       /**\r
+        * This class will not close the incoming stream! So the client should do\r
+        * so.\r
+        * \r
+        * @param inputStream\r
+        * @throws FileNotFoundException\r
+        */\r
+       public FastaReader(final InputStream inputStream)\r
+                       throws FileNotFoundException {\r
+               input = new Scanner(inputStream);\r
+               input.useDelimiter("\\s*>");\r
+       }\r
        /**\r
         * {@inheritDoc}\r
         * \r
@@ -135,26 +149,24 @@ public class FastaReader implements Iterator<FastaSequence> {
        }\r
 \r
        private static FastaSequence toFastaSequence(final String singleFastaEntry) {\r
-               final Scanner sc = new Scanner(singleFastaEntry);\r
-               // Use new line delimiter\r
-               sc.useDelimiter("\n");\r
-               if (!sc.hasNext()) {\r
+\r
+               assert !Util.isEmpty(singleFastaEntry) : "Empty String where FASTA sequence is expected!";\r
+\r
+               int nlineidx = singleFastaEntry.indexOf("\n");\r
+               if (nlineidx < 0) {\r
                        throw new AssertionError(\r
                                        "The FASTA sequence must contain the header information"\r
                                                        + " separated by the new line from the sequence. Given sequence does not appear to "\r
                                                        + "contain the header! Given data:\n "\r
                                                        + singleFastaEntry);\r
                }\r
-               String header = sc.next();\r
+               String header = singleFastaEntry.substring(0, nlineidx);\r
+\r
                // Get rid of the new line chars (should cover common cases)\r
                header = header.replaceAll("\r", "");\r
 \r
-               sc.useDelimiter("\\s*");\r
-               final StringBuilder sb = new StringBuilder();\r
-               while (sc.hasNext()) {\r
-                       sb.append(sc.next());\r
-               }\r
-               final String sequence = sb.toString();\r
+               String sequence = singleFastaEntry.substring(nlineidx);\r
+\r
                if (Util.isEmpty(sequence)) {\r
                        throw new AssertionError(\r
                                        "Empty sequences are not allowed! Please make sure the "\r