2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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 jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SequenceI;
27 import jalview.ext.paradise.Annotate3D;
28 import jalview.io.FastaFile;
29 import jalview.io.FormatAdapter;
31 import java.io.BufferedReader;
33 import java.io.Reader;
34 import java.util.Iterator;
36 import org.junit.Assert;
37 import org.junit.Test;
39 import MCview.PDBfile;
41 import compbio.util.FileUtil;
43 public class TestAnnotate3D
47 public void test1GIDbyId() throws Exception
49 // use same ID as standard tests given at
50 // https://bitbucket.org/fjossinet/pyrna-rest-clients
51 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("1GID");
52 assertTrue("Didn't retrieve 1GID by id.", ids != null);
53 testRNAMLcontent(ids, null);
57 public void testIdVsContent2GIS() throws Exception
59 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("2GIS");
60 assertTrue("Didn't retrieve 2GIS by id.", ids != null);
61 Iterator<Reader> files = Annotate3D.getRNAMLForPDBFileAsString(FileUtil
62 .readFileToString(new File("examples/2GIS.pdb")));
63 assertTrue("Didn't retrieve using examples/2GIS.pdb.", files != null);
65 while (ids.hasNext() && files.hasNext())
67 BufferedReader file = new BufferedReader(files.next()), id = new BufferedReader(
72 iline = id.readLine();
73 fline = file.readLine();
75 System.out.println(iline);
77 System.out.println(fline);
78 // next assert fails for latest RNAview - because the XMLID entries
79 // change between file and ID based RNAML generation.
81 "Results differ for ID and file upload based retrieval (chain entry "
83 ((iline == fline && iline == null) || (iline != null
84 && fline != null && iline.equals(fline))));
86 } while (iline != null);
91 * test to demonstrate JAL-1142 - compare sequences in RNAML returned from
92 * Annotate3d vs those extracted by Jalview from the originl PDB file
97 public void testPDBfileVsRNAML() throws Exception
99 PDBfile pdbf = new PDBfile("examples/2GIS.pdb", FormatAdapter.FILE);
100 Assert.assertTrue(pdbf.isValid());
101 // Comment - should add new FileParse constructor like new FileParse(Reader
102 // ..). for direct reading
103 Iterator<Reader> readers = Annotate3D
104 .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
105 "examples/2GIS.pdb")));
106 testRNAMLcontent(readers, pdbf);
109 private void testRNAMLcontent(Iterator<Reader> readers, PDBfile pdbf)
112 StringBuffer sb = new StringBuffer();
114 while (readers.hasNext())
116 System.out.println("Testing RNAML input number " + (++r));
117 BufferedReader br = new BufferedReader(readers.next());
119 while ((line = br.readLine()) != null)
121 sb.append(line + "\n");
123 assertTrue("No data returned by Annotate3D", sb.length() > 0);
124 AlignmentI al = new FormatAdapter().readFile(sb.toString(),
125 FormatAdapter.PASTE, "RNAML");
126 if (al == null || al.getHeight() == 0)
128 System.out.println(sb.toString());
130 assertTrue("No alignment returned.", al != null);
131 assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
134 for (SequenceI sq : al.getSequences())
137 SequenceI struseq = null;
138 String sq_ = new String(sq.getSequence()).toLowerCase();
139 for (SequenceI _struseq : pdbf.getSeqsAsArray())
141 if (new String(_struseq.getSequence()).toLowerCase().equals(
150 Assert.fail("Couldn't find this sequence in original input:\n"
151 + new FastaFile().print(new SequenceI[]
153 + "\n\nOriginal input:\n"
154 + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");