X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=32a50cfbfa30c359defac13060d2ebab1b8adf1b;hb=e4dca3706ab423352c26ac100f3ca5a3e7c3d2c4;hp=bfdc40bd9bb4ffde05afe1ba3b3fca758a55eca8;hpb=20403dbf83a2caa650a4ccd37f5a6dae7d0bd0f3;p=jalview.git
diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java
index bfdc40b..32a50cf 100755
--- a/src/jalview/gui/AlignFrame.java
+++ b/src/jalview/gui/AlignFrame.java
@@ -34,6 +34,7 @@ import jalview.io.*;
import jalview.jbgui.*;
import jalview.schemes.*;
import jalview.ws.*;
+import java.awt.dnd.*;
/**
@@ -43,7 +44,7 @@ import jalview.ws.*;
* @version $Revision$
*/
public class AlignFrame
- extends GAlignFrame implements ClipboardOwner
+ extends GAlignFrame implements DropTargetListener
{
/** DOCUMENT ME!! */
public static final int NEW_WINDOW_WIDTH = 700;
@@ -53,9 +54,6 @@ public class AlignFrame
AlignmentPanel alignPanel;
AlignViewport viewport;
- Vector viewports = new Vector();
- Vector alignPanels = new Vector();
-
/** DOCUMENT ME!! */
public String currentFileFormat = null;
Stack historyList = new Stack();
@@ -71,8 +69,8 @@ public class AlignFrame
public AlignFrame(AlignmentI al)
{
viewport = new AlignViewport(al);
- viewports.add(viewport);
+ this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
if(viewport.vconsensus==null)
{
@@ -86,7 +84,6 @@ public class AlignFrame
}
alignPanel = new AlignmentPanel(this, viewport);
- alignPanels.add(alignPanel);
String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
@@ -128,11 +125,17 @@ public class AlignFrame
});
- if (Desktop.desktop != null)
- {
- addServiceListeners();
- setGUINucleotide(al.isNucleotide());
- }
+ if (Desktop.desktop != null)
+ {
+ addServiceListeners();
+ setGUINucleotide(al.isNucleotide());
+ }
+
+ if(jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false))
+ {
+ wrapMenuItem.setSelected(true);
+ wrapMenuItem_actionPerformed(null);
+ }
}
/* Set up intrinsic listeners for dynamically generated GUI bits. */
@@ -172,18 +175,13 @@ public class AlignFrame
public void setGUINucleotide(boolean nucleotide)
{
showTranslation.setVisible( nucleotide );
- sequenceFeatures.setVisible(!nucleotide );
- featureSettings.setVisible( !nucleotide );
+ //sequenceFeatures.setVisible(!nucleotide );
+ //featureSettings.setVisible( !nucleotide );
conservationMenuItem.setVisible( !nucleotide );
modifyConservation.setVisible( !nucleotide );
- //Deal with separators
//Remember AlignFrame always starts as protein
- if(nucleotide)
- {
- viewMenu.remove(viewMenu.getItemCount()-2);
- }
- else
+ if(!nucleotide)
{
calculateMenu.remove(calculateMenu.getItemCount()-2);
}
@@ -198,99 +196,31 @@ public class AlignFrame
return jalview.bin.Cache.getProperty("VERSION");
}
-
- /**
- * DOCUMENT ME!
- *
- * @param String DOCUMENT ME!
- */
-
- public void parseGroupsFile(String file)
+ public FeatureRenderer getFeatureRenderer()
{
- try
- {
- BufferedReader in = new BufferedReader(new FileReader(file));
- SequenceI seq = null;
- String line, type, desc, token;
-
- int index, start, end;
- StringTokenizer st;
- SequenceFeature sf;
- FeatureRenderer fr = alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
- int lineNo = 0;
- while ( (line = in.readLine()) != null)
- {
- lineNo++;
- st = new StringTokenizer(line, "\t");
- if (st.countTokens() == 2)
- {
- type = st.nextToken();
- UserColourScheme ucs = new UserColourScheme(st.nextToken());
- fr.setColour(type, ucs.findColour("A"));
- continue;
- }
-
- while (st.hasMoreElements())
- {
- desc = st.nextToken();
- token = st.nextToken();
- if (!token.equals("ID_NOT_SPECIFIED"))
- {
- index = viewport.alignment.findIndex(viewport.alignment.findName(
- token));
- st.nextToken();
- }
- else
- {
- index = Integer.parseInt(st.nextToken());
- }
-
- start = Integer.parseInt(st.nextToken());
- end = Integer.parseInt(st.nextToken());
-
- seq = viewport.alignment.getSequenceAt(index);
- start = seq.findIndex(start) - 1;
- end = seq.findIndex(end) - 1;
-
- type = st.nextToken();
-
- if (fr.getColour(type) == null)
- {
- // Probably the old style groups file
- UserColourScheme ucs = new UserColourScheme(type);
- fr.setColour(type, ucs.findColour("A"));
- }
-
-
- sf = new SequenceFeature(type, desc, "", start, end);
-
- seq.getDatasetSequence().addSequenceFeature(sf);
-
-
- // sg = new SequenceGroup(text, ucs, true, true, false, start, end);
- // sg.addSequence(seq, false);
-
- // viewport.alignment.addGroup(sg);
-
- }
- }
+ return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
+ }
- viewport.showSequenceFeatures = true;
- alignPanel.repaint();
+ public void fetchSequence_actionPerformed(ActionEvent e)
+ {
+ new SequenceFetcher(this);
+ }
- }
- catch (Exception ex)
- {
- System.out.println("Error parsing groups file: " + ex);
- }
+ public void addFromFile_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
}
- public void fetchSequence_actionPerformed(ActionEvent e)
+ public void addFromText_actionPerformed(ActionEvent e)
{
- new SequenceFetcher(this);
+ Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
}
+ public void addFromURL_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
+ }
/**
* DOCUMENT ME!
@@ -300,19 +230,15 @@ public class AlignFrame
public void saveAlignmentMenu_actionPerformed(ActionEvent e)
{
JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
- getProperty(
- "LAST_DIRECTORY"),
+ getProperty( "LAST_DIRECTORY"),
new String[]
- {
- "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
- "jar"
- },
+ { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
new String[]
- {
- "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
- }, currentFileFormat);
+ { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
+ currentFileFormat,
+ false);
+
- chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle("Save Alignment to file");
chooser.setToolTipText("Save");
@@ -355,7 +281,7 @@ public class AlignFrame
java.io.File.separatorChar) + 1);
}
- Jalview2XML.SaveAlignment(this, file, shortName);
+ new Jalview2XML().SaveAlignment(this, file, shortName);
// USE Jalview2XML to save this file
return true;
@@ -377,6 +303,7 @@ public class AlignFrame
out.print(output);
out.close();
+ this.setTitle(file);
return true;
}
catch (Exception ex)
@@ -452,6 +379,41 @@ public class AlignFrame
thread.start();
}
+ public void exportFeatures_actionPerformed(ActionEvent e)
+ {
+ new AnnotationExporter().exportFeatures(alignPanel);
+ }
+
+ public void exportAnnotations_actionPerformed(ActionEvent e)
+ {
+ new AnnotationExporter().exportAnnotations(
+ alignPanel,
+ viewport.alignment.getAlignmentAnnotation()
+ );
+ }
+
+
+ public void associatedData_actionPerformed(ActionEvent e)
+ {
+ // Pick the tree file
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty(
+ "LAST_DIRECTORY"));
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Load Jalview Annotations or Features File");
+ chooser.setToolTipText("Load Jalview Annotations / Features file");
+
+ int value = chooser.showOpenDialog(null);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ String choice = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+ loadJalviewDataFile(choice);
+ }
+
+ }
+
/**
* DOCUMENT ME!
*
@@ -542,42 +504,8 @@ public class AlignFrame
// used by undo and redo
void restoreHistoryItem(HistoryItem hi)
{
- if (hi.getType() == HistoryItem.SORT)
- {
- for (int i = 0; i < hi.getSequences().size(); i++)
- {
- viewport.alignment.getSequences().setElementAt(hi.getSequences()
- .elementAt(i),
- i);
- }
- }
- else
- {
- for (int i = 0; i < hi.getSequences().size(); i++)
- {
- SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);
-
- if (restore.getLength() == 0)
- {
- restore.setSequence(hi.getHidden().elementAt(i).toString());
- viewport.alignment.getSequences().insertElementAt(restore,
- hi.getAlignIndex(i));
- }
- else
- {
- restore.setSequence(hi.getHidden().elementAt(i).toString());
- }
- }
- if (hi.getType() == HistoryItem.PASTE)
- {
- for (int i = viewport.alignment.getHeight() - 1;
- i > (hi.getSequences().size() - 1); i--)
- {
- viewport.alignment.deleteSequence(i);
- }
- }
- }
+ hi.restore();
updateEditMenuBar();
@@ -647,10 +575,6 @@ public class AlignFrame
alignPanel.repaint();
}
- public void lostOwnership(Clipboard clipboard, Transferable contents)
- {
- Desktop.jalviewClipboard = null;
- }
/**
@@ -731,12 +655,16 @@ public class AlignFrame
seqs[i].setDBRef(seq.getDBRef());
seqs[i].setSequenceFeatures(seq.getSequenceFeatures());
seqs[i].setDatasetSequence(seq.getDatasetSequence());
-
+ if(seq.getAnnotation()!=null)
+ {
+ for(int a=0; a>>This is a fix for the moment, until a better solution is found!!<<<
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
+ alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
+
+
+ if (title.startsWith("Copied sequences"))
+ {
+ newtitle = title;
+ }
+ else
+ {
+ newtitle = newtitle.concat("- from " + title);
+ }
+
+ Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH,
+ NEW_WINDOW_HEIGHT);
+
+ }
+
+
}
catch (Exception ex)
{
+ ex.printStackTrace();
+ System.out.println("Exception whilst pasting: "+ex);
// could be anything being pasted in here
}
@@ -885,24 +845,50 @@ public class AlignFrame
return;
}
- addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
- HistoryItem.HIDE));
SequenceGroup sg = viewport.getSelectionGroup();
- boolean allSequences = false;
- if (sg.sequences.size() == viewport.alignment.getHeight())
+
+
+
+ //Jalview no longer allows deletion of residues.
+ //Check here whether any residues are in selection area
+ /* if( sg.getEndRes()-sg.getStartRes() < viewport.alignment.getWidth()-1)
{
- allSequences = true;
- }
+ for (int i = 0; i < sg.sequences.size(); i++)
+ {
+ SequenceI seq = sg.getSequenceAt(i);
+ int j = sg.getStartRes();
+ do
+ {
+ if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
+ {
+ JOptionPane.showInternalMessageDialog(
+ Desktop.desktop, "Cannot delete residues from alignment!\n"
+ + "Try hiding columns instead.",
+ "Deletion of residues not permitted",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+ j++;
+ }while(j<=sg.getEndRes());
+ }
+ }*/
+
+
+ addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
+ HistoryItem.HIDE));
+
for (int i = 0; i < sg.sequences.size(); i++)
{
SequenceI seq = sg.getSequenceAt(i);
int index = viewport.getAlignment().findIndex(seq);
+
seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);
// If the cut affects all sequences, remove highlighted columns
- if (allSequences)
+ if (sg.sequences.size() == viewport.alignment.getHeight())
{
viewport.getColumnSelection().removeElements(sg.getStartRes(),
sg.getEndRes() + 1);
@@ -977,11 +963,16 @@ public class AlignFrame
*/
public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
{
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.keyboardNo1 = null;
+ alignPanel.seqPanel.keyboardNo2 = null;
+ }
viewport.setSelectionGroup(null);
viewport.getColumnSelection().clear();
viewport.setSelectionGroup(null);
alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
- alignPanel.annotationPanel.activeRes = null;
+ alignPanel.idPanel.idCanvas.searchResults = null;
PaintRefresher.Refresh(null, viewport.alignment);
}
@@ -1199,7 +1190,10 @@ public class AlignFrame
public void alignmentChanged()
{
- if(viewport.vconsensus!=null)
+ if(viewport.padGaps)
+ viewport.getAlignment().padGaps();
+
+ if(viewport.vconsensus!=null && viewport.autoCalculateConsensus)
{
viewport.updateConsensus();
viewport.updateConservation();
@@ -1208,6 +1202,8 @@ public class AlignFrame
if(alignPanel.overviewPanel!=null)
alignPanel.overviewPanel.updateOverviewImage();
+ viewport.alignment.adjustSequenceAnnotations();
+
alignPanel.repaint();
}
@@ -1259,8 +1255,11 @@ public class AlignFrame
{
addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,
HistoryItem.HIDE));
- if (viewport.getAlignment().padGaps())
- alignmentChanged();
+
+ viewport.padGaps = padGapsMenuitem.isSelected();
+
+ // if (viewport.padGaps)
+ alignmentChanged();
}
/**
@@ -1273,8 +1272,8 @@ public class AlignFrame
JInternalFrame frame = new JInternalFrame();
Finder finder = new Finder(viewport, alignPanel, frame);
frame.setContentPane(finder);
- Desktop.addInternalFrame(frame, "Find", 340, 110);
frame.setLayer(JLayeredPane.PALETTE_LAYER);
+ Desktop.addInternalFrame(frame, "Find", 340, 110);
}
/**
@@ -1287,6 +1286,14 @@ public class AlignFrame
new FontChooser(alignPanel);
}
+ public void smoothFont_actionPerformed(ActionEvent e)
+ {
+ viewport.antiAlias = smoothFont.isSelected();
+ alignPanel.annotationPanel.image = null;
+ alignPanel.repaint();
+ }
+
+
/**
* DOCUMENT ME!
*
@@ -1317,7 +1324,7 @@ public class AlignFrame
*
* @param e DOCUMENT ME!
*/
- protected void wrapMenuItem_actionPerformed(ActionEvent e)
+ public void wrapMenuItem_actionPerformed(ActionEvent e)
{
viewport.setWrapAlignment(wrapMenuItem.isSelected());
alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
@@ -1393,25 +1400,34 @@ public class AlignFrame
alignPanel.repaint();
}
+ public void fetchSeqFeatures_actionPerformed(ActionEvent e)
+ {
+ new DasSequenceFeatureFetcher(viewport.
+ alignment,
+ alignPanel);
+ viewport.setShowSequenceFeatures(true);
+ showSeqFeatures.setSelected(true);
+ }
+
+
+ public void featureSettings_actionPerformed(ActionEvent e)
+ {
+ new FeatureSettings(viewport, alignPanel);
+ }
+
/**
* DOCUMENT ME!
*
* @param evt DOCUMENT ME!
*/
- public void sequenceFeatures_actionPerformed(ActionEvent evt)
+ public void showSeqFeatures_actionPerformed(ActionEvent evt)
{
- viewport.showSequenceFeatures(sequenceFeatures.isSelected());
-
- if (viewport.showSequenceFeatures)
+ viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
+ alignPanel.repaint();
+ if (alignPanel.getOverviewPanel() != null)
{
- new SequenceFeatureFetcher(viewport.
- alignment,
- alignPanel);
+ alignPanel.getOverviewPanel().updateOverviewImage();
}
-
- featureSettings.setEnabled(true);
-
- alignPanel.repaint();
}
/**
@@ -1558,6 +1574,12 @@ public class AlignFrame
changeColour(new NucleotideColourScheme());
}
+ public void annotationColour_actionPerformed(ActionEvent e)
+ {
+ new AnnotationColourChooser(viewport, alignPanel);
+ }
+
+
/**
* DOCUMENT ME!
*
@@ -1965,6 +1987,17 @@ public class AlignFrame
new PCAPanel(viewport);
}
+
+ public void autoCalculate_actionPerformed(ActionEvent e)
+ {
+ viewport.autoCalculateConsensus = autoCalculate.isSelected();
+ if(viewport.autoCalculateConsensus)
+ {
+ alignmentChanged();
+ }
+ }
+
+
/**
* DOCUMENT ME!
*
@@ -2014,7 +2047,7 @@ public class AlignFrame
*/
void NewTreePanel(String type, String pwType, String title)
{
- final TreePanel tp;
+ TreePanel tp;
if ( (viewport.getSelectionGroup() != null) &&
(viewport.getSelectionGroup().getSize() > 3))
@@ -2066,7 +2099,6 @@ public class AlignFrame
}
addTreeMenuItem(tp, title);
- viewport.setCurrentTree(tp.getTree());
Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
}
@@ -2375,6 +2407,7 @@ public class AlignFrame
{
// Add any Multiple Sequence Alignment Services
final JMenu msawsmenu = new JMenu("Alignment");
+ final AlignFrame af = this;
for (int i = 0, j = msaws.size(); i < j; i++)
{
final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
@@ -2386,7 +2419,7 @@ public class AlignFrame
{
SequenceI[] msa = gatherSequencesForAlignment();
new jalview.ws.MsaWSClient(sh, title, msa,
- false, true, viewport.getAlignment().getDataset());
+ false, true, viewport.getAlignment().getDataset(), af);
}
@@ -2403,7 +2436,7 @@ public class AlignFrame
{
SequenceI[] msa = gatherSequencesForAlignment();
new jalview.ws.MsaWSClient(sh, title, msa,
- true, true, viewport.getAlignment().getDataset());
+ true, true, viewport.getAlignment().getDataset(), af);
}
@@ -2483,10 +2516,7 @@ public class AlignFrame
}
}*/
- public void featureSettings_actionPerformed(ActionEvent e)
- {
- new FeatureSettings(viewport, alignPanel);
- }
+
@@ -2503,6 +2533,8 @@ public void showTranslation_actionPerformed(ActionEvent e)
protein = new StringBuffer();
seq = AlignSeq.extractGaps("-. ", viewport.alignment.getSequenceAt(s).getSequence());
resSize = seq.length();
+ resSize -= resSize%3;
+
for(res = 0; res < resSize; res+=3)
{
String codon = seq.substring(res, res+3);
@@ -2528,42 +2560,42 @@ public void showTranslation_actionPerformed(ActionEvent e)
jalview.datamodel.AlignmentAnnotation[] annotations
= viewport.alignment.getAlignmentAnnotation();
int a, aSize;
- for (int i = 0; i < annotations.length; i++)
+ if(annotations!=null)
{
-
- if (annotations[i].label.equals("Quality") ||
- annotations[i].label.equals("Conservation") ||
- annotations[i].label.equals("Consensus"))
+ for (int i = 0; i < annotations.length; i++)
{
- continue;
- }
-
+ 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];
+ aSize = viewport.alignment.getWidth() / 3;
+ jalview.datamodel.Annotation[] anots =
+ new jalview.datamodel.Annotation[aSize];
- for(a=0; a