/**\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
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
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