X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=e870deaf4a6f3aa183c3eca359c28729dbca66fb;hb=29f633ca27df2db2790b81b1ca346d6692d4936c;hp=edd8cec41581c41f786eaf55060bebd73ce4a6ca;hpb=28aba3836346a81a1fe5514f59aa77f2579e64ff;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index edd8cec..e870dea 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -28,6 +28,7 @@ import java.awt.dnd.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; +import javax.swing.event.MenuEvent; import jalview.analysis.*; import jalview.commands.*; @@ -141,7 +142,7 @@ public class AlignFrame } setMenusFromViewport(viewport); - + buildSortByAnnotationScoresMenu(); if (viewport.wrapAlignment) { wrapMenuItem_actionPerformed(null); @@ -497,14 +498,17 @@ public class AlignFrame showTranslation.setVisible( nucleotide ); conservationMenuItem.setEnabled( !nucleotide ); modifyConservation.setEnabled( !nucleotide ); - + //Remember AlignFrame always starts as protein if(!nucleotide) { calculateMenu.remove(calculateMenu.getItemCount()-2); } + setShowProductsEnabled(); } + + /** * Need to call this method when tabs are selected for multiple views, * or when loading from Jalview2XML.java @@ -689,9 +693,9 @@ public class AlignFrame JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. getProperty( "LAST_DIRECTORY"), new String[] - { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" }, + { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","amsa","jar" }, new String[] - { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" }, + { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Jalview" }, currentFileFormat, false); @@ -722,7 +726,7 @@ public class AlignFrame jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName); - saveAlignment(fileName, currentFileFormat); + saveAlignment(fileName, currentFileFormat.substring(0,currentFileFormat.indexOf(" "))); } } @@ -765,11 +769,12 @@ public class AlignFrame omitHidden = viewport.getViewAsString(false); } } + FormatAdapter f = new FormatAdapter(); - String output = new FormatAdapter().formatSequences( + String output = f.formatSequences( format, - viewport.alignment.getSequencesArray(), - omitHidden); + (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future + omitHidden, f.getCacheSuffixDefault(format)); if (output == null) { @@ -840,7 +845,7 @@ public class AlignFrame cap.setText(new FormatAdapter().formatSequences( e.getActionCommand(), - viewport.alignment.getSequencesArray(), + viewport.alignment, omitHidden)); } @@ -1048,8 +1053,28 @@ public class AlignFrame } } - - + /** + * + * @return alignment objects for all views + */ + AlignmentI[] getViewAlignments() + { + if (alignPanels!=null) + { + Enumeration e = alignPanels.elements(); + AlignmentI[] als = new AlignmentI[alignPanels.size()]; + for (int i=0; e.hasMoreElements(); i++) + { + als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment(); + } + return als; + } + if (viewport!=null) + { + return new AlignmentI[] { viewport.alignment }; + } + return null; + } /** * DOCUMENT ME! * @@ -1057,9 +1082,11 @@ public class AlignFrame */ protected void undoMenuItem_actionPerformed(ActionEvent e) { + if (viewport.historyList.empty()) + return; CommandI command = (CommandI)viewport.historyList.pop(); viewport.redoList.push(command); - command.undoCommand(); + command.undoCommand(getViewAlignments()); AlignViewport originalSource = getOriginatingSource(command); updateEditMenuBar(); @@ -1087,7 +1114,7 @@ public class AlignFrame CommandI command = (CommandI) viewport.redoList.pop(); viewport.historyList.push(command); - command.doCommand(); + command.doCommand(getViewAlignments()); AlignViewport originalSource = getOriginatingSource(command); updateEditMenuBar(); @@ -1581,18 +1608,44 @@ public class AlignFrame alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a); } - - } } if (!newAlignment) { + // propagate alignment changed. viewport.setEndSeq(alignment.getHeight()); if (annotationAdded) { - alignPanel.annotationPanel.adjustPanelHeight(); + // Duplicate sequence annotation in all views. + AlignmentI[] alview = this.getViewAlignments(); + for (int i = 0; i < sequences.length; i++) + { + AlignmentAnnotation sann[] = sequences[i].getAnnotation(); + if (sann == null) + continue; + for (int avnum=0;avnumMaximum Sequence Length: "+max); contents.append("
Average Length: "+(int)avg); - if (((Alignment)viewport.alignment).alignmentProperties != null) + if (((Alignment)viewport.alignment).getProperties() != null) { - Hashtable props = ((Alignment)viewport.alignment).alignmentProperties; + Hashtable props = ((Alignment)viewport.alignment).getProperties(); Enumeration en = props.keys(); contents.append("

"); while(en.hasMoreElements()) { String key = en.nextElement().toString(); - contents.append(""); + 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("
"); + } + pos = npos+1; + } while (npos!=-1); + contents.append(""); } contents.append("
"+key+""+props.get(key)+"
"+key+""+val+"
"); } editPane.setText(contents.toString()+""); JInternalFrame frame = new JInternalFrame(); - frame.getContentPane().add(editPane); + frame.getContentPane().add(new JScrollPane(editPane)); Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400); } @@ -2818,7 +2885,6 @@ public class AlignFrame alignPanel.paintAlignment(true); } - /** * DOCUMENT ME! * @@ -3036,6 +3102,73 @@ public class AlignFrame } }); } + /** + * 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()==null) + { + return; + } + + 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 && i0); + scoreSorts.clear(); + + _annotationScoreVectorHash = + viewport.alignment.getAlignmentAnnotation().hashCode(); + } + } /** * Maintain the Order by->Displayed Tree menu. @@ -3398,7 +3531,7 @@ public class AlignFrame public void actionPerformed(ActionEvent e) { - new jalview.io.DBRefFetcher( + new jalview.ws.DBRefFetcher( alignPanel.av.getSequenceSelection(), alignPanel.alignFrame).fetchDBRefs(false); } @@ -3424,9 +3557,135 @@ public class AlignFrame vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this); } }*/ + /** + * prototype of an automatically enabled/disabled analysis function + * + */ + protected void setShowProductsEnabled() + { + SequenceI [] selection = viewport.getSequenceSelection(); + if (canShowProducts(selection, viewport.getSelectionGroup()!=null, viewport.getAlignment().getDataset())) + { + showProducts.setEnabled(true); + + } else { + showProducts.setEnabled(false); + } + } + /** + * search selection for sequence xRef products and build the + * show products menu. + * @param selection + * @param dataset + * @return true if showProducts menu should be enabled. + */ + public boolean canShowProducts(SequenceI[] selection, boolean isRegionSelection, Alignment dataset) + { + boolean showp=false; + try { + showProducts.removeAll(); + final boolean dna = viewport.getAlignment().isNucleotide(); + final Alignment ds = dataset; + String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection, dataset); + //Object[] prods = CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(), selection, dataset, true); + final SequenceI[] sel = selection; + for (int t=0; ptypes!=null && t0) + { + buildSortByAnnotationScoresMenu(); + } + } } class PrintThread