-/*\r
- * @(#)SequenceUtil.java 1.0 September 2009 Copyright (c) 2009 Peter Troshin\r
- * Jalview Web Services version: 2.0 This library is free software; you can\r
- * redistribute it and/or modify it under the terms of the Apache License\r
- * version 2 as published by the Apache Software Foundation This library is\r
- * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;\r
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\r
- * PARTICULAR PURPOSE. See the Apache License for more details. A copy of the\r
- * license is in apache_license.txt. It is also available here: see:\r
- * http://www.apache.org/licenses/LICENSE-2.0.txt Any republication or derived\r
- * work distributed in source code form must include this copyright and license\r
- * notice.\r
+/* Copyright (c) 2011 Peter Troshin\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 \r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
*/\r
\r
package compbio.data.sequence;\r
/**\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
* @throws IOException\r
* @throws UnknownFileFormatException\r
*/\r
- public static Map<String, Score> readIUPred(final File result,\r
- IUPredResult type) throws IOException, UnknownFileFormatException {\r
+ public static Map<String, Score> readIUPred(final File result)\r
+ throws IOException, UnknownFileFormatException {\r
InputStream input = new FileInputStream(result);\r
- Map<String, Score> sequences = readIUPred(input, type);\r
+ Map<String, Score> sequences = readIUPred(input,\r
+ IUPredResult.getType(result));\r
input.close();\r
return sequences;\r
}\r
while (scan.hasNext()) {\r
String nextEntry = scan.next();\r
Scanner entry = new Scanner(nextEntry);\r
- String name = entry.nextLine();\r
+ String name = entry.nextLine().trim();\r
// inside entry:\r
if (IUPredResult.Glob == type) {\r
// parse domains\r
/**\r
* Globular domains\r
*/\r
- Glob\r
+ Glob;\r
+\r
+ static IUPredResult getType(File file) {\r
+ assert file != null;\r
+ String name = file.getName();\r
+ if (name.endsWith(Long.toString().toLowerCase())) {\r
+ return Long;\r
+ }\r
+ if (name.endsWith(Short.toString().toLowerCase())) {\r
+ return Short;\r
+ }\r
+ if (name.endsWith(Glob.toString().toLowerCase())) {\r
+ return Glob;\r
+ }\r
+ throw new AssertionError(\r
+ "IUPred result file type cannot be recognised! "\r
+ + "\nFile must ends with one of [glob, long or short]"\r
+ + "\n but given file name was: " + file.getName());\r
+ }\r
}
\ No newline at end of file