Refactoring of all SequenceAnnotation web services
[jabaws.git] / datamodel / compbio / data / sequence / SequenceUtil.java
index 1c6d2e8..d65494e 100644 (file)
@@ -41,8 +41,9 @@ import compbio.util.Util;
 /**\r
  * Utility class for operations on sequences\r
  * \r
- * @author Petr Troshin\r
- * @version 1.0\r
+ * @author Peter Troshin\r
+ * @since 1.0\r
+ * @version 2.0 June 2011\r
  */\r
 public final class SequenceUtil {\r
 \r
@@ -99,19 +100,6 @@ public final class SequenceUtil {
        private SequenceUtil() {\r
        } // utility class, no instantiation\r
 \r
-       /*\r
-        * public static void write_PirSeq(OutputStream os, FastaSequence seq)\r
-        * throws IOException { BufferedWriter pir_out = new BufferedWriter(new\r
-        * OutputStreamWriter(os)); pir_out.write(">P1;" + seq.getId() +\r
-        * SysPrefs.newlinechar); pir_out.write(seq.getSequence() +\r
-        * SysPrefs.newlinechar); pir_out.close(); } public static void\r
-        * write_FastaSeq(OutputStream os, FastaSequence seq) throws IOException {\r
-        * BufferedWriter fasta_out = new BufferedWriter( new\r
-        * OutputStreamWriter(os)); fasta_out.write(">" + seq.getId() +\r
-        * SysPrefs.newlinechar); fasta_out.write(seq.getSequence() +\r
-        * SysPrefs.newlinechar); fasta_out.close(); }\r
-        */\r
-\r
        /**\r
         * @return true is the sequence contains only letters a,c, t, g, u\r
         */\r
@@ -268,28 +256,11 @@ public final class SequenceUtil {
        public static List<FastaSequence> readFasta(final InputStream inStream)\r
                        throws IOException {\r
                final List<FastaSequence> seqs = new ArrayList<FastaSequence>();\r
-\r
-               final BufferedReader infasta = new BufferedReader(\r
-                               new InputStreamReader(inStream, "UTF8"), 16000);\r
-               final Pattern pattern = Pattern.compile("//s+");\r
-\r
-               String line;\r
-               String sname = "", seqstr = null;\r
-               do {\r
-                       line = infasta.readLine();\r
-                       if ((line == null) || line.startsWith(">")) {\r
-                               if (seqstr != null) {\r
-                                       seqs.add(new FastaSequence(sname.substring(1), seqstr));\r
-                               }\r
-                               sname = line; // remove >\r
-                               seqstr = "";\r
-                       } else {\r
-                               final String subseq = pattern.matcher(line).replaceAll("");\r
-                               seqstr += subseq;\r
-                       }\r
-               } while (line != null);\r
-\r
-               infasta.close();\r
+               FastaReader reader = new FastaReader(inStream);\r
+               while (reader.hasNext()) {\r
+                       seqs.add(reader.next());\r
+               }\r
+               inStream.close();\r
                return seqs;\r
        }\r
 \r