/*
* Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
import java.awt.*;
import java.awt.datatransfer.*;
+import java.awt.dnd.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
+import javax.swing.event.MenuEvent;
import jalview.analysis.*;
+import jalview.commands.*;
import jalview.datamodel.*;
import jalview.io.*;
import jalview.jbgui.*;
import jalview.schemes.*;
-import jalview.commands.*;
import jalview.ws.*;
-import java.awt.dnd.*;
-import javax.swing.event.ChangeListener;
-import javax.swing.event.ChangeEvent;
/**
* DOCUMENT ME!
* @author $author$
* @version $Revision$
*/
-public class AlignFrame extends GAlignFrame implements DropTargetListener
+public class AlignFrame
+ extends GAlignFrame implements DropTargetListener
{
/** DOCUMENT ME!! */
public static final int DEFAULT_WIDTH = 700;
String fileName = null;
- private int treeCount = 0;
/**
* Creates a new AlignFrame object.
void init()
{
- this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
-
if (viewport.conservation == null)
{
BLOSUM62Colour.setEnabled(false);
String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
if (sortby.equals("Id"))
+ {
sortIDMenuItem_actionPerformed(null);
+ }
else if (sortby.equals("Pairwise Identity"))
+ {
sortPairwiseMenuItem_actionPerformed(null);
+ }
if (Desktop.desktop != null)
{
+ this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
addServiceListeners();
setGUINucleotide(viewport.alignment.isNucleotide());
}
setMenusFromViewport(viewport);
-
+ buildSortByAnnotationScoresMenu();
if (viewport.wrapAlignment)
{
wrapMenuItem_actionPerformed(null);
}
+ if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW",false))
+ {
+ this.overviewMenuItem_actionPerformed(null);
+ }
+
addKeyListener();
}
{
public void keyPressed(KeyEvent evt)
{
- if (viewport.cursorMode
- && evt.getKeyCode() >= KeyEvent.VK_0
- && evt.getKeyCode() <= KeyEvent.VK_9)
- {
+ if (viewport.cursorMode &&
+ ( (evt.getKeyCode() >= KeyEvent.VK_0 &&
+ evt.getKeyCode() <= KeyEvent.VK_9)
+ ||
+ (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0 &&
+ evt.getKeyCode() <= KeyEvent.VK_NUMPAD9)
+ )
+ && Character.isDigit(evt.getKeyChar()))
alignPanel.seqPanel.numberPressed(evt.getKeyChar());
- }
switch (evt.getKeyCode())
{
break;
case KeyEvent.VK_DOWN:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ moveSelectedSequences(false);
if (viewport.cursorMode)
- {
alignPanel.seqPanel.moveCursor(0, 1);
- }
- else
- moveSelectedSequences(false);
break;
case KeyEvent.VK_UP:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ moveSelectedSequences(true);
if (viewport.cursorMode)
- {
alignPanel.seqPanel.moveCursor(0, -1);
- }
- else
- moveSelectedSequences(true);
+
break;
case KeyEvent.VK_LEFT:
- if (viewport.cursorMode)
- {
+ if (evt.isAltDown() || !viewport.cursorMode)
+ slideSequences(false,
+ alignPanel.seqPanel.getKeyboardNo1());
+ else
alignPanel.seqPanel.moveCursor( -1, 0);
- }
+
+
break;
case KeyEvent.VK_RIGHT:
- if (viewport.cursorMode)
- {
+ if (evt.isAltDown() || !viewport.cursorMode)
+ slideSequences(true,
+ alignPanel.seqPanel.getKeyboardNo1());
+ else
alignPanel.seqPanel.moveCursor(1, 0);
- }
break;
case KeyEvent.VK_SPACE:
cut_actionPerformed(null);
}
else
+ {
alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
|| evt.isShiftDown()
|| evt.isAltDown());
+ }
break;
SequenceGroup sg = viewport.getSelectionGroup();
if (toggleSeqs)
{
- if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
+ if (sg != null && sg.getSize() != viewport.alignment.getHeight())
{
hideSelSequences_actionPerformed(null);
hide = true;
}
- else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
+ else if (! (toggleCols &&
+ viewport.colSel.getSelected().size() > 0))
+ {
showAllSeqs_actionPerformed(null);
}
+ }
if (toggleCols)
{
{
hideSelColumns_actionPerformed(null);
if (!toggleSeqs)
+ {
viewport.selectionGroup = sg;
}
+ }
else if (!hide)
+ {
showAllColumns_actionPerformed(null);
}
+ }
break;
}
case KeyEvent.VK_PAGE_UP:
if (viewport.wrapAlignment)
+ {
alignPanel.scrollUp(true);
+ }
else
+ {
alignPanel.setScrollValues(viewport.startRes,
viewport.startSeq
- viewport.endSeq + viewport.startSeq);
+ }
break;
case KeyEvent.VK_PAGE_DOWN:
if (viewport.wrapAlignment)
+ {
alignPanel.scrollUp(false);
+ }
else
+ {
alignPanel.setScrollValues(viewport.startRes,
viewport.startSeq
+ viewport.endSeq - viewport.startSeq);
+ }
break;
}
}
+
+ public void keyReleased(KeyEvent evt)
+ {
+ switch(evt.getKeyCode())
+ {
+ case KeyEvent.VK_LEFT:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+ break;
+
+ case KeyEvent.VK_RIGHT:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+ break;
+ }
+ }
});
}
expandViews.setEnabled(true);
gatherViews.setEnabled(true);
- tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap);
+ tabbedPane.addTab(ap.av.viewName, ap);
ap.setVisible(false);
}
if(newPanel)
{
if (ap.av.padGaps)
+ {
ap.av.alignment.padGaps();
+ }
ap.av.updateConservation(ap);
ap.av.updateConsensus(ap);
}
gatherViews.setEnabled(true);
tabbedPane.setVisible(true);
AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
- tabbedPane.addTab(first.av.viewName==null?"Original":first.av.viewName,first);
+ tabbedPane.addTab(first.av.viewName,first);
this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
}
idRightAlign.setSelected(av.rightAlignIds);
renderGapsMenuItem.setSelected(av.renderGaps);
wrapMenuItem.setSelected(av.wrapAlignment);
+ scaleAbove.setVisible(av.wrapAlignment);
+ scaleLeft.setVisible(av.wrapAlignment);
+ scaleRight.setVisible(av.wrapAlignment);
annotationPanelMenuItem.setState(av.showAnnotation);
viewBoxesMenuItem.setSelected(av.showBoxes);
viewTextMenuItem.setSelected(av.showText);
public void setProgressBar(String message, long id)
{
if(progressBars == null)
+ {
progressBars = new Hashtable();
+ }
JPanel progressPanel;
GridLayout layout = (GridLayout) statusPanel.getLayout();
progressBars.remove( progressPanel );
progressPanel = null;
if(message!=null)
+ {
statusBar.setText(message);
+ }
layout.setRows(layout.getRows() - 1);
}
&& frames[i] != this
&& ( (AlignFrame) frames[i]).fileName.equals(fileName))
{
- try{
+ try
+ {
frames[i].setSelected(true);
Desktop.instance.closeAssociatedWindows();
- }catch(java.beans.PropertyVetoException ex){}
+ }
+ catch (java.beans.PropertyVetoException ex)
+ {}
}
}
Desktop.instance.closeAssociatedWindows();
+ FileLoader loader = new FileLoader();
+ String protocol = fileName.startsWith("http:")? "URL":"File";
+ loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
}
else
{
- viewport.alignment.deleteAllGroups();
- viewport.sequenceColours=null;
- while (viewport.alignment.getHeight() > 0)
- {
- viewport.alignment.deleteSequence(0);
- }
+ Rectangle bounds = this.getBounds();
- viewport.historyList.clear();
- viewport.redoList.clear();
- Alignment dset = viewport.alignment.getDataset();
- while (dset.getHeight() > 0)
- {
- dset.deleteSequence(0);
- }
+ FileLoader loader = new FileLoader();
+ String protocol = fileName.startsWith("http:") ? "URL" : "File";
+ AlignFrame newframe =
+ loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
- firePropertyChange("Alignment", null, null);
+ newframe.setBounds(bounds);
- updateEditMenuBar();
+ this.closeMenuItem_actionPerformed(true);
}
-
- FileLoader loader = new FileLoader();
- String protocol = fileName.startsWith("http:")? "URL":"File";
- loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
-
}
}
public void save_actionPerformed(ActionEvent e)
{
- if(fileName==null || currentFileFormat==null)
+ if(fileName==null
+ || currentFileFormat==null
+ || fileName.startsWith("http")
+ )
+ {
saveAs_actionPerformed(null);
+ }
else
+ {
saveAlignment(fileName, currentFileFormat);
}
+ }
/**
* DOCUMENT ME!
public boolean saveAlignment(String file, String format)
{
+ boolean success = true;
+
if (format.equalsIgnoreCase("Jalview"))
{
String shortName = title;
java.io.File.separatorChar) + 1);
}
- new Jalview2XML().SaveAlignment(this, file, shortName);
+ success = new Jalview2XML().SaveAlignment(this, file, shortName);
statusBar.setText("Successfully saved to file: "
+fileName+" in "
+format +" format.");
-
- // USE Jalview2XML to save this file
- return true;
}
else
{
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (reply == JOptionPane.YES_OPTION)
+ {
omitHidden = viewport.getViewAsString(false);
}
+ }
String output = new FormatAdapter().formatSequences(
format,
if (output == null)
{
- return false;
- }
-
- try
- {
- java.io.PrintWriter out = new java.io.PrintWriter(
- new java.io.FileWriter(file));
-
- out.print(output);
- out.close();
- this.setTitle(file);
- statusBar.setText("Successfully saved to file: "
- +fileName+" in "
- +format +" format.");
- return true;
+ success = false;
}
- catch (Exception ex)
+ else
{
- ex.printStackTrace();
+ try
+ {
+ java.io.PrintWriter out = new java.io.PrintWriter(
+ new java.io.FileWriter(file));
+
+ out.print(output);
+ out.close();
+ this.setTitle(file);
+ statusBar.setText("Successfully saved to file: "
+ + fileName + " in "
+ + format + " format.");
+ }
+ catch (Exception ex)
+ {
+ success = false;
+ ex.printStackTrace();
+ }
}
}
- return false;
+
+ if (!success)
+ {
+ JOptionPane.showInternalMessageDialog(
+ this, "Couldn't save file: " + fileName,
+ "Error Saving File",
+ JOptionPane.WARNING_MESSAGE);
+ }
+
+ return success;
}
/**
*/
protected void htmlMenuItem_actionPerformed(ActionEvent e)
{
- new HTMLOutput(viewport,
+ new HTMLOutput(alignPanel,
alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
}
alignPanel.makeEPS(f);
}
+
+ public void pageSetup_actionPerformed(ActionEvent e)
+ {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
+ }
+
/**
* DOCUMENT ME!
*
public void printMenuItem_actionPerformed(ActionEvent e)
{
//Putting in a thread avoids Swing painting problems
- PrintThread thread = new PrintThread();
+ PrintThread thread = new PrintThread(alignPanel);
thread.start();
}
{
new AnnotationExporter().exportAnnotations(
alignPanel,
- viewport.alignment.getAlignmentAnnotation()
+ viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
+ viewport.alignment.getGroups(),
+ ((Alignment)viewport.alignment).alignmentProperties
);
}
public void closeMenuItem_actionPerformed(boolean closeAllTabs)
{
if(alignPanels!=null && alignPanels.size()<2)
+ {
closeAllTabs = true;
+ }
try
{
if(alignPanels!=null)
{
if (closeAllTabs)
+ {
for (int i = 0; i < alignPanels.size(); i++)
{
AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
+ jalview.structure.StructureSelectionManager.getStructureSelectionManager()
+ .removeStructureViewerListener(ap.seqPanel, null);
PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
PaintRefresher.RemoveComponent(ap);
+ ap.av.alignment = null;
}
+ }
else
{
int index = tabbedPane.getSelectedIndex();
- tabbedPane.removeTabAt(index);
alignPanels.removeElement(alignPanel);
PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
PaintRefresher.RemoveComponent(alignPanel);
+ viewport.alignment = null;
alignPanel = null;
viewport = null;
+
+ tabbedPane.removeTabAt(index);
tabbedPane.validate();
if(index==tabbedPane.getTabCount())
+ {
index --;
+ }
this.tabSelectionChanged(index);
}
}
if (closeAllTabs)
+ {
this.setClosed(true);
}
+ }
catch (Exception ex)
{
ex.printStackTrace();
command.undoCommand();
AlignViewport originalSource = getOriginatingSource(command);
-
- originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
updateEditMenuBar();
- originalSource.firePropertyChange("alignment", null,viewport.getAlignment().getSequences());
+
+ if(originalSource!=null)
+ {
+ originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
+ originalSource.firePropertyChange("alignment",
+ null,
+ originalSource.alignment.getSequences());
+ }
}
/**
*/
protected void redoMenuItem_actionPerformed(ActionEvent e)
{
+ if(viewport.redoList.size()<1)
+ {
+ return;
+ }
+
CommandI command = (CommandI) viewport.redoList.pop();
viewport.historyList.push(command);
command.doCommand();
AlignViewport originalSource = getOriginatingSource(command);
- originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
-
updateEditMenuBar();
- originalSource.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+
+ if(originalSource!=null)
+ {
+ originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
+ originalSource.firePropertyChange("alignment",
+ null,
+ originalSource.alignment.getSequences());
+ }
}
AlignViewport getOriginatingSource(CommandI command)
{
- AlignViewport originalSource = viewport;
+ AlignViewport originalSource = null;
//For sequence removal and addition, we need to fire
//the property change event FROM the viewport where the
//original alignment was altered
+ AlignmentI al=null;
if (command instanceof EditCommand)
{
EditCommand editCommand = (EditCommand) command;
- AlignmentI al = editCommand.getAlignment();
+ al = editCommand.getAlignment();
Vector comps = (Vector) PaintRefresher.components
.get(viewport.getSequenceSetId());
+
for (int i = 0; i < comps.size(); i++)
{
if (comps.elementAt(i) instanceof AlignmentPanel)
}
}
}
+
+ if (originalSource == null)
+ {
+ //The original view is closed, we must validate
+ //the current view against the closed view first
+ if (al != null)
+ {
+ PaintRefresher.validateSequences(al, viewport.alignment);
+ }
+
+ originalSource = viewport;
+ }
+
return originalSource;
}
{
SequenceI seq = viewport.alignment.getSequenceAt(i);
- if (!sg.getSequences(false).contains(seq))
+ if (!sg.getSequences(null).contains(seq))
{
continue;
}
SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
- if (sg.getSequences(false).contains(temp))
+ if (sg.getSequences(null).contains(temp))
{
continue;
}
{
SequenceI seq = viewport.alignment.getSequenceAt(i);
- if (!sg.getSequences(false).contains(seq))
+ if (!sg.getSequences(null).contains(seq))
{
continue;
}
SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
- if (sg.getSequences(false).contains(temp))
+ if (sg.getSequences(null).contains(temp))
{
continue;
}
}
}
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
+
+ synchronized void slideSequences(boolean right, int size)
+ {
+ Vector sg = new Vector();
+ if(viewport.cursorMode)
+ {
+ sg.addElement(viewport.alignment.getSequenceAt(
+ alignPanel.seqPanel.seqCanvas.cursorY));
+ }
+ else if(viewport.getSelectionGroup()!=null
+ && viewport.getSelectionGroup().getSize()!=viewport.alignment.getHeight())
+ {
+ sg = viewport.getSelectionGroup().getSequences(
+ viewport.hiddenRepSequences);
+ }
+
+ if(sg.size()<1)
+ {
+ return;
+ }
+
+ Vector invertGroup = new Vector();
+
+ for (int i = 0; i < viewport.alignment.getHeight(); i++)
+ {
+ if(!sg.contains(viewport.alignment.getSequenceAt(i)))
+ invertGroup.add(viewport.alignment.getSequenceAt(i));
+ }
+
+ SequenceI[] seqs1 = new SequenceI[sg.size()];
+ for (int i = 0; i < sg.size(); i++)
+ seqs1[i] = (SequenceI) sg.elementAt(i);
+
+ SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
+ for (int i = 0; i < invertGroup.size(); i++)
+ seqs2[i] = (SequenceI) invertGroup.elementAt(i);
+
+ SlideSequencesCommand ssc;
+ if (right)
+ ssc = new SlideSequencesCommand("Slide Sequences",
+ seqs2, seqs1, size,
+ viewport.getGapCharacter()
+ );
+ else
+ ssc = new SlideSequencesCommand("Slide Sequences",
+ seqs1, seqs2, size,
+ viewport.getGapCharacter()
+ );
+
+ int groupAdjustment = 0;
+ if (ssc.getGapsInsertedBegin() && right)
+ {
+ if (viewport.cursorMode)
+ alignPanel.seqPanel.moveCursor(size, 0);
+ else
+ groupAdjustment = size;
+ }
+ else if (!ssc.getGapsInsertedBegin() && !right)
+ {
+ if (viewport.cursorMode)
+ alignPanel.seqPanel.moveCursor( -size, 0);
+ else
+ groupAdjustment = -size;
+ }
+
+ if (groupAdjustment != 0)
+ {
+ viewport.getSelectionGroup().setStartRes(
+ viewport.getSelectionGroup().getStartRes() + groupAdjustment);
+ viewport.getSelectionGroup().setEndRes(
+ viewport.getSelectionGroup().getEndRes() + groupAdjustment);
+ }
+
+
+ boolean appendHistoryItem = false;
+ if(viewport.historyList!=null
+ && viewport.historyList.size()>0
+ && viewport.historyList.peek() instanceof SlideSequencesCommand)
+ {
+ appendHistoryItem = ssc.appendSlideCommand(
+ (SlideSequencesCommand)viewport.historyList.peek())
+ ;
+ }
+
+ if(!appendHistoryItem)
+ addHistoryItem(ssc);
+
+ repaint();
+ }
+
+
/**
* DOCUMENT ME!
*
{
return;
}
-
+ // TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
SequenceI [] seqs = viewport.getSelectionAsNewSequence();
String[] omitHidden = null;
try
{
+ jalview.gui.Desktop.internalCopy = true;
//Its really worth setting the clipboard contents
//to empty before setting the large StringSelection!!
Toolkit.getDefaultToolkit().getSystemClipboard()
{
hiddenColumns =new Vector();
int hiddenOffset = viewport.getSelectionGroup().getStartRes();
- for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
+ for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
+ i++)
{
int[] region = (int[])
viewport.getColumnSelection().getHiddenColumns().elementAt(i);
- hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
+ hiddenColumns.addElement(new int[]
+ {region[0] - hiddenOffset,
region[1]-hiddenOffset});
}
}
-
-
- Desktop.jalviewClipboard = new Object[]{ seqs,
+ Desktop.jalviewClipboard = new Object[]
+ {
+ seqs,
viewport.alignment.getDataset(),
hiddenColumns};
statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
*/
void paste(boolean newAlignment)
{
+ boolean externalPaste=true;
try
{
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
{
str = (String) contents.getTransferData(DataFlavor.stringFlavor);
if (str.length() < 1)
+ {
return;
+ }
format = new IdentifyFile().Identify(str, "Paste");
}
SequenceI[] sequences;
-
+ boolean annotationAdded = false;
+ AlignmentI alignment = null;
if(Desktop.jalviewClipboard!=null)
{
// The clipboard was filled from within Jalview, we must use the sequences
// And dataset from the copied alignment
- sequences = (SequenceI[])Desktop.jalviewClipboard[0];
+ SequenceI[] newseq = (SequenceI[])Desktop.jalviewClipboard[0];
+ // be doubly sure that we create *new* sequence objects.
+ sequences = new SequenceI[newseq.length];
+ for (int i=0;i<newseq.length;i++) {
+ sequences[i] = new Sequence(newseq[i]);
+ }
+ alignment = new Alignment(sequences);
+ externalPaste = false;
}
else
{
- sequences = new FormatAdapter().readFile(str, "Paste", format);
+ // parse the clipboard as an alignment.
+ alignment = new FormatAdapter().readFile(str, "Paste", format);
+ sequences = alignment.getSequencesArray();
}
- AlignmentI alignment = null;
+ int alwidth=0;
- if (newAlignment)
- {
- alignment = new Alignment(sequences);
+ if (newAlignment)
+ {
- if (Desktop.jalviewClipboard != null)
- alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
- else
- alignment.setDataset(null);
- }
- else
- {
- alignment = viewport.getAlignment();
+ if (Desktop.jalviewClipboard != null)
+ {
+ // dataset is inherited
+ alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
+ }
+ else
+ {
+ // new dataset is constructed
+ alignment.setDataset(null);
+ }
+ alwidth = alignment.getWidth()+1;
+ }
+ else
+ {
+ AlignmentI pastedal = alignment; // preserve pasted alignment object
+ // Add pasted sequences and dataset into existing alignment.
+ alignment = viewport.getAlignment();
+ alwidth = alignment.getWidth()+1;
+ // decide if we need to import sequences from an existing dataset
+ boolean importDs = Desktop.jalviewClipboard != null
+ && Desktop.jalviewClipboard[1] != alignment.getDataset();
+ // importDs==true instructs us to copy over new dataset sequences from
+ // an existing alignment
+ Vector newDs = (importDs) ? new Vector() : null; // used to create
+ // minimum dataset set
- //!newAlignment
- SequenceI [] newseqs = new SequenceI[sequences.length];
for (int i = 0; i < sequences.length; i++)
{
- newseqs[i] = new Sequence(sequences[i].getName(),
- sequences[i].getSequence(), sequences[i].getStart(),
- sequences[i].getEnd());
-
- alignment.addSequence(newseqs[i]);
+ if (importDs)
+ {
+ newDs.addElement(null);
+ }
+ SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
+ // paste
+ if (importDs && ds != null)
+ {
+ if (!newDs.contains(ds))
+ {
+ newDs.setElementAt(ds, i);
+ ds = new Sequence(ds);
+ // update with new dataset sequence
+ sequences[i].setDatasetSequence(ds);
+ }
+ else
+ {
+ ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
+ }
+ }
+ else
+ {
+ // copy and derive new dataset sequence
+ sequences[i] = sequences[i].deriveSequence();
+ alignment.getDataset().addSequence(sequences[i].getDatasetSequence());
+ // TODO: avoid creation of duplicate dataset sequences with a
+ // 'contains' method using SequenceI.equals()/SequenceI.contains()
+ }
+ alignment.addSequence(sequences[i]); // merges dataset
}
-
- /*
- //ADD HISTORY ITEM
- */
- addHistoryItem(new EditCommand(
- "Add sequences",
- EditCommand.PASTE,
- newseqs,
- 0,
- alignment.getWidth(),
- alignment)
- );
-
-
- viewport.setEndSeq(alignment.getHeight());
- alignment.getWidth();
- viewport.firePropertyChange("alignment", null, alignment.getSequences());
- }
-
-
-
- // Add any annotations attached to sequences
- for (int i = 0; i < sequences.length; i++)
+ if (newDs != null)
+ {
+ newDs.clear(); // tidy up
+ }
+ if (pastedal.getAlignmentAnnotation()!=null) {
+ // Add any annotation attached to alignment.
+ AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
+ for (int i=0; i<alann.length; i++)
+ {
+ annotationAdded=true;
+ if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
+ AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
+ newann.padAnnotation(alwidth);
+ alignment.addAnnotation(newann);
+ }
+ }
+ }
+ }
+ if (!newAlignment) {
+ ///////
+ // ADD HISTORY ITEM
+ //
+ addHistoryItem(new EditCommand(
+ "Add sequences",
+ EditCommand.PASTE,
+ sequences,
+ 0,
+ alignment.getWidth(),
+ alignment)
+ );
+ }
+ // Add any annotations attached to sequences
+ for (int i = 0; i < sequences.length; i++)
{
if (sequences[i].getAnnotation() != null)
{
for (int a = 0; a < sequences[i].getAnnotation().length; a++)
{
- AlignmentAnnotation newAnnot =
- new AlignmentAnnotation(
- sequences[i].getAnnotation()[a].label,
- sequences[i].getAnnotation()[a].description,
- sequences[i].getAnnotation()[a].annotations,
- sequences[i].getAnnotation()[a].graphMin,
- sequences[i].getAnnotation()[a].graphMax,
- sequences[i].getAnnotation()[a].graph);
-
- sequences[i].getAnnotation()[a] = newAnnot;
- newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
- sequenceMapping;
- newAnnot.sequenceRef = sequences[i];
- newAnnot.adjustForAlignment();
- alignment.addAnnotation(newAnnot);
- alignment.setAnnotationIndex(newAnnot, a);
+ annotationAdded=true;
+ sequences[i].getAnnotation()[a].adjustForAlignment();
+ sequences[i].getAnnotation()[a].padAnnotation(alwidth);
+ alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
+ alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
}
- alignPanel.annotationPanel.adjustPanelHeight();
+
}
}
-
- if(newAlignment)
- {
+ if (!newAlignment) {
+ // propagate alignment changed.
+ viewport.setEndSeq(alignment.getHeight());
+ if (annotationAdded)
+ {
+ alignPanel.annotationPanel.adjustPanelHeight();
+ buildSortByAnnotationScoresMenu();
+ }
+ viewport.firePropertyChange("alignment", null, alignment.getSequences());
+ } else {
AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
String newtitle = new String("Copied sequences");
af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
-
- if (title.startsWith("Copied sequences"))
- {
- newtitle = title;
- }
- else
- {
- newtitle = newtitle.concat("- from " + title);
+ // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
+ if (!externalPaste) {
+ if (title.startsWith("Copied sequences"))
+ {
+ newtitle = title;
+ }
+ else
+ {
+ newtitle = newtitle.concat("- from " + title);
+ }
+ } else {
+ newtitle = new String("Pasted sequences");
}
Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
Vector seqs = new Vector();
SequenceI seq;
- for (int i = 0; i < sg.getSize(false); i++)
+ for (int i = 0; i < sg.getSize(); i++)
{
seq = sg.getSequenceAt(i);
seqs.addElement(seq);
// If the cut affects all sequences, remove highlighted columns
- if (sg.getSize(false) == viewport.alignment.getHeight())
+ if (sg.getSize() == viewport.alignment.getHeight())
{
viewport.getColumnSelection().removeElements(sg.getStartRes(),
sg.getEndRes() + 1);
SequenceI [] cut = new SequenceI[seqs.size()];
for(int i=0; i<seqs.size(); i++)
+ {
cut[i] = (SequenceI)seqs.elementAt(i);
+ }
/*
protected void deleteGroups_actionPerformed(ActionEvent e)
{
viewport.alignment.deleteAllGroups();
- viewport.sequenceColours.clear();
+ viewport.sequenceColours = null;
viewport.setSelectionGroup(null);
PaintRefresher.Refresh(this, viewport.getSequenceSetId());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
sg.setEndRes(viewport.alignment.getWidth() - 1);
viewport.setSelectionGroup(sg);
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
}
viewport.setSelectionGroup(null);
alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
alignPanel.idPanel.idCanvas.searchResults = null;
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
}
sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
}
+ alignPanel.paintAlignment(true);
+
PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
}
public void invertColSel_actionPerformed(ActionEvent e)
{
viewport.invertColumnSelection();
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
if (colSel.size() > 0)
{
if(trimLeft)
+ {
column = colSel.getMin();
+ }
else
+ {
column = colSel.getMax();
+ }
SequenceI [] seqs;
if(viewport.getSelectionGroup()!=null)
- seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
+ {
+ seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
+ hiddenRepSequences);
+ }
else
+ {
seqs = viewport.alignment.getSequencesArray();
+ }
TrimRegionCommand trimRegion;
SequenceI[] seqs;
if (viewport.getSelectionGroup() != null)
{
- seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
+ seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
+ hiddenRepSequences);
start = viewport.getSelectionGroup().getStartRes();
end = viewport.getSelectionGroup().getEndRes();
}
else
+ {
seqs = viewport.alignment.getSequencesArray();
+ }
RemoveGapColCommand removeGapCols =
new RemoveGapColCommand("Remove Gapped Columns",
seqs,
start, end,
- viewport.getGapCharacter());
+ viewport.alignment);
addHistoryItem(removeGapCols);
// if (viewport.hasHiddenColumns)
// viewport.getColumnSelection().compensateForEdits(shifts);
viewport.setStartRes(seq.findIndex(startRes)-1);
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
}
SequenceI[] seqs;
if (viewport.getSelectionGroup() != null)
{
- seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
+ seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
+ hiddenRepSequences);
start = viewport.getSelectionGroup().getStartRes();
end = viewport.getSelectionGroup().getEndRes();
}
else
+ {
seqs = viewport.alignment.getSequencesArray();
+ }
//This is to maintain viewport position on first residue
//of first sequence
int startRes = seq.findPosition(viewport.startRes);
addHistoryItem(new RemoveGapsCommand("Remove Gaps",
- seqs,
- start, end,
- viewport.getGapCharacter()));
+ seqs,
+ start, end,
+ viewport.alignment));
viewport.setStartRes(seq.findIndex(startRes)-1);
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
}
AlignmentPanel newap =
new Jalview2XML().copyAlignPanel(alignPanel, true);
+ newap.av.gatherViewsHere = false;
+
if (viewport.viewName == null)
- viewport.viewName = "View 1";
+ {
+ viewport.viewName = "Original";
+ }
newap.av.historyList = viewport.historyList;
newap.av.redoList = viewport.redoList;
- newap.av.viewName = "View " +
- (Desktop.getViewCount(viewport.getSequenceSetId()) + 1);
+
+ int index = Desktop.getViewCount(viewport.getSequenceSetId());
+ String newViewName = "View " +index;
+
+ Vector comps = (Vector) PaintRefresher.components.get(viewport.
+ getSequenceSetId());
+ Vector existingNames = new Vector();
+ for(int i=0; i<comps.size(); i++)
+ {
+ if(comps.elementAt(i) instanceof AlignmentPanel)
+ {
+ AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
+ if(!existingNames.contains(ap.av.viewName))
+ {
+ existingNames.addElement(ap.av.viewName);
+ }
+ }
+ }
+
+ while(existingNames.contains(newViewName))
+ {
+ newViewName = "View "+ (++index);
+ }
+
+ newap.av.viewName = newViewName;
addAlignmentPanel(newap, false);
viewport.setShowJVSuffix(seqLimits.isSelected());
alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
public void idRightAlign_actionPerformed(ActionEvent e)
{
viewport.rightAlignIds = idRightAlign.isSelected();
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
protected void colourTextMenuItem_actionPerformed(ActionEvent e)
{
viewport.setColourText(colourTextMenuItem.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
public void hideSelSequences_actionPerformed(ActionEvent e)
{
viewport.hideAllSelectedSeqs();
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
public void hideSelColumns_actionPerformed(ActionEvent e)
{
viewport.hideSelectedColumns();
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
public void hiddenMarkers_actionPerformed(ActionEvent e)
protected void scaleAbove_actionPerformed(ActionEvent e)
{
viewport.setScaleAboveWrapped(scaleAbove.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
protected void scaleLeft_actionPerformed(ActionEvent e)
{
viewport.setScaleLeftWrapped(scaleLeft.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
protected void scaleRight_actionPerformed(ActionEvent e)
{
viewport.setScaleRightWrapped(scaleRight.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
{
viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
public void viewTextMenuItem_actionPerformed(ActionEvent e)
{
viewport.setShowText(viewTextMenuItem.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
{
viewport.setRenderGaps(renderGapsMenuItem.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
public void showSeqFeatures_actionPerformed(ActionEvent evt)
{
viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
if (alignPanel.getOverviewPanel() != null)
{
alignPanel.getOverviewPanel().updateOverviewImage();
alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
}
+ public void alignmentProperties()
+ {
+ JEditorPane editPane = new JEditorPane("text/html","");
+ editPane.setEditable(false);
+ StringBuffer contents = new StringBuffer("<html>");
+
+ float avg = 0;
+ int min=Integer.MAX_VALUE, max=0;
+ for(int i=0; i<viewport.alignment.getHeight(); i++)
+ {
+ int size = viewport.alignment.getSequenceAt(i).getEnd()
+ -viewport.alignment.getSequenceAt(i).getStart();
+ avg += size;
+ if(size>max)
+ max = size;
+ if(size<min)
+ min = size;
+ }
+ avg = avg/(float)viewport.alignment.getHeight();
+
+ contents.append("<br>Sequences: "+ viewport.alignment.getHeight());
+ contents.append("<br>Minimum Sequence Length: "+min);
+ contents.append("<br>Maximum Sequence Length: "+max);
+ contents.append("<br>Average Length: "+(int)avg);
+
+ if (((Alignment)viewport.alignment).getProperties() != null)
+ {
+ Hashtable props = ((Alignment)viewport.alignment).getProperties();
+ Enumeration en = props.keys();
+ contents.append("<br><br><table border=\"1\">");
+ while(en.hasMoreElements())
+ {
+ String key = en.nextElement().toString();
+ StringBuffer val = new StringBuffer();
+ String vals = props.get(key).toString();
+ int pos=0, npos;
+ do {
+ npos = vals.indexOf("\n",pos);
+ if (npos==-1)
+ {
+ val.append(vals.substring(pos));
+ } else {
+ val.append(vals.substring(pos, npos));
+ val.append("<br>");
+ }
+ pos = npos+1;
+ } while (npos!=-1);
+ contents.append("<tr><td>"+key+"</td><td>"+val+"</td></tr>");
+ }
+ contents.append("</table>");
+ }
+ editPane.setText(contents.toString()+"</html>");
+ JInternalFrame frame = new JInternalFrame();
+ frame.getContentPane().add(new JScrollPane(editPane));
+
+ Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
+ }
+
+
/**
* DOCUMENT ME!
*
if (cs instanceof ClustalxColourScheme)
{
sg.cs = new ClustalxColourScheme(
- sg.getSequences(true), sg.getWidth());
+ sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
}
else if (cs instanceof UserColourScheme)
{
viewport.getIgnoreGapsConsensus());
sg.cs.setConsensus(AAFrequency.calculate(
- sg.getSequences(true), sg.getStartRes(),
+ sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
sg.getEndRes()+1));
}
else
+ {
sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
+ }
if (viewport.getConservationSelected())
{
Conservation c = new Conservation("Group",
ResidueProperties.propHash, 3,
- sg.getSequences(true),
+ sg.getSequences(viewport.
+ hiddenRepSequences),
sg.getStartRes(),
sg.getEndRes()+1);
c.calculate();
sg.cs.setConservation(c);
}
else
+ {
sg.cs.setConservation(null);
}
}
+ }
if (alignPanel.getOverviewPanel() != null)
{
alignPanel.getOverviewPanel().updateOverviewImage();
}
- alignPanel.repaint();
+
+
+
+ alignPanel.paintAlignment(true);
}
/**
while (userColours.hasMoreElements())
{
- final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
+ final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
+ userColours.
nextElement().toString());
radioItem.setName("USER_DEFINED");
radioItem.addMouseListener(new MouseAdapter()
{
radioItem.removeActionListener(radioItem.getActionListeners()[0]);
- int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
+ int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
+ Desktop.desktop,
"Remove from default list?",
"Remove user defined colour",
JOptionPane.YES_NO_OPTION);
if(option == JOptionPane.YES_OPTION)
{
- jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
+ jalview.gui.UserDefinedColours.removeColourFromDefaults(
+ radioItem.getText());
colourMenu.remove(radioItem);
}
else
+ {
radioItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
});
}
}
+ }
});
radioItem.addActionListener(new ActionListener()
{
SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
AlignmentSorter.sortByPID(viewport.getAlignment(),
viewport.getAlignment().getSequenceAt(0));
- addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
- alignPanel.repaint();
+ addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
+ viewport.alignment));
+ alignPanel.paintAlignment(true);
}
/**
SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
AlignmentSorter.sortByID(viewport.getAlignment());
addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
/**
AlignmentSorter.sortByGroup(viewport.getAlignment());
addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
-
/**
* DOCUMENT ME!
*
public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
{
if ( (viewport.getSelectionGroup() == null) ||
- (viewport.getSelectionGroup().getSize(false) < 2))
+ (viewport.getSelectionGroup().getSize() < 2))
{
JOptionPane.showInternalMessageDialog(this,
"You must select at least 2 sequences.",
public void PCAMenuItem_actionPerformed(ActionEvent e)
{
if ( ( (viewport.getSelectionGroup() != null) &&
- (viewport.getSelectionGroup().getSize(false) < 4) &&
- (viewport.getSelectionGroup().getSize(false) > 0)) ||
+ (viewport.getSelectionGroup().getSize() < 4) &&
+ (viewport.getSelectionGroup().getSize() > 0)) ||
(viewport.getAlignment().getHeight() < 4))
{
JOptionPane.showInternalMessageDialog(this,
return;
}
- new PCAPanel(viewport);
+ new PCAPanel(alignPanel);
}
{
TreePanel tp;
- if (viewport.getSelectionGroup() != null) {
- if (viewport.getSelectionGroup().getSize(false) < 3) {
+ if (viewport.getSelectionGroup() != null)
+ {
+ if (viewport.getSelectionGroup().getSize() < 3)
+ {
JOptionPane.showMessageDialog(Desktop.desktop,
"You need to have more than two sequences selected to build a tree!",
"Not enough sequences",
SequenceGroup sg = viewport.getSelectionGroup();
/* Decide if the selection is a column region */
- while (s < sg.getSize(false))
+ while (s < sg.getSize())
{
- if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
+ if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
sg.getEndRes())
{
JOptionPane.showMessageDialog(Desktop.desktop,
}
if(viewport.alignment.getHeight()<2)
+ {
return;
+ }
tp = new TreePanel(alignPanel, type, pwType);
}
- addTreeMenuItem(tp, title);
+ title += " from ";
+
+ if(viewport.viewName!=null)
+ {
+ title+= viewport.viewName+" of ";
+ }
- Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
+ title += this.title;
+
+ Desktop.addInternalFrame(tp, title, 600, 500);
}
/**
// TODO: JBPNote - have to map order entries to curent SequenceI pointers
AlignmentSorter.sortBy(viewport.getAlignment(), order);
- addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
+ addHistoryItem(new OrderCommand(order.getName(), oldOrder,
+ viewport.alignment));
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
+ }
+ });
+ }
+ /**
+ * Add a new sort by annotation score menu item
+ * @param sort the menu to add the option to
+ * @param scoreLabel the label used to retrieve scores for each sequence on the alignment
+ */
+ public void addSortByAnnotScoreMenuItem(JMenu sort, final String scoreLabel)
+ {
+ final JMenuItem item = new JMenuItem(scoreLabel);
+ sort.add(item);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());
+ addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment));
+ alignPanel.paintAlignment(true);
}
});
}
+ /**
+ * last hash for alignment's annotation array - used to minimise cost of rebuild.
+ */
+ protected int _annotationScoreVectorHash;
+ /**
+ * search the alignment and rebuild the sort by annotation score submenu
+ * the last alignment annotation vector hash is stored to minimize
+ * cost of rebuilding in subsequence calls.
+ *
+ */
+ public void buildSortByAnnotationScoresMenu()
+ {
+ if (viewport.alignment.getAlignmentAnnotation().hashCode()!=_annotationScoreVectorHash)
+ {
+ sortByAnnotScore.removeAll();
+ // almost certainly a quicker way to do this - but we keep it simple
+ Hashtable scoreSorts=new Hashtable();
+ AlignmentAnnotation aann[];
+ Enumeration sq = viewport.alignment.getSequences().elements();
+ while (sq.hasMoreElements())
+ {
+ aann = ((SequenceI) sq.nextElement()).getAnnotation();
+ for (int i=0;aann!=null && i<aann.length; i++)
+ {
+ if (aann[i].hasScore() && aann[i].sequenceRef!=null)
+ {
+ scoreSorts.put(aann[i].label, aann[i].label);
+ }
+ }
+ }
+ Enumeration labels = scoreSorts.keys();
+ while (labels.hasMoreElements())
+ {
+ addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels.nextElement());
+ }
+ sortByAnnotScore.setVisible(scoreSorts.size()>0);
+ scoreSorts.clear();
+ }
+ }
/**
* Maintain the Order by->Displayed Tree menu.
* @param treePanel Displayed tree window.
* @param title SortBy menu item title.
*/
- void addTreeMenuItem(final TreePanel treePanel, String title)
+ public void buildTreeMenu()
{
- final JMenuItem item = new JMenuItem(title);
+ sortByTreeMenu.removeAll();
- treeCount++;
-
- if (treeCount == 1)
+ Vector comps = (Vector) PaintRefresher.components.get(viewport.
+ getSequenceSetId());
+ Vector treePanels = new Vector();
+ int i, iSize = comps.size();
+ for(i=0; i<iSize; i++)
{
- sort.add(sortByTreeMenu);
+ if(comps.elementAt(i) instanceof TreePanel)
+ {
+ treePanels.add(comps.elementAt(i));
+ }
}
- sortByTreeMenu.add(item);
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
- AlignmentSorter.sortByTree(viewport.getAlignment(),
- treePanel.getTree());
+ iSize = treePanels.size();
- addHistoryItem(new OrderCommand("Tree Sort",
- oldOrder,
- viewport.alignment));
+ if(iSize<1)
+ {
+ sortByTreeMenu.setVisible(false);
+ return;
+ }
+ sortByTreeMenu.setVisible(true);
- alignPanel.repaint();
- }
- });
-
- treePanel.addInternalFrameListener(new javax.swing.event.
- InternalFrameAdapter()
+ for(i=0; i<treePanels.size(); i++)
{
- public void internalFrameClosed(
- javax.swing.event.InternalFrameEvent evt)
+ TreePanel tp = (TreePanel)treePanels.elementAt(i);
+ final JMenuItem item = new JMenuItem(tp.getTitle());
+ final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
+ item.addActionListener(new java.awt.event.ActionListener()
{
- treeCount--;
- sortByTreeMenu.remove(item);
-
- if (treeCount == 0)
+ public void actionPerformed(ActionEvent e)
{
- sort.remove(sortByTreeMenu);
+ SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
+
+ addHistoryItem(new OrderCommand("Tree Sort",
+ oldOrder,
+ viewport.alignment));
+
+ alignPanel.paintAlignment(true);
}
- }
- ;
- });
+ });
+
+ sortByTreeMenu.add(item);
+ }
}
/**
AlignmentView msa = null;
if ( (viewport.getSelectionGroup() != null) &&
- (viewport.getSelectionGroup().getSize(false) > 1))
+ (viewport.getSelectionGroup().getSize() > 1))
{
// JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
/*SequenceGroup seqs = viewport.getSelectionGroup();
AlignmentView seqs = null;
if ( (viewport.getSelectionGroup() != null) &&
- (viewport.getSelectionGroup().getSize(false) > 0))
+ (viewport.getSelectionGroup().getSize() > 0))
{
seqs = viewport.getAlignmentView(true);
}
// TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
if (!viewport.alignment.isAligned())
{
- seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
+ seqs.setSequences(new SeqCigar[]
+ {seqs.getSequences()[0]});
}
return seqs;
}
{
return ShowNewickTree(nf,title,600,500,4,5);
}
- public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
+
+ public TreePanel ShowNewickTree(NewickFile nf, String title,
+ AlignmentView input)
{
return ShowNewickTree(nf,title, input, 600,500,4,5);
}
- public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
+
+ public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
+ int x, int y)
+ {
return ShowNewickTree(nf, title, null, w, h, x, y);
}
/**
* @param y position
* @return TreePanel handle
*/
- public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
+ public TreePanel ShowNewickTree(NewickFile nf, String title,
+ AlignmentView input, int w, int h, int x,
+ int y)
+ {
TreePanel tp = null;
try
tp.setSize(w,h);
if(x>0 && y>0)
+ {
tp.setLocation(x,y);
+ }
Desktop.addInternalFrame(tp, title, w, h);
- addTreeMenuItem(tp, title);
}
}
catch (Exception ex)
return tp;
}
- class PrintThread
- extends Thread
- {
- public void run()
- {
- PrinterJob printJob = PrinterJob.getPrinterJob();
- PageFormat pf = printJob.pageDialog(printJob.defaultPage());
- printJob.setPrintable(alignPanel, pf);
-
- if (printJob.printDialog())
- {
- try
- {
- printJob.print();
- }
- catch (Exception PrintException)
- {
- PrintException.printStackTrace();
- }
- }
- }
- }
/**
* Generates menu items and listener event actions for web service clients
{
AlignmentView msa = gatherSequencesForAlignment();
new jalview.ws.MsaWSClient(sh, title, msa,
- false, true, viewport.getAlignment().getDataset(), af);
+ false, true,
+ viewport.getAlignment().getDataset(),
+ af);
}
{
AlignmentView msa = gatherSequencesForAlignment();
new jalview.ws.MsaWSClient(sh, title, msa,
- true, true, viewport.getAlignment().getDataset(), af);
+ true, true,
+ viewport.getAlignment().getDataset(),
+ af);
}
}
wsmenu.add(secstrmenu);
}
- this.webService.removeAll();
+ resetWebServiceMenu();
for (int i = 0, j = wsmenu.size(); i < j; i++)
{
webService.add( (JMenu) wsmenu.get(i));
}
else
{
- this.webService.removeAll();
+ resetWebServiceMenu();
this.webService.add(this.webServiceNoServices);
}
// TODO: add in rediscovery function
// TODO: group services by location as well as function.
}
+
+ /**
+ * empty the web service menu and add any ad-hoc functions
+ * not dynamically discovered.
+ *
+ */
+ private void resetWebServiceMenu()
+ {
+ webService.removeAll();
+ // Temporary hack - DBRef Fetcher always top level ws entry.
+ JMenuItem rfetch = new JMenuItem("Fetch DB References");
+ rfetch.setToolTipText("Retrieve and parse uniprot records for the alignment or the currently selected sequences");
+ webService.add(rfetch);
+ rfetch.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ new jalview.io.DBRefFetcher(
+ alignPanel.av.getSequenceSelection(),
+ alignPanel.alignFrame).fetchDBRefs(false);
+ }
+
+ });
+ }
+
/* public void vamsasStore_actionPerformed(ActionEvent e)
{
JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
-
public void showTranslation_actionPerformed(ActionEvent e)
{
- SequenceI [] selection = viewport.getSelectionAsNewSequence();
- String [] seqstring = viewport.getViewAsString(true);
-
- int s, sSize = selection.length;
- SequenceI [] newSeq = new SequenceI[sSize];
-
- int res, resSize;
- StringBuffer protein;
- String seq;
- for(s=0; s<sSize; s++)
- {
- protein = new StringBuffer();
- seq = AlignSeq.extractGaps("-. ", seqstring[s]);
- resSize = seq.length();
- resSize -= resSize%3;
-
- for(res = 0; res < resSize; res+=3)
- {
- String codon = seq.substring(res, res+3);
- codon = codon.replace('U', 'T');
- String aa = ResidueProperties.codonTranslate(codon);
- if(aa==null)
- protein.append(viewport.getGapCharacter());
- else if(aa.equals("STOP"))
- protein.append("X");
- else
- protein.append( aa );
- }
- newSeq[s] = new Sequence(selection[s].getName(),
- protein.toString());
- }
-
-
- AlignmentI al = new Alignment(newSeq);
- al.setDataset(null);
-
-
- ////////////////////////////////
- // Copy annotations across
- jalview.datamodel.AlignmentAnnotation[] annotations
- = viewport.alignment.getAlignmentAnnotation();
- int a, aSize;
- if(annotations!=null)
- {
- for (int i = 0; i < annotations.length; i++)
- {
- if (annotations[i].label.equals("Quality") ||
- annotations[i].label.equals("Conservation") ||
- annotations[i].label.equals("Consensus"))
- {
- continue;
- }
-
- aSize = viewport.alignment.getWidth() / 3;
- jalview.datamodel.Annotation[] anots =
- new jalview.datamodel.Annotation[aSize];
-
- for (a = 0; a < viewport.alignment.getWidth(); a++)
- {
- if (annotations[i].annotations[a] == null
- || annotations[i].annotations[a] == null)
- continue;
-
- anots[a / 3] = new Annotation(
- annotations[i].annotations[a].displayCharacter,
- annotations[i].annotations[a].description,
- annotations[i].annotations[a].secondaryStructure,
- annotations[i].annotations[a].value,
- annotations[i].annotations[a].colour);
- }
-
- jalview.datamodel.AlignmentAnnotation aa
- = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
- annotations[i].description, anots);
- al.addAnnotation(aa);
- }
- }
+ ///////////////////////////////
+ // 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.alignment.getAlignmentAnnotation(),
+ viewport.alignment.getWidth());
+ } catch (Exception ex) {
+ al = null;
+ jalview.bin.Cache.log.debug("Exception during translation.",ex);
+ }
+ if (al==null)
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
+ "Translation Failed",
+ JOptionPane.WARNING_MESSAGE);
+ } else {
AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
DEFAULT_WIDTH,
DEFAULT_HEIGHT);
-
-
-
-
+ }
}
/**
public boolean parseFeaturesFile(String file, String type)
{
boolean featuresFile = false;
- try{
- featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
+ try
+ {
+ featuresFile = new FeaturesFile(file,
+ type).parse(viewport.alignment.getDataset(),
alignPanel.seqPanel.seqCanvas.
getFeatureRenderer().featureColours,
false);
{
viewport.showSequenceFeatures = true;
showSeqFeatures.setSelected(true);
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
return featuresFile;
try
{
- DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
+ 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);
+ files = (java.util.List) t.getTransferData(DataFlavor.
+ javaFileListFlavor);
}
else if (t.isDataFlavorSupported(uriListFlavor))
{
// AlignFrame
public void loadJalviewDataFile(String file)
{
- try{
+ try
+ {
String protocol = "File";
if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
}
boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
- alignment, file);
+ alignment, file, protocol);
if (!isAnnotation)
{
viewport.getAlignment(),
0, false);
alignPanel.adjustAnnotationHeight();
- alignPanel.repaint();
+ alignPanel.paintAlignment(true);
}
else
+ {
new FileLoader().LoadFile(viewport, file, protocol, format);
}
}
+ }
else
{
// (isAnnotation)
alignPanel.adjustAnnotationHeight();
+ buildSortByAnnotationScoresMenu();
}
- }catch(Exception ex)
+ }
+ catch (Exception ex)
{
ex.printStackTrace();
}
{
return viewport;
}
-}
\ No newline at end of file
+
+
+ /**
+ * Open the dialog for regex description parsing.
+ */
+ protected void extractScores_actionPerformed(ActionEvent e)
+ {
+ ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment);
+ if (pp.getScoresFromDescription("col", "score column ", "\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)")>0)
+ {
+ buildSortByAnnotationScoresMenu();
+ }
+ }
+}
+
+class PrintThread
+ extends Thread
+{
+ AlignmentPanel ap;
+ public PrintThread(AlignmentPanel ap)
+ {
+ this.ap = ap;
+ }
+ static PageFormat pf;
+ public void run()
+ {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+
+ if (pf != null)
+ {
+ printJob.setPrintable(ap, pf);
+ }
+ else
+ {
+ printJob.setPrintable(ap);
+ }
+
+ if (printJob.printDialog())
+ {
+ try
+ {
+ printJob.print();
+ }
+ catch (Exception PrintException)
+ {
+ PrintException.printStackTrace();
+ }
+ }
+ }
+}