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.HashMap;
\r
28 import java.util.HashSet;
\r
29 import java.util.List;
\r
30 import java.util.Map;
\r
31 import java.util.Set;
\r
33 import org.testng.annotations.Test;
\r
35 import compbio.metadata.AllTestSuit;
\r
37 public class SequenceUtilTester {
\r
40 public void testisNonAmbNucleotideSequence() {
\r
41 String dnaseq = "atgatTGACGCTGCTGatgtcgtgagtgga";
\r
42 assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dnaseq));
\r
43 String dirtyDnaseq = "atgAGTggt\taGGTgc\ncgcACTgc gACtcgcGAt cgA ";
\r
44 assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dirtyDnaseq));
\r
45 String nonDna = "atgfctgatgcatgcatgatgctga";
\r
46 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
48 nonDna = "atgc1tgatgcatgcatgatgctga";
\r
49 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
51 nonDna = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";
\r
52 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
53 // String ambDna = "AGTCRYMKSWHBVDN"; // see IUPAC Nucleotide Code
\r
54 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
59 public void testCleanSequence() {
\r
60 String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";
\r
61 assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),
\r
62 SequenceUtil.cleanSequence(dirtySeq));
\r
66 public void testDeepCleanSequence() {
\r
67 String dirtySeq = "a!t?g.A;GTggt\ta12GGTgc\ncgc23AC\rTgc gAC<>.,?!|\\|/t@cg-c¬GA=_+(0){]}[:£$&^*\"t cgA ";
\r
68 assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),
\r
69 SequenceUtil.deepCleanSequence(dirtySeq));
\r
73 public void testisProteinSequence() {
\r
74 String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";
\r
75 assertFalse(SequenceUtil.isProteinSequence(dirtySeq));
\r
76 String notaSeq = "atgc1tgatgcatgcatgatgctga";
\r
77 assertFalse(SequenceUtil.isProteinSequence(notaSeq));
\r
78 String AAseq = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";
\r
79 assertTrue(SequenceUtil.isProteinSequence(AAseq));
\r
81 assertFalse(SequenceUtil.isProteinSequence(AAseq));
\r
86 public void testReadWriteFasta() {
\r
89 FileInputStream fio = new FileInputStream(
\r
90 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta");
\r
92 List<FastaSequence> fseqs = SequenceUtil.readFasta(fio);
\r
93 assertNotNull(fseqs);
\r
94 assertEquals(3, fseqs.size());
\r
95 assertEquals(3, fseqs.size());
\r
97 FileOutputStream fou = new FileOutputStream(
\r
98 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta.written");
\r
99 SequenceUtil.writeFasta(fou, fseqs);
\r
101 FileOutputStream fou20 = new FileOutputStream(
\r
102 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta20.written");
\r
103 SequenceUtil.writeFasta(fou20, fseqs, 21);
\r
106 } catch (FileNotFoundException e) {
\r
107 e.printStackTrace();
\r
108 fail(e.getLocalizedMessage());
\r
109 } catch (IOException e) {
\r
110 e.printStackTrace();
\r
111 fail(e.getLocalizedMessage());
\r
116 * This test tests the loading of horizontally formatted Jronn output file
\r
119 public void loadJronnFile() {
\r
121 FileInputStream fio;
\r
123 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "jronn.out");
\r
124 Map<String, Score> aseqs = SequenceUtil.readJRonn(fio);
\r
125 assertNotNull(aseqs);
\r
126 assertEquals(aseqs.size(), 3);
\r
127 Score aseq = aseqs.get("Foobar");
\r
128 assertNotNull(aseq);
\r
129 assertNotNull(aseq.getScores());
\r
130 // System.out.println(aseq);
\r
131 assertEquals(aseq.getScores().size(), aseq.getScores().size());
\r
133 } catch (FileNotFoundException e) {
\r
134 e.printStackTrace();
\r
135 fail(e.getLocalizedMessage());
\r
136 } catch (IOException e) {
\r
137 e.printStackTrace();
\r
138 fail(e.getLocalizedMessage());
\r
139 } catch (UnknownFileFormatException e) {
\r
140 e.printStackTrace();
\r
141 fail(e.getLocalizedMessage());
\r
151 * This test tests the loading of horizontally formatted Jronn output file
\r
155 * M 0.86010 0.88512 0.37094
\r
157 * T 0.79983 0.85864 0.44331
\r
160 @SuppressWarnings("unchecked")
\r
162 public void testReadDisemblResults() {
\r
164 FileInputStream fio;
\r
166 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
168 Map<FastaSequence, HashSet<Score>> aseqs = SequenceUtil
\r
170 assertNotNull(aseqs);
\r
171 assertEquals(aseqs.size(), 3);
\r
172 // System.out.println(aseqs);
\r
173 for (FastaSequence fs : aseqs.keySet()) {
\r
174 assertTrue(" Foobar_dundeefriends Foobar dundeefriends "
\r
175 .contains(fs.getId()));
\r
176 Set<Score> scores = aseqs.get(fs);
\r
177 assertEquals(scores.size(), 3);
\r
180 } catch (FileNotFoundException e) {
\r
181 e.printStackTrace();
\r
182 fail(e.getLocalizedMessage());
\r
183 } catch (IOException e) {
\r
184 e.printStackTrace();
\r
185 fail(e.getLocalizedMessage());
\r
186 } catch (UnknownFileFormatException e) {
\r
187 e.printStackTrace();
\r
188 fail(e.getLocalizedMessage());
\r
193 * This test tests the loading of horizontally formatted Jronn output file
\r
197 * >Foobar_dundeefriends
\r
199 * # GlobDoms 2-358, 373-568
\r
201 * # Disorder 1-5, 206-218, 243-250, 288-300, 313-324, 359-372, 475-481
\r
203 * # RESIDUE DYDX RAW SMOOTHED
\r
205 * M 0.0044 -0.2259 -0.2259
\r
207 * T -0.1308 -0.2170 -0.2170
\r
211 * > Second sequence
\r
213 @SuppressWarnings("unchecked")
\r
215 public void testReadGlobPlotResults() {
\r
217 FileInputStream fio;
\r
219 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
221 HashMap<FastaSequence, HashSet<Score>> aseqs = SequenceUtil
\r
222 .readGlobPlot(fio);
\r
223 assertNotNull(aseqs);
\r
224 assertEquals(aseqs.size(), 3);
\r
226 FastaSequence fsdf = null;
\r
227 Set<Score> scores = null;
\r
228 for (FastaSequence fs : aseqs.keySet()) {
\r
229 if ("Foobar_dundeefriends".contains(fs.getId())) {
\r
231 scores = aseqs.get(fs);
\r
233 assertEquals(scores.size(), 5);
\r
235 for (Score score : scores) {
\r
237 if (score.getMethod() == (Enum<?>) GlobProtResult.Disorder) {
\r
238 assertEquals(score.getRanges().size(), 7);
\r
239 assertTrue(score.getScores().isEmpty());
\r
241 if (score.getMethod() == (Enum<?>) GlobProtResult.Dydx) {
\r
242 assertFalse(score.getScores().isEmpty());
\r
243 assertTrue(score.getRanges().isEmpty());
\r
247 } catch (FileNotFoundException e) {
\r
248 e.printStackTrace();
\r
249 fail(e.getLocalizedMessage());
\r
250 } catch (IOException e) {
\r
251 e.printStackTrace();
\r
252 fail(e.getLocalizedMessage());
\r
253 } catch (UnknownFileFormatException e) {
\r
254 e.printStackTrace();
\r
255 fail(e.getLocalizedMessage());
\r
260 public void testReadAAConResults() {
\r
262 InputStream inStream = new FileInputStream(
\r
263 AllTestSuit.TEST_DATA_PATH + "aacon_results.txt");
\r
264 HashSet<Score> result = SequenceUtil.readAAConResults(inStream);
\r
266 assertNotNull(result);
\r
267 assertEquals(result.size(), 18);
\r
269 inStream = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
270 + "aacon_result_single.out");
\r
271 result = SequenceUtil.readAAConResults(inStream);
\r
273 assertNotNull(result);
\r
274 assertEquals(result.size(), 1);
\r
275 assertEquals(result.iterator().next().getScores().size(), 568);
\r
276 } catch (IOException e) {
\r
277 e.printStackTrace();
\r
278 fail(e.getMessage());
\r