functions that operate on references to sequences in alignment rather than copies.
[jalview.git] / src / jalview / gui / AlignFrame.java
index c9819a2..c60355c 100755 (executable)
@@ -1309,8 +1309,8 @@ public class AlignFrame
     {
       return;
     }
-
-    SequenceI [] seqs = viewport.getSelectionAsNewSequence();
+    //  TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
+    SequenceI [] seqs = viewport.getSelectionAsNewSequence();  
     String[] omitHidden = null;
 
     if (viewport.hasHiddenColumns)
@@ -1473,10 +1473,11 @@ public class AlignFrame
        sequences = alignment.getSequencesArray();
      }
 
+     int alwidth=0;
 
      if (newAlignment)
      {
-
+       
        if (Desktop.jalviewClipboard != null)
        {
          // dataset is inherited
@@ -1487,12 +1488,14 @@ public class AlignFrame
          // new dataset is constructed
          alignment.setDataset(null);
        }
+       alwidth = alignment.getWidth()+1;
      }
      else
      {
        AlignmentI pastedal = alignment; // preserve pasted alignment object
        // Add pasted sequences and dataset into existing alignment.
        alignment = viewport.getAlignment();
+       alwidth = alignment.getWidth()+1;
         // decide if we need to import sequences from an existing dataset
         boolean importDs = Desktop.jalviewClipboard != null
                 && Desktop.jalviewClipboard[1] != alignment.getDataset();
@@ -1500,10 +1503,10 @@ public class AlignFrame
         // an existing alignment
         Vector newDs = (importDs) ? new Vector() : null; // used to create
                                                           // minimum dataset set
-
+        
         for (int i = 0; i < sequences.length; i++)
         {
-          if (importDs)
+          if (importDs) 
           {
             newDs.addElement(null);
           }
@@ -1513,7 +1516,7 @@ public class AlignFrame
           {
             if (!newDs.contains(ds))
             {
-              newDs.setElementAt(ds, i);
+              newDs.setElementAt(ds, i); 
               ds = new Sequence(ds);
               // update with new dataset sequence
               sequences[i].setDatasetSequence(ds);
@@ -1544,7 +1547,9 @@ public class AlignFrame
           {
             annotationAdded=true;
             if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
-              alignment.addAnnotation(new AlignmentAnnotation(alann[i]));
+              AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
+              newann.padAnnotation(alwidth);
+              alignment.addAnnotation(newann);
             }
           }
         }
@@ -1571,11 +1576,12 @@ public class AlignFrame
          {
            annotationAdded=true;
            sequences[i].getAnnotation()[a].adjustForAlignment();
+           sequences[i].getAnnotation()[a].padAnnotation(alwidth);
            alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
            alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
          }
 
-
+         
        }
      }
      if (!newAlignment) {
@@ -1604,7 +1610,7 @@ public class AlignFrame
        //>>>This is a fix for the moment, until a better solution is found!!<<<
        af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
            alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
-
+       
        // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
        if (!externalPaste) {
          if (title.startsWith("Copied sequences"))
@@ -3313,7 +3319,7 @@ public class AlignFrame
         }
         wsmenu.add(secstrmenu);
       }
-      this.webService.removeAll();
+      resetWebServiceMenu();
       for (int i = 0, j = wsmenu.size(); i < j; i++)
       {
         webService.add( (JMenu) wsmenu.get(i));
@@ -3321,7 +3327,7 @@ public class AlignFrame
     }
     else
     {
-      this.webService.removeAll();
+      resetWebServiceMenu();
       this.webService.add(this.webServiceNoServices);
     }
     // TODO: add in rediscovery function
@@ -3329,6 +3335,31 @@ public class AlignFrame
     // TODO: group services by location as well as function.
   }
 
+
+  /**
+   * empty the web service menu and add any ad-hoc functions
+   * not dynamically discovered.
+   *
+   */
+  private void resetWebServiceMenu()
+  {
+    webService.removeAll();
+    // Temporary hack - DBRef Fetcher always top level ws entry.
+    JMenuItem rfetch = new JMenuItem("Fetch DB References");
+    rfetch.setToolTipText("Retrieve and parse uniprot records for the alignment or the currently selected sequences");
+    webService.add(rfetch);
+    rfetch.addActionListener(new ActionListener() {
+
+      public void actionPerformed(ActionEvent e)
+      {
+        new jalview.io.DBRefFetcher(
+                alignPanel.av.getSequenceSelection(),
+                alignPanel.alignFrame).fetchDBRefs(false);
+      }
+      
+    });
+  }
+
  /* public void vamsasStore_actionPerformed(ActionEvent e)
   {
     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
@@ -3350,13 +3381,12 @@ public class AlignFrame
 
 
 
-
 public void showTranslation_actionPerformed(ActionEvent e)
 {
   ///////////////////////////////
   // Collect Data to be translated/transferred
 
-  SequenceI [] selection = viewport.getSelectionAsNewSequence();
+  SequenceI [] selection = viewport.getSequenceSelection();
   String [] seqstring = viewport.getViewAsString(true);
   AlignmentI al  = null;
   try {