X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=c61c7995addc84ae5c1ec23ff2a06f0dfe6fc528;hb=62df38e7204f2903d1b4e5aaef7762acf96f317d;hp=e75b535e3a8842ed0c641494e854286367b8278c;hpb=7b23bc325bac59784fee854f77c49b2f785b9aca;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index e75b535..c61c799 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -34,7 +34,8 @@ import jalview.io.*; import jalview.jbgui.*; import jalview.schemes.*; import jalview.ws.*; -import javax.swing.event.AncestorEvent; +import java.awt.dnd.*; + /** * DOCUMENT ME! @@ -43,7 +44,7 @@ import javax.swing.event.AncestorEvent; * @version $Revision$ */ public class AlignFrame - extends GAlignFrame implements ClipboardOwner + extends GAlignFrame implements DropTargetListener { /** DOCUMENT ME!! */ public static final int NEW_WINDOW_WIDTH = 700; @@ -53,9 +54,6 @@ public class AlignFrame AlignmentPanel alignPanel; AlignViewport viewport; - Vector viewports = new Vector(); - Vector alignPanels = new Vector(); - /** DOCUMENT ME!! */ public String currentFileFormat = null; Stack historyList = new Stack(); @@ -71,8 +69,8 @@ public class AlignFrame public AlignFrame(AlignmentI al) { viewport = new AlignViewport(al); - viewports.add(viewport); + this.setDropTarget(new java.awt.dnd.DropTarget(this, this)); if(viewport.vconsensus==null) { @@ -86,7 +84,6 @@ public class AlignFrame } alignPanel = new AlignmentPanel(this, viewport); - alignPanels.add(alignPanel); String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort"); @@ -172,18 +169,13 @@ public class AlignFrame public void setGUINucleotide(boolean nucleotide) { showTranslation.setVisible( nucleotide ); - sequenceFeatures.setVisible(!nucleotide ); - featureSettings.setVisible( !nucleotide ); + //sequenceFeatures.setVisible(!nucleotide ); + //featureSettings.setVisible( !nucleotide ); conservationMenuItem.setVisible( !nucleotide ); modifyConservation.setVisible( !nucleotide ); - //Deal with separators //Remember AlignFrame always starts as protein - if(nucleotide) - { - viewMenu.remove(viewMenu.getItemCount()-2); - } - else + if(!nucleotide) { calculateMenu.remove(calculateMenu.getItemCount()-2); } @@ -198,99 +190,31 @@ public class AlignFrame return jalview.bin.Cache.getProperty("VERSION"); } - - /** - * DOCUMENT ME! - * - * @param String DOCUMENT ME! - */ - - public void parseGroupsFile(String file) + public FeatureRenderer getFeatureRenderer() { - try - { - BufferedReader in = new BufferedReader(new FileReader(file)); - SequenceI seq = null; - String line, type, desc, token; - - int index, start, end; - StringTokenizer st; - SequenceFeature sf; - FeatureRenderer fr = alignPanel.seqPanel.seqCanvas.getFeatureRenderer(); - int lineNo = 0; - while ( (line = in.readLine()) != null) - { - lineNo++; - st = new StringTokenizer(line, "\t"); - if (st.countTokens() == 2) - { - type = st.nextToken(); - UserColourScheme ucs = new UserColourScheme(st.nextToken()); - fr.setColour(type, ucs.findColour("A")); - continue; - } - - while (st.hasMoreElements()) - { - desc = st.nextToken(); - token = st.nextToken(); - if (!token.equals("ID_NOT_SPECIFIED")) - { - index = viewport.alignment.findIndex(viewport.alignment.findName( - token)); - st.nextToken(); - } - else - { - index = Integer.parseInt(st.nextToken()); - } - - start = Integer.parseInt(st.nextToken()); - end = Integer.parseInt(st.nextToken()); - - seq = viewport.alignment.getSequenceAt(index); - start = seq.findIndex(start) - 1; - end = seq.findIndex(end) - 1; - - type = st.nextToken(); - - if (fr.getColour(type) == null) - { - // Probably the old style groups file - UserColourScheme ucs = new UserColourScheme(type); - fr.setColour(type, ucs.findColour("A")); - } - - - sf = new SequenceFeature(type, desc, "", start, end); - - seq.getDatasetSequence().addSequenceFeature(sf); - - - // sg = new SequenceGroup(text, ucs, true, true, false, start, end); - // sg.addSequence(seq, false); - - // viewport.alignment.addGroup(sg); - - } - } + return alignPanel.seqPanel.seqCanvas.getFeatureRenderer(); + } - viewport.showSequenceFeatures = true; - alignPanel.repaint(); + public void fetchSequence_actionPerformed(ActionEvent e) + { + new SequenceFetcher(this); + } - } - catch (Exception ex) - { - System.out.println("Error parsing groups file: " + ex); - } + public void addFromFile_actionPerformed(ActionEvent e) + { + Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport); } - public void fetchSequence_actionPerformed(ActionEvent e) + public void addFromText_actionPerformed(ActionEvent e) { - new SequenceFetcher(this); + Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport); } + public void addFromURL_actionPerformed(ActionEvent e) + { + Desktop.instance.inputURLMenuItem_actionPerformed(viewport); + } /** * DOCUMENT ME! @@ -355,7 +279,7 @@ public class AlignFrame java.io.File.separatorChar) + 1); } - Jalview2XML.SaveAlignment(this, file, shortName); + new Jalview2XML().SaveAlignment(this, file, shortName); // USE Jalview2XML to save this file return true; @@ -377,6 +301,7 @@ public class AlignFrame out.print(output); out.close(); + this.setTitle(file); return true; } catch (Exception ex) @@ -452,6 +377,27 @@ public class AlignFrame thread.start(); } + public void associatedData_actionPerformed(ActionEvent e) + { + // Pick the tree file + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty( + "LAST_DIRECTORY")); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Load Jalview Annotations or Features File"); + chooser.setToolTipText("Load Jalview Annotations / Features file"); + + int value = chooser.showOpenDialog(null); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + loadJalviewDataFile(choice); + } + + } + /** * DOCUMENT ME! * @@ -542,42 +488,8 @@ public class AlignFrame // used by undo and redo void restoreHistoryItem(HistoryItem hi) { - if (hi.getType() == HistoryItem.SORT) - { - for (int i = 0; i < hi.getSequences().size(); i++) - { - viewport.alignment.getSequences().setElementAt(hi.getSequences() - .elementAt(i), - i); - } - } - else - { - for (int i = 0; i < hi.getSequences().size(); i++) - { - SequenceI restore = (SequenceI) hi.getSequences().elementAt(i); - if (restore.getLength() == 0) - { - restore.setSequence(hi.getHidden().elementAt(i).toString()); - viewport.alignment.getSequences().insertElementAt(restore, - hi.getAlignIndex(i)); - } - else - { - restore.setSequence(hi.getHidden().elementAt(i).toString()); - } - } - - if (hi.getType() == HistoryItem.PASTE) - { - for (int i = viewport.alignment.getHeight() - 1; - i > (hi.getSequences().size() - 1); i--) - { - viewport.alignment.deleteSequence(i); - } - } - } + hi.restore(); updateEditMenuBar(); @@ -647,10 +559,6 @@ public class AlignFrame alignPanel.repaint(); } - public void lostOwnership(Clipboard clipboard, Transferable contents) - { - Desktop.jalviewClipboard = null; - } /** @@ -731,12 +639,16 @@ public class AlignFrame seqs[i].setDBRef(seq.getDBRef()); seqs[i].setSequenceFeatures(seq.getSequenceFeatures()); seqs[i].setDatasetSequence(seq.getDatasetSequence()); - + if(seq.getAnnotation()!=null) + { + for(int a=0; a>>This is a fix for the moment, until a better solution is found!!<<< + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings( + alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); + + + if (title.startsWith("Copied sequences")) + { + newtitle = title; + } + else + { + newtitle = newtitle.concat("- from " + title); + } + + Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, + NEW_WINDOW_HEIGHT); + + } + + } catch (Exception ex) { + ex.printStackTrace(); + System.out.println("Exception whilst pasting: "+ex); // could be anything being pasted in here } @@ -883,24 +829,50 @@ public class AlignFrame return; } - addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, - HistoryItem.HIDE)); SequenceGroup sg = viewport.getSelectionGroup(); - boolean allSequences = false; - if (sg.sequences.size() == viewport.alignment.getHeight()) + + + + //Jalview no longer allows deletion of residues. + //Check here whether any residues are in selection area + /* if( sg.getEndRes()-sg.getStartRes() < viewport.alignment.getWidth()-1) { - allSequences = true; - } + for (int i = 0; i < sg.sequences.size(); i++) + { + SequenceI seq = sg.getSequenceAt(i); + int j = sg.getStartRes(); + do + { + if (!jalview.util.Comparison.isGap(seq.getCharAt(j))) + { + JOptionPane.showInternalMessageDialog( + Desktop.desktop, "Cannot delete residues from alignment!\n" + + "Try hiding columns instead.", + "Deletion of residues not permitted", + JOptionPane.WARNING_MESSAGE); + + return; + } + j++; + }while(j<=sg.getEndRes()); + } + }*/ + + + addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, + HistoryItem.HIDE)); + for (int i = 0; i < sg.sequences.size(); i++) { SequenceI seq = sg.getSequenceAt(i); int index = viewport.getAlignment().findIndex(seq); + seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); // If the cut affects all sequences, remove highlighted columns - if (allSequences) + if (sg.sequences.size() == viewport.alignment.getHeight()) { viewport.getColumnSelection().removeElements(sg.getStartRes(), sg.getEndRes() + 1); @@ -975,11 +947,16 @@ public class AlignFrame */ public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) { + if(viewport.cursorMode) + { + alignPanel.seqPanel.keyboardNo1 = null; + alignPanel.seqPanel.keyboardNo2 = null; + } viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); viewport.setSelectionGroup(null); alignPanel.seqPanel.seqCanvas.highlightSearchResults(null); - alignPanel.annotationPanel.activeRes = null; + alignPanel.idPanel.idCanvas.searchResults = null; PaintRefresher.Refresh(null, viewport.alignment); } @@ -1197,7 +1174,10 @@ public class AlignFrame public void alignmentChanged() { - if(viewport.vconsensus!=null) + if(viewport.padGaps) + viewport.getAlignment().padGaps(); + + if(viewport.vconsensus!=null && viewport.autoCalculateConsensus) { viewport.updateConsensus(); viewport.updateConservation(); @@ -1206,6 +1186,8 @@ public class AlignFrame if(alignPanel.overviewPanel!=null) alignPanel.overviewPanel.updateOverviewImage(); + viewport.alignment.adjustSequenceAnnotations(); + alignPanel.repaint(); } @@ -1258,20 +1240,9 @@ public class AlignFrame addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, HistoryItem.HIDE)); - SequenceI current; - int Width = viewport.getAlignment().getWidth(); - - for (int i = 0; i < viewport.getAlignment().getSequences().size(); - i++) - { - current = viewport.getAlignment().getSequenceAt(i); - - if (current.getLength() < Width) - { - current.insertCharAt(Width - 1, viewport.getGapCharacter()); - } - } + viewport.padGaps = padGapsMenuitem.isSelected(); + // if (viewport.padGaps) alignmentChanged(); } @@ -1285,8 +1256,8 @@ public class AlignFrame JInternalFrame frame = new JInternalFrame(); Finder finder = new Finder(viewport, alignPanel, frame); frame.setContentPane(finder); - Desktop.addInternalFrame(frame, "Find", 340, 110); frame.setLayer(JLayeredPane.PALETTE_LAYER); + Desktop.addInternalFrame(frame, "Find", 340, 110); } /** @@ -1299,6 +1270,14 @@ public class AlignFrame new FontChooser(alignPanel); } + public void smoothFont_actionPerformed(ActionEvent e) + { + viewport.antiAlias = smoothFont.isSelected(); + alignPanel.annotationPanel.image = null; + alignPanel.repaint(); + } + + /** * DOCUMENT ME! * @@ -1405,25 +1384,37 @@ public class AlignFrame alignPanel.repaint(); } + public void fetchSeqFeatures_actionPerformed(ActionEvent e) + { + if (!viewport.alignment.isNucleotide()) + { + new DasSequenceFeatureFetcher(viewport. + alignment, + alignPanel); + viewport.setShowSequenceFeatures(true); + showSeqFeatures.setSelected(true); + } + } + + + public void featureSettings_actionPerformed(ActionEvent e) + { + new FeatureSettings(viewport, alignPanel); + } + /** * DOCUMENT ME! * * @param evt DOCUMENT ME! */ - public void sequenceFeatures_actionPerformed(ActionEvent evt) + public void showSeqFeatures_actionPerformed(ActionEvent evt) { - viewport.showSequenceFeatures(sequenceFeatures.isSelected()); - - if (viewport.showSequenceFeatures) + viewport.setShowSequenceFeatures(showSeqFeatures.isSelected()); + alignPanel.repaint(); + if (alignPanel.getOverviewPanel() != null) { - new SequenceFeatureFetcher(viewport. - alignment, - alignPanel); + alignPanel.getOverviewPanel().updateOverviewImage(); } - - featureSettings.setEnabled(true); - - alignPanel.repaint(); } /** @@ -1570,6 +1561,12 @@ public class AlignFrame changeColour(new NucleotideColourScheme()); } + public void annotationColour_actionPerformed(ActionEvent e) + { + new AnnotationColourChooser(viewport, alignPanel); + } + + /** * DOCUMENT ME! * @@ -1977,6 +1974,17 @@ public class AlignFrame new PCAPanel(viewport); } + + public void autoCalculate_actionPerformed(ActionEvent e) + { + viewport.autoCalculateConsensus = autoCalculate.isSelected(); + if(viewport.autoCalculateConsensus) + { + alignmentChanged(); + } + } + + /** * DOCUMENT ME! * @@ -2026,7 +2034,7 @@ public class AlignFrame */ void NewTreePanel(String type, String pwType, String title) { - final TreePanel tp; + TreePanel tp; if ( (viewport.getSelectionGroup() != null) && (viewport.getSelectionGroup().getSize() > 3)) @@ -2078,7 +2086,6 @@ public class AlignFrame } addTreeMenuItem(tp, title); - viewport.setCurrentTree(tp.getTree()); Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500); } @@ -2387,6 +2394,7 @@ public class AlignFrame { // Add any Multiple Sequence Alignment Services final JMenu msawsmenu = new JMenu("Alignment"); + final AlignFrame af = this; for (int i = 0, j = msaws.size(); i < j; i++) { final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws. @@ -2398,7 +2406,7 @@ public class AlignFrame { SequenceI[] msa = gatherSequencesForAlignment(); new jalview.ws.MsaWSClient(sh, title, msa, - false, true, viewport.getAlignment().getDataset()); + false, true, viewport.getAlignment().getDataset(), af); } @@ -2415,7 +2423,7 @@ public class AlignFrame { SequenceI[] msa = gatherSequencesForAlignment(); new jalview.ws.MsaWSClient(sh, title, msa, - true, true, viewport.getAlignment().getDataset()); + true, true, viewport.getAlignment().getDataset(), af); } @@ -2495,10 +2503,7 @@ public class AlignFrame } }*/ - public void featureSettings_actionPerformed(ActionEvent e) - { - new FeatureSettings(viewport, alignPanel); - } + @@ -2515,6 +2520,8 @@ public void showTranslation_actionPerformed(ActionEvent e) protein = new StringBuffer(); seq = AlignSeq.extractGaps("-. ", viewport.alignment.getSequenceAt(s).getSequence()); resSize = seq.length(); + resSize -= resSize%3; + for(res = 0; res < resSize; res+=3) { String codon = seq.substring(res, res+3); @@ -2540,42 +2547,42 @@ public void showTranslation_actionPerformed(ActionEvent e) jalview.datamodel.AlignmentAnnotation[] annotations = viewport.alignment.getAlignmentAnnotation(); int a, aSize; - for (int i = 0; i < annotations.length; i++) + if(annotations!=null) { - - if (annotations[i].label.equals("Quality") || - annotations[i].label.equals("Conservation") || - annotations[i].label.equals("Consensus")) + for (int i = 0; i < annotations.length; i++) { - continue; - } - + if (annotations[i].label.equals("Quality") || + annotations[i].label.equals("Conservation") || + annotations[i].label.equals("Consensus")) + { + continue; + } - aSize = viewport.alignment.getWidth()/3; - jalview.datamodel.Annotation [] anots = - new jalview.datamodel.Annotation[aSize]; + aSize = viewport.alignment.getWidth() / 3; + jalview.datamodel.Annotation[] anots = + new jalview.datamodel.Annotation[aSize]; - for(a=0; a