import jalview.io.JnetAnnotationMaker;
import jalview.io.NewickFile;
import jalview.io.TCoffeeScoreFile;
+import jalview.io.gff.SequenceOntologyI;
import jalview.jbgui.GAlignFrame;
import jalview.schemes.Blosum62ColourScheme;
import jalview.schemes.BuriedColourScheme;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
-import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
{
formatMenu.add(vsel);
}
+ addFocusListener(new FocusAdapter()
+ {
+ @Override
+ public void focusGained(FocusEvent e)
+ {
+ Jalview.setCurrentAlignFrame(AlignFrame.this);
+ }
+ });
}
.setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
showProducts.setEnabled(canShowProducts());
+ setGroovyEnabled(Desktop.getGroovyConsole() != null);
updateEditMenuBar();
}
+ /**
+ * Set the enabled state of the 'Run Groovy' option in the Calculate menu
+ *
+ * @param b
+ */
+ public void setGroovyEnabled(boolean b)
+ {
+ runGroovy.setEnabled(b);
+ }
+
private IProgressIndicator progressBar;
/*
AlignmentI alignmentToExport = null;
AlignExportSettingI settings = exportSettings;
String[] omitHidden = null;
- int[] alignmentStartEnd = new int[2];
HiddenSequences hiddenSeqs = viewport.getAlignment()
.getHiddenSequences();
alignmentToExport = viewport.getAlignment();
- alignmentStartEnd = new int[] { 0, alignmentToExport.getWidth() - 1 };
boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
if (settings == null)
if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
{
- omitHidden = viewport.getViewAsString(false);
+ omitHidden = viewport.getViewAsString(false,
+ settings.isExportHiddenSequences());
}
+ int[] alignmentStartEnd = new int[2];
if (hasHiddenSeqs && settings.isExportHiddenSequences())
{
alignmentToExport = hiddenSeqs.getFullAlignment();
else
{
alignmentToExport = viewport.getAlignment();
- alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
- .getColumnSelection().getHiddenColumns());
}
+ alignmentStartEnd = alignmentToExport
+ .getVisibleStartAndEndIndex(viewport.getColumnSelection()
+ .getHiddenColumns());
AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
omitHidden, alignmentStartEnd, settings);
return ed;
}
- public static int[] getStartEnd(int[] aligmentStartEnd,
- List<int[]> hiddenCols)
- {
- int startPos = aligmentStartEnd[0];
- int endPos = aligmentStartEnd[1];
-
- int[] lowestRange = new int[] { -1, -1 };
- int[] higestRange = new int[] { -1, -1 };
-
- for (int[] hiddenCol : hiddenCols)
- {
- lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
- higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
- }
-
- if (lowestRange[0] == -1 && lowestRange[1] == -1)
- {
- startPos = aligmentStartEnd[0];
- }
- else
- {
- startPos = lowestRange[1] + 1;
- }
-
- if (higestRange[0] == -1 && higestRange[1] == -1)
- {
- endPos = aligmentStartEnd[1];
- }
- else
- {
- endPos = higestRange[0] - 1;
- }
-
- // System.out.println("Export range : " + startPos + " - " + endPos);
- return new int[] { startPos, endPos };
- }
-
- public static void main(String[] args)
- {
- ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
- hiddenCols.add(new int[] { 0, 0 });
- hiddenCols.add(new int[] { 6, 9 });
- hiddenCols.add(new int[] { 11, 12 });
- hiddenCols.add(new int[] { 33, 33 });
- hiddenCols.add(new int[] { 50, 50 });
-
- int[] x = getStartEnd(new int[] { 0, 50 }, hiddenCols);
- // System.out.println("Export range : " + x[0] + " - " + x[1]);
- }
-
/**
* DOCUMENT ME!
*
@Override
public void mousePressed(MouseEvent evt)
{
- if (evt.isControlDown()
- || SwingUtilities.isRightMouseButton(evt))
+ if (evt.isPopupTrigger())
{
radioItem.removeActionListener(radioItem.getActionListeners()[0]);
{
JMenuItem tm = new JMenuItem();
ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
- if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
+ if (sm.isDNA() == viewport.getAlignment().isNucleotide()
+ || sm.isProtein() == !viewport.getAlignment()
+ .isNucleotide())
{
String smn = MessageManager.getStringOrReturn(
"label.score_model_", sm.getName());
return showp;
}
+ /**
+ * Finds and displays cross-references for the selected sequences (protein
+ * products for nucleotide sequences, dna coding sequences for peptides).
+ *
+ * @param sel
+ * the sequences to show cross-references for
+ * @param dna
+ * true if from a nucleotide alignment (so showing proteins)
+ * @param source
+ * the database to show cross-references for
+ */
protected void showProductsFor(final SequenceI[] sel, final boolean dna,
final String source)
{
AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH,
DEFAULT_HEIGHT);
+ if (Cache.getDefault("HIDE_INTRONS", true))
+ {
+ newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
+ }
String newtitle = String.format("%s %s %s",
MessageManager.getString(dna ? "label.proteins"
: "label.nucleotides"), MessageManager
System.err.println("Failed to make CDS alignment");
}
al.getCodonFrames().clear();
- al.getCodonFrames().addAll(copyAlignment.getCodonFrames());
+ al.addCodonFrames(copyAlignment.getCodonFrames());
+ al.addCodonFrames(cf);
/*
* pending getting Embl transcripts to 'align',
* we are only doing this for Ensembl
*/
- // TODO want to do this also when fetching UNIPROT for Ensembl
- if (DBRefSource.ENSEMBL.equalsIgnoreCase(source))
+ // TODO proper criteria for 'can align as cdna'
+ if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
+ || AlignmentUtils.looksLikeEnsembl(alignment))
{
copyAlignment.alignAs(alignment);
copyAlignmentIsAligned = true;
{
copyAlignment = AlignmentUtils.makeCopyAlignment(
sequenceSelection, xrefs.getSequencesArray());
- copyAlignment.getCodonFrames().addAll(cf);
+ copyAlignment.addCodonFrames(cf);
+ al.addCodonFrames(copyAlignment.getCodonFrames());
+ al.addCodonFrames(cf);
}
copyAlignment.setGapCharacter(AlignFrame.this.viewport
.getGapCharacter());
}
} catch (Exception e)
{
- Cache.log.error(
- "Exception when finding crossreferences", e);
+ Cache.log.error("Exception when finding crossreferences", e);
} catch (OutOfMemoryError e)
{
new OOMWarning("whilst fetching crossreferences", e);
} catch (Throwable e)
{
- Cache.log.error("Error when finding crossreferences",
- e);
+ Cache.log.error("Error when finding crossreferences", e);
} finally
{
AlignFrame.this.setProgressBar(MessageManager.formatMessage(
.getString("label.error_when_translating_sequences_submit_bug_report");
final String errorTitle = MessageManager
.getString("label.implementation_error")
- + MessageManager.getString("translation_failed");
+ + MessageManager.getString("label.translation_failed");
JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
JOptionPane.ERROR_MESSAGE);
return;
public void drop(DropTargetDropEvent evt)
{
Transferable t = evt.getTransferable();
- java.util.List files = null;
+ java.util.List<String> files = new ArrayList<String>(), protocols = new ArrayList<String>();
try
{
- DataFlavor uriListFlavor = new DataFlavor(
- "text/uri-list;class=java.lang.String");
- if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
- {
- // Works on Windows and MacOSX
- evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
- files = (java.util.List) t
- .getTransferData(DataFlavor.javaFileListFlavor);
- }
- else if (t.isDataFlavorSupported(uriListFlavor))
- {
- // This is used by Unix drag system
- evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
- String data = (String) t.getTransferData(uriListFlavor);
- files = new java.util.ArrayList(1);
- for (java.util.StringTokenizer st = new java.util.StringTokenizer(
- data, "\r\n"); st.hasMoreTokens();)
- {
- String s = st.nextToken();
- if (s.startsWith("#"))
- {
- // the line is a comment (as per the RFC 2483)
- continue;
- }
-
- java.net.URI uri = new java.net.URI(s);
- // check to see if we can handle this kind of URI
- if (uri.getScheme().toLowerCase().startsWith("http"))
- {
- files.add(uri.toString());
- }
- else
- {
- // otherwise preserve old behaviour: catch all for file objects
- java.io.File file = new java.io.File(uri);
- files.add(file.toString());
- }
- }
- }
+ Desktop.transferFromDropTarget(files, protocols, evt, t);
} catch (Exception e)
{
e.printStackTrace();
@Override
public void tabbedPane_mousePressed(MouseEvent e)
{
- if (SwingUtilities.isRightMouseButton(e))
+ if (e.isPopupTrigger())
{
String msg = MessageManager.getString("label.enter_view_name");
String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
AlignFrame.this.setMenusForViewport();
}
});
- dbRefFetcher
- .fetchDBRefs(false);
+ dbRefFetcher.fetchDBRefs(false);
}
}).start();
protected void setAnnotationsVisibility(boolean visible,
boolean forSequences, boolean forAlignment)
{
- for (AlignmentAnnotation aa : alignPanel.getAlignment()
- .getAlignmentAnnotation())
+ AlignmentAnnotation[] anns = alignPanel.getAlignment()
+ .getAlignmentAnnotation();
+ if (anns == null)
+ {
+ return;
+ }
+ for (AlignmentAnnotation aa : anns)
{
/*
* don't display non-positional annotations on an alignment
try
{
Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
-
al = dna.reverseCdna(complement);
viewport.addAlignment(al, "");
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.add_sequences"),
+ Action.PASTE, al.getSequencesArray(), 0, al.getWidth(),
+ viewport.getAlignment()));
} 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()
+ {
+ Jalview.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;
+ }
}
class PrintThread extends Thread