JAL-2154 major rejigging of test looping again
authorJim Procter <jprocter@issues.jalview.org>
Fri, 19 Aug 2016 15:26:07 +0000 (16:26 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 19 Aug 2016 15:33:36 +0000 (16:33 +0100)
probably not 100% correct, but now fails when:

Recovered view for 'UNIPROT P01731 -> EMBL{1} -> ENSEMBL{0}' from '/var/folders/km/m8_86nbd4bbcpd5s2h8xqtk4_kj190/T/crossRefTest9144214145355720129.jvp'

Cause is:
Parsing as Jalview Version 2 file failed.
java.lang.ArrayIndexOutOfBoundsException: 73
at jalview.gui.Jalview2XML.loadFromObject(Jalview2XML.java:2827)
at jalview.gui.Jalview2XML.loadJalviewAlign(Jalview2XML.java:2390)
at jalview.gui.Jalview2XML.loadJalviewAlign(Jalview2XML.java:2277)
at jalview.io.FileLoader.run(FileLoader.java:308)
at java.lang.Thread.run(Thread.java:745)

test/jalview/io/CrossRef2xmlTests.java

index cc26d7e..64c800b 100644 (file)
@@ -87,6 +87,11 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
       {
         String first = did[0] + " " + did[1];
         AlignFrame af = null;
+        boolean dna;
+        AlignmentI retral;
+        AlignmentI dataset;
+        SequenceI[] seqs;
+        List<String> ptypes = null;
         if (pass1 == 0)
         {
           // retrieve dbref
@@ -101,9 +106,11 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
           AlignmentTest.assertAlignmentDatasetRefs(af.getViewport()
                   .getAlignment(), "Pass (" + pass1 + "," + pass2 + ","
                   + pass3 + "): Fetch " + first + ":");
+          dna = af.getViewport().getAlignment().isNucleotide();
+          retral = af.getViewport().getAlignment();
+          dataset = retral.getDataset();
+          seqs = retral.getSequencesArray();
 
-          // store project to recover on next pass
-          stringify(dbtoviewBit, savedProjects, first, af.alignPanel);
         }
         else
         {
@@ -111,6 +118,12 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
           // recover stored project
           af = new FileLoader(false).LoadFileWaitTillLoaded(savedProjects
                   .get(first).toString(), FormatAdapter.FILE);
+          System.out.println("Recovered view for '" + first + "' from '"
+                  + savedProjects.get(first).toString() + "'");
+          dna = af.getViewport().getAlignment().isNucleotide();
+          retral = af.getViewport().getAlignment();
+          dataset = retral.getDataset();
+          seqs = retral.getSequencesArray();
 
           // verify references for recovered data
           AlignmentTest.assertAlignmentDatasetRefs(af.getViewport()
@@ -119,23 +132,24 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
 
         }
 
-        boolean dna = af.getViewport().getAlignment().isNucleotide();
-        AlignmentI retral = af.getViewport().getAlignment();
-        AlignmentI dataset = retral.getDataset();
-        SequenceI[] seqs = retral.getSequencesArray();
-        List<String> ptypes = (seqs == null || seqs.length == 0) ? null
-                : new CrossRef(seqs, dataset)
-                        .findXrefSourcesForSequences(dna);
+        // store project on first pass, compare next pass
+        stringify(dbtoviewBit, savedProjects, first, af.alignPanel);
 
+        ptypes = (seqs == null || seqs.length == 0) ? null : new CrossRef(
+                seqs, dataset).findXrefSourcesForSequences(dna);
+
+        // start of pass2: retrieve each cross-ref for fetched or restored
+        // project.
         pass2 = 0;
         do // second cross ref and recover crossref loop
         {
-        for (String db : ptypes)
-        {
+
+          for (String db : ptypes)
+          {
             // counter for splitframe views retrieved via crossref
-            int p = 0;
+            int firstcr_ap = 0;
             // build next key so we an retrieve all views
-            String nextxref = first + " -> " + db + "{" + p + "}";
+            String nextxref = first + " -> " + db + "{" + firstcr_ap + "}";
             // perform crossref action, or retrieve stored project
             List<AlignmentViewPanel> cra_views = new ArrayList<AlignmentViewPanel>();
             CrossRefAction cra = null;
@@ -154,6 +168,9 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
               AlignFrame af2 = new FileLoader(false)
                       .LoadFileWaitTillLoaded(savedProjects.get(nextxref)
                               .toString(), FormatAdapter.FILE);
+              System.out.println("Recovered view for '" + nextxref
+                      + "' from '" + savedProjects.get(nextxref).toString()
+                      + "'");
               // gymnastics to recover the alignPanel/Complementary alignPanel
               if (af2.getViewport().isNucleotide())
               {
@@ -174,47 +191,61 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
 
               }
             }
+            HashMap<String, List<String>> xrptypes = new HashMap<String, List<String>>();
+            // first save/verify views.
             for (AlignmentViewPanel avp : cra_views)
             {
-              nextxref = first + " -> " + db + "{" + p++ + "}";
-
+              nextxref = first + " -> " + db + "{" + firstcr_ap++ + "}";
               // verify references for this panel
               AlignmentTest.assertAlignmentDatasetRefs(avp.getAlignment(),
-                      "" + "Pass (" + pass1 + "," + pass2 + "): For "
-                              + nextxref + ":");
+                      "Pass (" + pass1 + "," + pass2 + "," + pass3
+                              + "): before start of pass3: " + nextxref
+                              + ":");
 
               SequenceI[] xrseqs = avp.getAlignment().getSequencesArray();
 
-              stringify(dbtoviewBit, savedProjects, nextxref, avp);
-              keyseq.add(nextxref);
-
-              List<String> xrptypes = (seqs == null || seqs.length == 0) ? null
+              List<String> _xrptypes = (seqs == null || seqs.length == 0) ? null
                       : new CrossRef(xrseqs, dataset)
                               .findXrefSourcesForSequences(avp
                                       .getAlignViewport().isNucleotide());
-              pass3 = 0;
-              do // 3rd cross ref and recover crossref loop
+              
+              stringify(dbtoviewBit, savedProjects, nextxref, avp);
+              xrptypes.put(nextxref, _xrptypes);
+
+            }
+            // now do the next xref pass starting from either saved or just
+            // recovered split pane, in sequence
+            pass3 = 0;
+            do // 3rd cross ref and recover crossref loop, for each view from
+               // second xref view set or recover viewset
+            {
+              firstcr_ap = 0;
+              for (AlignmentViewPanel avp : cra_views)
               {
-                for (String xrefdb : xrptypes)
+                nextxref = first + " -> " + db + "{" + firstcr_ap++ + "}";
+                for (String xrefdb : xrptypes.get(nextxref))
                 {
                   List<AlignmentViewPanel> cra_views2 = new ArrayList<AlignmentViewPanel>();
                   int q = 0;
-                  String nextnextxref = "{" + p + "}" + nextxref + " -> "
-                          + xrefdb + "{" + q + "}";
+                  String nextnextxref = nextxref
+                          + " -> " + xrefdb + "{" + q + "}";
 
                   if (pass3 == 0)
                   {
 
+                    SequenceI[] xrseqs = avp.getAlignment()
+                            .getSequencesArray();
                     AlignFrame nextaf = Desktop.getAlignFrameFor(avp
                             .getAlignViewport());
 
                     cra = new CrossRefAction(nextaf, xrseqs, avp
                             .getAlignViewport().isNucleotide(), xrefdb);
                     cra.run();
-                    Assert.assertTrue(cra.getXrefViews().size() > 0,
-                            "No crossrefs found for '" + nextxref + "' to "
-                                    + xrefdb + " via '" + nextaf.getTitle()
-                                    + "'");
+                    Assert.assertTrue(
+                            cra.getXrefViews().size() > 0,
+                            "No crossrefs found for '" + nextnextxref
+                                    + "' to " + xrefdb + " via '"
+                                    + nextaf.getTitle() + "'");
                     cra_views2 = cra.getXrefViews();
                   }
                   else
@@ -225,6 +256,10 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
                             .LoadFileWaitTillLoaded(
                                     savedProjects.get(nextnextxref)
                                             .toString(), FormatAdapter.FILE);
+                    System.out.println("Recovered view for '"
+                            + nextnextxref + "' from '"
+                            + savedProjects.get(nextnextxref).toString()
+                            + "'");
                     // gymnastics to recover the alignPanel/Complementary
                     // alignPanel
                     if (af2.getViewport().isNucleotide())
@@ -251,8 +286,8 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
 
                   for (AlignmentViewPanel nextavp : cra_views2)
                   {
-                    nextnextxref = "{" + p + "}" + nextxref + " -> "
-                            + xrefdb + "{" + q++ + "}";
+                    nextnextxref = nextxref
+                            + " -> " + xrefdb + "{" + q++ + "}";
 
                     // verify references for this panel
                     AlignmentTest.assertAlignmentDatasetRefs(
@@ -265,12 +300,14 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
                     keyseq.add(nextnextxref);
                   }
                 } // end of loop around showing all xrefdb for crossrf2
-                // fetchdb->crossref1->crossref-2->verify for xrefs we
-                // either loop twice when pass2=0, or just once when pass2=1
-                // (recovered project from previous crossref)
-              } while (pass3++ < 2 && pass2 < 1);
-            }
-        }
+
+              } // end of loop around all viewpanels from crossrf1
+            } while (pass3++ < 2 && pass2 < 1);
+            // fetchdb->crossref1->crossref-2->verify for xrefs we
+            // either loop twice when pass2=0, or just once when pass2=1
+            // (recovered project from previous crossref)
+
+          }
           // fetchdb-->crossref1
           // for each xref we try to retrieve xref, store and verify when
           // pass1=0, or just retrieve and verify when pass1=1
@@ -278,7 +315,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
         // fetchdb
         // for each ref we
         // loop twice: first, do the retrieve, second recover from saved project
-      } while (++pass1 < 2);
+      } while (pass1++ < 2);
     }
   }