- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getCharHeight()
- {
- return charHeight;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param w DOCUMENT ME!
- */
- public void setWrappedWidth(int w)
- {
- this.wrappedWidth = w;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getWrappedWidth()
- {
- return wrappedWidth;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public AlignmentI getAlignment()
- {
- return alignment;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param align DOCUMENT ME!
- */
- public void setAlignment(AlignmentI align)
- {
- this.alignment = align;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setWrapAlignment(boolean state)
- {
- wrapAlignment = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setShowText(boolean state)
- {
- showText = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setRenderGaps(boolean state)
- {
- renderGaps = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getColourText()
- {
- return showColourText;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setColourText(boolean state)
- {
- showColourText = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setShowBoxes(boolean state)
- {
- showBoxes = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getWrapAlignment()
- {
- return wrapAlignment;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowText()
- {
- return showText;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowBoxes()
- {
- return showBoxes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public char getGapCharacter()
- {
- return getAlignment().getGapCharacter();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param gap DOCUMENT ME!
- */
- public void setGapCharacter(char gap)
- {
- if (getAlignment() != null)
- {
- getAlignment().setGapCharacter(gap);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param thresh DOCUMENT ME!
- */
- public void setThreshold(int thresh)
- {
- threshold = thresh;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getThreshold()
- {
- return threshold;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param inc DOCUMENT ME!
- */
- public void setIncrement(int inc)
- {
- increment = inc;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getIncrement()
- {
- return increment;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ColumnSelection getColumnSelection()
- {
- return colSel;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param tree DOCUMENT ME!
- */
- public void setCurrentTree(NJTree tree)
- {
- currentTree = tree;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public NJTree getCurrentTree()
- {
- return currentTree;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setColourAppliesToAllGroups(boolean b)
- {
- colourAppliesToAllGroups = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getColourAppliesToAllGroups()
- {
- return colourAppliesToAllGroups;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowJVSuffix()
- {
- return showJVSuffix;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setShowJVSuffix(boolean b)
- {
- showJVSuffix = b;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowAnnotation()
- {
- return showAnnotation;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setShowAnnotation(boolean b)
- {
- showAnnotation = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getScaleAboveWrapped()
- {
- return scaleAboveWrapped;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getScaleLeftWrapped()
- {
- return scaleLeftWrapped;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getScaleRightWrapped()
- {
- return scaleRightWrapped;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setScaleAboveWrapped(boolean b)
- {
- scaleAboveWrapped = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setScaleLeftWrapped(boolean b)
- {
- scaleLeftWrapped = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setScaleRightWrapped(boolean b)
- {
- scaleRightWrapped = b;
- }
-
- /**
- * Property change listener for changes in alignment
- *
- * @param listener DOCUMENT ME!
- */
- public void addPropertyChangeListener(
- java.beans.PropertyChangeListener listener)
- {
- changeSupport.addPropertyChangeListener(listener);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param listener DOCUMENT ME!
- */
- public void removePropertyChangeListener(
- java.beans.PropertyChangeListener listener)
- {
- changeSupport.removePropertyChangeListener(listener);
- }
-
- /**
- * Property change listener for changes in alignment
- *
- * @param prop DOCUMENT ME!
- * @param oldvalue DOCUMENT ME!
- * @param newvalue DOCUMENT ME!
- */
- public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
- {
- changeSupport.firePropertyChange(prop, oldvalue, newvalue);
- }
-
- public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
- {
- ignoreGapsInConsensusCalculation = b;
- updateConsensus(ap);
- if(globalColourScheme!=null)
- {
- globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
- }
- }
-
- public boolean getIgnoreGapsConsensus()
- {
- return ignoreGapsInConsensusCalculation;
- }
-
- public void setDataset(boolean b)
- {
- isDataset = b;
- }
-
- public boolean isDataset()
- {
- return isDataset;
- }
-
-
- public void hideSelectedColumns()
- {
- if (colSel.size() < 1)
- return;
-
- colSel.hideSelectedColumns();
- setSelectionGroup(null);
-
- hasHiddenColumns = true;
- }
-
-
- public void hideColumns(int start, int end)
- {
- if(start==end)
- colSel.hideColumns(start);
- else
- colSel.hideColumns(start, end);
-
- hasHiddenColumns = true;
- }
-
- public void hideAllSelectedSeqs()
- {
- if (selectionGroup == null)
- return;
-
- SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
-
- hideSequence(seqs);
-
- setSelectionGroup(null);
- }
-
- public void hideSequence(SequenceI [] seq)
- {
- if(seq!=null)
- {
- for (int i = 0; i < seq.length; i++)
- alignment.getHiddenSequences().hideSequence(seq[i]);
-
- hasHiddenRows = true;
- firePropertyChange("alignment", null, alignment.getSequences());
- }
- }
-
- public void showSequence(int index)
- {
- Vector tmp = alignment.getHiddenSequences().showSequence(index);
- if(tmp.size()>0)
- {
- if(selectionGroup==null)
- {
- selectionGroup = new SequenceGroup();
- selectionGroup.setEndRes(alignment.getWidth()-1);
- }
-
- for (int t = 0; t < tmp.size(); t++)
- {
- selectionGroup.addSequence(
- (SequenceI) tmp.elementAt(t), false
- );
- }
- firePropertyChange("alignment", null, alignment.getSequences());
- }
-
- if(alignment.getHiddenSequences().getSize()<1)
- hasHiddenRows = false;
- }
-
- public void showColumn(int col)
- {
- colSel.revealHiddenColumns(col);
- if(colSel.getHiddenColumns()==null)
- hasHiddenColumns = false;
- }
-
- public void showAllHiddenColumns()
- {
- colSel.revealAllHiddenColumns();
- hasHiddenColumns = false;
- }
-
- public void showAllHiddenSeqs()
- {
- if(alignment.getHiddenSequences().getSize()>0)
- {
- if(selectionGroup==null)
- {
- selectionGroup = new SequenceGroup();
- selectionGroup.setEndRes(alignment.getWidth()-1);
- }
- Vector tmp = alignment.getHiddenSequences().showAll();
- for(int t=0; t<tmp.size(); t++)
- {
- selectionGroup.addSequence(
- (SequenceI)tmp.elementAt(t), false
- );
- }
- firePropertyChange("alignment", null, alignment.getSequences());
- hasHiddenRows = false;
- }
- }
-
- public void invertColumnSelection()
- {
- int column;
- for(int i=0; i<alignment.getWidth(); i++)
- {
- column = i;
-
- if(colSel.contains(column))
- colSel.removeElement(column);
- else
- colSel.addElement(column);
-
- }
-
- }
-
- public int adjustForHiddenSeqs(int alignmentIndex)
- {
- return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
- }
-
- /**
- * This method returns the a new SequenceI [] with
- * the selection sequence and start and end points adjusted
- * @return String[]
- */
- public SequenceI[] getSelectionAsNewSequence()
- {
- SequenceI[] sequences;
-
- if (selectionGroup == null)
- sequences = alignment.getSequencesArray();
- else
- sequences = selectionGroup.getSelectionAsNewSequences(alignment);
-
- return sequences;
- }
-
- /**
- * This method returns the visible alignment as text, as
- * seen on the GUI, ie if columns are hidden they will not
- * be returned in the result.
- * Use this for calculating trees, PCA, redundancy etc on views
- * which contain hidden columns.
- * @return String[]
- */
- public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
- {
- CigarArray selection=null;
- SequenceI [] seqs= null;
- int i, iSize;
- int start = 0, end = 0;
- if(selectedRegionOnly && selectionGroup!=null)
- {
- iSize = selectionGroup.getSize(false);
- seqs = selectionGroup.getSequencesInOrder(alignment);
- start = selectionGroup.getStartRes();
- end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
- }
- else
- {
- iSize = alignment.getHeight();
- seqs = alignment.getSequencesArray();
- end = alignment.getWidth()-1;
- }
- SeqCigar[] selseqs = new SeqCigar[iSize];
- for(i=0; i<iSize; i++)
- {
- selseqs[i] = new SeqCigar(seqs[i], start, end);
- }
- selection=new CigarArray(selseqs);
- // now construct the CigarArray operations
- if (hasHiddenColumns) {
- Vector regions = colSel.getHiddenColumns();
- int [] region;
- int hideStart, hideEnd;
- int last=start;
- for (int j = 0; last<end & j < regions.size(); j++)
- {
- region = (int[]) regions.elementAt(j);
- hideStart = region[0];
- hideEnd = region[1];
- // edit hidden regions to selection range
- if(hideStart<last) {
- if (hideEnd > last)
- {
- hideStart = last;
- } else
- continue;
- }
-
- if (hideStart>end)
- break;
-
- if (hideEnd>end)
- hideEnd=end;
-
- if (hideStart>hideEnd)
- break;
- /**
- * form operations...
- */
- if (last<hideStart)
- selection.addOperation(CigarArray.M, hideStart-last);
- selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
- last = hideEnd+1;
- }
- // Final match if necessary.
- if (last<end)
- selection.addOperation(CigarArray.M, end-last+1);
- } else {
- selection.addOperation(CigarArray.M, end-start+1);
- }
- return selection;
- }
- /**
- * return a compact representation of the current alignment selection to
- * pass to an analysis function
- * @param selectedOnly boolean true to just return the selected view
- * @return AlignmentView
- */
- jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
- // JBPNote:
- // this is here because the AlignmentView constructor modifies the CigarArray
- // object. Refactoring of Cigar and alignment view representation should
- // be done to remove redundancy.
- CigarArray aligview = getViewAsCigars(selectedOnly);
- if (aligview!=null) {
- return new AlignmentView(aligview,
- (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
- }
- return null;
- }
- /**
- * This method returns the visible alignment as text, as
- * seen on the GUI, ie if columns are hidden they will not
- * be returned in the result.
- * Use this for calculating trees, PCA, redundancy etc on views
- * which contain hidden columns.
- * @return String[]
- */
- public String [] getViewAsString(boolean selectedRegionOnly)
- {
- String [] selection = null;
- SequenceI [] seqs= null;
- int i, iSize;
- int start = 0, end = 0;
- if(selectedRegionOnly && selectionGroup!=null)
- {
- iSize = selectionGroup.getSize(false);
- seqs = selectionGroup.getSequencesInOrder(alignment);
- start = selectionGroup.getStartRes();
- end = selectionGroup.getEndRes()+1;
- }
- else
- {
- iSize = alignment.getHeight();
- seqs = alignment.getSequencesArray();
- end = alignment.getWidth();
- }
-
- selection = new String[iSize];
- if (hasHiddenColumns) {
- selection = colSel.getVisibleSequenceStrings(start, end, seqs);
- } else {
- for(i=0; i<iSize; i++)
- {
- selection[i] = seqs[i].getSequence(start, end);
- }
-
- }
- return selection;
- }
-
- public boolean getShowHiddenMarkers()
- {
- return showHiddenMarkers;
- }
-
- public void setShowHiddenMarkers(boolean show)
- {
- showHiddenMarkers = show;
- }
-
- public String getSequenceSetId()
- {
- if(sequenceSetID==null)
- sequenceSetID = alignment.hashCode()+"";
-
- return sequenceSetID;
- }
-
- public void alignmentChanged(AlignmentPanel ap)
- {
- if (padGaps)
- alignment.padGaps();
-
- if (hconsensus != null && autoCalculateConsensus)
- {
- updateConsensus(ap);
- updateConservation(ap);
- }
-
- resetAllColourSchemes();
-
- alignment.adjustSequenceAnnotations();
- }
-
-
- void resetAllColourSchemes()
- {
- ColourSchemeI cs = globalColourScheme;
- if(cs!=null)
- {
- if (cs instanceof ClustalxColourScheme)
- {
- ( (ClustalxColourScheme) cs).
- resetClustalX(alignment.getSequences(),
- alignment.getWidth());
- }
-
- cs.setConsensus(hconsensus);
- if (cs.conservationApplied())
- {
- Alignment al = (Alignment) alignment;
- Conservation c = new Conservation("All",
- ResidueProperties.propHash, 3,
- al.getSequences(), 0,
- al.getWidth() - 1);
- c.calculate();
- c.verdict(false, ConsPercGaps);
-
- cs.setConservation(c);
- }
- }
-
- int s, sSize = alignment.getGroups().size();
- for(s=0; s<sSize; s++)
- {
- SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
- if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
- {
- ((ClustalxColourScheme)sg.cs).resetClustalX(
- sg.getSequences(true), sg.getWidth());
- }
- sg.recalcConservation();
- }
- }
-
-
-
+ /**
+ * Show a dialog with the option to open and link (cDNA <-> protein) as a new
+ * alignment. Returns true if the new alignment was opened, false if not,
+ * because the user declined the offer.
+ *
+ * @param title
+ */
+ protected boolean openLinkedAlignment(AlignmentI al, String title)
+ {
+ String[] options = new String[]
+ { MessageManager.getString("action.no"),
+ MessageManager.getString("label.split_window"),
+ MessageManager.getString("label.new_window"), };
+ final String question = JvSwingUtils.wrapTooltip(true,
+ MessageManager.getString("label.open_linked_alignment?"));
+ int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
+ MessageManager.getString("label.open_linked_alignment"),
+ JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
+ options, options[0]);
+
+ if (response != 1 && response != 2)
+ {
+ return false;
+ }
+ final boolean openSplitPane = (response == 1);
+ final boolean openInNewWindow = (response == 2);
+
+ /*
+ * Create the AlignFrame first (which creates the new alignment's datasets),
+ * before attempting sequence mapping.
+ */
+ AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ newAlignFrame.setTitle(title);
+
+ /*
+ * Identify protein and dna alignments. Make a copy of this one if opening
+ * in a new split pane.
+ */
+ AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
+ : getAlignment();
+ AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
+ final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
+
+ newAlignFrame.statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_loaded_file", new Object[]
+ { title }));
+
+ // TODO if we want this (e.g. to enable reload of the alignment from file),
+ // we will need to add parameters to the stack.
+ // if (!protocol.equals(AppletFormatAdapter.PASTE))
+ // {
+ // alignFrame.setFileName(file, format);
+ // }
+
+ if (openInNewWindow)
+ {
+ Desktop.addInternalFrame(newAlignFrame, title,
+ AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ }
+
+ /*
+ * Try to find mappings for at least one sequence. Any mappings made will be
+ * added to the protein alignment.
+ */
+ MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
+ if (mapped != MappingResult.Mapped)
+ {
+ /*
+ * No mapping possible - warn the user, but leave window open.
+ */
+ final String msg = JvSwingUtils.wrapTooltip(true,
+ MessageManager.getString("label.mapping_failed"));
+ JOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
+ MessageManager.getString("label.no_mappings"),
+ JOptionPane.WARNING_MESSAGE);
+ }
+
+ try
+ {
+ newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
+ "SHOW_FULLSCREEN",
+ false));
+ } catch (java.beans.PropertyVetoException ex)
+ {
+ }
+
+ if (openSplitPane)
+ {
+ protein = openSplitFrame(newAlignFrame, thisAlignment);
+ }
+
+ /*
+ * Register the mappings (held on the protein alignment) with the
+ * StructureSelectionManager (for mouseover linking).
+ */
+ final StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ ssm.addMappings(protein.getCodonFrames());
+
+ return true;
+ }
+
+ /**
+ * Helper method to open a new SplitFrame holding linked dna and protein
+ * alignments.
+ *
+ * @param newAlignFrame
+ * containing a new alignment to be shown
+ * @param existingAlignment
+ * an existing alignment to be copied for display in the split frame
+ * @return the protein alignment in the split frame
+ */
+ protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
+ AlignmentI existingAlignment)
+ {
+ // TODO: move this to a factory/controller method ?
+ /*
+ * Open in split pane. DNA sequence above, protein below.
+ */
+ AlignFrame copyMe = new AlignFrame(existingAlignment,
+ AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
+
+ AlignmentI al = newAlignFrame.viewport.getAlignment();
+ final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
+ : newAlignFrame;
+ final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
+ : copyMe;
+ AlignmentI protein = proteinFrame.viewport.getAlignment();
+
+ cdnaFrame.setVisible(true);
+ proteinFrame.setVisible(true);
+ String linkedTitle = MessageManager
+ .getString("label.linked_view_title");
+ JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
+ Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
+
+ /*
+ * Set the frames to listen for each other's edit and sort commands.
+ */
+ final StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ ssm.addCommandListener(cdnaFrame.getViewport());
+ ssm.addCommandListener(proteinFrame.getViewport());
+
+ /*
+ * 'Coding complement' (dna/protein) views will mirror each others' edits,
+ * selections, sorting etc as decided from time to time by the relevant
+ * authorities.
+ */
+ proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());
+ return protein;
+ }
+
+ public AnnotationColumnChooser getAnnotationColumnSelectionState()
+ {
+ return annotationColumnSelectionState;
+ }
+
+ public void setAnnotationColumnSelectionState(
+ AnnotationColumnChooser currentAnnotationColumnSelectionState)
+ {
+ this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
+ }
+
+ @Override
+ public void setIdWidth(int i)
+ {
+ super.setIdWidth(i);
+ AlignmentPanel ap = getAlignPanel();
+ if (ap != null)
+ {
+ // modify GUI elements to reflect geometry change
+ Dimension idw = getAlignPanel().getIdPanel().getIdCanvas()
+ .getPreferredSize();
+ idw.width = i;
+ getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);
+ }
+ }
+
+ public Rectangle getExplodedGeometry()
+ {
+ return explodedGeometry;
+ }
+
+ public void setExplodedGeometry(Rectangle explodedPosition)
+ {
+ this.explodedGeometry = explodedPosition;
+ }
+
+ public boolean isGatherViewsHere()
+ {
+ return gatherViewsHere;
+ }
+
+ public void setGatherViewsHere(boolean gatherViewsHere)
+ {
+ this.gatherViewsHere = gatherViewsHere;
+ }