2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 java.awt.Container;
42 import java.awt.Dimension;
44 import java.awt.Rectangle;
45 import java.util.ArrayList;
46 import java.util.Hashtable;
47 import java.util.List;
49 import java.util.Vector;
51 import javax.swing.JInternalFrame;
52 import javax.swing.JOptionPane;
54 import jalview.analysis.AlignmentUtils;
55 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
56 import jalview.analysis.NJTree;
57 import jalview.api.AlignViewportI;
58 import jalview.api.ViewStyleI;
59 import jalview.bin.Cache;
60 import jalview.commands.CommandI;
61 import jalview.datamodel.AlignedCodonFrame;
62 import jalview.datamodel.Alignment;
63 import jalview.datamodel.AlignmentI;
64 import jalview.datamodel.ColumnSelection;
65 import jalview.datamodel.HiddenSequences;
66 import jalview.datamodel.PDBEntry;
67 import jalview.datamodel.SearchResults;
68 import jalview.datamodel.Sequence;
69 import jalview.datamodel.SequenceGroup;
70 import jalview.datamodel.SequenceI;
71 import jalview.schemes.ColourSchemeProperty;
72 import jalview.schemes.UserColourScheme;
73 import jalview.structure.CommandListener;
74 import jalview.structure.SelectionSource;
75 import jalview.structure.StructureSelectionManager;
76 import jalview.structure.VamsasSource;
77 import jalview.util.Comparison;
78 import jalview.util.MappingUtils;
79 import jalview.util.MessageManager;
80 import jalview.viewmodel.AlignmentViewport;
81 import jalview.ws.params.AutoCalcSetting;
87 * @version $Revision: 1.141 $
89 public class AlignViewport extends AlignmentViewport implements
90 SelectionSource, AlignViewportI, CommandListener
102 NJTree currentTree = null;
104 boolean cursorMode = false;
106 boolean antiAlias = false;
108 private Rectangle explodedGeometry;
113 * Flag set true on the view that should 'gather' multiple views of the same
114 * sequence set id when a project is reloaded. Set false on all views when
115 * they are 'exploded' into separate windows. Set true on the current view
116 * when 'Gather' is performed, and also on the first tab when the first new
119 private boolean gatherViewsHere = false;
121 private AnnotationColumnChooser annotationColumnSelectionState;
123 * Creates a new AlignViewport object.
128 public AlignViewport(AlignmentI al)
135 * Create a new AlignViewport object with a specific sequence set ID
139 * (may be null - but potential for ambiguous constructor exception)
141 public AlignViewport(AlignmentI al, String seqsetid)
143 this(al, seqsetid, null);
146 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
148 sequenceSetID = seqsetid;
150 // TODO remove these once 2.4.VAMSAS release finished
151 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
153 Cache.log.debug("Setting viewport's sequence set id : "
156 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
158 Cache.log.debug("Setting viewport's view id : " + viewId);
165 * Create a new AlignViewport with hidden regions
169 * @param hiddenColumns
172 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
175 if (hiddenColumns != null)
177 colSel = hiddenColumns;
183 * New viewport with hidden columns and an existing sequence set id
186 * @param hiddenColumns
190 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
193 this(al, hiddenColumns, seqsetid, null);
197 * New viewport with hidden columns and an existing sequence set id and viewid
200 * @param hiddenColumns
206 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
207 String seqsetid, String viewid)
209 sequenceSetID = seqsetid;
211 // TODO remove these once 2.4.VAMSAS release finished
212 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
214 Cache.log.debug("Setting viewport's sequence set id : "
217 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
219 Cache.log.debug("Setting viewport's view id : " + viewId);
222 if (hiddenColumns != null)
224 colSel = hiddenColumns;
230 * Apply any settings saved in user preferences
232 private void applyViewProperties()
234 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
236 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
237 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
239 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
240 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
241 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
243 setPadGaps(Cache.getDefault("PAD_GAPS", true));
244 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
245 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
246 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
247 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
248 viewStyle.setShowUnconserved(Cache
249 .getDefault("SHOW_UNCONSERVED", false));
250 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
251 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
252 sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
253 Preferences.SORT_ANNOTATIONS,
254 SequenceAnnotationOrder.NONE.name()));
255 showAutocalculatedAbove = Cache.getDefault(
256 Preferences.SHOW_AUTOCALC_ABOVE, false);
257 viewStyle.setScaleProteinAsCdna(Cache.getDefault(
258 Preferences.SCALE_PROTEIN_TO_CDNA, false));
264 this.endRes = alignment.getWidth() - 1;
266 this.endSeq = alignment.getHeight() - 1;
267 applyViewProperties();
269 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
270 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
271 String fontSize = Cache.getDefault("FONT_SIZE", "10");
275 if (fontStyle.equals("bold"))
279 else if (fontStyle.equals("italic"))
284 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
287 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
289 // We must set conservation and consensus before setting colour,
290 // as Blosum and Clustal require this to be done
291 if (hconsensus == null && !isDataset)
293 if (!alignment.isNucleotide())
295 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
296 showQuality = Cache.getDefault("SHOW_QUALITY", true);
297 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
300 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
302 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
303 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
305 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
306 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
308 initAutoAnnotation();
309 String colourProperty = alignment.isNucleotide() ? Preferences.DEFAULT_COLOUR_NUC
310 : Preferences.DEFAULT_COLOUR_PROT;
311 String propertyValue = Cache.getProperty(colourProperty);
312 if (propertyValue == null)
314 // fall back on this property for backwards compatibility
315 propertyValue = Cache.getProperty(Preferences.DEFAULT_COLOUR);
317 if (propertyValue != null)
319 globalColourScheme = ColourSchemeProperty.getColour(alignment,
322 if (globalColourScheme instanceof UserColourScheme)
324 globalColourScheme = UserDefinedColours.loadDefaultColours();
325 ((UserColourScheme) globalColourScheme).setThreshold(0,
326 isIgnoreGapsConsensus());
329 if (globalColourScheme != null)
331 globalColourScheme.setConsensus(hconsensus);
337 * get the consensus sequence as displayed under the PID consensus annotation
340 * @return consensus sequence as a new sequence object
342 public SequenceI getConsensusSeq()
344 if (consensus == null)
346 updateConsensus(null);
348 if (consensus == null)
352 StringBuffer seqs = new StringBuffer();
353 for (int i = 0; i < consensus.annotations.length; i++)
355 if (consensus.annotations[i] != null)
357 if (consensus.annotations[i].description.charAt(0) == '[')
359 seqs.append(consensus.annotations[i].description.charAt(1));
363 seqs.append(consensus.annotations[i].displayCharacter);
368 SequenceI sq = new Sequence("Consensus", seqs.toString());
369 sq.setDescription("Percentage Identity Consensus "
370 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
377 * @return DOCUMENT ME!
379 public int getStartRes()
387 * @return DOCUMENT ME!
389 public int getEndRes()
397 * @return DOCUMENT ME!
399 public int getStartSeq()
410 public void setStartRes(int res)
421 public void setStartSeq(int seq)
432 public void setEndRes(int res)
434 if (res > (alignment.getWidth() - 1))
436 // log.System.out.println(" Corrected res from " + res + " to maximum " +
437 // (alignment.getWidth()-1));
438 res = alignment.getWidth() - 1;
455 public void setEndSeq(int seq)
457 if (seq > alignment.getHeight())
459 seq = alignment.getHeight();
473 * @return DOCUMENT ME!
475 public int getEndSeq()
480 boolean validCharWidth;
483 * update view settings with the given font. You may need to call
484 * alignPanel.fontChanged to update the layout geometry
487 * when true, charWidth/height is set according to font mentrics
489 public void setFont(Font f, boolean setGrid)
493 Container c = new Container();
495 java.awt.FontMetrics fm = c.getFontMetrics(font);
496 int w = viewStyle.getCharWidth(), ww = fm.charWidth('M'), h = viewStyle
500 setCharHeight(fm.getHeight());
503 viewStyle.setFontName(font.getName());
504 viewStyle.setFontStyle(font.getStyle());
505 viewStyle.setFontSize(font.getSize());
507 validCharWidth = true;
511 public void setViewStyle(ViewStyleI settingsForView)
513 super.setViewStyle(settingsForView);
514 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
515 viewStyle.getFontSize()), false);
521 * @return DOCUMENT ME!
523 public Font getFont()
534 public void setAlignment(AlignmentI align)
536 if (alignment != null && alignment.getCodonFrames() != null)
538 StructureSelectionManager.getStructureSelectionManager(
539 Desktop.instance).removeMappings(alignment.getCodonFrames());
541 this.alignment = align;
542 if (alignment != null && alignment.getCodonFrames() != null)
544 StructureSelectionManager.getStructureSelectionManager(
545 Desktop.instance).addMappings(alignment.getCodonFrames());
552 * @return DOCUMENT ME!
554 public char getGapCharacter()
556 return getAlignment().getGapCharacter();
565 public void setGapCharacter(char gap)
567 if (getAlignment() != null)
569 getAlignment().setGapCharacter(gap);
576 * @return DOCUMENT ME!
578 public ColumnSelection getColumnSelection()
589 public void setCurrentTree(NJTree tree)
597 * @return DOCUMENT ME!
599 public NJTree getCurrentTree()
605 * returns the visible column regions of the alignment
607 * @param selectedRegionOnly
608 * true to just return the contigs intersecting with the selected
612 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
614 int[] viscontigs = null;
615 int start = 0, end = 0;
616 if (selectedRegionOnly && selectionGroup != null)
618 start = selectionGroup.getStartRes();
619 end = selectionGroup.getEndRes() + 1;
623 end = alignment.getWidth();
625 viscontigs = colSel.getVisibleContigs(start, end);
630 * get hash of undo and redo list for the alignment
632 * @return long[] { historyList.hashCode, redoList.hashCode };
634 public long[] getUndoRedoHash()
637 if (historyList == null || redoList == null)
643 { historyList.hashCode(), this.redoList.hashCode() };
647 * test if a particular set of hashcodes are different to the hashcodes for
648 * the undo and redo list.
651 * the stored set of hashcodes as returned by getUndoRedoHash
652 * @return true if the hashcodes differ (ie the alignment has been edited) or
653 * the stored hashcode array differs in size
655 public boolean isUndoRedoHashModified(long[] undoredo)
657 if (undoredo == null)
661 long[] cstate = getUndoRedoHash();
662 if (cstate.length != undoredo.length)
667 for (int i = 0; i < cstate.length; i++)
669 if (cstate[i] != undoredo[i])
678 * when set, view will scroll to show the highlighted position
680 public boolean followHighlight = true;
683 * @return true if view should scroll to show the highlighted region of a
687 public boolean getFollowHighlight()
689 return followHighlight;
692 public boolean followSelection = true;
695 * @return true if view selection should always follow the selections
696 * broadcast by other selection sources
698 public boolean getFollowSelection()
700 return followSelection;
704 * Send the current selection to be broadcast to any selection listeners.
706 public void sendSelection()
708 jalview.structure.StructureSelectionManager
709 .getStructureSelectionManager(Desktop.instance).sendSelection(
710 new SequenceGroup(getSelectionGroup()),
711 new ColumnSelection(getColumnSelection()), this);
715 * return the alignPanel containing the given viewport. Use this to get the
716 * components currently handling the given viewport.
719 * @return null or an alignPanel guaranteed to have non-null alignFrame
722 public AlignmentPanel getAlignPanel()
724 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
725 .getSequenceSetId());
726 for (int p = 0; aps != null && p < aps.length; p++)
728 if (aps[p].av == this)
736 public boolean getSortByTree()
741 public void setSortByTree(boolean sort)
747 * synthesize a column selection if none exists so it covers the given
748 * selection group. if wholewidth is false, no column selection is made if the
749 * selection group covers the whole alignment width.
754 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
758 && (sgs = sg.getStartRes()) >= 0
759 && sg.getStartRes() <= (sge = sg.getEndRes())
760 && (colSel == null || colSel.getSelected() == null || colSel
761 .getSelected().size() == 0))
763 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
770 colSel = new ColumnSelection();
772 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
774 colSel.addElement(cspos);
780 * Returns the (Desktop) instance of the StructureSelectionManager
783 public StructureSelectionManager getStructureSelectionManager()
785 return StructureSelectionManager
786 .getStructureSelectionManager(Desktop.instance);
792 * @return a series of SequenceI arrays, one for each PDBEntry, listing which
793 * sequence in the alignment holds a reference to it
795 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
797 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
798 for (PDBEntry pdb : pdbEntries)
800 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
801 for (int i = 0; i < alignment.getHeight(); i++)
803 Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
810 for (int p = 0; p < pdbs.size(); p++)
812 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
813 if (p1.getId().equals(pdb.getId()))
815 if (!seqs.contains(sq = alignment.getSequenceAt(i)))
824 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
826 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
829 public boolean isNormaliseSequenceLogo()
831 return normaliseSequenceLogo;
834 public void setNormaliseSequenceLogo(boolean state)
836 normaliseSequenceLogo = state;
841 * @return true if alignment characters should be displayed
843 public boolean isValidCharWidth()
845 return validCharWidth;
848 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
850 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
852 return calcIdParams.get(calcId);
855 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
858 calcIdParams.put(calcId, settings);
859 // TODO: create a restart list to trigger any calculations that need to be
860 // restarted after load
861 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
864 Cache.log.debug("trigger update for " + calcId);
869 * Method called when another alignment's edit (or possibly other) command is
872 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
873 * 'unwind' the command on the source sequences (in simulation, not in fact),
874 * and then for each edit in turn:
876 * <li>compute the equivalent edit on the mapped sequences</li>
877 * <li>apply the mapped edit</li>
878 * <li>'apply' the source edit to the working copy of the source sequences</li>
886 public void mirrorCommand(CommandI command, boolean undo,
887 StructureSelectionManager ssm, VamsasSource source)
890 * Do nothing unless we are a 'complement' of the source. May replace this
891 * with direct calls not via SSM.
893 if (source instanceof AlignViewportI
894 && ((AlignViewportI) source).getCodingComplement() == this)
903 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
905 if (mappedCommand != null)
907 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
908 mappedCommand.doCommand(views);
909 getAlignPanel().alignmentChanged();
914 * Add the sequences from the given alignment to this viewport. Optionally,
915 * may give the user the option to open a new frame, or split panel, with cDNA
916 * and protein linked.
921 public void addAlignment(AlignmentI al, String title)
923 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
925 // JBPComment: title is a largely redundant parameter at the moment
926 // JBPComment: this really should be an 'insert/pre/append' controller
927 // JBPComment: but the DNA/Protein check makes it a bit more complex
929 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
931 // TODO: create undo object for this JAL-1101
934 * If one alignment is protein and one nucleotide, with at least one
935 * sequence name in common, offer to open a linked alignment.
937 if (AlignmentUtils.isMappable(al, getAlignment()))
939 if (openLinkedAlignment(al, title))
944 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
945 // provenance) should share the same dataset sequence
947 for (int i = 0; i < al.getHeight(); i++)
949 getAlignment().addSequence(al.getSequenceAt(i));
951 // TODO this call was done by SequenceFetcher but not FileLoader or
952 // CutAndPasteTransfer. Is it needed?
953 // JBPComment: this repositions the view to show the new sequences
954 // JBPComment: so it is needed for UX
955 setEndSeq(getAlignment().getHeight());
956 firePropertyChange("alignment", null, getAlignment().getSequences());
960 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
961 * alignment. Returns true if the new alignment was opened, false if not,
962 * because the user declined the offer.
966 protected boolean openLinkedAlignment(AlignmentI al, String title)
968 String[] options = new String[]
969 { MessageManager.getString("action.no"),
970 MessageManager.getString("label.split_window"),
971 MessageManager.getString("label.new_window"), };
972 final String question = JvSwingUtils.wrapTooltip(true,
973 MessageManager.getString("label.open_split_window?"));
974 int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
975 MessageManager.getString("label.open_split_window"),
976 JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
977 options, options[0]);
979 if (response != 1 && response != 2)
983 final boolean openSplitPane = (response == 1);
984 final boolean openInNewWindow = (response == 2);
987 * Create the AlignFrame first (which creates the new alignment's datasets),
988 * before attempting sequence mapping.
990 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
991 AlignFrame.DEFAULT_HEIGHT);
992 newAlignFrame.setTitle(title);
995 * Identify protein and dna alignments. Make a copy of this one if opening
996 * in a new split pane.
998 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
1000 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
1001 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
1003 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1004 "label.successfully_loaded_file", new Object[]
1007 // TODO if we want this (e.g. to enable reload of the alignment from file),
1008 // we will need to add parameters to the stack.
1009 // if (!protocol.equals(AppletFormatAdapter.PASTE))
1011 // alignFrame.setFileName(file, format);
1014 if (openInNewWindow)
1016 Desktop.addInternalFrame(newAlignFrame, title,
1017 AlignFrame.DEFAULT_WIDTH,
1018 AlignFrame.DEFAULT_HEIGHT);
1022 * Map sequences. At least one should get mapped as we have already passed
1023 * the test for 'mappability'. Any mappings made will be added to the
1024 * protein alignment.
1026 AlignmentUtils.mapProteinToCdna(protein, cdna);
1030 newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
1033 } catch (java.beans.PropertyVetoException ex)
1039 protein = openSplitFrame(newAlignFrame, thisAlignment,
1040 protein.getCodonFrames());
1044 * Register the mappings (held on the protein alignment) with the
1045 * StructureSelectionManager (for mouseover linking).
1047 final StructureSelectionManager ssm = StructureSelectionManager
1048 .getStructureSelectionManager(Desktop.instance);
1049 ssm.addMappings(protein.getCodonFrames());
1055 * Helper method to open a new SplitFrame holding linked dna and protein
1058 * @param newAlignFrame
1059 * containing a new alignment to be shown
1061 * cdna/protein complement alignment to show in the other split half
1063 * @return the protein alignment in the split frame
1065 protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
1066 AlignmentI complement, Set<AlignedCodonFrame> mappings)
1069 * Open in split pane. DNA sequence above, protein below.
1071 AlignFrame copyMe = new AlignFrame(complement,
1072 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1073 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
1075 AlignmentI al = newAlignFrame.viewport.getAlignment();
1076 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
1078 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
1080 AlignmentI protein = proteinFrame.viewport.getAlignment();
1081 protein.setCodonFrames(mappings);
1083 cdnaFrame.setVisible(true);
1084 proteinFrame.setVisible(true);
1085 String linkedTitle = MessageManager
1086 .getString("label.linked_view_title");
1087 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
1088 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
1093 public AnnotationColumnChooser getAnnotationColumnSelectionState()
1095 return annotationColumnSelectionState;
1098 public void setAnnotationColumnSelectionState(
1099 AnnotationColumnChooser currentAnnotationColumnSelectionState)
1101 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
1105 public void setIdWidth(int i)
1107 super.setIdWidth(i);
1108 AlignmentPanel ap = getAlignPanel();
1111 // modify GUI elements to reflect geometry change
1112 Dimension idw = getAlignPanel().getIdPanel().getIdCanvas()
1113 .getPreferredSize();
1115 getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);
1119 public Rectangle getExplodedGeometry()
1121 return explodedGeometry;
1124 public void setExplodedGeometry(Rectangle explodedPosition)
1126 this.explodedGeometry = explodedPosition;
1129 public boolean isGatherViewsHere()
1131 return gatherViewsHere;
1134 public void setGatherViewsHere(boolean gatherViewsHere)
1136 this.gatherViewsHere = gatherViewsHere;
1140 * If this viewport has a (Protein/cDNA) complement, then scroll the
1141 * complementary alignment to match this one.
1144 * true for horizontal scroll event, false for vertical
1146 public void scrollComplementaryAlignment(boolean horizontal)
1149 * If no complement, or it is not following scrolling, do nothing.
1151 // TODO pull up followHighlight to AlignmentViewport/AlignViewportI
1152 final AlignViewport codingComplement = (AlignViewport) getCodingComplement();
1153 if (codingComplement == null || !codingComplement.followHighlight)
1157 boolean iAmProtein = !getAlignment().isNucleotide();
1158 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
1159 : codingComplement.getAlignment();
1160 if (proteinAlignment == null)
1164 final Set<AlignedCodonFrame> mappings = proteinAlignment
1168 * Heuristic: find the first mapped sequence (if any) with a non-gapped
1169 * residue in the middle column of the visible region. Scroll the
1170 * complementary alignment to line up the corresponding residue.
1173 SequenceI sequence = null;
1174 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
1175 final HiddenSequences hiddenSequences = getAlignment()
1176 .getHiddenSequences();
1177 for (int seqNo = getStartSeq(); seqNo < getEndSeq(); seqNo++, seqOffset++)
1179 sequence = getAlignment().getSequenceAt(seqNo);
1180 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
1184 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
1188 List<AlignedCodonFrame> seqMappings = MappingUtils
1189 .findMappingsForSequence(sequence, mappings);
1190 if (!seqMappings.isEmpty())
1196 if (sequence == null)
1199 * No ungapped mapped sequence in middle column - do nothing
1203 SearchResults sr = MappingUtils.buildSearchResults(sequence,
1204 sequence.findPosition(middleColumn), mappings);
1205 codingComplement.getAlignPanel().scrollAsComplement(sr, seqOffset,