+
+ /**
+ * Open a new alignment window, with the cDNA associated with this (protein)
+ * alignment, aligned as is the protein.
+ */
+ protected void viewAsCdna_actionPerformed()
+ {
+ // TODO no longer a menu action - refactor as required
+ final AlignmentI alignment = getViewport().getAlignment();
+ List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
+ if (mappings == null)
+ {
+ return;
+ }
+ List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
+ for (SequenceI aaSeq : alignment.getSequences())
+ {
+ for (AlignedCodonFrame acf : mappings)
+ {
+ SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
+ if (dnaSeq != null)
+ {
+ /*
+ * There is a cDNA mapping for this protein sequence - add to new
+ * alignment. It will share the same dataset sequence as other mapped
+ * cDNA (no new mappings need to be created).
+ */
+ final Sequence newSeq = new Sequence(dnaSeq);
+ newSeq.setDatasetSequence(dnaSeq);
+ cdnaSeqs.add(newSeq);
+ }
+ }
+ }
+ if (cdnaSeqs.size() == 0)
+ {
+ // show a warning dialog no mapped cDNA
+ return;
+ }
+ AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
+ .size()]));
+ AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ cdna.alignAs(alignment);
+ String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
+ + this.title;
+ Desktop.addInternalFrame(alignFrame, newtitle,
+ AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ }
+
+ /**
+ * Set visibility of dna/protein complement view (available when shown in a
+ * split frame).
+ *
+ * @param show
+ */
+ @Override
+ protected void showComplement_actionPerformed(boolean show)
+ {
+ SplitContainerI sf = getSplitViewContainer();
+ if (sf != null)
+ {
+ sf.setComplementVisible(this, show);
+ }
+ }
+
+ /**
+ * Generate the reverse (optionally complemented) of the selected sequences,
+ * and add them to the alignment
+ */
+ @Override
+ protected void showReverse_actionPerformed(boolean complement)
+ {
+ AlignmentI al = null;
+ try
+ {
+ Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
+
+ al = dna.reverseCdna(complement);
+ viewport.addAlignment(al, "");
+ } catch (Exception ex)
+ {
+ System.err.println(ex.getMessage());
+ return;
+ }
+ }
+
+ /**
+ * Try to run a script in the Groovy console, having first ensured that this
+ * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
+ * be targeted at this alignment.
+ */
+ @Override
+ protected void runGroovy_actionPerformed()
+ {
+ Desktop.setCurrentAlignFrame(this);
+ groovy.ui.Console console = Desktop.getGroovyConsole();
+ if (console != null)
+ {
+ try
+ {
+ console.runScript();
+ } catch (Exception ex)
+ {
+ System.err.println((ex.toString()));
+ JOptionPane
+ .showInternalMessageDialog(Desktop.desktop, MessageManager
+ .getString("label.couldnt_run_groovy_script"),
+ MessageManager
+ .getString("label.groovy_support_failed"),
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ else
+ {
+ System.err.println("Can't run Groovy script as console not found");
+ }
+ }
+
+ /**
+ * Hides columns containing (or not containing) a specified feature, provided
+ * that would not leave all columns hidden
+ *
+ * @param featureType
+ * @param columnsContaining
+ * @return
+ */
+ public boolean hideFeatureColumns(String featureType,
+ boolean columnsContaining)
+ {
+ boolean notForHiding = avc.markColumnsContainingFeatures(
+ columnsContaining, false, false, featureType);
+ if (notForHiding)
+ {
+ if (avc.markColumnsContainingFeatures(!columnsContaining, false,
+ false, featureType))
+ {
+ getViewport().hideSelectedColumns();
+ return true;
+ }
+ }
+ return false;
+ }