import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
+import javax.swing.event.MenuEvent;
import jalview.analysis.*;
import jalview.commands.*;
}
setMenusFromViewport(viewport);
-
+ buildSortByAnnotationScoresMenu();
if (viewport.wrapAlignment)
{
wrapMenuItem_actionPerformed(null);
new AnnotationExporter().exportAnnotations(
alignPanel,
viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
- viewport.alignment.getGroups()
+ viewport.alignment.getGroups(),
+ ((Alignment)viewport.alignment).alignmentProperties
);
}
if (annotationAdded)
{
alignPanel.annotationPanel.adjustPanelHeight();
+ buildSortByAnnotationScoresMenu();
}
viewport.firePropertyChange("alignment", null, alignment.getSequences());
} else {
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).getProperties() != null)
+ {
+ Hashtable props = ((Alignment)viewport.alignment).getProperties();
+ Enumeration en = props.keys();
+ contents.append("<br><br><table border=\"1\">");
+ while(en.hasMoreElements())
+ {
+ String key = en.nextElement().toString();
+ StringBuffer val = new StringBuffer();
+ String vals = props.get(key).toString();
+ int pos=0, npos;
+ do {
+ npos = vals.indexOf("\n",pos);
+ if (npos==-1)
+ {
+ val.append(vals.substring(pos));
+ } else {
+ val.append(vals.substring(pos, npos));
+ val.append("<br>");
+ }
+ pos = npos+1;
+ } while (npos!=-1);
+ contents.append("<tr><td>"+key+"</td><td>"+val+"</td></tr>");
+ }
+ contents.append("</table>");
+ }
+ editPane.setText(contents.toString()+"</html>");
+ JInternalFrame frame = new JInternalFrame();
+ frame.getContentPane().add(new JScrollPane(editPane));
+
+ Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
+ }
+
+
/**
* DOCUMENT ME!
*
alignPanel.paintAlignment(true);
}
-
/**
* DOCUMENT ME!
*
}
});
}
+ /**
+ * Add a new sort by annotation score menu item
+ * @param sort the menu to add the option to
+ * @param scoreLabel the label used to retrieve scores for each sequence on the alignment
+ */
+ public void addSortByAnnotScoreMenuItem(JMenu sort, final String scoreLabel)
+ {
+ final JMenuItem item = new JMenuItem(scoreLabel);
+ sort.add(item);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());
+ addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment));
+ alignPanel.paintAlignment(true);
+ }
+ });
+ }
+ /**
+ * last hash for alignment's annotation array - used to minimise cost of rebuild.
+ */
+ protected int _annotationScoreVectorHash;
+ /**
+ * search the alignment and rebuild the sort by annotation score submenu
+ * the last alignment annotation vector hash is stored to minimize
+ * cost of rebuilding in subsequence calls.
+ *
+ */
+ public void buildSortByAnnotationScoresMenu()
+ {
+ if (viewport.alignment.getAlignmentAnnotation().hashCode()!=_annotationScoreVectorHash)
+ {
+ sortByAnnotScore.removeAll();
+ // almost certainly a quicker way to do this - but we keep it simple
+ Hashtable scoreSorts=new Hashtable();
+ AlignmentAnnotation aann[];
+ Enumeration sq = viewport.alignment.getSequences().elements();
+ while (sq.hasMoreElements())
+ {
+ aann = ((SequenceI) sq.nextElement()).getAnnotation();
+ for (int i=0;aann!=null && i<aann.length; i++)
+ {
+ if (aann[i].hasScore() && aann[i].sequenceRef!=null)
+ {
+ scoreSorts.put(aann[i].label, aann[i].label);
+ }
+ }
+ }
+ Enumeration labels = scoreSorts.keys();
+ while (labels.hasMoreElements())
+ {
+ addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels.nextElement());
+ }
+ sortByAnnotScore.setVisible(scoreSorts.size()>0);
+ scoreSorts.clear();
+ }
+ }
/**
* Maintain the Order by->Displayed Tree menu.
}
+ /**
+ * 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.alignment.getSequencesArray(),
+ alignPanel.av.getSequenceSelection(),
alignPanel.alignFrame).fetchDBRefs(false);
}
///////////////////////////////
// Collect Data to be translated/transferred
- SequenceI [] selection = viewport.getSelectionAsNewSequence();
+ SequenceI [] selection = viewport.getSequenceSelection();
String [] seqstring = viewport.getViewAsString(true);
AlignmentI al = null;
try {
{
// (isAnnotation)
alignPanel.adjustAnnotationHeight();
+ buildSortByAnnotationScoresMenu();
}
}
{
return viewport;
}
+
+
+ /**
+ * Open the dialog for regex description parsing.
+ */
+ protected void extractScores_actionPerformed(ActionEvent e)
+ {
+ ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment);
+ if (pp.getScoresFromDescription("col", "score column ", "\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)")>0)
+ {
+ buildSortByAnnotationScoresMenu();
+ }
+ }
}
class PrintThread