JAL-2269 JAL-2195 review and revised test
[jalview.git] / test / jalview / ext / jmol / JmolParserTest.java
index a68f7c8..b2d3253 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.ext.jmol;
 
 import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.bin.Cache;
@@ -30,6 +31,8 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.FileLoader;
+import jalview.structure.StructureImportSettings;
+import jalview.structure.StructureImportSettings.StructureParser;
 
 import java.util.Vector;
 
@@ -50,11 +53,12 @@ public class JmolParserTest
    * 1QCF is the full PDB file including headers, HETATM etc
    */
   String[] testFile = new String[] { "./examples/1GAQ.txt",
-      "./test/jalview/ext/jmol/1xyz.pdb" };
+      "./test/jalview/ext/jmol/1xyz.pdb",
+      "./test/jalview/ext/jmol/1qcf.pdb" };
 
   //@formatter:off
   // a modified and very cut-down extract of 4UJ4
-  String pdbWithChainBreak =
+  String pastePDBDataWithChainBreak =
      "HEADER    TRANSPORT PROTEIN                       08-APR-15   4UJ4\n" +
      // chain B has missing residues; these should all go in the same sequence:
      "ATOM   1909  CA  VAL B 358      21.329 -19.739 -67.740  1.00201.05           C\n" +
@@ -83,10 +87,16 @@ public class JmolParserTest
   @BeforeMethod(alwaysRun = true)
   public void setUp()
   {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
     Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
             Boolean.TRUE.toString());
+    Cache.applicationProperties.setProperty("ADD_TEMPFACT_ANN",
+            Boolean.FALSE.toString());
     Cache.applicationProperties.setProperty("ADD_SS_ANN",
             Boolean.TRUE.toString());
+    StructureImportSettings.setDefaultStructureFileFormat("PDB");
+    StructureImportSettings
+            .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
   }
 
   @Test(groups = { "Functional" })
@@ -108,8 +118,7 @@ public class JmolParserTest
     {
       PDBfile mctest = new PDBfile(false, false, false, pdbStr,
               AppletFormatAdapter.FILE);
-      JmolParser jtest = new JmolParser(false, false, false, pdbStr,
-              jalview.io.AppletFormatAdapter.FILE);
+      JmolParser jtest = new JmolParser(pdbStr, AppletFormatAdapter.FILE);
       Vector<SequenceI> seqs = jtest.getSeqs(), mcseqs = mctest.getSeqs();
 
       assertTrue(
@@ -127,6 +136,7 @@ public class JmolParserTest
         validateSecStrRows(al);
       }
     }
+
   }
 
   private void validateSecStrRows(AlignmentI al)
@@ -156,7 +166,8 @@ public class JmolParserTest
 
   private void checkFirstAAIsAssoc(SequenceI sq)
   {
-    assertTrue("No secondary structure assigned for protein sequence.",
+    assertTrue("No secondary structure assigned for protein sequence for "
+            + sq.getName(),
             sq.getAnnotation() != null && sq.getAnnotation().length >= 1
                     && sq.getAnnotation()[0].hasIcons);
     assertTrue(
@@ -172,15 +183,10 @@ public class JmolParserTest
   @Test(groups = { "Functional" })
   public void testParse_missingResidues() throws Exception
   {
-    PDBfile mctest = new PDBfile(false, false, false, pdbWithChainBreak,
+    PDBfile mctest = new PDBfile(false, false, false,
+            pastePDBDataWithChainBreak, AppletFormatAdapter.PASTE);
+    JmolParser jtest = new JmolParser(pastePDBDataWithChainBreak,
             AppletFormatAdapter.PASTE);
-    boolean annotFromStructure = false;
-    boolean localSecondaryStruct = false;
-    boolean serviceSecondaryStruct = false;
-    JmolParser jtest = new JmolParser(annotFromStructure,
-            localSecondaryStruct, serviceSecondaryStruct,
-            pdbWithChainBreak,
-            jalview.io.AppletFormatAdapter.PASTE);
     Vector<SequenceI> seqs = jtest.getSeqs();
     Vector<SequenceI> mcseqs = mctest.getSeqs();
 
@@ -202,15 +208,11 @@ public class JmolParserTest
   {
     PDBfile mctest = new PDBfile(false, false, false, pdbWithAltLoc,
             AppletFormatAdapter.PASTE);
-    boolean annotFromStructure = false;
-    boolean localSecondaryStruct = false;
-    boolean serviceSecondaryStruct = false;
-    JmolParser jtest = new JmolParser(annotFromStructure,
-            localSecondaryStruct, serviceSecondaryStruct, pdbWithAltLoc,
-            jalview.io.AppletFormatAdapter.PASTE);
+    JmolParser jtest = new JmolParser(pdbWithAltLoc,
+            AppletFormatAdapter.PASTE);
     Vector<SequenceI> seqs = jtest.getSeqs();
     Vector<SequenceI> mcseqs = mctest.getSeqs();
-  
+
     assertEquals("Failed to find 1 sequence\n", 1, seqs.size());
     assertEquals("Failed to find 1 sequence\n", 1, mcseqs.size());
     assertEquals("ALC", seqs.get(0).getSequenceAsString());
@@ -247,4 +249,30 @@ public class JmolParserTest
     assertEquals('H', structCode[4]);
     assertEquals('E', structCode[5]);
   }
+
+  @Test(groups = "Functional")
+  public void testLocalPDBId() throws Exception
+  {
+    JmolParser structureData;
+    /*
+     * reads a local structure
+     */
+    structureData = new JmolParser("examples/testdata/localstruct.pdb",
+            AppletFormatAdapter.FILE);
+    assertNotNull(structureData);
+    /*
+     * local structure files should yield a false ID based on the filename
+     */
+    assertNotNull(structureData.getId());
+    assertEquals(structureData.getId(), "localstruct.pdb");
+    assertNotNull(structureData.getSeqs());
+    /*
+     * the ID is also the group for features derived from structure data 
+     */
+    assertNotNull(structureData.getSeqs().get(0).getSequenceFeatures()[0].featureGroup);
+    assertEquals(
+            structureData.getSeqs().get(0).getSequenceFeatures()[0].featureGroup,
+            "localstruct.pdb");
+
+  }
 }