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 testCleanProteinSequence() {
\r
87 String dirtySeq = "atgAGTggt\taGGTgc\ncgcAC\rTgc gACtcgcGAt cgA ";
\r
88 assertFalse(SequenceUtil.isProteinSequence(dirtySeq));
\r
89 // This will still be NON protein sequence despite having only correct
\r
90 // letters because the letters match perfectly the nucleotide sequence!
\r
91 assertFalse(SequenceUtil.isProteinSequence(SequenceUtil
\r
92 .cleanProteinSequence(dirtySeq)));
\r
94 String notaSeq = "atgc1tgatgcatgcatgatgmctga";
\r
95 assertFalse(SequenceUtil.isProteinSequence(notaSeq));
\r
96 assertTrue(SequenceUtil.isProteinSequence(SequenceUtil
\r
97 .cleanProteinSequence(notaSeq)));
\r
99 String AAseq = "ARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQL";
\r
100 assertTrue(SequenceUtil.isProteinSequence(AAseq));
\r
101 assertTrue(SequenceUtil.isProteinSequence(SequenceUtil
\r
102 .cleanProteinSequence(AAseq)));
\r
105 assertFalse(SequenceUtil.isProteinSequence(AAseq));
\r
106 assertTrue(SequenceUtil.isProteinSequence(SequenceUtil
\r
107 .cleanProteinSequence(AAseq)));
\r
111 public void testReadWriteFasta() {
\r
114 FileInputStream fio = new FileInputStream(
\r
115 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta");
\r
116 assertNotNull(fio);
\r
117 List<FastaSequence> fseqs = SequenceUtil.readFasta(fio);
\r
118 assertNotNull(fseqs);
\r
119 assertEquals(3, fseqs.size());
\r
120 assertEquals(3, fseqs.size());
\r
122 FileOutputStream fou = new FileOutputStream(
\r
123 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta.written");
\r
124 SequenceUtil.writeFasta(fou, fseqs);
\r
126 FileOutputStream fou20 = new FileOutputStream(
\r
127 AllTestSuit.TEST_DATA_PATH + "TO1381.fasta20.written");
\r
128 SequenceUtil.writeFasta(fou20, fseqs, 21);
\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
141 * This test tests the loading of horizontally formatted Jronn output file
\r
144 public void loadJronnFile() {
\r
146 FileInputStream fio;
\r
148 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "jronn.out");
\r
149 Map<String, Score> aseqs = SequenceUtil.readJRonn(fio);
\r
150 assertNotNull(aseqs);
\r
151 assertEquals(aseqs.size(), 3);
\r
152 Score aseq = aseqs.get("Foobar");
\r
153 assertNotNull(aseq);
\r
154 assertNotNull(aseq.getScores());
\r
155 // System.out.println(aseq);
\r
156 assertEquals(aseq.getScores().size(), aseq.getScores().size());
\r
158 } catch (FileNotFoundException e) {
\r
159 e.printStackTrace();
\r
160 fail(e.getLocalizedMessage());
\r
161 } catch (IOException e) {
\r
162 e.printStackTrace();
\r
163 fail(e.getLocalizedMessage());
\r
164 } catch (UnknownFileFormatException e) {
\r
165 e.printStackTrace();
\r
166 fail(e.getLocalizedMessage());
\r
176 * This test tests the loading of horizontally formatted Jronn output file
\r
180 * M 0.86010 0.88512 0.37094
\r
182 * T 0.79983 0.85864 0.44331
\r
185 @SuppressWarnings("unchecked")
\r
187 public void testReadDisemblResults() {
\r
189 FileInputStream fio;
\r
191 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
193 Map<String, Set<Score>> aseqs = SequenceUtil.readDisembl(fio);
\r
194 assertNotNull(aseqs);
\r
195 assertEquals(aseqs.size(), 3);
\r
196 // System.out.println(aseqs);
\r
197 for (String fs : aseqs.keySet()) {
\r
198 assertTrue(" Foobar_dundeefriends Foobar dundeefriends "
\r
200 Set<Score> scores = aseqs.get(fs);
\r
201 assertEquals(scores.size(), 3);
\r
204 } catch (FileNotFoundException e) {
\r
205 e.printStackTrace();
\r
206 fail(e.getLocalizedMessage());
\r
207 } catch (IOException e) {
\r
208 e.printStackTrace();
\r
209 fail(e.getLocalizedMessage());
\r
210 } catch (UnknownFileFormatException e) {
\r
211 e.printStackTrace();
\r
212 fail(e.getLocalizedMessage());
\r
217 * This test tests the loading of horizontally formatted Jronn output file
\r
221 * >Foobar_dundeefriends
\r
223 * # GlobDoms 2-358, 373-568
\r
225 * # Disorder 1-5, 206-218, 243-250, 288-300, 313-324, 359-372, 475-481
\r
227 * # RESIDUE DYDX RAW SMOOTHED
\r
229 * M 0.0044 -0.2259 -0.2259
\r
231 * T -0.1308 -0.2170 -0.2170
\r
235 * > Second sequence
\r
237 @SuppressWarnings("unchecked")
\r
239 public void testReadGlobPlotResults() {
\r
241 FileInputStream fio;
\r
243 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
245 HashMap<String, Set<Score>> aseqs = SequenceUtil.readGlobPlot(fio);
\r
246 assertNotNull(aseqs);
\r
247 assertEquals(aseqs.size(), 3);
\r
249 String fsdf = null;
\r
250 Set<Score> scores = null;
\r
251 for (String fs : aseqs.keySet()) {
\r
252 if ("Foobar_dundeefriends".contains(fs)) {
\r
254 scores = aseqs.get(fs);
\r
256 assertEquals(scores.size(), 5);
\r
258 for (Score score : scores) {
\r
260 if (score.getMethod()
\r
261 .equals(GlobProtResult.Disorder.toString())) {
\r
262 assertEquals(score.getRanges().size(), 7);
\r
263 assertTrue(score.getScores().isEmpty());
\r
265 if (GlobProtResult.valueOf(score.getMethod()) == GlobProtResult.Dydx) {
\r
266 assertFalse(score.getScores().isEmpty());
\r
267 assertTrue(score.getRanges().isEmpty());
\r
271 } catch (FileNotFoundException e) {
\r
272 e.printStackTrace();
\r
273 fail(e.getLocalizedMessage());
\r
274 } catch (IOException e) {
\r
275 e.printStackTrace();
\r
276 fail(e.getLocalizedMessage());
\r
277 } catch (UnknownFileFormatException e) {
\r
278 e.printStackTrace();
\r
279 fail(e.getLocalizedMessage());
\r
284 public void testReadAAConResults() {
\r
286 InputStream inStream = new FileInputStream(
\r
287 AllTestSuit.TEST_DATA_PATH + "aacon_results.txt");
\r
288 HashSet<Score> result = SequenceUtil.readAAConResults(inStream);
\r
290 assertNotNull(result);
\r
291 assertEquals(result.size(), 18);
\r
293 inStream = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
294 + "aacon_result_single.out");
\r
295 result = SequenceUtil.readAAConResults(inStream);
\r
297 assertNotNull(result);
\r
298 assertEquals(result.size(), 1);
\r
299 assertEquals(result.iterator().next().getScores().size(), 568);
\r
300 } catch (IOException e) {
\r
301 e.printStackTrace();
\r
302 fail(e.getMessage());
\r