-/* Copyright (c) 2009 Peter Troshin\r
- * \r
- * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.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
+ * Copyright (c) 2009 Peter Troshin JAva Bioinformatics Analysis Web Services\r
+ * (JABAWS) @version: 1.0 This library is free software; you can redistribute it\r
+ * and/or modify it under the terms of the Apache License version 2 as published\r
+ * by the Apache Software Foundation This library is distributed in the hope\r
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * Apache License for more details. A copy of the license is in\r
+ * apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt Any republication or\r
+ * derived work distributed in source code form must include this copyright and\r
+ * license notice.\r
*/\r
-\r
package compbio.data.sequence;\r
\r
import static org.testng.AssertJUnit.assertEquals;\r
import java.io.FileNotFoundException;\r
import java.io.FileOutputStream;\r
import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.PrintWriter;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
\r
import org.testng.annotations.Test;\r
\r
}\r
\r
@Test()\r
+ public void testCleanProteinSequence() {\r
+ String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";\r
+ assertFalse(SequenceUtil.isProteinSequence(dirtySeq));\r
+ // This will still be NON protein sequence despite having only correct\r
+ // letters because the letters match perfectly the nucleotide sequence!\r
+ assertFalse(SequenceUtil.isProteinSequence(SequenceUtil\r
+ .cleanProteinSequence(dirtySeq)));\r
+\r
+ String notaSeq = "atgc1tgatgcatgcatgatgmctga";\r
+ assertFalse(SequenceUtil.isProteinSequence(notaSeq));\r
+ assertTrue(SequenceUtil.isProteinSequence(SequenceUtil\r
+ .cleanProteinSequence(notaSeq)));\r
+\r
+ String AAseq = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";\r
+ assertTrue(SequenceUtil.isProteinSequence(AAseq));\r
+ assertTrue(SequenceUtil.isProteinSequence(SequenceUtil\r
+ .cleanProteinSequence(AAseq)));\r
+ AAseq += "XU";\r
+\r
+ assertFalse(SequenceUtil.isProteinSequence(AAseq));\r
+ assertTrue(SequenceUtil.isProteinSequence(SequenceUtil\r
+ .cleanProteinSequence(AAseq)));\r
+ }\r
+\r
+ @Test()\r
public void testReadWriteFasta() {\r
\r
try {\r
fou.close();\r
FileOutputStream fou20 = new FileOutputStream(\r
AllTestSuit.TEST_DATA_PATH + "TO1381.fasta20.written");\r
- SequenceUtil.writeFasta(fou20, fseqs, 20);\r
+ SequenceUtil.writeFasta(fou20, fseqs, 21);\r
fou20.close();\r
\r
} catch (FileNotFoundException e) {\r
}\r
}\r
\r
+ /**\r
+ * This test tests the loading of horizontally formatted Jronn output file\r
+ */\r
+ @Test\r
+ public void loadJronnFile() {\r
+\r
+ FileInputStream fio;\r
+ try {\r
+ fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "jronn.out");\r
+ Map<String, Score> aseqs = SequenceUtil.readJRonn(fio);\r
+ assertNotNull(aseqs);\r
+ assertEquals(aseqs.size(), 3);\r
+ Score aseq = aseqs.get("Foobar");\r
+ assertNotNull(aseq);\r
+ assertNotNull(aseq.getScores());\r
+ // System.out.println(aseq);\r
+ assertEquals(aseq.getScores().size(), aseq.getScores().size());\r
+ fio.close();\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (UnknownFileFormatException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+\r
+ }\r
+\r
+ enum Trial {\r
+ one, two, three\r
+ };\r
+\r
+ /**\r
+ * This test tests the loading of horizontally formatted Jronn output file\r
+ * \r
+ * First seq\r
+ * \r
+ * M 0.86010 0.88512 0.37094\r
+ * \r
+ * T 0.79983 0.85864 0.44331\r
+ * \r
+ */\r
+ @SuppressWarnings("unchecked")\r
+ @Test\r
+ public void testReadDisemblResults() {\r
+\r
+ FileInputStream fio;\r
+ try {\r
+ fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+ + "disembl.out");\r
+ Map<String, Set<Score>> aseqs = SequenceUtil.readDisembl(fio);\r
+ assertNotNull(aseqs);\r
+ assertEquals(aseqs.size(), 3);\r
+ ScoreManager sman = ScoreManager.newInstance(aseqs);\r
+\r
+ for (String fs : aseqs.keySet()) {\r
+ assertTrue(" Foobar_dundeefriends Foobar dundeefriends "\r
+ .contains(fs));\r
+ Set<Score> scores = aseqs.get(fs);\r
+ assertEquals(scores.size(), 3);\r
+ }\r
+ fio.close();\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (UnknownFileFormatException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+ }\r
+\r
+ /**\r
+ * This test tests the loading of horizontally formatted Jronn output file\r
+ * \r
+ * First sequence:\r
+ * \r
+ * >Foobar_dundeefriends\r
+ * \r
+ * # GlobDoms 2-358, 373-568\r
+ * \r
+ * # Disorder 1-5, 206-218, 243-250, 288-300, 313-324, 359-372, 475-481\r
+ * \r
+ * # RESIDUE DYDX RAW SMOOTHED\r
+ * \r
+ * M 0.0044 -0.2259 -0.2259\r
+ * \r
+ * T -0.1308 -0.2170 -0.2170\r
+ * \r
+ * ............\r
+ * \r
+ * > Second sequence\r
+ */\r
+ @SuppressWarnings("unchecked")\r
+ @Test\r
+ public void testReadGlobPlotResults() {\r
+\r
+ FileInputStream fio;\r
+ try {\r
+ fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+ + "globplot.out");\r
+ HashMap<String, Set<Score>> aseqs = SequenceUtil.readGlobPlot(fio);\r
+ assertNotNull(aseqs);\r
+ assertEquals(aseqs.size(), 3);\r
+\r
+ String fsdf = null;\r
+ Set<Score> scores = null;\r
+ for (String fs : aseqs.keySet()) {\r
+ if ("Foobar_dundeefriends".contains(fs)) {\r
+ fsdf = fs;\r
+ scores = aseqs.get(fs);\r
+ }\r
+ assertEquals(scores.size(), 5);\r
+ }\r
+\r
+ ScoreManager sm = ScoreManager.newInstanceSingleSequence(scores);\r
+ sm.writeOut(new PrintWriter(System.out, true));\r
+\r
+ for (Score score : scores) {\r
+\r
+ if (score.getMethod()\r
+ .equals(GlobProtResult.Disorder.toString())) {\r
+ assertEquals(score.getRanges().size(), 7);\r
+ assertTrue(score.getScores().isEmpty());\r
+ }\r
+ if (GlobProtResult.valueOf(score.getMethod()) == GlobProtResult.Dydx) {\r
+ assertFalse(score.getScores().isEmpty());\r
+ assertTrue(score.getRanges().isEmpty());\r
+ }\r
+ }\r
+ fio.close();\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (UnknownFileFormatException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testReadAAConResults() {\r
+ try {\r
+ InputStream inStream = new FileInputStream(\r
+ AllTestSuit.TEST_DATA_PATH + "aacon_results.txt");\r
+ HashSet<Score> result = SequenceUtil.readAAConResults(inStream);\r
+ inStream.close();\r
+ assertNotNull(result);\r
+ assertEquals(result.size(), 18);\r
+\r
+ inStream = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+ + "aacon_result_single.out");\r
+ result = SequenceUtil.readAAConResults(inStream);\r
+ inStream.close();\r
+ assertNotNull(result);\r
+ assertEquals(result.size(), 1);\r
+ assertEquals(result.iterator().next().getScores().size(), 568);\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ }\r
+ }\r
}\r