1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.data.sequence;
\r
21 import static org.testng.AssertJUnit.assertEquals;
\r
22 import static org.testng.AssertJUnit.assertNotNull;
\r
23 import static org.testng.AssertJUnit.assertTrue;
\r
24 import static org.testng.AssertJUnit.fail;
\r
26 import java.io.FileInputStream;
\r
27 import java.io.FileNotFoundException;
\r
28 import java.io.FileWriter;
\r
29 import java.io.IOException;
\r
30 import java.io.Writer;
\r
32 import org.testng.annotations.Test;
\r
34 import compbio.metadata.AllTestSuit;
\r
36 public class ClustalAlignmentUtilTester {
\r
39 public void testReadClustalFile() {
\r
41 readWriteClustal("TO1381.aln");
\r
42 } catch (FileNotFoundException e) {
\r
43 e.printStackTrace();
\r
44 fail(e.getMessage());
\r
45 } catch (Exception e) {
\r
46 e.printStackTrace();
\r
47 fail(e.getMessage());
\r
51 static void readWriteClustal(String fname) throws IOException,
\r
52 UnknownFileFormatException {
\r
53 FileInputStream fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH
\r
55 Alignment seqAl = ClustalAlignmentUtil.readClustalFile(fio);
\r
56 assertTrue(seqAl != null);
\r
57 assertTrue(seqAl.getSize() == 3);
\r
58 assertNotNull(seqAl.getSequences());
\r
59 assertEquals(3, seqAl.getSequences().size());
\r
61 // Now try to write the alignment read
\r
62 Writer os = new FileWriter(AllTestSuit.TEST_DATA_PATH + fname
\r
64 ClustalAlignmentUtil.writeClustalAlignment(os, seqAl);
\r
68 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + fname
\r
70 Alignment readseqs = ClustalAlignmentUtil.readClustalFile(fio);
\r
71 assertTrue(readseqs != null);
\r
72 assertTrue(readseqs.getSize() == 3);
\r
77 public void testReadClustalFileShortNames() {
\r
79 readWriteClustal("TO1381s.aln");
\r
80 } catch (FileNotFoundException e) {
\r
81 e.printStackTrace();
\r
82 fail(e.getMessage());
\r
83 } catch (Exception e) {
\r
84 e.printStackTrace();
\r
85 fail(e.getMessage());
\r
90 public void testReadClustalFileLongNames() {
\r
92 readWriteClustal("TO1381L.aln");
\r
93 } catch (FileNotFoundException e) {
\r
94 e.printStackTrace();
\r
95 fail(e.getMessage());
\r
96 } catch (Exception e) {
\r
97 e.printStackTrace();
\r
98 fail(e.getMessage());
\r