JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / structure / Mapping.java
index cc8138c..f1feced 100644 (file)
@@ -1,26 +1,54 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.structure;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import MCview.PDBfile;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
+import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
+import jalview.io.StructureFile;
+
+import org.testng.Assert;
+import org.testng.AssertJUnit;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
 
 public class Mapping
 {
 
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   /*
    * more test data
    * 
@@ -28,11 +56,10 @@ public class Mapping
    * 115 in PDB Res Numbering secondary structure numbers in jmol seem to be in
    * msd numbering, not pdb res numbering.
    */
-  @Test
-  @Ignore
+  @Test(groups = { "Functional" }, enabled = false)
   public void pdbEntryPositionMap() throws Exception
   {
-    fail("This test intentionally left to fail");
+    Assert.fail("This test intentionally left to fail");
     for (int offset = 0; offset < 20; offset += 6)
     {
       // check we put the secondary structure in the right position
@@ -45,16 +72,15 @@ public class Mapping
       // original numbers taken from
       // http://www.ebi.ac.uk/pdbe-srv/view/entry/1qcf/secondary.html
       // these are in numbering relative to the subsequence above
-      int coils[] =
-      { 266, 275, 278, 287, 289, 298, 302, 316 }, helices[] = new int[]
-      { 303, 315 }, sheets[] = new int[]
-      { 267, 268, 269, 270 };
+      int coils[] = { 266, 275, 278, 287, 289, 298, 302, 316 },
+              helices[] = new int[]
+              { 303, 315 }, sheets[] = new int[] { 267, 268, 269, 270 };
 
       StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
-      PDBfile pmap = ssm.setMapping(true, new SequenceI[]
-      { uprot }, new String[]
-      { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
-              jalview.io.FormatAdapter.FILE);
+      StructureFile pmap = ssm.setMapping(true, new SequenceI[] { uprot },
+              new String[]
+              { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
+              DataSourceType.FILE);
       assertTrue(pmap != null);
       SequenceI protseq = pmap.getSeqsAsArray()[0];
       AlignmentAnnotation pstra = protseq
@@ -83,10 +109,10 @@ public class Mapping
         char expected = 'H';
         for (int p : helices)
         {
-          Annotation a = ss.annotations[op = (uprot.findIndex(offset + p) - 1)];
-          assertTrue(
-                  "Expected a helix at position " + p + uprot.getCharAt(op)
-                          + " but got coil", a != null);
+          Annotation a = ss.annotations[op = (uprot.findIndex(offset + p)
+                  - 1)];
+          assertTrue("Expected a helix at position " + p
+                  + uprot.getCharAt(op) + " but got coil", a != null);
           assertEquals("Expected a helix at position " + p,
                   a.secondaryStructure, expected);
         }
@@ -94,8 +120,7 @@ public class Mapping
         for (int p : sheets)
         {
           Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
-          assertTrue(
-                  "Expected a strand at position " + p + " but got coil",
+          assertTrue("Expected a strand at position " + p + " but got coil",
                   a != null);
           assertEquals("Expected a strand at position " + p,
                   a.secondaryStructure, expected);
@@ -111,22 +136,20 @@ public class Mapping
     }
   }
 
-  @Test
-  @Ignore
+  @Test(groups = { "Functional" }, enabled = false)
   public void testPDBentryMapping() throws Exception
   {
-    fail("This test intentionally left to fail");
-    Sequence sq = new Sequence(
-            "1GAQ A subseq 126 to 219",
+    Assert.fail("This test intentionally left to fail");
+    Sequence sq = new Sequence("1GAQ A subseq 126 to 219",
             "EIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPNATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKM");
     Sequence sq1 = new Sequence(sq);
     String inFile;
     StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
     // Associate the 1GAQ pdb file with the subsequence 'imported' from another
     // source
-    PDBfile pde = ssm.setMapping(true, new SequenceI[]
-    { sq }, new String[]
-    { "A" }, inFile = "examples/1gaq.txt", jalview.io.FormatAdapter.FILE);
+    StructureFile pde = ssm.setMapping(true, new SequenceI[] { sq },
+            new String[]
+            { "A" }, inFile = "examples/1gaq.txt", DataSourceType.FILE);
     assertTrue("PDB File couldn't be found", pde != null);
     StructureMapping[] mp = ssm.getMapping(inFile);
     assertTrue("No mappings made.", mp != null && mp.length > 0);
@@ -155,8 +178,8 @@ public class Mapping
       if (origMap.getSequence() == sq)
       {
         assertEquals("Mapping was incomplete.", sq.getLength() - 1,
-                (origMap.getPDBResNum(sq.getEnd()) - origMap
-                        .getPDBResNum(sq.getStart())));
+                (origMap.getPDBResNum(sq.getEnd())
+                        - origMap.getPDBResNum(sq.getStart())));
         // sanity check - if this fails, mapping from first position in sequence
         // we want to transfer to is not where we expect
         assertEquals(1, origMap.getSeqPos(126));
@@ -175,8 +198,8 @@ public class Mapping
           {
             // walk along the pdb chain's jalview sequence
             int rseqpos;
-            int fpos = origMap.getSeqPos(rseqpos = firstChain
-                    .findPosition(p));
+            int fpos = origMap
+                    .getSeqPos(rseqpos = firstChain.findPosition(p));
             // only look at positions where there is a corresponding position in
             // mapping
             if (fpos < 1)
@@ -194,10 +217,12 @@ public class Mapping
               break;
             }
 
-            Annotation a = transfer.annotations[tanpos], b = alan.annotations[p];
-            assertEquals("Non-equivalent annotation element at " + p + "("
-                    + rseqpos + ")" + " expected at " + fpos + " (alIndex "
-                    + tanpos + ")",
+            Annotation a = transfer.annotations[tanpos],
+                    b = alan.annotations[p];
+            assertEquals(
+                    "Non-equivalent annotation element at " + p + "("
+                            + rseqpos + ")" + " expected at " + fpos
+                            + " (alIndex " + tanpos + ")",
                     a == null ? a : a.toString(),
                     b == null ? b : b.toString());
             System.out.print("(" + a + "|" + b + ")");
@@ -213,22 +238,20 @@ public class Mapping
    * transform
    * 
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void mapFer1From3W5V() throws Exception
   {
-    AlignFrame seqf = new FileLoader(false)
-            .LoadFileWaitTillLoaded(
-                    ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
-                    FormatAdapter.PASTE, "FASTA");
+    AlignFrame seqf = new FileLoader(false).LoadFileWaitTillLoaded(
+            ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
+            DataSourceType.PASTE, FileFormat.Fasta);
     SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);
     StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
-    PDBfile pmap = ssm.setMapping(true, new SequenceI[]
-    { newseq }, new String[]
-    { null }, "examples/3W5V.pdb",
-            jalview.io.FormatAdapter.FILE);
+    StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
+            new String[]
+            { null }, "examples/3W5V.pdb", DataSourceType.FILE);
     if (pmap == null)
     {
-      Assert.fail("Couldn't make a mapping for 3W5V to FER1_MAIZE");
+      AssertJUnit.fail("Couldn't make a mapping for 3W5V to FER1_MAIZE");
     }
   }
 
@@ -236,12 +259,14 @@ public class Mapping
    * compare reference annotation for imported pdb sequence to identical
    * seuqence with transferred annotation from mapped pdb file
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void compareTransferredToRefPDBAnnot() throws Exception
   {
-    AlignFrame ref = new FileLoader(false)
-            .LoadFileWaitTillLoaded("test/jalview/ext/jmol/1QCF.pdb",
-                    jalview.io.FormatAdapter.FILE);
+    StructureImportSettings.setProcessSecondaryStructure(true);
+    StructureImportSettings.setVisibleChainAnnotation(true);
+    StructureImportSettings.setShowSeqFeatures(true);
+    AlignFrame ref = new FileLoader(false).LoadFileWaitTillLoaded(
+            "test/jalview/ext/jmol/1QCF.pdb", DataSourceType.FILE);
     SequenceI refseq = ref.getViewport().getAlignment().getSequenceAt(0);
     SequenceI newseq = new Sequence(refseq.getName() + "Copy",
             refseq.getSequenceAsString());
@@ -251,10 +276,10 @@ public class Mapping
     StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
     ssm.setProcessSecondaryStructure(true);
     ssm.setAddTempFacAnnot(true);
-    PDBfile pmap = ssm.setMapping(true, new SequenceI[]
-    { newseq }, new String[]
-    { null }, "test/jalview/ext/jmol/1QCF.pdb",
-            jalview.io.FormatAdapter.FILE);
+    StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
+            new String[]
+            { null }, "test/jalview/ext/jmol/1QCF.pdb",
+            DataSourceType.FILE);
     assertTrue(pmap != null);
     assertEquals("Original and copied sequence of different lengths.",
             refseq.getLength(), newseq.getLength());
@@ -268,9 +293,10 @@ public class Mapping
       {
         for (int p = 0, pSize = refseq.getLength(); p < pSize; p++)
         {
-          Annotation orig = oannot.annotations[p], tran = tannot.annotations[p];
-          assertTrue("Mismatch: coil and non coil site " + p, orig == tran
-                  || orig != null && tran != null);
+          Annotation orig = oannot.annotations[p],
+                  tran = tannot.annotations[p];
+          assertTrue("Mismatch: coil and non coil site " + p,
+                  orig == tran || orig != null && tran != null);
           if (tran != null)
           {
             assertEquals("Mismatch in secondary structure at site " + p,