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.bin.Cache;
47 import jalview.commands.CommandI;
48 import jalview.datamodel.Alignment;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.ColumnSelection;
51 import jalview.datamodel.PDBEntry;
52 import jalview.datamodel.Sequence;
53 import jalview.datamodel.SequenceGroup;
54 import jalview.datamodel.SequenceI;
55 import jalview.schemes.ColourSchemeProperty;
56 import jalview.schemes.UserColourScheme;
57 import jalview.structure.CommandListener;
58 import jalview.structure.SelectionSource;
59 import jalview.structure.StructureSelectionManager;
60 import jalview.structure.VamsasSource;
61 import jalview.util.MessageManager;
62 import jalview.util.StringUtils;
63 import jalview.viewmodel.AlignmentViewport;
64 import jalview.ws.params.AutoCalcSetting;
66 import java.awt.Color;
67 import java.awt.Container;
69 import java.awt.Rectangle;
71 import java.util.ArrayDeque;
72 import java.util.ArrayList;
73 import java.util.Deque;
74 import java.util.Hashtable;
76 import java.util.Vector;
78 import javax.swing.JInternalFrame;
79 import javax.swing.JOptionPane;
85 * @version $Revision: 1.141 $
87 public class AlignViewport extends AlignmentViewport implements
88 SelectionSource, VamsasSource, AlignViewportI, CommandListener
98 boolean showJVSuffix = true;
100 boolean showText = true;
102 boolean showColourText = false;
104 boolean showBoxes = true;
106 boolean wrapAlignment = false;
108 boolean renderGaps = true;
110 SequenceAnnotationOrder sortAnnotationsBy = null;
116 boolean validCharWidth;
122 boolean seqNameItalics;
124 NJTree currentTree = null;
126 boolean scaleAboveWrapped = false;
128 boolean scaleLeftWrapped = true;
130 boolean scaleRightWrapped = true;
132 boolean showHiddenMarkers = true;
134 boolean cursorMode = false;
136 boolean antiAlias = false;
138 Rectangle explodedPosition;
142 boolean gatherViewsHere = false;
144 private Deque<CommandI> historyList = new ArrayDeque<CommandI>();
146 private Deque<CommandI> redoList = new ArrayDeque<CommandI>();
148 int thresholdTextColour = 0;
150 Color textColour = Color.black;
152 Color textColour2 = Color.white;
154 private AnnotationColumnChooser annotationColumnSelectionState;
156 * Creates a new AlignViewport object.
161 public AlignViewport(AlignmentI al)
168 * Create a new AlignViewport object with a specific sequence set ID
172 * (may be null - but potential for ambiguous constructor exception)
174 public AlignViewport(AlignmentI al, String seqsetid)
176 this(al, seqsetid, null);
179 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
181 sequenceSetID = seqsetid;
183 // TODO remove these once 2.4.VAMSAS release finished
184 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
186 Cache.log.debug("Setting viewport's sequence set id : "
189 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
191 Cache.log.debug("Setting viewport's view id : " + viewId);
198 * Create a new AlignViewport with hidden regions
202 * @param hiddenColumns
205 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
208 if (hiddenColumns != null)
210 colSel = hiddenColumns;
216 * New viewport with hidden columns and an existing sequence set id
219 * @param hiddenColumns
223 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
226 this(al, hiddenColumns, seqsetid, null);
230 * New viewport with hidden columns and an existing sequence set id and viewid
233 * @param hiddenColumns
239 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
240 String seqsetid, String viewid)
242 sequenceSetID = seqsetid;
244 // TODO remove these once 2.4.VAMSAS release finished
245 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
247 Cache.log.debug("Setting viewport's sequence set id : "
250 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
252 Cache.log.debug("Setting viewport's view id : " + viewId);
255 if (hiddenColumns != null)
257 colSel = hiddenColumns;
265 this.endRes = alignment.getWidth() - 1;
267 this.endSeq = alignment.getHeight() - 1;
269 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
271 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
272 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
274 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
275 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
276 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
278 setPadGaps(Cache.getDefault("PAD_GAPS", true));
279 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
280 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
282 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
283 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
284 String fontSize = Cache.getDefault("FONT_SIZE", "10");
286 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
290 if (fontStyle.equals("bold"))
294 else if (fontStyle.equals("italic"))
299 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
302 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
304 // We must set conservation and consensus before setting colour,
305 // as Blosum and Clustal require this to be done
306 if (hconsensus == null && !isDataset)
308 if (!alignment.isNucleotide())
310 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
311 showQuality = Cache.getDefault("SHOW_QUALITY", true);
312 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
315 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
317 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
318 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
320 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
321 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
323 initAutoAnnotation();
324 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
326 globalColourScheme = ColourSchemeProperty.getColour(alignment,
327 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
329 if (globalColourScheme instanceof UserColourScheme)
331 globalColourScheme = UserDefinedColours.loadDefaultColours();
332 ((UserColourScheme) globalColourScheme).setThreshold(0,
333 getIgnoreGapsConsensus());
336 if (globalColourScheme != null)
338 globalColourScheme.setConsensus(hconsensus);
342 wrapAlignment = Cache.getDefault("WRAP_ALIGNMENT", false);
343 showUnconserved = Cache.getDefault("SHOW_UNCONSERVED", false);
344 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
345 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
346 sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
347 Preferences.SORT_ANNOTATIONS,
348 SequenceAnnotationOrder.NONE.name()));
349 showAutocalculatedAbove = Cache.getDefault(
350 Preferences.SHOW_AUTOCALC_ABOVE, false);
354 * centre columnar annotation labels in displayed alignment annotation TODO:
355 * add to jalviewXML and annotation display settings
357 boolean centreColumnLabels = false;
359 private boolean showdbrefs;
361 private boolean shownpfeats;
363 // --------END Structure Conservation
366 * get the consensus sequence as displayed under the PID consensus annotation
369 * @return consensus sequence as a new sequence object
371 public SequenceI getConsensusSeq()
373 if (consensus == null)
375 updateConsensus(null);
377 if (consensus == null)
381 StringBuffer seqs = new StringBuffer();
382 for (int i = 0; i < consensus.annotations.length; i++)
384 if (consensus.annotations[i] != null)
386 if (consensus.annotations[i].description.charAt(0) == '[')
388 seqs.append(consensus.annotations[i].description.charAt(1));
392 seqs.append(consensus.annotations[i].displayCharacter);
397 SequenceI sq = new Sequence("Consensus", seqs.toString());
398 sq.setDescription("Percentage Identity Consensus "
399 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
406 * @return DOCUMENT ME!
408 public int getStartRes()
416 * @return DOCUMENT ME!
418 public int getEndRes()
426 * @return DOCUMENT ME!
428 public int getStartSeq()
439 public void setStartRes(int res)
450 public void setStartSeq(int seq)
461 public void setEndRes(int res)
463 if (res > (alignment.getWidth() - 1))
465 // log.System.out.println(" Corrected res from " + res + " to maximum " +
466 // (alignment.getWidth()-1));
467 res = alignment.getWidth() - 1;
484 public void setEndSeq(int seq)
486 if (seq > alignment.getHeight())
488 seq = alignment.getHeight();
502 * @return DOCUMENT ME!
504 public int getEndSeq()
515 public void setFont(Font f)
519 Container c = new Container();
521 java.awt.FontMetrics fm = c.getFontMetrics(font);
522 setCharHeight(fm.getHeight());
523 setCharWidth(fm.charWidth('M'));
524 validCharWidth = true;
530 * @return DOCUMENT ME!
532 public Font getFont()
543 public void setCharWidth(int w)
551 * @return DOCUMENT ME!
553 public int getCharWidth()
564 public void setCharHeight(int h)
572 * @return DOCUMENT ME!
574 public int getCharHeight()
585 public void setWrappedWidth(int w)
587 this.wrappedWidth = w;
593 * @return DOCUMENT ME!
595 public int getWrappedWidth()
603 * @return DOCUMENT ME!
605 public AlignmentI getAlignment()
616 public void setAlignment(AlignmentI align)
618 if (alignment != null && alignment.getCodonFrames() != null)
620 StructureSelectionManager.getStructureSelectionManager(
621 Desktop.instance).removeMappings(alignment.getCodonFrames());
623 this.alignment = align;
624 if (alignment != null && alignment.getCodonFrames() != null)
626 StructureSelectionManager.getStructureSelectionManager(
627 Desktop.instance).addMappings(alignment.getCodonFrames());
637 public void setWrapAlignment(boolean state)
639 wrapAlignment = state;
648 public void setShowText(boolean state)
659 public void setRenderGaps(boolean state)
667 * @return DOCUMENT ME!
669 public boolean getColourText()
671 return showColourText;
680 public void setColourText(boolean state)
682 showColourText = state;
691 public void setShowBoxes(boolean state)
699 * @return DOCUMENT ME!
701 public boolean getWrapAlignment()
703 return wrapAlignment;
709 * @return DOCUMENT ME!
711 public boolean getShowText()
719 * @return DOCUMENT ME!
721 public boolean getShowBoxes()
729 * @return DOCUMENT ME!
731 public char getGapCharacter()
733 return getAlignment().getGapCharacter();
742 public void setGapCharacter(char gap)
744 if (getAlignment() != null)
746 getAlignment().setGapCharacter(gap);
753 * @return DOCUMENT ME!
755 public ColumnSelection getColumnSelection()
766 public void setCurrentTree(NJTree tree)
774 * @return DOCUMENT ME!
776 public NJTree getCurrentTree()
784 * @return DOCUMENT ME!
786 public boolean getShowJVSuffix()
797 public void setShowJVSuffix(boolean b)
805 * @return DOCUMENT ME!
807 public boolean getScaleAboveWrapped()
809 return scaleAboveWrapped;
815 * @return DOCUMENT ME!
817 public boolean getScaleLeftWrapped()
819 return scaleLeftWrapped;
825 * @return DOCUMENT ME!
827 public boolean getScaleRightWrapped()
829 return scaleRightWrapped;
838 public void setScaleAboveWrapped(boolean b)
840 scaleAboveWrapped = b;
849 public void setScaleLeftWrapped(boolean b)
851 scaleLeftWrapped = b;
860 public void setScaleRightWrapped(boolean b)
862 scaleRightWrapped = b;
865 public void setDataset(boolean b)
870 public boolean isDataset()
875 public boolean getShowHiddenMarkers()
877 return showHiddenMarkers;
880 public void setShowHiddenMarkers(boolean show)
882 showHiddenMarkers = show;
886 * returns the visible column regions of the alignment
888 * @param selectedRegionOnly
889 * true to just return the contigs intersecting with the selected
893 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
895 int[] viscontigs = null;
896 int start = 0, end = 0;
897 if (selectedRegionOnly && selectionGroup != null)
899 start = selectionGroup.getStartRes();
900 end = selectionGroup.getEndRes() + 1;
904 end = alignment.getWidth();
906 viscontigs = colSel.getVisibleContigs(start, end);
911 * get hash of undo and redo list for the alignment
913 * @return long[] { historyList.hashCode, redoList.hashCode };
915 public long[] getUndoRedoHash()
918 if (historyList == null || redoList == null)
924 { historyList.hashCode(), this.redoList.hashCode() };
928 * test if a particular set of hashcodes are different to the hashcodes for
929 * the undo and redo list.
932 * the stored set of hashcodes as returned by getUndoRedoHash
933 * @return true if the hashcodes differ (ie the alignment has been edited) or
934 * the stored hashcode array differs in size
936 public boolean isUndoRedoHashModified(long[] undoredo)
938 if (undoredo == null)
942 long[] cstate = getUndoRedoHash();
943 if (cstate.length != undoredo.length)
948 for (int i = 0; i < cstate.length; i++)
950 if (cstate[i] != undoredo[i])
958 public boolean getCentreColumnLabels()
960 return centreColumnLabels;
963 public void setCentreColumnLabels(boolean centrecolumnlabels)
965 centreColumnLabels = centrecolumnlabels;
969 * enable or disable the display of Database Cross References in the sequence
972 public void setShowDbRefs(boolean show)
979 * @return true if Database References are to be displayed on tooltips.
981 public boolean isShowDbRefs()
988 * @return true if Non-positional features are to be displayed on tooltips.
990 public boolean isShowNpFeats()
996 * enable or disable the display of Non-Positional sequence features in the
997 * sequence ID tooltip
1001 public void setShowNpFeats(boolean show)
1008 * when set, view will scroll to show the highlighted position
1010 public boolean followHighlight = true;
1013 * @return true if view should scroll to show the highlighted region of a
1017 public boolean getFollowHighlight()
1019 return followHighlight;
1022 public boolean followSelection = true;
1025 * @return true if view selection should always follow the selections
1026 * broadcast by other selection sources
1028 public boolean getFollowSelection()
1030 return followSelection;
1034 * Send the current selection to be broadcast to any selection listeners.
1036 public void sendSelection()
1038 jalview.structure.StructureSelectionManager
1039 .getStructureSelectionManager(Desktop.instance).sendSelection(
1040 new SequenceGroup(getSelectionGroup()),
1041 new ColumnSelection(getColumnSelection()), this);
1045 * return the alignPanel containing the given viewport. Use this to get the
1046 * components currently handling the given viewport.
1049 * @return null or an alignPanel guaranteed to have non-null alignFrame
1052 public AlignmentPanel getAlignPanel()
1054 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
1055 .getSequenceSetId());
1056 for (int p = 0; aps != null && p < aps.length; p++)
1058 if (aps[p].av == this)
1066 public boolean getSortByTree()
1071 public void setSortByTree(boolean sort)
1077 * synthesize a column selection if none exists so it covers the given
1078 * selection group. if wholewidth is false, no column selection is made if the
1079 * selection group covers the whole alignment width.
1084 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
1088 && (sgs = sg.getStartRes()) >= 0
1089 && sg.getStartRes() <= (sge = sg.getEndRes())
1090 && (colSel == null || colSel.getSelected() == null || colSel
1091 .getSelected().size() == 0))
1093 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
1100 colSel = new ColumnSelection();
1102 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
1104 colSel.addElement(cspos);
1109 public StructureSelectionManager getStructureSelectionManager()
1111 return StructureSelectionManager
1112 .getStructureSelectionManager(Desktop.instance);
1118 * @return a series of SequenceI arrays, one for each PDBEntry, listing which
1119 * sequence in the alignment holds a reference to it
1121 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
1123 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
1124 for (PDBEntry pdb : pdbEntries)
1126 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
1127 for (int i = 0; i < alignment.getHeight(); i++)
1129 Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
1136 for (int p = 0; p < pdbs.size(); p++)
1138 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
1139 if (p1.getId().equals(pdb.getId()))
1141 if (!seqs.contains(sq = alignment.getSequenceAt(i)))
1150 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
1152 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
1155 public boolean isNormaliseSequenceLogo()
1157 return normaliseSequenceLogo;
1160 public void setNormaliseSequenceLogo(boolean state)
1162 normaliseSequenceLogo = state;
1167 * @return true if alignment characters should be displayed
1169 public boolean isValidCharWidth()
1171 return validCharWidth;
1174 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
1176 private boolean showAutocalculatedAbove;
1178 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
1180 return calcIdParams.get(calcId);
1183 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
1184 boolean needsUpdate)
1186 calcIdParams.put(calcId, settings);
1187 // TODO: create a restart list to trigger any calculations that need to be
1188 // restarted after load
1189 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
1192 Cache.log.debug("trigger update for " + calcId);
1196 protected SequenceAnnotationOrder getSortAnnotationsBy()
1198 return sortAnnotationsBy;
1201 protected void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
1203 this.sortAnnotationsBy = sortAnnotationsBy;
1206 protected boolean isShowAutocalculatedAbove()
1208 return showAutocalculatedAbove;
1211 protected void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
1213 this.showAutocalculatedAbove = showAutocalculatedAbove;
1217 * Method called when another alignment's edit (or possibly other) command is
1218 * broadcast to here.
1220 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
1221 * 'unwind' the command on the source sequences (in simulation, not in fact),
1222 * and then for each edit in turn:
1224 * <li>compute the equivalent edit on the mapped sequences</li>
1225 * <li>apply the mapped edit</li>
1226 * <li>'apply' the source edit to the working copy of the source sequences</li>
1234 public void mirrorCommand(CommandI command, boolean undo,
1235 StructureSelectionManager ssm, VamsasSource source)
1238 * ...work in progress... do nothing unless we are a 'complement' of the
1239 * source May replace this with direct calls not via SSM.
1241 if (source instanceof AlignViewportI
1242 && ((AlignViewportI) source).getCodingComplement() == this)
1251 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
1253 if (mappedCommand != null)
1255 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
1256 mappedCommand.doCommand(views);
1257 getAlignPanel().alignmentChanged();
1262 public VamsasSource getVamsasSource()
1268 * Add one command to the command history list.
1272 public void addToHistoryList(CommandI command)
1274 if (this.historyList != null)
1276 this.historyList.push(command);
1277 broadcastCommand(command, false);
1281 protected void broadcastCommand(CommandI command, boolean undo)
1283 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
1287 * Add one command to the command redo list.
1291 public void addToRedoList(CommandI command)
1293 if (this.redoList != null)
1295 this.redoList.push(command);
1297 broadcastCommand(command, true);
1301 * Clear the command redo list.
1303 public void clearRedoList()
1305 if (this.redoList != null)
1307 this.redoList.clear();
1311 public void setHistoryList(Deque<CommandI> list)
1313 this.historyList = list;
1316 public Deque<CommandI> getHistoryList()
1318 return this.historyList;
1321 public void setRedoList(Deque<CommandI> list)
1323 this.redoList = list;
1326 public Deque<CommandI> getRedoList()
1328 return this.redoList;
1332 * Add the sequences from the given alignment to this viewport. Optionally,
1333 * may give the user the option to open a new frame, or split panel, with cDNA
1334 * and protein linked.
1339 public void addAlignment(AlignmentI al, String title)
1341 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
1343 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
1345 // TODO: create undo object for this JAL-1101
1348 * If one alignment is protein and one nucleotide, with at least one
1349 * sequence name in common, offer to open a linked alignment.
1351 if (getAlignment().isNucleotide() != al.isNucleotide())
1353 final Set<String> sequenceNames = getAlignment().getSequenceNames();
1354 sequenceNames.retainAll(al.getSequenceNames());
1355 if (!sequenceNames.isEmpty()) // at least one sequence name in both
1357 if (openLinkedAlignment(al, title))
1364 for (int i = 0; i < al.getHeight(); i++)
1366 getAlignment().addSequence(al.getSequenceAt(i));
1368 // TODO this call was done by SequenceFetcher but not FileLoader or
1369 // CutAndPasteTransfer. Is it needed?
1370 setEndSeq(getAlignment().getHeight());
1371 firePropertyChange("alignment", null, getAlignment().getSequences());
1375 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
1376 * alignment. Returns true if the new alignment was opened, false if not,
1377 * because the user declined the offer.
1381 protected boolean openLinkedAlignment(AlignmentI al, String title)
1383 String[] options = new String[]
1384 { MessageManager.getString("action.no"),
1385 MessageManager.getString("label.split_window"),
1386 MessageManager.getString("label.new_window"), };
1387 final String question = JvSwingUtils.wrapTooltip(true,
1388 MessageManager.getString("label.open_linked_alignment?"));
1389 int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
1390 MessageManager.getString("label.open_linked_alignment"),
1391 JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
1392 options, options[0]);
1394 if (response != 1 && response != 2)
1398 final boolean openSplitPane = (response == 1);
1399 final boolean openInNewWindow = (response == 2);
1402 * Create the AlignFrame first (which creates the new alignment's datasets),
1403 * before attempting sequence mapping.
1405 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
1406 AlignFrame.DEFAULT_HEIGHT);
1407 newAlignFrame.setTitle(title);
1410 * Identify protein and dna alignments. Make a copy of this one if opening
1411 * in a new split pane.
1413 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
1415 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
1416 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
1418 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1419 "label.successfully_loaded_file", new Object[]
1422 // TODO if we want this (e.g. to enable reload of the alignment from file),
1423 // we will need to add parameters to the stack.
1424 // if (!protocol.equals(AppletFormatAdapter.PASTE))
1426 // alignFrame.setFileName(file, format);
1429 if (openInNewWindow)
1431 Desktop.addInternalFrame(newAlignFrame, title,
1432 AlignFrame.DEFAULT_WIDTH,
1433 AlignFrame.DEFAULT_HEIGHT);
1437 * Try to find mappings for at least one sequence. Any mappings made will be
1438 * added to the protein alignment.
1440 MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
1441 final StructureSelectionManager ssm = StructureSelectionManager
1442 .getStructureSelectionManager(Desktop.instance);
1443 if (mapped != MappingResult.Mapped)
1446 * No mapping possible - warn the user, but leave window open.
1448 final String msg = JvSwingUtils.wrapTooltip(true,
1449 MessageManager.getString("label.mapping_failed"));
1450 JOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
1451 MessageManager.getString("label.no_mappings"),
1452 JOptionPane.WARNING_MESSAGE);
1457 newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
1460 } catch (java.beans.PropertyVetoException ex)
1467 * Open in split pane. DNA sequence above, protein below.
1469 AlignFrame copyMe = new AlignFrame(thisAlignment,
1470 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1471 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
1472 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
1474 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
1476 protein = proteinFrame.viewport.getAlignment();
1478 cdnaFrame.setVisible(true);
1479 proteinFrame.setVisible(true);
1480 String sep = String.valueOf(File.separatorChar);
1481 String proteinShortName = StringUtils.getLastToken(
1482 proteinFrame.getTitle(), sep);
1483 String dnaShortName = StringUtils.getLastToken(cdnaFrame.getTitle(),
1485 String linkedTitle = MessageManager.formatMessage(
1486 "label.linked_view_title", dnaShortName, proteinShortName);
1487 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
1488 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
1491 * Set the frames to listen for each other's edit and sort commands.
1493 ssm.addCommandListener(cdnaFrame.getViewport());
1494 ssm.addCommandListener(proteinFrame.getViewport());
1497 * 'Coding complement' (dna/protein) views will mirror each others' edits,
1498 * selections, sorting etc as decided from time to time by the relevant
1501 proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());
1505 * Register the mappings (held on the protein alignment) with the
1506 * StructureSelectionManager (for mouseover linking).
1508 ssm.addMappings(protein.getCodonFrames());
1513 public AnnotationColumnChooser getAnnotationColumnSelectionState()
1515 return annotationColumnSelectionState;
1518 public void setAnnotationColumnSelectionState(
1519 AnnotationColumnChooser currentAnnotationColumnSelectionState)
1521 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;