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.junit.Assert.assertTrue;
25 import java.io.BufferedReader;
27 import java.io.Reader;
28 import java.util.Iterator;
30 import org.junit.Assert;
31 import org.junit.Test;
33 import MCview.PDBfile;
34 import compbio.util.FileUtil;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.SequenceI;
38 import jalview.io.FastaFile;
39 import jalview.io.FormatAdapter;
41 public class TestAnnotate3D
45 public void test1GIDbyId() throws Exception
47 // use same ID as standard tests given at
48 // https://bitbucket.org/fjossinet/pyrna-rest-clients
49 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("1GID");
50 assertTrue("Didn't retrieve 1GID by id.", ids != null);
51 testRNAMLcontent(ids, null);
55 public void testIdVsContent2GIS() throws Exception
57 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("2GIS");
58 assertTrue("Didn't retrieve 2GIS by id.", ids != null);
59 Iterator<Reader> files = Annotate3D.getRNAMLForPDBFileAsString(FileUtil
60 .readFileToString(new File("examples/2GIS.pdb")));
61 assertTrue("Didn't retrieve using examples/2GIS.pdb.", files != null);
63 while (ids.hasNext() && files.hasNext())
65 BufferedReader file = new BufferedReader(files.next()), id = new BufferedReader(
70 iline = id.readLine();
71 fline = file.readLine();
74 System.out.println(iline);
78 System.out.println(fline);
80 // next assert fails for latest RNAview - because the XMLID entries
81 // change between file and ID based RNAML generation.
83 "Results differ for ID and file upload based retrieval (chain entry "
85 ((iline == fline && iline == null) || (iline != null
86 && fline != null && iline.equals(fline))));
88 } while (iline != null);
93 * test to demonstrate JAL-1142 - compare sequences in RNAML returned from
94 * Annotate3d vs those extracted by Jalview from the originl PDB file
99 public void testPDBfileVsRNAML() throws Exception
101 PDBfile pdbf = new PDBfile(true, false, true, "examples/2GIS.pdb",
103 Assert.assertTrue(pdbf.isValid());
104 // Comment - should add new FileParse constructor like new FileParse(Reader
105 // ..). for direct reading
106 Iterator<Reader> readers = Annotate3D
107 .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
108 "examples/2GIS.pdb")));
109 testRNAMLcontent(readers, pdbf);
112 private void testRNAMLcontent(Iterator<Reader> readers, PDBfile pdbf)
115 StringBuffer sb = new StringBuffer();
117 while (readers.hasNext())
119 System.out.println("Testing RNAML input number " + (++r));
120 BufferedReader br = new BufferedReader(readers.next());
122 while ((line = br.readLine()) != null)
124 sb.append(line + "\n");
126 assertTrue("No data returned by Annotate3D", sb.length() > 0);
127 final String lines = sb.toString();
128 AlignmentI al = new FormatAdapter().readFile(lines,
129 FormatAdapter.PASTE, "RNAML");
130 if (al == null || al.getHeight() == 0)
132 System.out.println(lines);
134 assertTrue("No alignment returned.", al != null);
135 assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
138 for (SequenceI sq : al.getSequences())
141 SequenceI struseq = null;
142 String sq_ = new String(sq.getSequence()).toLowerCase();
143 for (SequenceI _struseq : pdbf.getSeqsAsArray())
145 final String lowerCase = new String(_struseq.getSequence()).toLowerCase();
146 if (lowerCase.equals(
155 Assert.fail("Couldn't find this sequence in original input:\n"
156 + new FastaFile().print(new SequenceI[]
158 + "\n\nOriginal input:\n"
159 + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");