2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 * Jalview - A Sequence Alignment Editor and Viewer
23 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version 2
28 * of the License, or (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
41 import jalview.analysis.AlignmentUtils;
42 import jalview.analysis.AlignmentUtils.MappingResult;
43 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
44 import jalview.analysis.NJTree;
45 import jalview.api.AlignViewportI;
46 import jalview.api.ViewStyleI;
47 import jalview.bin.Cache;
48 import jalview.commands.CommandI;
49 import jalview.datamodel.Alignment;
50 import jalview.datamodel.AlignmentI;
51 import jalview.datamodel.ColumnSelection;
52 import jalview.datamodel.PDBEntry;
53 import jalview.datamodel.Sequence;
54 import jalview.datamodel.SequenceGroup;
55 import jalview.datamodel.SequenceI;
56 import jalview.schemes.ColourSchemeProperty;
57 import jalview.schemes.UserColourScheme;
58 import jalview.structure.CommandListener;
59 import jalview.structure.SelectionSource;
60 import jalview.structure.StructureSelectionManager;
61 import jalview.structure.VamsasSource;
62 import jalview.util.MessageManager;
63 import jalview.util.StringUtils;
64 import jalview.viewmodel.AlignmentViewport;
65 import jalview.ws.params.AutoCalcSetting;
67 import java.awt.Container;
68 import java.awt.Dimension;
70 import java.awt.Rectangle;
72 import java.util.ArrayDeque;
73 import java.util.ArrayList;
74 import java.util.Deque;
75 import java.util.Hashtable;
77 import java.util.Vector;
79 import javax.swing.JInternalFrame;
80 import javax.swing.JOptionPane;
86 * @version $Revision: 1.141 $
88 public class AlignViewport extends AlignmentViewport implements
89 SelectionSource, VamsasSource, AlignViewportI, CommandListener
100 SequenceAnnotationOrder sortAnnotationsBy = null;
104 NJTree currentTree = null;
106 boolean cursorMode = false;
108 boolean antiAlias = false;
110 Rectangle explodedPosition;
114 boolean gatherViewsHere = false;
116 private Deque<CommandI> historyList = new ArrayDeque<CommandI>();
118 private Deque<CommandI> redoList = new ArrayDeque<CommandI>();
120 private AnnotationColumnChooser annotationColumnSelectionState;
122 * Creates a new AlignViewport object.
127 public AlignViewport(AlignmentI al)
134 * Create a new AlignViewport object with a specific sequence set ID
138 * (may be null - but potential for ambiguous constructor exception)
140 public AlignViewport(AlignmentI al, String seqsetid)
142 this(al, seqsetid, null);
145 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
147 sequenceSetID = seqsetid;
149 // TODO remove these once 2.4.VAMSAS release finished
150 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
152 Cache.log.debug("Setting viewport's sequence set id : "
155 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
157 Cache.log.debug("Setting viewport's view id : " + viewId);
164 * Create a new AlignViewport with hidden regions
168 * @param hiddenColumns
171 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
174 if (hiddenColumns != null)
176 colSel = hiddenColumns;
182 * New viewport with hidden columns and an existing sequence set id
185 * @param hiddenColumns
189 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
192 this(al, hiddenColumns, seqsetid, null);
196 * New viewport with hidden columns and an existing sequence set id and viewid
199 * @param hiddenColumns
205 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
206 String seqsetid, String viewid)
208 sequenceSetID = seqsetid;
210 // TODO remove these once 2.4.VAMSAS release finished
211 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
213 Cache.log.debug("Setting viewport's sequence set id : "
216 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
218 Cache.log.debug("Setting viewport's view id : " + viewId);
221 if (hiddenColumns != null)
223 colSel = hiddenColumns;
228 private void applyViewProperties()
230 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
232 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
233 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
235 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
236 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
237 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
239 setPadGaps(Cache.getDefault("PAD_GAPS", true));
240 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
241 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
242 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
243 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
244 viewStyle.setShowUnconserved(Cache
245 .getDefault("SHOW_UNCONSERVED", false));
246 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
247 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
248 sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
249 Preferences.SORT_ANNOTATIONS,
250 SequenceAnnotationOrder.NONE.name()));
251 showAutocalculatedAbove = Cache.getDefault(
252 Preferences.SHOW_AUTOCALC_ABOVE, false);
259 this.endRes = alignment.getWidth() - 1;
261 this.endSeq = alignment.getHeight() - 1;
262 applyViewProperties();
264 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
265 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
266 String fontSize = Cache.getDefault("FONT_SIZE", "10");
270 if (fontStyle.equals("bold"))
274 else if (fontStyle.equals("italic"))
279 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
282 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
284 // We must set conservation and consensus before setting colour,
285 // as Blosum and Clustal require this to be done
286 if (hconsensus == null && !isDataset)
288 if (!alignment.isNucleotide())
290 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
291 showQuality = Cache.getDefault("SHOW_QUALITY", true);
292 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
295 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
297 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
298 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
300 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
301 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
303 initAutoAnnotation();
304 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
306 globalColourScheme = ColourSchemeProperty.getColour(alignment,
307 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
309 if (globalColourScheme instanceof UserColourScheme)
311 globalColourScheme = UserDefinedColours.loadDefaultColours();
312 ((UserColourScheme) globalColourScheme).setThreshold(0,
313 isIgnoreGapsConsensus());
316 if (globalColourScheme != null)
318 globalColourScheme.setConsensus(hconsensus);
324 * get the consensus sequence as displayed under the PID consensus annotation
327 * @return consensus sequence as a new sequence object
329 public SequenceI getConsensusSeq()
331 if (consensus == null)
333 updateConsensus(null);
335 if (consensus == null)
339 StringBuffer seqs = new StringBuffer();
340 for (int i = 0; i < consensus.annotations.length; i++)
342 if (consensus.annotations[i] != null)
344 if (consensus.annotations[i].description.charAt(0) == '[')
346 seqs.append(consensus.annotations[i].description.charAt(1));
350 seqs.append(consensus.annotations[i].displayCharacter);
355 SequenceI sq = new Sequence("Consensus", seqs.toString());
356 sq.setDescription("Percentage Identity Consensus "
357 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
364 * @return DOCUMENT ME!
366 public int getStartRes()
374 * @return DOCUMENT ME!
376 public int getEndRes()
384 * @return DOCUMENT ME!
386 public int getStartSeq()
397 public void setStartRes(int res)
408 public void setStartSeq(int seq)
419 public void setEndRes(int res)
421 if (res > (alignment.getWidth() - 1))
423 // log.System.out.println(" Corrected res from " + res + " to maximum " +
424 // (alignment.getWidth()-1));
425 res = alignment.getWidth() - 1;
442 public void setEndSeq(int seq)
444 if (seq > alignment.getHeight())
446 seq = alignment.getHeight();
460 * @return DOCUMENT ME!
462 public int getEndSeq()
467 boolean validCharWidth;
475 public void setFont(Font f)
479 Container c = new Container();
481 java.awt.FontMetrics fm = c.getFontMetrics(font);
482 int w = viewStyle.getCharWidth(), ww = fm.charWidth('M'), h = viewStyle
484 // only update width/height if the new font won't fit
485 if (h < fm.getHeight())
487 setCharHeight(fm.getHeight());
493 viewStyle.setFontName(font.getName());
494 viewStyle.setFontStyle(font.getStyle());
495 viewStyle.setFontSize(font.getSize());
497 validCharWidth = true;
501 public void setViewStyle(ViewStyleI settingsForView)
503 super.setViewStyle(settingsForView);
504 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
505 viewStyle.getFontSize()));
511 * @return DOCUMENT ME!
513 public Font getFont()
524 public void setAlignment(AlignmentI align)
526 if (alignment != null && alignment.getCodonFrames() != null)
528 StructureSelectionManager.getStructureSelectionManager(
529 Desktop.instance).removeMappings(alignment.getCodonFrames());
531 this.alignment = align;
532 if (alignment != null && alignment.getCodonFrames() != null)
534 StructureSelectionManager.getStructureSelectionManager(
535 Desktop.instance).addMappings(alignment.getCodonFrames());
542 * @return DOCUMENT ME!
544 public char getGapCharacter()
546 return getAlignment().getGapCharacter();
555 public void setGapCharacter(char gap)
557 if (getAlignment() != null)
559 getAlignment().setGapCharacter(gap);
566 * @return DOCUMENT ME!
568 public ColumnSelection getColumnSelection()
579 public void setCurrentTree(NJTree tree)
587 * @return DOCUMENT ME!
589 public NJTree getCurrentTree()
595 * returns the visible column regions of the alignment
597 * @param selectedRegionOnly
598 * true to just return the contigs intersecting with the selected
602 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
604 int[] viscontigs = null;
605 int start = 0, end = 0;
606 if (selectedRegionOnly && selectionGroup != null)
608 start = selectionGroup.getStartRes();
609 end = selectionGroup.getEndRes() + 1;
613 end = alignment.getWidth();
615 viscontigs = colSel.getVisibleContigs(start, end);
620 * get hash of undo and redo list for the alignment
622 * @return long[] { historyList.hashCode, redoList.hashCode };
624 public long[] getUndoRedoHash()
627 if (historyList == null || redoList == null)
633 { historyList.hashCode(), this.redoList.hashCode() };
637 * test if a particular set of hashcodes are different to the hashcodes for
638 * the undo and redo list.
641 * the stored set of hashcodes as returned by getUndoRedoHash
642 * @return true if the hashcodes differ (ie the alignment has been edited) or
643 * the stored hashcode array differs in size
645 public boolean isUndoRedoHashModified(long[] undoredo)
647 if (undoredo == null)
651 long[] cstate = getUndoRedoHash();
652 if (cstate.length != undoredo.length)
657 for (int i = 0; i < cstate.length; i++)
659 if (cstate[i] != undoredo[i])
668 * when set, view will scroll to show the highlighted position
670 public boolean followHighlight = true;
673 * @return true if view should scroll to show the highlighted region of a
677 public boolean getFollowHighlight()
679 return followHighlight;
682 public boolean followSelection = true;
685 * @return true if view selection should always follow the selections
686 * broadcast by other selection sources
688 public boolean getFollowSelection()
690 return followSelection;
694 * Send the current selection to be broadcast to any selection listeners.
696 public void sendSelection()
698 jalview.structure.StructureSelectionManager
699 .getStructureSelectionManager(Desktop.instance).sendSelection(
700 new SequenceGroup(getSelectionGroup()),
701 new ColumnSelection(getColumnSelection()), this);
705 * return the alignPanel containing the given viewport. Use this to get the
706 * components currently handling the given viewport.
709 * @return null or an alignPanel guaranteed to have non-null alignFrame
712 public AlignmentPanel getAlignPanel()
714 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
715 .getSequenceSetId());
716 for (int p = 0; aps != null && p < aps.length; p++)
718 if (aps[p].av == this)
726 public boolean getSortByTree()
731 public void setSortByTree(boolean sort)
737 * synthesize a column selection if none exists so it covers the given
738 * selection group. if wholewidth is false, no column selection is made if the
739 * selection group covers the whole alignment width.
744 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
748 && (sgs = sg.getStartRes()) >= 0
749 && sg.getStartRes() <= (sge = sg.getEndRes())
750 && (colSel == null || colSel.getSelected() == null || colSel
751 .getSelected().size() == 0))
753 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
760 colSel = new ColumnSelection();
762 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
764 colSel.addElement(cspos);
769 public StructureSelectionManager getStructureSelectionManager()
771 return StructureSelectionManager
772 .getStructureSelectionManager(Desktop.instance);
778 * @return a series of SequenceI arrays, one for each PDBEntry, listing which
779 * sequence in the alignment holds a reference to it
781 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
783 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
784 for (PDBEntry pdb : pdbEntries)
786 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
787 for (int i = 0; i < alignment.getHeight(); i++)
789 Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
796 for (int p = 0; p < pdbs.size(); p++)
798 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
799 if (p1.getId().equals(pdb.getId()))
801 if (!seqs.contains(sq = alignment.getSequenceAt(i)))
810 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
812 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
815 public boolean isNormaliseSequenceLogo()
817 return normaliseSequenceLogo;
820 public void setNormaliseSequenceLogo(boolean state)
822 normaliseSequenceLogo = state;
827 * @return true if alignment characters should be displayed
829 public boolean isValidCharWidth()
831 return validCharWidth;
834 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
836 private boolean showAutocalculatedAbove;
838 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
840 return calcIdParams.get(calcId);
843 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
846 calcIdParams.put(calcId, settings);
847 // TODO: create a restart list to trigger any calculations that need to be
848 // restarted after load
849 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
852 Cache.log.debug("trigger update for " + calcId);
856 protected SequenceAnnotationOrder getSortAnnotationsBy()
858 return sortAnnotationsBy;
861 protected void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
863 this.sortAnnotationsBy = sortAnnotationsBy;
866 protected boolean isShowAutocalculatedAbove()
868 return showAutocalculatedAbove;
871 protected void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
873 this.showAutocalculatedAbove = showAutocalculatedAbove;
877 * Method called when another alignment's edit (or possibly other) command is
880 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
881 * 'unwind' the command on the source sequences (in simulation, not in fact),
882 * and then for each edit in turn:
884 * <li>compute the equivalent edit on the mapped sequences</li>
885 * <li>apply the mapped edit</li>
886 * <li>'apply' the source edit to the working copy of the source sequences</li>
894 public void mirrorCommand(CommandI command, boolean undo,
895 StructureSelectionManager ssm, VamsasSource source)
898 * ...work in progress... do nothing unless we are a 'complement' of the
899 * source May replace this with direct calls not via SSM.
901 if (source instanceof AlignViewportI
902 && ((AlignViewportI) source).getCodingComplement() == this)
911 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
913 if (mappedCommand != null)
915 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
916 mappedCommand.doCommand(views);
917 getAlignPanel().alignmentChanged();
922 public VamsasSource getVamsasSource()
928 * Add one command to the command history list.
932 public void addToHistoryList(CommandI command)
934 if (this.historyList != null)
936 this.historyList.push(command);
937 broadcastCommand(command, false);
941 protected void broadcastCommand(CommandI command, boolean undo)
943 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
947 * Add one command to the command redo list.
951 public void addToRedoList(CommandI command)
953 if (this.redoList != null)
955 this.redoList.push(command);
957 broadcastCommand(command, true);
961 * Clear the command redo list.
963 public void clearRedoList()
965 if (this.redoList != null)
967 this.redoList.clear();
971 public void setHistoryList(Deque<CommandI> list)
973 this.historyList = list;
976 public Deque<CommandI> getHistoryList()
978 return this.historyList;
981 public void setRedoList(Deque<CommandI> list)
983 this.redoList = list;
986 public Deque<CommandI> getRedoList()
988 return this.redoList;
992 * Add the sequences from the given alignment to this viewport. Optionally,
993 * may give the user the option to open a new frame, or split panel, with cDNA
994 * and protein linked.
999 public void addAlignment(AlignmentI al, String title)
1001 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
1003 // JBPComment: title is a largely redundant parameter at the moment
1004 // JBPComment: this really should be an 'insert/pre/append' controller
1005 // JBPComment: but the DNA/Protein check makes it a bit more complex
1007 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
1009 // TODO: create undo object for this JAL-1101
1012 * If one alignment is protein and one nucleotide, with at least one
1013 * sequence name in common, offer to open a linked alignment.
1015 if (getAlignment().isNucleotide() != al.isNucleotide())
1017 // TODO: JAL-845 try a bit harder to link up imported sequences
1018 final Set<String> sequenceNames = getAlignment().getSequenceNames();
1019 sequenceNames.retainAll(al.getSequenceNames());
1020 if (!sequenceNames.isEmpty()) // at least one sequence name in both
1022 if (openLinkedAlignment(al, title))
1028 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
1029 // provenance) should share the same dataset sequence
1031 for (int i = 0; i < al.getHeight(); i++)
1033 getAlignment().addSequence(al.getSequenceAt(i));
1035 // TODO this call was done by SequenceFetcher but not FileLoader or
1036 // CutAndPasteTransfer. Is it needed?
1037 // JBPComment: this repositions the view to show the new sequences
1038 // JBPComment: so it is needed for UX
1039 setEndSeq(getAlignment().getHeight());
1040 firePropertyChange("alignment", null, getAlignment().getSequences());
1044 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
1045 * alignment. Returns true if the new alignment was opened, false if not,
1046 * because the user declined the offer.
1050 protected boolean openLinkedAlignment(AlignmentI al, String title)
1052 String[] options = new String[]
1053 { MessageManager.getString("action.no"),
1054 MessageManager.getString("label.split_window"),
1055 MessageManager.getString("label.new_window"), };
1056 final String question = JvSwingUtils.wrapTooltip(true,
1057 MessageManager.getString("label.open_linked_alignment?"));
1058 int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
1059 MessageManager.getString("label.open_linked_alignment"),
1060 JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
1061 options, options[0]);
1063 if (response != 1 && response != 2)
1067 final boolean openSplitPane = (response == 1);
1068 final boolean openInNewWindow = (response == 2);
1071 * Create the AlignFrame first (which creates the new alignment's datasets),
1072 * before attempting sequence mapping.
1074 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
1075 AlignFrame.DEFAULT_HEIGHT);
1076 newAlignFrame.setTitle(title);
1079 * Identify protein and dna alignments. Make a copy of this one if opening
1080 * in a new split pane.
1082 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
1084 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
1085 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
1087 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1088 "label.successfully_loaded_file", new Object[]
1091 // TODO if we want this (e.g. to enable reload of the alignment from file),
1092 // we will need to add parameters to the stack.
1093 // if (!protocol.equals(AppletFormatAdapter.PASTE))
1095 // alignFrame.setFileName(file, format);
1098 if (openInNewWindow)
1100 Desktop.addInternalFrame(newAlignFrame, title,
1101 AlignFrame.DEFAULT_WIDTH,
1102 AlignFrame.DEFAULT_HEIGHT);
1106 * Try to find mappings for at least one sequence. Any mappings made will be
1107 * added to the protein alignment.
1109 MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
1110 final StructureSelectionManager ssm = StructureSelectionManager
1111 .getStructureSelectionManager(Desktop.instance);
1112 if (mapped != MappingResult.Mapped)
1115 * No mapping possible - warn the user, but leave window open.
1117 final String msg = JvSwingUtils.wrapTooltip(true,
1118 MessageManager.getString("label.mapping_failed"));
1119 JOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
1120 MessageManager.getString("label.no_mappings"),
1121 JOptionPane.WARNING_MESSAGE);
1126 newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
1129 } catch (java.beans.PropertyVetoException ex)
1136 * Open in split pane. DNA sequence above, protein below.
1138 AlignFrame copyMe = new AlignFrame(thisAlignment,
1139 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1140 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
1141 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
1143 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
1145 protein = proteinFrame.viewport.getAlignment();
1147 cdnaFrame.setVisible(true);
1148 proteinFrame.setVisible(true);
1149 String sep = String.valueOf(File.separatorChar);
1150 String proteinShortName = StringUtils.getLastToken(
1151 proteinFrame.getTitle(), sep);
1152 String dnaShortName = StringUtils.getLastToken(cdnaFrame.getTitle(),
1154 String linkedTitle = MessageManager.formatMessage(
1155 "label.linked_view_title", dnaShortName, proteinShortName);
1156 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
1157 Desktop.addInternalFrame(splitFrame, linkedTitle,
1158 AlignFrame.DEFAULT_WIDTH,
1159 AlignFrame.DEFAULT_HEIGHT);
1162 * Set the frames to listen for each other's edit and sort commands.
1164 ssm.addCommandListener(cdnaFrame.getViewport());
1165 ssm.addCommandListener(proteinFrame.getViewport());
1168 * 'Coding complement' (dna/protein) views will mirror each others' edits,
1169 * selections, sorting etc as decided from time to time by the relevant
1172 proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());
1176 * Register the mappings (held on the protein alignment) with the
1177 * StructureSelectionManager (for mouseover linking).
1179 ssm.addMappings(protein.getCodonFrames());
1184 public AnnotationColumnChooser getAnnotationColumnSelectionState()
1186 return annotationColumnSelectionState;
1189 public void setAnnotationColumnSelectionState(
1190 AnnotationColumnChooser currentAnnotationColumnSelectionState)
1192 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
1196 public void setIdWidth(int i)
1198 super.setIdWidth(i);
1199 AlignmentPanel ap = getAlignPanel();
1202 // modify GUI elements to reflect geometry change
1203 Dimension idw = getAlignPanel().getIdPanel().getIdCanvas()
1204 .getPreferredSize();
1206 getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);