2 * Copyright (c) 2009 Peter Troshin JAva Bioinformatics Analysis Web Services
\r
3 * (JABAWS) @version: 1.0 This library is free software; you can redistribute it
\r
4 * and/or modify it under the terms of the Apache License version 2 as published
\r
5 * by the Apache Software Foundation This library is distributed in the hope
\r
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
\r
7 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
8 * Apache License for more details. A copy of the license is in
\r
9 * apache_license.txt. It is also available here:
\r
10 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt Any republication or
\r
11 * derived work distributed in source code form must include this copyright and
\r
14 package compbio.data.sequence;
\r
16 import static org.testng.AssertJUnit.assertEquals;
\r
17 import static org.testng.AssertJUnit.assertFalse;
\r
18 import static org.testng.AssertJUnit.assertNotNull;
\r
19 import static org.testng.AssertJUnit.assertTrue;
\r
20 import static org.testng.AssertJUnit.fail;
\r
22 import java.io.FileInputStream;
\r
23 import java.io.FileNotFoundException;
\r
24 import java.io.FileOutputStream;
\r
25 import java.io.IOException;
\r
26 import java.io.InputStream;
\r
27 import java.util.HashSet;
\r
28 import java.util.List;
\r
30 import org.testng.annotations.Test;
\r
32 import compbio.metadata.AllTestSuit;
\r
34 public class SequenceUtilTester {
\r
37 public void testisNonAmbNucleotideSequence() {
\r
38 String dnaseq = "atgatTGACGCTGCTGatgtcgtgagtgga";
\r
39 assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dnaseq));
\r
40 String dirtyDnaseq = "atgAGTggt\taGGTgc\ncgcACTgc gACtcgcGAt cgA ";
\r
41 assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dirtyDnaseq));
\r
42 String nonDna = "atgfctgatgcatgcatgatgctga";
\r
43 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
45 nonDna = "atgc1tgatgcatgcatgatgctga";
\r
46 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
48 nonDna = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";
\r
49 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
50 // String ambDna = "AGTCRYMKSWHBVDN"; // see IUPAC Nucleotide Code
\r
51 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
56 public void testCleanSequence() {
\r
57 String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";
\r
58 assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),
\r
59 SequenceUtil.cleanSequence(dirtySeq));
\r
63 public void testDeepCleanSequence() {
\r
64 String dirtySeq = "a!t?g.A;GTggt\ta12GGTgc\ncgc23AC\rTgc gAC<>.,?!|\\|/t@cg-c¬GA=_+(0){]}[:£$&^*\"t cgA ";
\r
65 assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),
\r
66 SequenceUtil.deepCleanSequence(dirtySeq));
\r
70 public void testisProteinSequence() {
\r
71 String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";
\r
72 assertFalse(SequenceUtil.isProteinSequence(dirtySeq));
\r
73 String notaSeq = "atgc1tgatgcatgcatgatgctga";
\r
74 assertFalse(SequenceUtil.isProteinSequence(notaSeq));
\r
75 String AAseq = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";
\r
76 assertTrue(SequenceUtil.isProteinSequence(AAseq));
\r
78 assertFalse(SequenceUtil.isProteinSequence(AAseq));
\r
83 public void testReadWriteFasta() {
\r
86 FileInputStream fio = new FileInputStream(
\r
87 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta");
\r
89 List<FastaSequence> fseqs = SequenceUtil.readFasta(fio);
\r
90 assertNotNull(fseqs);
\r
91 assertEquals(3, fseqs.size());
\r
92 assertEquals(3, fseqs.size());
\r
94 FileOutputStream fou = new FileOutputStream(
\r
95 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta.written");
\r
96 SequenceUtil.writeFasta(fou, fseqs);
\r
98 FileOutputStream fou20 = new FileOutputStream(
\r
99 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta20.written");
\r
100 SequenceUtil.writeFasta(fou20, fseqs, 21);
\r
103 } catch (FileNotFoundException e) {
\r
104 e.printStackTrace();
\r
105 fail(e.getLocalizedMessage());
\r
106 } catch (IOException e) {
\r
107 e.printStackTrace();
\r
108 fail(e.getLocalizedMessage());
\r
113 * This test tests the loading of horizontally formatted Jronn output file
\r
116 public void loadJronnFile() {
\r
118 FileInputStream fio;
\r
120 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "jronn.out");
\r
121 List<AnnotatedSequence> aseqs = SequenceUtil.readJRonn(fio);
\r
122 assertNotNull(aseqs);
\r
123 assertEquals(aseqs.size(), 3);
\r
124 AnnotatedSequence aseq = aseqs.get(0);
\r
125 assertNotNull(aseq);
\r
126 assertNotNull(aseq.getAnnotation());
\r
127 // System.out.println(aseq);
\r
128 assertEquals(aseq.getAnnotation().length, aseq.getSequence()
\r
131 } catch (FileNotFoundException e) {
\r
132 e.printStackTrace();
\r
133 fail(e.getLocalizedMessage());
\r
134 } catch (IOException e) {
\r
135 e.printStackTrace();
\r
136 fail(e.getLocalizedMessage());
\r
137 } catch (UnknownFileFormatException e) {
\r
138 e.printStackTrace();
\r
139 fail(e.getLocalizedMessage());
\r
149 * This test tests the loading of horizontally formatted Jronn output file
\r
151 @SuppressWarnings("unchecked")
\r
153 public void testMultiAnnotatedSequence() {
\r
155 FileInputStream fio;
\r
157 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
159 List<MultiAnnotatedSequence<DisemblResultAnnot>> aseqs = SequenceUtil
\r
161 assertNotNull(aseqs);
\r
164 * Map<Trial, List<Number>> val = ma.getInstance(Trial.class);
\r
165 * List<Number> list = new ArrayList<Number>(); list.add(new
\r
166 * Float(1.2)); list.add(new Double(5.662)); val.put(Trial.one,
\r
167 * list); val.put(Trial.two, Arrays.asList(6.22f, 1, 37.6f));
\r
168 * System.out.println(val); AnnotatedSequence aseq = aseqs.get(0);
\r
171 } catch (FileNotFoundException e) {
\r
172 e.printStackTrace();
\r
173 fail(e.getLocalizedMessage());
\r
174 } catch (IOException e) {
\r
175 e.printStackTrace();
\r
176 fail(e.getLocalizedMessage());
\r
177 } catch (UnknownFileFormatException e) {
\r
178 e.printStackTrace();
\r
179 fail(e.getLocalizedMessage());
\r
184 public void testReadAAConResults() {
\r
186 InputStream inStream = new FileInputStream(
\r
187 AllTestSuit.TEST_DATA_PATH + "aacon_results.txt");
\r
188 HashSet<Score> result = SequenceUtil.readAAConResults(inStream);
\r
190 assertNotNull(result);
\r
191 assertEquals(result.size(), 18);
\r
193 inStream = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
194 + "aacon_result_single.out");
\r
195 result = SequenceUtil.readAAConResults(inStream);
\r
197 assertNotNull(result);
\r
198 assertEquals(result.size(), 1);
\r
199 assertEquals(result.iterator().next().getScores().size(), 568);
\r
200 } catch (IOException e) {
\r
201 e.printStackTrace();
\r
202 fail(e.getMessage());
\r