getContentPane().add alignmentProperties popup.
[jalview.git] / src / jalview / gui / AlignFrame.java
index c9819a2..edd8cec 100755 (executable)
@@ -911,7 +911,8 @@ public class AlignFrame
     new AnnotationExporter().exportAnnotations(
       alignPanel,
         viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
-      viewport.alignment.getGroups()
+      viewport.alignment.getGroups(),
+      ((Alignment)viewport.alignment).alignmentProperties
         );
   }
 
@@ -1309,7 +1310,7 @@ public class AlignFrame
     {
       return;
     }
-
+    //  TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
     SequenceI [] seqs = viewport.getSelectionAsNewSequence();
     String[] omitHidden = null;
 
@@ -1473,6 +1474,7 @@ public class AlignFrame
        sequences = alignment.getSequencesArray();
      }
 
+     int alwidth=0;
 
      if (newAlignment)
      {
@@ -1487,12 +1489,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();
@@ -1544,7 +1548,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,6 +1577,7 @@ 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);
          }
@@ -2260,6 +2267,51 @@ public class AlignFrame
     alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
   }
 
+  public void alignmentProperties()
+  {
+    JEditorPane editPane = new JEditorPane("text/html","");
+    editPane.setEditable(false);
+    StringBuffer contents = new StringBuffer("<html>");
+
+    float avg  = 0;
+    int min=Integer.MAX_VALUE, max=0;
+    for(int i=0; i<viewport.alignment.getHeight(); i++)
+    {
+      int size = viewport.alignment.getSequenceAt(i).getEnd()
+          -viewport.alignment.getSequenceAt(i).getStart();
+      avg += size;
+      if(size>max)
+        max = size;
+      if(size<min)
+        min = size;
+    }
+    avg = avg/(float)viewport.alignment.getHeight();
+
+    contents.append("<br>Sequences: "+ viewport.alignment.getHeight());
+    contents.append("<br>Minimum Sequence Length: "+min);
+    contents.append("<br>Maximum Sequence Length: "+max);
+    contents.append("<br>Average Length: "+(int)avg);
+
+    if (((Alignment)viewport.alignment).alignmentProperties != null)
+    {
+      Hashtable props = ((Alignment)viewport.alignment).alignmentProperties;
+      Enumeration en = props.keys();
+      contents.append("<br><br><table border=\"1\">");
+      while(en.hasMoreElements())
+      {
+        String key = en.nextElement().toString();
+        contents.append("<tr><td>"+key+"</td><td>"+props.get(key)+"</td></tr>");
+      }
+      contents.append("</table>");
+    }
+    editPane.setText(contents.toString()+"</html>");
+    JInternalFrame frame = new JInternalFrame();
+    frame.getContentPane().add(editPane);
+
+    Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
+  }
+
+
   /**
    * DOCUMENT ME!
    *
@@ -3313,7 +3365,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 +3373,7 @@ public class AlignFrame
     }
     else
     {
-      this.webService.removeAll();
+      resetWebServiceMenu();
       this.webService.add(this.webServiceNoServices);
     }
     // TODO: add in rediscovery function
@@ -3329,6 +3381,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 +3427,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 {