import jalview.analysis.AlignmentUtils;
import jalview.analysis.Conservation;
import jalview.analysis.CrossRef;
+import jalview.analysis.Dna;
import jalview.analysis.NJTree;
import jalview.analysis.ParseProperties;
import jalview.analysis.SequenceIdMatcher;
import jalview.api.AlignViewControllerGuiI;
import jalview.api.AlignViewControllerI;
+import jalview.api.AlignmentViewPanel;
import jalview.api.analysis.ScoreModelI;
import jalview.bin.Cache;
import jalview.commands.CommandI;
import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
import jalview.commands.OrderCommand;
import jalview.commands.RemoveGapColCommand;
import jalview.commands.RemoveGapsCommand;
import jalview.schemes.TurnColourScheme;
import jalview.schemes.UserColourScheme;
import jalview.schemes.ZappoColourScheme;
+import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
public void setGUINucleotide(boolean nucleotide)
{
showTranslation.setVisible(nucleotide);
+ cdna.setVisible(!nucleotide);
conservationMenuItem.setEnabled(!nucleotide);
modifyConservation.setEnabled(!nucleotide);
showGroupConservation.setEnabled(!nucleotide);
rnahelicesColour.setEnabled(nucleotide);
purinePyrimidineColour.setEnabled(nucleotide);
- // Remember AlignFrame always starts as protein
- // if (!nucleotide)
- // {
- // showTr
- // calculateMenu.remove(calculateMenu.getItemCount() - 2);
- // }
}
/**
- * set up menus for the currently viewport. This may be called after any
+ * Builds codon mappings from this (protein) alignment to any compatible
+ * nucleotide alignments. Mappings are built between sequences with the same
+ * name and compatible lengths. Also makes the cDNA alignment a
+ * CommandListener for the protein alignment so that edits are mirrored.
+ */
+ @Override
+ protected void linkCdna_actionPerformed()
+ {
+ int linkedCount = 0;
+ int alreadyLinkedCount = 0;
+ final AlignmentI thisAlignment = this.alignPanel.getAlignment();
+
+ for (AlignFrame af : Desktop.getAlignframes())
+ {
+ if (af.alignPanel != null)
+ {
+ final AlignmentI thatAlignment = af.alignPanel.getAlignment();
+ if (thatAlignment.isNucleotide())
+ {
+ // TODO exclude an AlignFrame which is already mapped to this one
+ // temporary version: exclude if already a CommandListener (should
+ // cover most cases but not all)
+ final boolean alreadyMapped = this.viewport
+ .getStructureSelectionManager().hasCommandListener(
+ af.viewport);
+ if (alreadyMapped)
+ {
+ alreadyLinkedCount++;
+ }
+ else
+ {
+ boolean mapped = AlignmentUtils.mapProteinToCdna(thisAlignment,
+ thatAlignment);
+ if (mapped)
+ {
+ final StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ ssm.addMappings(thisAlignment.getCodonFrames());
+ ssm.addCommandListener(af.getViewport());
+ linkedCount++;
+ }
+ }
+ }
+ }
+ }
+ String msg = "";
+ if (linkedCount == 0 && alreadyLinkedCount == 0)
+ {
+ msg = MessageManager.getString("label.no_cdna");
+ }
+ else if (linkedCount > 0)
+ {
+ msg = MessageManager.formatMessage("label.linked_cdna", linkedCount);
+ }
+ else
+ {
+ msg = MessageManager.formatMessage("label.cdna_all_linked",
+ alreadyLinkedCount);
+ }
+ setStatus(msg);
+ }
+
+ /**
+ * Align any linked cDNA to match the alignment of this (protein) alignment.
+ * Any mapped sequence regions will be realigned, unmapped sequences are not
+ * affected.
+ */
+ @Override
+ protected void alignCdna_actionPerformed()
+ {
+ int seqCount = 0;
+ int alignCount = 0;
+ final AlignmentI thisAlignment = this.alignPanel.getAlignment();
+ for (AlignFrame af : Desktop.getAlignframes())
+ {
+ if (af.alignPanel != null)
+ {
+ final AlignmentI thatAlignment = af.alignPanel.getAlignment();
+ if (thatAlignment.isNucleotide())
+ {
+ int seqsAligned = thatAlignment.alignAs(thisAlignment);
+ seqCount += seqsAligned;
+ if (seqsAligned > 0)
+ {
+ af.alignPanel.alignmentChanged();
+ alignCount++;
+ }
+ }
+ }
+ }
+ setStatus(MessageManager.formatMessage("label.cdna_aligned", seqCount,
+ alignCount));
+ }
+ /**
+ * set up menus for the current viewport. This may be called after any
* operation that affects the data in the current view (selection changed,
* etc) to update the menus to reflect the new state.
*/
if (value == JalviewFileChooser.APPROVE_OPTION)
{
currentFileFormat = chooser.getSelectedFormat();
- if (currentFileFormat == null)
+ while (currentFileFormat == null)
{
JOptionPane
.showInternalMessageDialog(
MessageManager
.getString("label.file_format_not_specified"),
JOptionPane.WARNING_MESSAGE);
+ currentFileFormat = chooser.getSelectedFormat();
value = chooser.showSaveDialog(this);
- return;
+ if (value != JalviewFileChooser.APPROVE_OPTION)
+ {
+ return;
+ }
}
fileName = chooser.getSelectedFile().getPath();
alignPanel.makeEPS(f);
}
+ public void createSVG(File f)
+ {
+ alignPanel.makeSVG(f);
+ }
@Override
public void pageSetup_actionPerformed(ActionEvent e)
{
void updateEditMenuBar()
{
- if (viewport.historyList.size() > 0)
+ if (viewport.getHistoryList().size() > 0)
{
undoMenuItem.setEnabled(true);
- CommandI command = (CommandI) viewport.historyList.peek();
+ CommandI command = viewport.getHistoryList().peek();
undoMenuItem.setText(MessageManager.formatMessage(
"label.undo_command", new String[]
{ command.getDescription() }));
undoMenuItem.setText(MessageManager.getString("action.undo"));
}
- if (viewport.redoList.size() > 0)
+ if (viewport.getRedoList().size() > 0)
{
redoMenuItem.setEnabled(true);
- CommandI command = (CommandI) viewport.redoList.peek();
+ CommandI command = viewport.getRedoList().peek();
redoMenuItem.setText(MessageManager.formatMessage(
"label.redo_command", new String[]
{ command.getDescription() }));
{
if (command.getSize() > 0)
{
- viewport.historyList.push(command);
- viewport.redoList.clear();
+ viewport.addToHistoryList(command);
+ viewport.clearRedoList();
updateEditMenuBar();
viewport.updateHiddenColumns();
// viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
@Override
protected void undoMenuItem_actionPerformed(ActionEvent e)
{
- if (viewport.historyList.empty())
+ if (viewport.getHistoryList().isEmpty())
{
return;
}
- CommandI command = (CommandI) viewport.historyList.pop();
- viewport.redoList.push(command);
+ CommandI command = viewport.getHistoryList().pop();
+ viewport.addToRedoList(command);
+ // TODO: execute command before adding to redo list / broadcasting?
command.undoCommand(getViewAlignments());
AlignViewport originalSource = getOriginatingSource(command);
@Override
protected void redoMenuItem_actionPerformed(ActionEvent e)
{
- if (viewport.redoList.size() < 1)
+ if (viewport.getRedoList().size() < 1)
{
return;
}
- CommandI command = (CommandI) viewport.redoList.pop();
- viewport.historyList.push(command);
+ CommandI command = viewport.getRedoList().pop();
+ viewport.addToHistoryList(command);
command.doCommand(getViewAlignments());
AlignViewport originalSource = getOriginatingSource(command);
}
boolean appendHistoryItem = false;
- if (viewport.historyList != null && viewport.historyList.size() > 0
- && viewport.historyList.peek() instanceof SlideSequencesCommand)
+ if (viewport.getHistoryList() != null
+ && viewport.getHistoryList().size() > 0
+ && viewport.getHistoryList().peek() instanceof SlideSequencesCommand)
{
appendHistoryItem = ssc
- .appendSlideCommand((SlideSequencesCommand) viewport.historyList
+ .appendSlideCommand((SlideSequencesCommand) viewport
+ .getHistoryList()
.peek());
}
// /////
// ADD HISTORY ITEM
//
- addHistoryItem(new EditCommand(MessageManager.getString("label.add_sequences"), EditCommand.PASTE,
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.add_sequences"),
+ Action.PASTE,
sequences, 0, alignment.getWidth(), alignment));
}
// Add any annotations attached to sequences
/*
* //ADD HISTORY ITEM
*/
- addHistoryItem(new EditCommand(MessageManager.getString("label.cut_sequences"), EditCommand.CUT, cut,
- sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.cut_sequences"), Action.CUT,
+ cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
viewport.getAlignment()));
viewport.setSelectionGroup(null);
new Finder();
}
+ /**
+ * Create a new view of the current alignment.
+ */
@Override
public void newView_actionPerformed(ActionEvent e)
{
viewport.viewName = "Original";
}
- newap.av.historyList = viewport.historyList;
- newap.av.redoList = viewport.redoList;
+ newap.av.setHistoryList(viewport.getHistoryList());
+ newap.av.setRedoList(viewport.getRedoList());
int index = Desktop.getViewCount(viewport.getSequenceSetId());
// make sure the new view has a unique name - this is essential for Jalview
*/
msa = viewport.getAlignmentView(true);
}
+ else if (viewport.getSelectionGroup() != null
+ && viewport.getSelectionGroup().getSize() == 1)
+ {
+ int option = JOptionPane.showConfirmDialog(this,
+ MessageManager.getString("warn.oneseq_msainput_selection"),
+ MessageManager.getString("label.invalid_selection"),
+ JOptionPane.OK_CANCEL_OPTION);
+ if (option == JOptionPane.OK_OPTION)
+ {
+ msa = viewport.getAlignmentView(false);
+ }
+ }
else
{
- /*
- * Vector seqs = viewport.getAlignment().getSequences();
- *
- * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
- *
- * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
- * seqs.elementAt(i); } }
- */
msa = viewport.getAlignmentView(false);
}
return msa;
}
}
- @Override
- public void showProducts_actionPerformed(ActionEvent e)
- {
- // /////////////////////////////
- // Collect Data to be translated/transferred
-
- SequenceI[] selection = viewport.getSequenceSelection();
- AlignmentI al = null;
- try
- {
- al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
- .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
- viewport.getAlignment().getDataset());
- } catch (Exception ex)
- {
- al = null;
- jalview.bin.Cache.log.debug("Exception during translation.", ex);
- }
- if (al == null)
- {
- JOptionPane
- .showMessageDialog(
- Desktop.desktop,
- MessageManager
- .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
- MessageManager.getString("label.translation_failed"),
- JOptionPane.WARNING_MESSAGE);
- }
- else
- {
- AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
- Desktop.addInternalFrame(af, MessageManager.formatMessage(
- "label.translation_of_params", new String[]
- { this.getTitle() }), DEFAULT_WIDTH, DEFAULT_HEIGHT);
- }
- }
-
+ /**
+ * Construct and display a new frame containing the translation of this
+ * frame's cDNA sequences to their aligned protein (amino acid) equivalents.
+ */
@Override
public void showTranslation_actionPerformed(ActionEvent e)
{
- // /////////////////////////////
- // Collect Data to be translated/transferred
-
- SequenceI[] selection = viewport.getSequenceSelection();
- String[] seqstring = viewport.getViewAsString(true);
AlignmentI al = null;
try
{
- al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
- viewport.getViewAsVisibleContigs(true), viewport
- .getGapCharacter(), viewport.getAlignment()
- .getAlignmentAnnotation(), viewport.getAlignment()
- .getWidth(), viewport.getAlignment().getDataset());
+ Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
+
+ al = dna.translateCdna();
} catch (Exception ex)
{
- al = null;
jalview.bin.Cache.log.error(
"Exception during translation. Please report this !", ex);
- JOptionPane
- .showMessageDialog(
- Desktop.desktop,
- MessageManager
- .getString("label.error_when_translating_sequences_submit_bug_report"),
- MessageManager
- .getString("label.implementation_error")
- + MessageManager
- .getString("translation_failed"),
- JOptionPane.ERROR_MESSAGE);
+ final String msg = MessageManager
+ .getString("label.error_when_translating_sequences_submit_bug_report");
+ final String title = MessageManager
+ .getString("label.implementation_error")
+ + MessageManager.getString("translation_failed");
+ JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
+ JOptionPane.ERROR_MESSAGE);
return;
}
if (al == null)
{
- JOptionPane
- .showMessageDialog(
- Desktop.desktop,
- MessageManager
- .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
- MessageManager.getString("label.translation_failed"),
- JOptionPane.WARNING_MESSAGE);
+ final String msg = MessageManager
+ .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
+ final String title = MessageManager
+ .getString("label.translation_failed");
+ JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
+ JOptionPane.WARNING_MESSAGE);
}
else
{
Desktop.addInternalFrame(af, MessageManager.formatMessage(
"label.translation_of_params", new String[]
{ this.getTitle() }), DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ viewport.getStructureSelectionManager().addCommandListener(viewport);
}
}
aa.visible = visible;
}
}
- this.alignPanel.paintAlignment(true);
+ alignPanel.validateAnnotationDimensions(false);
+ alignPanel.alignmentChanged();
}
/**
.setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
alignPanel.paintAlignment(true);
}
+
+ /**
+ *
+ * @return alignment panels in this alignemnt frame
+ */
+ public List<AlignmentViewPanel> getAlignPanels()
+ {
+ return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
+ }
}
class PrintThread extends Thread