JAL-2609 enabled (still broken/incomplete) fast paint
[jalview.git] / src / jalview / ws / DBRefFetcher.java
index 453cd00..8c8a717 100644 (file)
@@ -26,7 +26,6 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.Mapping;
-import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.CutAndPasteTransfer;
 import jalview.gui.DasSourceBrowser;
@@ -115,7 +114,8 @@ public class DBRefFetcher implements Runnable
    */
   public DBRefFetcher(SequenceI[] seqs,
           IProgressIndicator progressIndicatorFrame,
-          DbSourceProxy[] sources, FeatureSettings featureSettings, boolean isNucleotide)
+          DbSourceProxy[] sources, FeatureSettings featureSettings,
+          boolean isNucleotide)
   {
     listeners = new ArrayList<FetchFinishedListenerI>();
     this.progressWindow = progressIndicatorFrame;
@@ -340,7 +340,7 @@ public class DBRefFetcher implements Runnable
     {
       progressWindow.setProgressBar(
               MessageManager.getString("status.fetching_db_refs"),
-            startTime);
+              startTime);
     }
     try
     {
@@ -389,8 +389,8 @@ public class DBRefFetcher implements Runnable
           // Still queries to make for current seqIndex
           StringBuffer queryString = new StringBuffer("");
           int numq = 0;
-          int nqSize = (maxqlen > queries.size()) ? queries
-                  .size() : maxqlen;
+          int nqSize = (maxqlen > queries.size()) ? queries.size()
+                  : maxqlen;
 
           while (queries.size() > 0 && numq < nqSize)
           {
@@ -514,8 +514,7 @@ public class DBRefFetcher implements Runnable
       output.setText(sb.toString());
 
       Desktop.addInternalFrame(output,
-              MessageManager.getString("label.sequences_updated"),
-              600, 300);
+              MessageManager.getString("label.sequences_updated"), 600, 300);
       // The above is the dataset, we must now find out the index
       // of the viewed sequence
 
@@ -551,8 +550,7 @@ public class DBRefFetcher implements Runnable
    * @param warningMessages
    *          a list of messages to add to
    */
-  boolean transferReferences(Vector<SequenceI> sdataset,
-          String dbSource,
+  boolean transferReferences(Vector<SequenceI> sdataset, String dbSource,
           AlignmentI retrievedAl, boolean trimDatasetSeqs,
           List<String> warningMessages)
   {
@@ -573,8 +571,8 @@ public class DBRefFetcher implements Runnable
       // taking into account all accessionIds and names in the file
       Vector<SequenceI> sequenceMatches = new Vector<SequenceI>();
       // look for corresponding accession ids
-      DBRefEntry[] entryRefs = DBRefUtils.selectRefs(retrievedSeq.getDBRefs(),
-              new String[] { dbSource });
+      DBRefEntry[] entryRefs = DBRefUtils.selectRefs(
+              retrievedSeq.getDBRefs(), new String[] { dbSource });
       if (entryRefs == null)
       {
         System.err
@@ -684,8 +682,8 @@ public class DBRefFetcher implements Runnable
            */
           mp = new Mapping(null, new int[] { sequenceStart + absStart,
               sequenceStart + absStart + entrySeq.length() - 1 }, new int[]
-          { retrievedSeq.getStart(), retrievedSeq.getStart() + entrySeq.length() - 1 },
-                  1, 1);
+          { retrievedSeq.getStart(),
+              retrievedSeq.getStart() + entrySeq.length() - 1 }, 1, 1);
           updateRefFrame = false;
         }
         else
@@ -698,34 +696,20 @@ public class DBRefFetcher implements Runnable
 
           if (updateRefFrame)
           {
-            SequenceFeature[] sfs = sequence.getSequenceFeatures();
-            if (sfs != null)
+            /*
+             * relocate existing sequence features by offset
+             */
+            int startShift = absStart - sequenceStart + 1;
+            if (startShift != 0)
             {
-              /*
-               * relocate existing sequence features by offset
-               */
-              int start = sequenceStart;
-              int end = sequence.getEnd();
-              int startShift = 1 - absStart - start;
-
-              if (startShift != 0)
-              {
-                for (SequenceFeature sf : sfs)
-                {
-                  if (sf.getBegin() >= start && sf.getEnd() <= end)
-                  {
-                    sf.setBegin(sf.getBegin() + startShift);
-                    sf.setEnd(sf.getEnd() + startShift);
-                    modified = true;
-                  }
-                }
-              }
+              modified |= sequence.getFeatures().shiftFeatures(startShift);
             }
           }
         }
 
         System.out.println("Adding dbrefs to " + sequence.getName()
-                + " from " + dbSource + " sequence : " + retrievedSeq.getName());
+                + " from " + dbSource + " sequence : "
+                + retrievedSeq.getName());
         sequence.transferAnnotation(retrievedSeq, mp);
 
         absStart += retrievedSeq.getStart();