1 package jalview.ext.paradise;
3 import static org.junit.Assert.assertTrue;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.SequenceI;
7 import jalview.ext.paradise.Annotate3D;
8 import jalview.io.FastaFile;
9 import jalview.io.FormatAdapter;
11 import java.io.BufferedReader;
13 import java.io.Reader;
14 import java.util.Iterator;
16 import org.junit.Assert;
17 import org.junit.Test;
19 import MCview.PDBfile;
21 import compbio.util.FileUtil;
23 public class TestAnnotate3D
27 public void test1GIDbyId() throws Exception
29 // use same ID as standard tests given at https://bitbucket.org/fjossinet/pyrna-rest-clients
30 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("1GID");
31 assertTrue("Didn't retrieve 1GID by id.", ids != null);
32 testRNAMLcontent(ids,null);
36 public void testIdVsContent2GIS() throws Exception
38 Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("2GIS");
39 assertTrue("Didn't retrieve 2GIS by id.", ids != null);
40 Iterator<Reader> files = Annotate3D.getRNAMLForPDBFileAsString(FileUtil
41 .readFileToString(new File("examples/2GIS.pdb")));
42 assertTrue("Didn't retrieve using examples/2GIS.pdb.", files != null);
44 while (ids.hasNext() && files.hasNext())
46 BufferedReader file = new BufferedReader(files.next()), id = new BufferedReader(
51 iline = id.readLine();
52 fline = file.readLine();
54 System.out.println(iline);
56 System.out.println(fline);
57 // next assert fails for latest RNAview - because the XMLID entries
58 // change between file and ID based RNAML generation.
60 "Results differ for ID and file upload based retrieval (chain entry "
62 ((iline == fline && iline == null) || (iline != null
63 && fline != null && iline.equals(fline))));
65 } while (iline != null);
70 * test to demonstrate JAL-1142 - compare sequences in RNAML returned from
71 * Annotate3d vs those extracted by Jalview from the originl PDB file
76 public void testPDBfileVsRNAML() throws Exception
78 PDBfile pdbf = new PDBfile("examples/2GIS.pdb", FormatAdapter.FILE);
79 Assert.assertTrue(pdbf.isValid());
80 // Comment - should add new FileParse constructor like new FileParse(Reader
81 // ..). for direct reading
82 Iterator<Reader> readers = Annotate3D
83 .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
84 "examples/2GIS.pdb")));
85 testRNAMLcontent(readers, pdbf);
88 private void testRNAMLcontent(Iterator<Reader> readers, PDBfile pdbf)
91 StringBuffer sb = new StringBuffer();
93 while (readers.hasNext())
95 System.out.println("Testing RNAML input number " + (++r));
96 BufferedReader br = new BufferedReader(readers.next());
98 while ((line = br.readLine()) != null)
100 sb.append(line + "\n");
102 assertTrue("No data returned by Annotate3D", sb.length() > 0);
103 AlignmentI al = new FormatAdapter().readFile(sb.toString(),
104 FormatAdapter.PASTE, "RNAML");
105 if (al==null || al.getHeight()==0) {
106 System.out.println(sb.toString());
108 assertTrue("No alignment returned.", al != null);
109 assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
112 for (SequenceI sq : al.getSequences())
115 SequenceI struseq = null;
116 String sq_ = new String(sq.getSequence()).toLowerCase();
117 for (SequenceI _struseq : pdbf.getSeqsAsArray())
119 if (new String(_struseq.getSequence()).toLowerCase().equals(
128 Assert.fail("Couldn't find this sequence in original input:\n"
129 + new FastaFile().print(new SequenceI[]
131 + "\n\nOriginal input:\n"
132 + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");