X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=ccf7303f35160d152b5f9854d58296cc4b07c7fb;hb=b2319fcc38be5c500ed7cafc014cf9da96a4ce98;hp=3319b338db89f9b4e00ac3e7aa9b76941c884733;hpb=df1c58f9669c477db082016aa919d6c6cc9da071;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 3319b33..ccf7303 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -174,18 +174,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); } @@ -205,8 +200,6 @@ public class AlignFrame { new SequenceFetcher(this); } - - /** * DOCUMENT ME! * @@ -270,7 +263,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; @@ -367,6 +360,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! * @@ -457,42 +471,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(); @@ -698,7 +678,7 @@ public class AlignFrame if(str.length()<1) return; - String format = IdentifyFile.Identify(str, "Paste"); + String format = new IdentifyFile().Identify(str, "Paste"); SequenceI[] sequences; if(Desktop.jalviewClipboard!=null) @@ -726,6 +706,10 @@ public class AlignFrame AlignFrame af = new AlignFrame(alignment); String newtitle = new String("Copied sequences"); + //>>>This is a fix for the moment, until a better solution is found!!<<< + FeatureRenderer fr = af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer(); + fr.featureColours = alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours; + if (title.startsWith("Copied sequences")) { newtitle = title; @@ -810,24 +794,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); @@ -902,12 +912,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.idPanel.idCanvas.searchResults = null; - alignPanel.annotationPanel.activeRes = null; PaintRefresher.Refresh(null, viewport.alignment); } @@ -1125,7 +1139,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(); @@ -1187,8 +1204,11 @@ public class AlignFrame { addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, HistoryItem.HIDE)); - if (viewport.getAlignment().padGaps()) - alignmentChanged(); + + viewport.padGaps = padGapsMenuitem.isSelected(); + + // if (viewport.padGaps) + alignmentChanged(); } /** @@ -1201,8 +1221,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); } /** @@ -1329,25 +1349,37 @@ public class AlignFrame alignPanel.repaint(); } + public void fetchSeqFeatures_actionPerformed(ActionEvent e) + { + if (!viewport.alignment.isNucleotide()) + { + new SequenceFeatureFetcher(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(); } /** @@ -1907,6 +1939,13 @@ public class AlignFrame new PCAPanel(viewport); } + + public void autoCalculate_actionPerformed(ActionEvent e) + { + viewport.autoCalculateConsensus = autoCalculate.isSelected(); + } + + /** * DOCUMENT ME! * @@ -1956,7 +1995,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)) @@ -2008,7 +2047,6 @@ public class AlignFrame } addTreeMenuItem(tp, title); - viewport.setCurrentTree(tp.getTree()); Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500); } @@ -2425,10 +2463,7 @@ public class AlignFrame } }*/ - public void featureSettings_actionPerformed(ActionEvent e) - { - new FeatureSettings(viewport, alignPanel); - } + @@ -2445,6 +2480,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); @@ -2546,16 +2583,18 @@ public void showTranslation_actionPerformed(ActionEvent e) */ public boolean parseGroupsFile(String file) { + String line = null; try { BufferedReader in = new BufferedReader(new FileReader(file)); SequenceI seq = null; - String line, type, desc, token; + String type, desc, token; int index, start, end; StringTokenizer st; SequenceFeature sf; int lineNo = 0; + String featureGroup = null; while ( (line = in.readLine()) != null) { lineNo++; @@ -2563,8 +2602,23 @@ public boolean parseGroupsFile(String file) if (st.countTokens() == 2) { type = st.nextToken(); - UserColourScheme ucs = new UserColourScheme(st.nextToken()); - alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(type, ucs.findColour("A")); + if (type.equalsIgnoreCase("startgroup")) + { + featureGroup = st.nextToken(); + } + else if (type.equalsIgnoreCase("endgroup")) + { + //We should check whether this is the current group, + //but at present theres no way of showing more than 1 group + st.nextToken(); + featureGroup = null; + } + else + { + UserColourScheme ucs = new UserColourScheme(st.nextToken()); + alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(type, + ucs.findColour("A")); + } continue; } @@ -2586,8 +2640,6 @@ public boolean parseGroupsFile(String file) end = Integer.parseInt(st.nextToken()); seq = viewport.alignment.getSequenceAt(index); - start = seq.findIndex(start) - 1; - end = seq.findIndex(end) - 1; type = st.nextToken(); @@ -2598,7 +2650,7 @@ public boolean parseGroupsFile(String file) alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(type, ucs.findColour("A")); } - sf = new SequenceFeature(type, desc, "", start, end); + sf = new SequenceFeature(type, desc, "", start, end, featureGroup); seq.getDatasetSequence().addSequenceFeature(sf); } @@ -2606,11 +2658,14 @@ public boolean parseGroupsFile(String file) } catch (Exception ex) { - System.out.println("Error parsing groups file: " + ex); + System.out.println(line); + ex.printStackTrace(); + System.out.println("Error parsing groups file: " + ex +"\n"+line); return false; } viewport.showSequenceFeatures = true; + showSeqFeatures.setSelected(true); alignPanel.repaint(); return true; } @@ -2669,57 +2724,68 @@ public void drop(DropTargetDropEvent evt) { e.printStackTrace(); } - if (files != null) { try { - boolean isAnnotation = false; for (int i = 0; i < files.size(); i++) { - String file = files.get(i).toString(); - - isAnnotation = new AnnotationReader().readAnnotationFile(viewport.alignment, file); - - if( !isAnnotation ) - { - boolean isGroupsFile = parseGroupsFile(file); - if (!isGroupsFile) - { - String protocol = "File"; - String format = jalview.io.IdentifyFile.Identify(file, protocol); - SequenceI[] sequences = new FormatAdapter().readFile(file, protocol, format); - - FastaFile ff = new FastaFile(); - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - c.setContents(new StringSelection(ff.print(sequences)), this); - - this.paste(false); - - } - } + loadJalviewDataFile(files.get(i).toString()); } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } +} + + // This method will attempt to load a "dropped" file first by testing + // whether its and Annotation file, then features file. If both are + // false then the user may have dropped an alignment file onto this + // AlignFrame + public void loadJalviewDataFile(String file) + { + try{ + boolean isAnnotation = new AnnotationReader().readAnnotationFile(viewport. + alignment, file); - if(isAnnotation) + if (!isAnnotation) + { + boolean isGroupsFile = parseGroupsFile(file); + if (!isGroupsFile) { - int height = alignPanel.annotationPanel.adjustPanelHeight(); - alignPanel.annotationScroller.setPreferredSize( - new Dimension(alignPanel.annotationScroller.getWidth(), - height)); + String protocol = "File"; + String format = new IdentifyFile().Identify(file, protocol); + SequenceI[] sequences = new FormatAdapter().readFile(file, protocol, + format); - alignPanel.annotationSpaceFillerHolder.setPreferredSize(new Dimension( - alignPanel.annotationSpaceFillerHolder.getWidth(), - height)); + FastaFile ff = new FastaFile(); + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + c.setContents(new StringSelection(ff.print(sequences)), this); - alignPanel.addNotify(); + this.paste(false); } } - catch (Exception ex) + + if (isAnnotation) { - ex.printStackTrace(); + int height = alignPanel.annotationPanel.adjustPanelHeight(); + alignPanel.annotationScroller.setPreferredSize( + new Dimension(alignPanel.annotationScroller.getWidth(), + height)); + + alignPanel.annotationSpaceFillerHolder.setPreferredSize(new Dimension( + alignPanel.annotationSpaceFillerHolder.getWidth(), + height)); + + alignPanel.addNotify(); } - } -} + }catch(Exception ex) + { + ex.printStackTrace(); + } + } }