Merge branch 'features/JAL-2681_duplicatecrossrefs' into documentation/JAL-2675_relea...
authorJim Procter <jprocter@issues.jalview.org>
Sun, 3 Sep 2017 10:38:15 +0000 (11:38 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 3 Sep 2017 10:38:15 +0000 (11:38 +0100)
src/jalview/datamodel/xdb/embl/EmblEntry.java
src/jalview/ws/dbsources/EmblXmlSource.java
src/jalview/ws/seqfetcher/ASequenceFetcher.java
test/jalview/io/CrossRef2xmlTests.java

index fe3f6ef..2de100b 100644 (file)
@@ -279,7 +279,7 @@ public class EmblEntry
     String translation = null;
     String proteinName = "";
     String proteinId = null;
-    Map<String, String> vals = new Hashtable<String, String>();
+    Map<String, String> vals = new Hashtable<>();
 
     /*
      * codon_start 1/2/3 in EMBL corresponds to phase 0/1/2 in CDS
index 21b226b..ca90d60 100644 (file)
@@ -91,7 +91,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
           File reply) throws Exception
   {
     EmblFile efile = null;
-    List<SequenceI> seqs = new ArrayList<SequenceI>();
+    List<SequenceI> seqs = new ArrayList<>();
 
     if (reply != null && reply.exists())
     {
@@ -107,7 +107,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
      * EmbFile reads something like (e.g.) this ungrammatical phrase
      * Entry: <acc> display type is either not supported or entry is not found.
      */
-    List<SequenceI> peptides = new ArrayList<SequenceI>();
+    List<SequenceI> peptides = new ArrayList<>();
     if (efile != null && efile.getEntries() != null)
     {
       for (EmblEntry entry : efile.getEntries())
index 977f9da..9284f82 100644 (file)
@@ -126,15 +126,16 @@ public class ASequenceFetcher
    */
   public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
   {
-    Vector<SequenceI> rseqs = new Vector<SequenceI>();
-    Hashtable<String, List<String>> queries = new Hashtable<String, List<String>>();
+    Vector<SequenceI> rseqs = new Vector<>();
+    Hashtable<String, List<String>> queries = new Hashtable<>();
     for (DBRefEntry ref : refs)
     {
-      if (!queries.containsKey(ref.getSource()))
+      String canonical = DBRefUtils.getCanonicalName(ref.getSource());
+      if (!queries.containsKey(canonical))
       {
-        queries.put(ref.getSource(), new ArrayList<String>());
+        queries.put(canonical, new ArrayList<String>());
       }
-      List<String> qset = queries.get(ref.getSource());
+      List<String> qset = queries.get(canonical);
       if (!qset.contains(ref.getAccessionId()))
       {
         qset.add(ref.getAccessionId());
@@ -154,14 +155,14 @@ public class ASequenceFetcher
         continue;
       }
 
-      Stack<String> queriesLeft = new Stack<String>();
+      Stack<String> queriesLeft = new Stack<>();
       queriesLeft.addAll(query);
 
       List<DbSourceProxy> proxies = getSourceProxy(db);
       for (DbSourceProxy fetcher : proxies)
       {
-        List<String> queriesMade = new ArrayList<String>();
-        HashSet<String> queriesFound = new HashSet<String>();
+        List<String> queriesMade = new ArrayList<>();
+        HashSet<String> queriesFound = new HashSet<>();
         try
         {
           if (fetcher.isDnaCoding() != dna)
@@ -306,13 +307,13 @@ public class ASequenceFetcher
     Map<String, DbSourceProxy> dblist = fetchableDbs.get(db);
     if (dblist == null)
     {
-      return new ArrayList<DbSourceProxy>();
+      return new ArrayList<>();
     }
 
     /*
      * sort so that primary sources precede secondary
      */
-    List<DbSourceProxy> dbs = new ArrayList<DbSourceProxy>(dblist.values());
+    List<DbSourceProxy> dbs = new ArrayList<>(dblist.values());
     Collections.sort(dbs, proxyComparator);
     return dbs;
   }
@@ -357,14 +358,14 @@ public class ASequenceFetcher
     {
       if (fetchableDbs == null)
       {
-        fetchableDbs = new Hashtable<String, Map<String, DbSourceProxy>>();
+        fetchableDbs = new Hashtable<>();
       }
       Map<String, DbSourceProxy> slist = fetchableDbs
               .get(proxy.getDbSource());
       if (slist == null)
       {
         fetchableDbs.put(proxy.getDbSource(),
-                slist = new Hashtable<String, DbSourceProxy>());
+                slist = new Hashtable<>());
       }
       slist.put(proxy.getDbName(), proxy);
     }
@@ -391,7 +392,7 @@ public class ASequenceFetcher
       return null;
     }
     String[] sources = null;
-    Vector<String> src = new Vector<String>();
+    Vector<String> src = new Vector<>();
     Enumeration<String> dbs = fetchableDbs.keys();
     while (dbs.hasMoreElements())
     {
@@ -413,7 +414,7 @@ public class ASequenceFetcher
 
   public DbSourceProxy[] getDbSourceProxyInstances(Class class1)
   {
-    List<DbSourceProxy> prlist = new ArrayList<DbSourceProxy>();
+    List<DbSourceProxy> prlist = new ArrayList<>();
     for (String fetchable : getSupportedDb())
     {
       for (DbSourceProxy pr : getSourceProxy(fetchable))
index ec5855f..0715857 100644 (file)
@@ -31,10 +31,12 @@ import jalview.gui.CrossRefAction;
 import jalview.gui.Desktop;
 import jalview.gui.Jalview2XML;
 import jalview.gui.JvOptionPane;
+import jalview.util.DBRefUtils;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 
@@ -65,10 +67,13 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
   public void testRetrieveAndShowCrossref() throws Exception
   {
 
-    List<String> failedDBRetr = new ArrayList<String>();
-    List<String> failedXrefMenuItems = new ArrayList<String>();
-    List<String> failedProjectRecoveries = new ArrayList<String>();
-
+    List<String> failedDBRetr = new ArrayList<>();
+    List<String> failedXrefMenuItems = new ArrayList<>();
+    List<String> failedProjectRecoveries = new ArrayList<>();
+    // only search for ensembl or Uniprot crossrefs
+    List<String> limit=Arrays.asList(new String[] {
+        DBRefUtils.getCanonicalName("ENSEMBL"), 
+        DBRefUtils.getCanonicalName("Uniprot")});
     // for every set of db queries
     // retrieve db query
     // verify presence of expected xrefs
@@ -85,12 +90,11 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
     // . codonframes
     //
     //
-    HashMap<String, String> dbtoviewBit = new HashMap<String, String>();
-    List<String> keyseq = new ArrayList<String>();
-    HashMap<String, File> savedProjects = new HashMap<String, File>();
+    HashMap<String, String> dbtoviewBit = new HashMap<>();
+    List<String> keyseq = new ArrayList<>();
+    HashMap<String, File> savedProjects = new HashMap<>();
 
-    for (String[] did : new String[][] { { "ENSEMBL", "ENSG00000157764" },
-    { "UNIPROT", "P01731" } })
+    for (String[] did : new String[][] { { "UNIPROT", "P00338" } })
     {
       // pass counters - 0 - first pass, 1 means retrieve project rather than
       // perform action
@@ -163,7 +167,8 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
 
         ptypes = (seqs == null || seqs.length == 0) ? null : new CrossRef(
                 seqs, dataset).findXrefSourcesForSequences(dna);
-
+        filterDbRefs(ptypes, limit);
+        
         // start of pass2: retrieve each cross-ref for fetched or restored
         // project.
         do // first cross ref and recover crossref loop
@@ -176,7 +181,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
             // build next key so we an retrieve all views
             String nextxref = first + " -> " + db + "{" + firstcr_ap + "}";
             // perform crossref action, or retrieve stored project
-            List<AlignmentViewPanel> cra_views = new ArrayList<AlignmentViewPanel>();
+            List<AlignmentViewPanel> cra_views = new ArrayList<>();
             CrossRefAction cra = null;
 
             if (pass2 == 0)
@@ -237,7 +242,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
 
               }
             }
-            HashMap<String, List<String>> xrptypes = new HashMap<String, List<String>>();
+            HashMap<String, List<String>> xrptypes = new HashMap<>();
             // first save/verify views.
             for (AlignmentViewPanel avp : cra_views)
             {
@@ -274,7 +279,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
                 nextxref = first + " -> " + db + "{" + firstcr_ap++ + "}";
                 for (String xrefdb : xrptypes.get(nextxref))
                 {
-                  List<AlignmentViewPanel> cra_views2 = new ArrayList<AlignmentViewPanel>();
+                  List<AlignmentViewPanel> cra_views2 = new ArrayList<>();
                   int q = 0;
                   String nextnextxref = nextxref + " -> " + xrefdb + "{"
                           + q + "}";
@@ -437,6 +442,25 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
     }
   }
 
+  private void filterDbRefs(List<String> ptypes, List<String> limit)
+  {
+    if (limit != null)
+    {
+      int p = 0;
+      while (ptypes.size() > p)
+      {
+        if (!limit.contains(ptypes.get(p)))
+        {
+          ptypes.remove(p);
+        }
+        else
+        {
+          p++;
+        }
+      }
+    }
+  }
+
   /**
    * wrapper to trap known defect for AH002001 testcase
    * 
@@ -480,7 +504,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
   private void assertType(boolean expectProtein,
           AlignmentViewPanel alignmentViewPanel, String message)
   {
-    List<SequenceI> nonType = new ArrayList<SequenceI>();
+    List<SequenceI> nonType = new ArrayList<>();
     for (SequenceI sq : alignmentViewPanel.getAlignViewport()
             .getAlignment().getSequences())
     {