JAL-2773 add new flag to paintAlignment(updateOverview,updateStructures) and first...
[jalview.git] / src / jalview / ws / DasSequenceFeatureFetcher.java
index c1db0b1..c661e2c 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
- * Copyright (C) 2015 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -22,11 +22,14 @@ package jalview.ws;
 
 import jalview.bin.Cache;
 import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.FeatureSettings;
+import jalview.gui.JvOptionPane;
+import jalview.util.DBRefUtils;
 import jalview.util.MessageManager;
 import jalview.util.UrlLink;
 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
@@ -44,8 +47,6 @@ import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
-import javax.swing.JOptionPane;
-
 import org.biodas.jdas.client.FeaturesClient;
 import org.biodas.jdas.client.adapters.features.DasGFFAdapter;
 import org.biodas.jdas.client.adapters.features.DasGFFAdapter.GFFAdapter;
@@ -134,7 +135,7 @@ public class DasSequenceFeatureFetcher
           boolean useJDasMultiThread)
   {
     this.useJDASMultiThread = useJDasMultiThread;
-    this.selectedSources = new ArrayList<jalviewSourceI>();
+    this.selectedSources = new ArrayList<>();
     // filter both sequences and sources to eliminate duplicates
     for (jalviewSourceI src : selectedSources2)
     {
@@ -181,13 +182,12 @@ public class DasSequenceFeatureFetcher
     int refCount = 0;
     for (int i = 0; i < sequences.length; i++)
     {
-      DBRefEntry[] dbref = sequences[i].getDBRef();
+      DBRefEntry[] dbref = sequences[i].getDBRefs();
       if (dbref != null)
       {
         for (int j = 0; j < dbref.length; j++)
         {
-          if (dbref[j].getSource().equals(
-                  jalview.datamodel.DBRefSource.UNIPROT))
+          if (dbref[j].getSource().equals(DBRefSource.UNIPROT))
           {
             refCount++;
             break;
@@ -199,21 +199,18 @@ public class DasSequenceFeatureFetcher
     if (checkDbrefs && refCount < sequences.length && uniprotCount > 0)
     {
 
-      int reply = JOptionPane.YES_OPTION;
+      int reply = JvOptionPane.YES_OPTION;
       if (promptFetchDbrefs)
       {
-        reply = JOptionPane
-                .showInternalConfirmDialog(
-                        Desktop.desktop,
-                        MessageManager
-                                .getString("info.you_want_jalview_to_find_uniprot_accessions"),
-                        MessageManager
-                                .getString("label.find_uniprot_accession_ids"),
-                        JOptionPane.YES_NO_OPTION,
-                        JOptionPane.QUESTION_MESSAGE);
+        reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
+                MessageManager.getString(
+                        "info.you_want_jalview_to_find_uniprot_accessions"),
+                MessageManager
+                        .getString("label.find_uniprot_accession_ids"),
+                JvOptionPane.YES_NO_OPTION, JvOptionPane.QUESTION_MESSAGE);
       }
 
-      if (reply == JOptionPane.YES_OPTION)
+      if (reply == JvOptionPane.YES_OPTION)
       {
         Thread thread = new Thread(new FetchDBRefs());
         thread.start();
@@ -238,6 +235,7 @@ public class DasSequenceFeatureFetcher
 
   class FetchSeqFeatures implements Runnable
   {
+    @Override
     public void run()
     {
       startFetching();
@@ -247,10 +245,14 @@ public class DasSequenceFeatureFetcher
 
   class FetchDBRefs implements Runnable
   {
+    @Override
     public void run()
     {
       running = true;
-      new DBRefFetcher(sequences, af).fetchDBRefs(true);
+      boolean isNucleotide = af.getViewport().getAlignment().isNucleotide();
+      new DBRefFetcher(sequences, af, null, af.featureSettings,
+              isNucleotide).fetchDBRefs(true);
+
       startFetching();
       setGuiFetchComplete();
     }
@@ -266,9 +268,8 @@ public class DasSequenceFeatureFetcher
     startTime = System.currentTimeMillis();
     if (af != null)
     {
-      af.setProgressBar(MessageManager
-              .getString("status.fetching_das_sequence_features"),
-              startTime);
+      af.setProgressBar(MessageManager.getString(
+              "status.fetching_das_sequence_features"), startTime);
     }
     if (sourceRegistry == null)
     {
@@ -278,10 +279,9 @@ public class DasSequenceFeatureFetcher
     {
       try
       {
-        jalviewSourceI[] sources = sourceRegistry.getSources().toArray(
-                new jalviewSourceI[0]);
-        String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",
-                "uniprot");
+        jalviewSourceI[] sources = sourceRegistry.getSources()
+                .toArray(new jalviewSourceI[0]);
+        String active = Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");
         StringTokenizer st = new StringTokenizer(active, "\t");
         selectedSources = new Vector();
         String token;
@@ -316,17 +316,17 @@ public class DasSequenceFeatureFetcher
     FeaturesClientMultipleSources fc = new FeaturesClientMultipleSources();
     fc.setConnProps(sourceRegistry.getSessionHandler());
     // Now sending requests one at a time to each server
-    ArrayList<jalviewSourceI> srcobj = new ArrayList<jalviewSourceI>();
-    ArrayList<String> src = new ArrayList<String>();
-    List<List<String>> ids = new ArrayList<List<String>>();
-    List<List<DBRefEntry>> idobj = new ArrayList<List<DBRefEntry>>();
-    List<Map<String, SequenceI>> sqset = new ArrayList<Map<String, SequenceI>>();
+    ArrayList<jalviewSourceI> srcobj = new ArrayList<>();
+    ArrayList<String> src = new ArrayList<>();
+    List<List<String>> ids = new ArrayList<>();
+    List<List<DBRefEntry>> idobj = new ArrayList<>();
+    List<Map<String, SequenceI>> sqset = new ArrayList<>();
     for (jalviewSourceI _sr : selectedSources)
     {
 
-      Map<String, SequenceI> slist = new HashMap<String, SequenceI>();
-      List<DBRefEntry> idob = new ArrayList<DBRefEntry>();
-      List<String> qset = new ArrayList<String>();
+      Map<String, SequenceI> slist = new HashMap<>();
+      List<DBRefEntry> idob = new ArrayList<>();
+      List<String> qset = new ArrayList<>();
 
       for (SequenceI seq : sequences)
       {
@@ -368,8 +368,8 @@ public class DasSequenceFeatureFetcher
         sqset.add(slist);
       }
     }
-    Map<String, Map<List<String>, Exception>> errors = new HashMap<String, Map<List<String>, Exception>>();
-    Map<String, Map<List<String>, DasGFFAdapter>> results = new HashMap<String, Map<List<String>, DasGFFAdapter>>();
+    Map<String, Map<List<String>, Exception>> errors = new HashMap<>();
+    Map<String, Map<List<String>, DasGFFAdapter>> results = new HashMap<>();
     if (!useJDASMultiThread)
     {
       Iterator<String> sources = src.iterator();
@@ -377,9 +377,9 @@ public class DasSequenceFeatureFetcher
       for (List<String> idl : ids)
       {
         String source = sources.next();
-        FeaturesClient featuresc = new FeaturesClient(sourceRegistry
-                .getSessionHandler().getConnectionPropertyProviderFor(
-                        source));
+        FeaturesClient featuresc = new FeaturesClient(
+                sourceRegistry.getSessionHandler()
+                        .getConnectionPropertyProviderFor(source));
         for (String id : idl)
         {
           List<String> qid = Arrays.asList(new String[] { id });
@@ -390,7 +390,7 @@ public class DasSequenceFeatureFetcher
             if (ers == null)
             {
               results.put(source,
-                      ers = new HashMap<List<String>, DasGFFAdapter>());
+                      ers = new HashMap<>());
             }
             ers.put(qid, dga);
           } catch (Exception ex)
@@ -399,7 +399,7 @@ public class DasSequenceFeatureFetcher
             if (ers == null)
             {
               errors.put(source,
-                      ers = new HashMap<List<String>, Exception>());
+                      ers = new HashMap<>());
             }
             ers.put(qid, ex);
           }
@@ -434,11 +434,11 @@ public class DasSequenceFeatureFetcher
   }
 
   private void processResponse(Map<String, SequenceI> sequencemap,
-          jalviewSourceI jvsource, List<String> ids,
-          List<DBRefEntry> idobj, Map<List<String>, DasGFFAdapter> results,
+          jalviewSourceI jvsource, List<String> ids, List<DBRefEntry> idobj,
+          Map<List<String>, DasGFFAdapter> results,
           Map<List<String>, Exception> errors)
   {
-    Set<SequenceI> sequences = new HashSet<SequenceI>();
+    Set<SequenceI> sequences = new HashSet<>();
     String source = jvsource.getSourceURL();
     // process features
     DasGFFAdapter result = (results == null) ? null : results.get(ids);
@@ -498,8 +498,8 @@ public class DasSequenceFeatureFetcher
                   vf = dbref.getMap().locateFeature(f);
                 } catch (Exception ex)
                 {
-                  Cache.log
-                          .warn("Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org.");
+                  Cache.log.warn(
+                          "Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org.");
                   Cache.log.warn("Mapping feature from " + f.getBegin()
                           + " to " + f.getEnd() + " in dbref "
                           + dbref.getAccessionId() + " in "
@@ -572,9 +572,8 @@ public class DasSequenceFeatureFetcher
   {
     if (af != null)
     {
-      af.setProgressBar(MessageManager
-              .getString("status.das_feature_fetching_cancelled"),
-              startTime);
+      af.setProgressBar(MessageManager.getString(
+              "status.das_feature_fetching_cancelled"), startTime);
     }
     cancelled = true;
   }
@@ -589,8 +588,8 @@ public class DasSequenceFeatureFetcher
     if (!cancelled && af != null)
     {
       // only update the progress bar if we've completed the fetch normally
-      af.setProgressBar(MessageManager
-              .getString("status.das_feature_fetching_complete"), startTime);
+      af.setProgressBar(MessageManager.getString(
+              "status.das_feature_fetching_complete"), startTime);
     }
 
     if (af != null && af.featureSettings != null)
@@ -613,8 +612,8 @@ public class DasSequenceFeatureFetcher
     }
     af.getFeatureRenderer().featuresAdded();
 
-    int start = af.getViewport().getStartSeq();
-    int end = af.getViewport().getEndSeq();
+    int start = af.getViewport().getRanges().getStartSeq();
+    int end = af.getViewport().getRanges().getEndSeq();
     int index;
     for (index = start; index < end; index++)
     {
@@ -623,7 +622,7 @@ public class DasSequenceFeatureFetcher
         if (seq == af.getViewport().getAlignment().getSequenceAt(index)
                 .getDatasetSequence())
         {
-          af.alignPanel.paintAlignment(true);
+          af.alignPanel.paintAlignment(true, true);
           index = end;
           break;
         }
@@ -637,18 +636,19 @@ public class DasSequenceFeatureFetcher
     {
       return null;
     }
-    DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(
-            seq.getDBRef(), new String[] {
-            // jalview.datamodel.DBRefSource.PDB,
-            jalview.datamodel.DBRefSource.UNIPROT,
+    DBRefEntry[] uprefs = DBRefUtils.selectRefs(seq.getDBRefs(),
+            new String[]
+            {
+                // jalview.datamodel.DBRefSource.PDB,
+                DBRefSource.UNIPROT,
             // jalview.datamodel.DBRefSource.EMBL - not tested on any EMBL coord
             // sys sources
             });
     // TODO: minimal list of DAS queries to make by querying with untyped ID if
     // distinct from any typed IDs
 
-    List<DBRefEntry> ids = new ArrayList<DBRefEntry>();
-    List<String> qstring = new ArrayList<String>();
+    List<DBRefEntry> ids = new ArrayList<>();
+    List<String> qstring = new ArrayList<>();
     boolean dasCoordSysFound = false;
 
     if (uprefs != null)
@@ -659,8 +659,8 @@ public class DasSequenceFeatureFetcher
 
         for (COORDINATES csys : dasSource.getVersion().getCOORDINATES())
         {
-          if (jalview.util.DBRefUtils.isDasCoordinateSystem(
-                  csys.getAuthority(), uprefs[j]))
+          if (DBRefUtils.isDasCoordinateSystem(csys.getAuthority(),
+                  uprefs[j]))
           {
             debug("Launched fetcher for coordinate system "
                     + csys.getAuthority());
@@ -668,9 +668,9 @@ public class DasSequenceFeatureFetcher
             // - the start/end for the DBRefEntry may not be the same as the
             // sequence's start/end
 
-            System.out.println(seq.getName() + " "
-                    + (seq.getDatasetSequence() == null) + " "
-                    + csys.getUri());
+            System.out.println(
+                    seq.getName() + " " + (seq.getDatasetSequence() == null)
+                            + " " + csys.getUri());
 
             dasCoordSysFound = true; // break's out of the loop
             ids.add(uprefs[j]);
@@ -880,9 +880,8 @@ public class DasSequenceFeatureFetcher
       {
       }
 
-      SequenceFeature f = new SequenceFeature(
-              getTypeString(feat.getTYPE()), desc, start, end, score,
-              nickname);
+      SequenceFeature f = new SequenceFeature(getTypeString(feat.getTYPE()),
+              desc, start, end, score, nickname);
 
       if (feat.getLINK() != null)
       {