2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.paradise;
23 import static org.testng.AssertJUnit.assertTrue;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SequenceI;
27 import jalview.gui.JvOptionPane;
28 import jalview.io.DataSourceType;
29 import jalview.io.FastaFile;
30 import jalview.io.FileFormat;
31 import jalview.io.FormatAdapter;
33 import java.io.BufferedReader;
35 import java.io.Reader;
36 import java.util.Iterator;
38 import org.testng.Assert;
39 import org.testng.AssertJUnit;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.Test;
43 import MCview.PDBfile;
45 import compbio.util.FileUtil;
47 public class TestAnnotate3D
50 @BeforeClass(alwaysRun = true)
51 public void setUpJvOptionPane()
53 JvOptionPane.setInteractiveMode(false);
54 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
57 @Test(groups = { "Network" }, enabled = true)
58 public void test1GIDbyId() throws Exception
60 // use same ID as standard tests given at
61 // https://bitbucket.org/fjossinet/pyrna-rest-clients
62 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("1GID");
63 assertTrue("Didn't retrieve 1GID by id.", ids != null);
64 testRNAMLcontent(ids, null);
67 @Test(groups = { "Network" }, enabled = true)
68 public void testIdVsContent2GIS() throws Exception
70 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("2GIS");
71 assertTrue("Didn't retrieve 2GIS by id.", ids != null);
72 Iterator<Reader> files = Annotate3D.getRNAMLForPDBFileAsString(FileUtil
73 .readFileToString(new File("examples/2GIS.pdb")));
74 assertTrue("Didn't retrieve using examples/2GIS.pdb.", files != null);
76 while (ids.hasNext() && files.hasNext())
78 BufferedReader file = new BufferedReader(files.next()), id = new BufferedReader(
83 iline = id.readLine();
84 fline = file.readLine();
87 System.out.println(iline);
91 System.out.println(fline);
93 // next assert fails for latest RNAview - because the XMLID entries
94 // change between file and ID based RNAML generation.
96 "Results differ for ID and file upload based retrieval (chain entry "
98 ((iline == fline && iline == null) || (iline != null
99 && fline != null && iline.equals(fline))));
101 } while (iline != null);
106 * test to demonstrate JAL-1142 - compare sequences in RNAML returned from
107 * Annotate3d vs those extracted by Jalview from the originl PDB file
111 @Test(groups = { "Network" }, enabled = true)
112 public void testPDBfileVsRNAML() throws Exception
114 PDBfile pdbf = new PDBfile(true, false, true, "examples/2GIS.pdb",
115 DataSourceType.FILE);
116 Assert.assertTrue(pdbf.isValid());
117 // Comment - should add new FileParse constructor like new FileParse(Reader
118 // ..). for direct reading
119 Iterator<Reader> readers = Annotate3D
120 .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
121 "examples/2GIS.pdb")));
122 testRNAMLcontent(readers, pdbf);
125 private void testRNAMLcontent(Iterator<Reader> readers, PDBfile pdbf)
128 StringBuffer sb = new StringBuffer();
130 while (readers.hasNext())
132 System.out.println("Testing RNAML input number " + (++r));
133 BufferedReader br = new BufferedReader(readers.next());
135 while ((line = br.readLine()) != null)
137 sb.append(line + "\n");
139 assertTrue("No data returned by Annotate3D", sb.length() > 0);
140 final String lines = sb.toString();
141 AlignmentI al = new FormatAdapter().readFile(lines,
142 DataSourceType.PASTE, FileFormat.Rnaml);
143 if (al == null || al.getHeight() == 0)
145 System.out.println(lines);
147 assertTrue("No alignment returned.", al != null);
148 assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
151 for (SequenceI sq : al.getSequences())
154 SequenceI struseq = null;
155 String sq_ = new String(sq.getSequence()).toLowerCase();
156 for (SequenceI _struseq : pdbf.getSeqsAsArray())
158 final String lowerCase = new String(_struseq.getSequence())
160 if (lowerCase.equals(sq_))
169 .fail("Couldn't find this sequence in original input:\n"
170 + new FastaFile().print(
171 new SequenceI[] { sq }, true)
172 + "\n\nOriginal input:\n"
173 + new FastaFile().print(
174 pdbf.getSeqsAsArray(), true) + "\n");