+ * 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