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