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
29 import java.util.Map;
\r
30 import java.util.Set;
\r
32 import org.testng.annotations.Test;
\r
34 import compbio.metadata.AllTestSuit;
\r
36 public class SequenceUtilTester {
\r
39 public void testisNonAmbNucleotideSequence() {
\r
40 String dnaseq = "atgatTGACGCTGCTGatgtcgtgagtgga";
\r
41 assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dnaseq));
\r
42 String dirtyDnaseq = "atgAGTggt\taGGTgc\ncgcACTgc gACtcgcGAt cgA ";
\r
43 assertTrue(SequenceUtil.isNonAmbNucleotideSequence(dirtyDnaseq));
\r
44 String nonDna = "atgfctgatgcatgcatgatgctga";
\r
45 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
47 nonDna = "atgc1tgatgcatgcatgatgctga";
\r
48 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
50 nonDna = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";
\r
51 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
52 // String ambDna = "AGTCRYMKSWHBVDN"; // see IUPAC Nucleotide Code
\r
53 assertFalse(SequenceUtil.isNonAmbNucleotideSequence(nonDna));
\r
58 public void testCleanSequence() {
\r
59 String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";
\r
60 assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),
\r
61 SequenceUtil.cleanSequence(dirtySeq));
\r
65 public void testDeepCleanSequence() {
\r
66 String dirtySeq = "a!t?g.A;GTggt\ta12GGTgc\ncgc23AC\rTgc gAC<>.,?!|\\|/t@cg-c¬GA=_+(0){]}[:£$&^*\"t cgA ";
\r
67 assertEquals("atgAGTggtaGGTgccgcACTgcgACtcgcGAtcgA".toUpperCase(),
\r
68 SequenceUtil.deepCleanSequence(dirtySeq));
\r
72 public void testisProteinSequence() {
\r
73 String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";
\r
74 assertFalse(SequenceUtil.isProteinSequence(dirtySeq));
\r
75 String notaSeq = "atgc1tgatgcatgcatgatgctga";
\r
76 assertFalse(SequenceUtil.isProteinSequence(notaSeq));
\r
77 String AAseq = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";
\r
78 assertTrue(SequenceUtil.isProteinSequence(AAseq));
\r
80 assertFalse(SequenceUtil.isProteinSequence(AAseq));
\r
85 public void testReadWriteFasta() {
\r
88 FileInputStream fio = new FileInputStream(
\r
89 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta");
\r
91 List<FastaSequence> fseqs = SequenceUtil.readFasta(fio);
\r
92 assertNotNull(fseqs);
\r
93 assertEquals(3, fseqs.size());
\r
94 assertEquals(3, fseqs.size());
\r
96 FileOutputStream fou = new FileOutputStream(
\r
97 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta.written");
\r
98 SequenceUtil.writeFasta(fou, fseqs);
\r
100 FileOutputStream fou20 = new FileOutputStream(
\r
101 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta20.written");
\r
102 SequenceUtil.writeFasta(fou20, fseqs, 21);
\r
105 } catch (FileNotFoundException e) {
\r
106 e.printStackTrace();
\r
107 fail(e.getLocalizedMessage());
\r
108 } catch (IOException e) {
\r
109 e.printStackTrace();
\r
110 fail(e.getLocalizedMessage());
\r
115 * This test tests the loading of horizontally formatted Jronn output file
\r
118 public void loadJronnFile() {
\r
120 FileInputStream fio;
\r
122 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "jronn.out");
\r
123 Map<String, Score> aseqs = SequenceUtil.readJRonn(fio);
\r
124 assertNotNull(aseqs);
\r
125 assertEquals(aseqs.size(), 3);
\r
126 Score aseq = aseqs.get("Foobar");
\r
127 assertNotNull(aseq);
\r
128 assertNotNull(aseq.getScores());
\r
129 // System.out.println(aseq);
\r
130 assertEquals(aseq.getScores().size(), aseq.getScores().size());
\r
132 } catch (FileNotFoundException e) {
\r
133 e.printStackTrace();
\r
134 fail(e.getLocalizedMessage());
\r
135 } catch (IOException e) {
\r
136 e.printStackTrace();
\r
137 fail(e.getLocalizedMessage());
\r
138 } catch (UnknownFileFormatException e) {
\r
139 e.printStackTrace();
\r
140 fail(e.getLocalizedMessage());
\r
150 * This test tests the loading of horizontally formatted Jronn output file
\r
154 * M 0.86010 0.88512 0.37094
\r
156 * T 0.79983 0.85864 0.44331
\r
159 @SuppressWarnings("unchecked")
\r
161 public void testReadDisemblResults() {
\r
163 FileInputStream fio;
\r
165 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
167 Map<FastaSequence, Set<Score>> aseqs = SequenceUtil
\r
169 assertNotNull(aseqs);
\r
170 assertEquals(aseqs.size(), 3);
\r
171 System.out.println(aseqs);
\r
172 for (FastaSequence fs : aseqs.keySet()) {
\r
173 assertTrue(" Foobar_dundeefriends Foobar dundeefriends "
\r
174 .contains(fs.getId()));
\r
175 Set<Score> scores = aseqs.get(fs);
\r
176 assertEquals(scores.size(), 3);
\r
179 } catch (FileNotFoundException e) {
\r
180 e.printStackTrace();
\r
181 fail(e.getLocalizedMessage());
\r
182 } catch (IOException e) {
\r
183 e.printStackTrace();
\r
184 fail(e.getLocalizedMessage());
\r
185 } catch (UnknownFileFormatException e) {
\r
186 e.printStackTrace();
\r
187 fail(e.getLocalizedMessage());
\r
192 * This test tests the loading of horizontally formatted Jronn output file
\r
196 * >Foobar_dundeefriends
\r
198 * # GlobDoms 2-358, 373-568
\r
200 * # Disorder 1-5, 206-218, 243-250, 288-300, 313-324, 359-372, 475-481
\r
202 * # RESIDUE DYDX RAW SMOOTHED
\r
204 * M 0.0044 -0.2259 -0.2259
\r
206 * T -0.1308 -0.2170 -0.2170
\r
210 * > Second sequence
\r
212 @SuppressWarnings("unchecked")
\r
214 public void testReadGlobPlotResults() {
\r
216 FileInputStream fio;
\r
218 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
220 Map<FastaSequence, Set<Score>> aseqs = SequenceUtil
\r
221 .readGlobPlot(fio);
\r
222 assertNotNull(aseqs);
\r
223 assertEquals(aseqs.size(), 3);
\r
225 FastaSequence fsdf = null;
\r
226 Set<Score> scores = null;
\r
227 for (FastaSequence fs : aseqs.keySet()) {
\r
228 if ("Foobar_dundeefriends".contains(fs.getId())) {
\r
230 scores = aseqs.get(fs);
\r
232 assertEquals(scores.size(), 5);
\r
234 for (Score score : scores) {
\r
236 if (score.getMethod() == (Enum<?>) GlobProtResult.Disorder) {
\r
237 assertEquals(score.getRanges().size(), 7);
\r
238 assertTrue(score.getScores().isEmpty());
\r
240 if (score.getMethod() == (Enum<?>)GlobProtResult.Dydx) {
\r
241 assertFalse(score.getScores().isEmpty());
\r
242 assertTrue(score.getRanges().isEmpty());
\r
246 } catch (FileNotFoundException e) {
\r
247 e.printStackTrace();
\r
248 fail(e.getLocalizedMessage());
\r
249 } catch (IOException e) {
\r
250 e.printStackTrace();
\r
251 fail(e.getLocalizedMessage());
\r
252 } catch (UnknownFileFormatException e) {
\r
253 e.printStackTrace();
\r
254 fail(e.getLocalizedMessage());
\r
259 public void testReadAAConResults() {
\r
261 InputStream inStream = new FileInputStream(
\r
262 AllTestSuit.TEST_DATA_PATH + "aacon_results.txt");
\r
263 HashSet<Score> result = SequenceUtil.readAAConResults(inStream);
\r
265 assertNotNull(result);
\r
266 assertEquals(result.size(), 18);
\r
268 inStream = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
269 + "aacon_result_single.out");
\r
270 result = SequenceUtil.readAAConResults(inStream);
\r
272 assertNotNull(result);
\r
273 assertEquals(result.size(), 1);
\r
274 assertEquals(result.iterator().next().getScores().size(), 568);
\r
275 } catch (IOException e) {
\r
276 e.printStackTrace();
\r
277 fail(e.getMessage());
\r