JAL-1142 - test to demonstrate mismatch between rnaview and Jalview PDB parsing with...
[jalview.git] / test / jalview / ext / paradise / TestAnnotate3D.java
1 package jalview.ext.paradise;
2
3 import static org.junit.Assert.assertTrue;
4
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;
10
11 import java.io.BufferedReader;
12 import java.io.File;
13
14 import org.junit.Assert;
15 import org.junit.Test;
16
17 import MCview.PDBfile;
18
19 import compbio.util.FileUtil;
20
21 public class TestAnnotate3D
22 {
23
24   @Test
25   public void testIdVsContent() throws Exception
26   {
27     BufferedReader id = (BufferedReader) Annotate3D
28             .getRNAMLForPDBId("2GIS");
29     assertTrue("Didn't retrieve 2GIS by id.", id != null);
30     BufferedReader file = (BufferedReader) Annotate3D
31             .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
32                     "examples/2GIS.pdb")));
33     assertTrue("Didn't retrieve using examples/2GIS.pdb.", file != null);
34     String iline, fline;
35     do
36     {
37       iline = id.readLine();
38       fline = file.readLine();
39       if (iline != null)
40         System.out.println(iline);
41       if (fline != null)
42         System.out.println(fline);
43
44       assertTrue("Results differ for ID and file upload based retrieval",
45               ((iline == fline && iline == null) || (iline != null
46                       && fline != null && iline.equals(fline))));
47
48     } while (iline != null);
49   }
50
51   /**
52    * test to demonstrate JAL-1142 - compare sequences in RNAML returned from
53    * Annotate3d vs those extracted by Jalview from the originl PDB file
54    * 
55    * @throws Exception
56    */
57   @Test
58   public void testPDBfileVsRNAML() throws Exception
59   {
60     PDBfile pdbf = new PDBfile("examples/2GIS.pdb", FormatAdapter.FILE);
61     Assert.assertTrue(pdbf.isValid());
62     StringBuffer sb = new StringBuffer();
63     // Comment - should add new FileParse constructor like new FileParse(Reader
64     // ..). for direct reading
65     BufferedReader br = new BufferedReader(
66             Annotate3D.getRNAMLForPDBFileAsString(FileUtil
67                     .readFileToString(new File("examples/2GIS.pdb"))));
68     String line;
69     while ((line = br.readLine()) != null)
70     {
71       sb.append(line + "\n");
72     }
73     assertTrue("No data returned by Annotate3D", sb.length() > 0);
74     AlignmentI al = new FormatAdapter().readFile(sb.toString(),
75             FormatAdapter.PASTE, "RNAML");
76
77     assertTrue("No alignment returned.", al != null);
78     assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
79     for (SequenceI sq : al.getSequences())
80     {
81       {
82         SequenceI struseq = null;
83         String sq_ = new String(sq.getSequence()).toLowerCase();
84         for (SequenceI _struseq : pdbf.getSeqsAsArray())
85         {
86           if (new String(_struseq.getSequence()).toLowerCase().equals(sq_))
87           {
88             struseq = _struseq;
89             break;
90           }
91         }
92         if (struseq == null)
93         {
94           Assert.fail("Couldn't find this sequence in original input:\n"
95                   + new FastaFile().print(new SequenceI[]
96                   { sq }) + "\n\nOriginal input:\n"
97                   + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");
98         }
99       }
100     }
101   }
102 }