Adding AAConWS
[jabaws.git] / testsrc / compbio / data / sequence / SequenceUtilTester.java
index f2af670..720037b 100644 (file)
@@ -1,21 +1,16 @@
-/* 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
@@ -36,112 +31,152 @@ import compbio.metadata.AllTestSuit;
 \r
 public class SequenceUtilTester {\r
 \r
-    @Test()\r
-    public void testisNonAmbNucleotideSequence() {\r
-       String dnaseq = "atgatTGACGCTGCTGatgtcgtgagtgga";\r
-       assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dnaseq));\r
-       String dirtyDnaseq = "atgAGTggt\taGGTgc\ncgcACTgc gACtcgcGAt cgA ";\r
-       assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dirtyDnaseq));\r
-       String nonDna = "atgfctgatgcatgcatgatgctga";\r
-       assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
-\r
-       nonDna = "atgc1tgatgcatgcatgatgctga";\r
-       assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
-\r
-       nonDna = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";\r
-       assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
-       // String ambDna = "AGTCRYMKSWHBVDN"; // see IUPAC Nucleotide Code\r
-       assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
-\r
-    }\r
-\r
-    @Test()\r
-    public void testCleanSequence() {\r
-       String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";\r
-       assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),\r
-               SequenceUtil.cleanSequence(dirtySeq));\r
-    }\r
-\r
-    @Test()\r
-    public void testDeepCleanSequence() {\r
-       String dirtySeq = "a!t?g.A;GTggt\ta12GGTgc\ncgc23AC\rTgc gAC<>.,?!|\\|/t@cg-c¬GA=_+(0){]}[:£$&^*\"t cgA ";\r
-       assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),\r
-               SequenceUtil.deepCleanSequence(dirtySeq));\r
-    }\r
-\r
-    @Test()\r
-    public void testisProteinSequence() {\r
-       String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";\r
-       assertFalse(SequenceUtil.isProteinSequence(dirtySeq));\r
-       String notaSeq = "atgc1tgatgcatgcatgatgctga";\r
-       assertFalse(SequenceUtil.isProteinSequence(notaSeq));\r
-       String AAseq = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";\r
-       assertTrue(SequenceUtil.isProteinSequence(AAseq));\r
-       AAseq += "XU";\r
-       assertFalse(SequenceUtil.isProteinSequence(AAseq));\r
-\r
-    }\r
-\r
-    @Test()\r
-    public void testReadWriteFasta() {\r
-\r
-       try {\r
-           FileInputStream fio = new FileInputStream(\r
-                   AllTestSuit.TEST_DATA_PATH + "TO1381.fasta");\r
-           assertNotNull(fio);\r
-           List<FastaSequence> fseqs = SequenceUtil.readFasta(fio);\r
-           assertNotNull(fseqs);\r
-           assertEquals(3, fseqs.size());\r
-           assertEquals(3, fseqs.size());\r
-           fio.close();\r
-           FileOutputStream fou = new FileOutputStream(\r
-                   AllTestSuit.TEST_DATA_PATH + "TO1381.fasta.written");\r
-           SequenceUtil.writeFasta(fou, fseqs);\r
-           fou.close();\r
-           FileOutputStream fou20 = new FileOutputStream(\r
-                   AllTestSuit.TEST_DATA_PATH + "TO1381.fasta20.written");\r
-           SequenceUtil.writeFasta(fou20, fseqs, 20);\r
-           fou20.close();\r
-\r
-       } catch (FileNotFoundException e) {\r
-           e.printStackTrace();\r
-           fail(e.getLocalizedMessage());\r
-       } catch (IOException e) {\r
-           e.printStackTrace();\r
-           fail(e.getLocalizedMessage());\r
+       @Test()\r
+       public void testisNonAmbNucleotideSequence() {\r
+               String dnaseq = "atgatTGACGCTGCTGatgtcgtgagtgga";\r
+               assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dnaseq));\r
+               String dirtyDnaseq = "atgAGTggt\taGGTgc\ncgcACTgc gACtcgcGAt cgA ";\r
+               assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dirtyDnaseq));\r
+               String nonDna = "atgfctgatgcatgcatgatgctga";\r
+               assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
+\r
+               nonDna = "atgc1tgatgcatgcatgatgctga";\r
+               assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
+\r
+               nonDna = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";\r
+               assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
+               // String ambDna = "AGTCRYMKSWHBVDN"; // see IUPAC Nucleotide Code\r
+               assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));\r
+\r
+       }\r
+\r
+       @Test()\r
+       public void testCleanSequence() {\r
+               String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";\r
+               assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),\r
+                               SequenceUtil.cleanSequence(dirtySeq));\r
+       }\r
+\r
+       @Test()\r
+       public void testDeepCleanSequence() {\r
+               String dirtySeq = "a!t?g.A;GTggt\ta12GGTgc\ncgc23AC\rTgc gAC<>.,?!|\\|/t@cg-c¬GA=_+(0){]}[:£$&^*\"t cgA ";\r
+               assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),\r
+                               SequenceUtil.deepCleanSequence(dirtySeq));\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
-           List<AnnotatedSequence> aseqs = SequenceUtil.readJRonn(fio);\r
-           assertNotNull(aseqs);\r
-           assertEquals(aseqs.size(), 3);\r
-           AnnotatedSequence aseq = aseqs.get(0);\r
-           assertNotNull(aseq);\r
-           assertNotNull(aseq.getAnnotation());\r
-           //System.out.println(aseq);\r
-           assertEquals(aseq.getAnnotation().length, aseq.getSequence()\r
-                   .length());\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
+       @Test()\r
+       public void testisProteinSequence() {\r
+               String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";\r
+               assertFalse(SequenceUtil.isProteinSequence(dirtySeq));\r
+               String notaSeq = "atgc1tgatgcatgcatgatgctga";\r
+               assertFalse(SequenceUtil.isProteinSequence(notaSeq));\r
+               String AAseq = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";\r
+               assertTrue(SequenceUtil.isProteinSequence(AAseq));\r
+               AAseq += "XU";\r
+               assertFalse(SequenceUtil.isProteinSequence(AAseq));\r
+\r
+       }\r
+\r
+       @Test()\r
+       public void testReadWriteFasta() {\r
+\r
+               try {\r
+                       FileInputStream fio = new FileInputStream(\r
+                                       AllTestSuit.TEST_DATA_PATH + "TO1381.fasta");\r
+                       assertNotNull(fio);\r
+                       List<FastaSequence> fseqs = SequenceUtil.readFasta(fio);\r
+                       assertNotNull(fseqs);\r
+                       assertEquals(3, fseqs.size());\r
+                       assertEquals(3, fseqs.size());\r
+                       fio.close();\r
+                       FileOutputStream fou = new FileOutputStream(\r
+                                       AllTestSuit.TEST_DATA_PATH + "TO1381.fasta.written");\r
+                       SequenceUtil.writeFasta(fou, fseqs);\r
+                       fou.close();\r
+                       FileOutputStream fou20 = new FileOutputStream(\r
+                                       AllTestSuit.TEST_DATA_PATH + "TO1381.fasta20.written");\r
+                       SequenceUtil.writeFasta(fou20, fseqs, 21);\r
+                       fou20.close();\r
+\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getLocalizedMessage());\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getLocalizedMessage());\r
+               }\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
+                       List<AnnotatedSequence> aseqs = SequenceUtil.readJRonn(fio);\r
+                       assertNotNull(aseqs);\r
+                       assertEquals(aseqs.size(), 3);\r
+                       AnnotatedSequence aseq = aseqs.get(0);\r
+                       assertNotNull(aseq);\r
+                       assertNotNull(aseq.getAnnotation());\r
+                       // System.out.println(aseq);\r
+                       assertEquals(aseq.getAnnotation().length, aseq.getSequence()\r
+                                       .length());\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
+       @SuppressWarnings("unchecked")\r
+       @Test\r
+       public void testMultiAnnotatedSequence() {\r
+\r
+               FileInputStream fio;\r
+               try {\r
+                       fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+                                       + "disembl.out");\r
+                       List<MultiAnnotatedSequence<DisemblResultAnnot>> aseqs = SequenceUtil\r
+                                       .readDisembl(fio);\r
+                       assertNotNull(aseqs);\r
+\r
+                       /*\r
+                        * MultiAnnotatedSequence ma = new MultiAnnotatedSequence();\r
+                        * Map<Trial, List<Number>> val = ma.getInstance(Trial.class);\r
+                        * List<Number> list = new ArrayList<Number>(); list.add(new\r
+                        * Float(1.2)); list.add(new Double(5.662)); val.put(Trial.one,\r
+                        * list); val.put(Trial.two, Arrays.asList(6.22f, 1, 37.6f));\r
+                        * System.out.println(val); AnnotatedSequence aseq = aseqs.get(0);\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