From e894eb87d40be6e8452d19032ddffe80dad5f804 Mon Sep 17 00:00:00 2001
From: jprocter
Date: Sun, 10 Sep 2006 12:48:27 +0000
Subject: [PATCH] updated to jalview 2.1 and begun
ArchiveClient/VamsasClient/VamsasStore updates.
---
src/MCview/AppletPDBCanvas.java | 2006 +++----
src/MCview/AppletPDBViewer.java | 531 +-
src/MCview/Atom.java | 116 +-
src/MCview/Bond.java | 156 +-
src/MCview/MCMatrix.java | 304 +-
src/MCview/PDBCanvas.java | 2011 +++----
src/MCview/PDBChain.java | 538 +-
src/MCview/PDBViewer.java | 133 +-
src/MCview/PDBfile.java | 357 +-
src/MCview/Residue.java | 96 +-
src/MCview/Zsort.java | 126 +-
src/ext/vamsas/MuscleWS.java | 40 +-
src/ext/vamsas/MuscleWSService.java | 30 +-
src/ext/vamsas/MuscleWSServiceLocator.java | 270 +-
src/ext/vamsas/MuscleWSSoapBindingStub.java | 746 +--
src/jalview/analysis/AAFrequency.java | 278 +-
src/jalview/analysis/AlignSeq.java | 1648 +++---
src/jalview/analysis/AlignmentSorter.java | 939 ++--
src/jalview/analysis/Conservation.java | 1139 ++--
src/jalview/analysis/NJTree.java | 2438 ++++-----
src/jalview/analysis/PCA.java | 482 +-
src/jalview/analysis/SeqsetUtils.java | 444 +-
src/jalview/analysis/SequenceIdMatcher.java | 374 +-
src/jalview/appletgui/APopupMenu.java | 1104 ++--
src/jalview/appletgui/AlignFrame.java | 4582 ++++++++--------
src/jalview/appletgui/AlignViewport.java | 1773 +++---
src/jalview/appletgui/AlignmentPanel.java | 1152 ++--
src/jalview/appletgui/AnnotationColourChooser.java | 806 +--
src/jalview/appletgui/AnnotationLabels.java | 446 +-
src/jalview/appletgui/AnnotationPanel.java | 1464 ++---
src/jalview/appletgui/ColumnSelection.java | 124 -
src/jalview/appletgui/CutAndPasteTransfer.java | 368 +-
src/jalview/appletgui/FeatureRenderer.java | 844 +--
src/jalview/appletgui/FeatureSettings.java | 888 +--
src/jalview/appletgui/Finder.java | 696 +--
src/jalview/appletgui/FontChooser.java | 516 +-
src/jalview/appletgui/IdCanvas.java | 621 ++-
src/jalview/appletgui/IdPanel.java | 689 ++-
src/jalview/appletgui/IdwidthAdjuster.java | 208 +-
src/jalview/appletgui/OverviewPanel.java | 813 +--
src/jalview/appletgui/PCAPanel.java | 551 +-
src/jalview/appletgui/PaintRefresher.java | 144 +-
src/jalview/appletgui/PairwiseAlignPanel.java | 299 +-
src/jalview/appletgui/RedundancyPanel.java | 418 +-
src/jalview/appletgui/RotatableCanvas.java | 1238 ++---
src/jalview/appletgui/ScalePanel.java | 642 ++-
src/jalview/appletgui/SeqCanvas.java | 1430 ++---
src/jalview/appletgui/SeqPanel.java | 2306 +++++---
src/jalview/appletgui/SequenceRenderer.java | 564 +-
src/jalview/appletgui/SliderPanel.java | 685 +--
src/jalview/appletgui/TreeCanvas.java | 1133 ++--
src/jalview/appletgui/TreePanel.java | 569 +-
src/jalview/appletgui/UserDefinedColours.java | 950 ++--
src/jalview/bin/Cache.java | 595 +--
src/jalview/bin/Jalview.java | 631 +--
src/jalview/bin/JalviewLite.java | 870 +--
src/jalview/datamodel/Alignment.java | 1684 +++---
src/jalview/datamodel/AlignmentAnnotation.java | 589 +-
src/jalview/datamodel/AlignmentI.java | 583 +-
src/jalview/datamodel/AlignmentOrder.java | 459 +-
src/jalview/datamodel/Annotation.java | 128 +-
src/jalview/datamodel/BinaryNode.java | 568 +-
src/jalview/datamodel/BinarySequence.java | 338 +-
src/jalview/datamodel/DBRefEntry.java | 82 +-
src/jalview/datamodel/GraphLine.java | 74 +-
src/jalview/datamodel/HiddenSequences.java | 299 +-
src/jalview/datamodel/HistoryItem.java | 336 +-
src/jalview/datamodel/PDBEntry.java | 115 +-
src/jalview/datamodel/Provenance.java | 88 +-
src/jalview/datamodel/ProvenanceEntry.java | 82 +-
src/jalview/datamodel/SearchResults.java | 260 +-
src/jalview/datamodel/Sequence.java | 1419 ++---
src/jalview/datamodel/SequenceFeature.java | 408 +-
src/jalview/datamodel/SequenceGroup.java | 1106 ++--
src/jalview/datamodel/SequenceI.java | 543 +-
src/jalview/datamodel/SequenceNode.java | 298 +-
src/jalview/datamodel/SequencePoint.java | 86 +-
src/jalview/datamodel/UniprotEntry.java | 185 +-
src/jalview/datamodel/UniprotFile.java | 66 +-
src/jalview/datamodel/UniprotSequence.java | 84 +-
src/jalview/gui/AlignFrame.java | 5639 ++++++++++----------
src/jalview/gui/AlignViewport.java | 2527 +++++----
src/jalview/gui/AlignmentPanel.java | 2573 ++++-----
src/jalview/gui/AnnotationColourChooser.java | 924 ++--
src/jalview/gui/AnnotationLabels.java | 1099 ++--
src/jalview/gui/AnnotationPanel.java | 2239 ++++----
src/jalview/gui/ColumnSelection.java | 362 --
src/jalview/gui/CutAndPasteTransfer.java | 472 +-
src/jalview/gui/Desktop.java | 1327 ++---
src/jalview/gui/EPSOptions.java | 276 +-
src/jalview/gui/FeatureRenderer.java | 947 ++--
src/jalview/gui/FeatureSettings.java | 1369 ++---
src/jalview/gui/Finder.java | 671 +--
src/jalview/gui/FontChooser.java | 486 +-
src/jalview/gui/IdCanvas.java | 743 +--
src/jalview/gui/IdPanel.java | 881 ++-
src/jalview/gui/IdwidthAdjuster.java | 324 +-
src/jalview/gui/Jalview2XML.java | 2452 +++++----
src/jalview/gui/OverviewPanel.java | 931 ++--
src/jalview/gui/PCAPanel.java | 773 +--
src/jalview/gui/PaintRefresher.java | 197 +-
src/jalview/gui/PairwiseAlignPanel.java | 292 +-
src/jalview/gui/PopupMenu.java | 2297 ++++----
src/jalview/gui/Preferences.java | 929 ++--
src/jalview/gui/RedundancyPanel.java | 499 +-
src/jalview/gui/RotatableCanvas.java | 1515 +++---
src/jalview/gui/ScalePanel.java | 837 +--
src/jalview/gui/SeqCanvas.java | 1696 +++---
src/jalview/gui/SeqPanel.java | 2878 +++++-----
src/jalview/gui/SequenceFetcher.java | 967 ++--
src/jalview/gui/SequenceRenderer.java | 758 +--
src/jalview/gui/SliderPanel.java | 697 +--
src/jalview/gui/SplashScreen.java | 338 +-
src/jalview/gui/TreeCanvas.java | 1621 +++---
src/jalview/gui/TreePanel.java | 1027 ++--
src/jalview/gui/UserDefinedColours.java | 1514 +++---
src/jalview/gui/WebserviceInfo.java | 807 +--
src/jalview/io/AlignFile.java | 376 +-
src/jalview/io/AnnotationReader.java | 275 -
src/jalview/io/AppletFormatAdapter.java | 436 +-
src/jalview/io/BLCFile.java | 461 +-
src/jalview/io/ClustalFile.java | 451 +-
src/jalview/io/EBIFetchClient.java | 491 +-
src/jalview/io/FastaFile.java | 350 +-
src/jalview/io/FileLoader.java | 334 +-
src/jalview/io/FileParse.java | 136 +-
src/jalview/io/FormatAdapter.java | 233 +-
src/jalview/io/HTMLOutput.java | 802 +--
src/jalview/io/IdentifyFile.java | 300 +-
src/jalview/io/JPredFile.java | 794 +--
src/jalview/io/JalviewFileChooser.java | 456 +-
src/jalview/io/JalviewFileFilter.java | 344 +-
src/jalview/io/JalviewFileView.java | 222 +-
src/jalview/io/MSFfile.java | 813 ++-
src/jalview/io/ModellerDescription.java | 767 +--
src/jalview/io/NewickFile.java | 1584 +++---
src/jalview/io/PIRFile.java | 354 +-
src/jalview/io/PfamFile.java | 361 +-
src/jalview/io/PileUpfile.java | 376 +-
src/jalview/io/SequenceFeatureFetcher.java | 359 --
src/jalview/io/VamsasDatastore.java | 2129 +++++---
src/jalview/io/WSWUBlastClient.java | 611 ++-
src/jalview/jbgui/GAlignFrame.java | 3009 ++++++-----
src/jalview/jbgui/GAlignmentPanel.java | 216 +-
src/jalview/jbgui/GCutAndPasteTransfer.java | 420 +-
src/jalview/jbgui/GDesktop.java | 652 +--
src/jalview/jbgui/GFinder.java | 365 +-
src/jalview/jbgui/GFontChooser.java | 462 +-
src/jalview/jbgui/GPCAPanel.java | 449 +-
src/jalview/jbgui/GPairwiseAlignPanel.java | 148 +-
src/jalview/jbgui/GPreferences.java | 1053 ++--
src/jalview/jbgui/GSequenceLink.java | 296 +-
src/jalview/jbgui/GSliderPanel.java | 339 +-
src/jalview/jbgui/GTreePanel.java | 435 +-
src/jalview/jbgui/GUserDefinedColours.java | 483 +-
src/jalview/jbgui/GWebserviceInfo.java | 204 +-
src/jalview/math/Matrix.java | 1704 +++---
src/jalview/math/RotatableMatrix.java | 664 +--
src/jalview/schemes/AnnotationColourGradient.java | 348 +-
src/jalview/schemes/Blosum62ColourScheme.java | 176 +-
src/jalview/schemes/BuriedColourScheme.java | 104 +-
src/jalview/schemes/ClustalxColourScheme.java | 610 +--
src/jalview/schemes/ColourSchemeI.java | 88 +-
src/jalview/schemes/ColourSchemeProperty.java | 848 +--
src/jalview/schemes/Consensus.java | 160 +-
src/jalview/schemes/HelixColourScheme.java | 72 +-
src/jalview/schemes/HydrophobicColourScheme.java | 104 +-
src/jalview/schemes/NucleotideColourScheme.java | 168 +-
src/jalview/schemes/PIDColourScheme.java | 166 +-
src/jalview/schemes/ResidueColourScheme.java | 526 +-
src/jalview/schemes/ResidueProperties.java | 2421 ++++-----
src/jalview/schemes/ScoreColourScheme.java | 242 +-
src/jalview/schemes/StrandColourScheme.java | 104 +-
src/jalview/schemes/TaylorColourScheme.java | 56 +-
src/jalview/schemes/TurnColourScheme.java | 104 +-
src/jalview/schemes/UserColourScheme.java | 293 +-
src/jalview/schemes/ZappoColourScheme.java | 74 +-
src/jalview/util/BrowserLauncher.java | 1856 +++----
src/jalview/util/Comparison.java | 496 +-
src/jalview/util/DBRefUtils.java | 76 +-
src/jalview/util/ImageMaker.java | 354 +-
src/jalview/util/QuickSort.java | 260 +-
src/jalview/ws/Discoverer.java | 53 +-
src/jalview/ws/JPredClient.java | 1325 +++--
src/jalview/ws/MsaWSClient.java | 646 +--
src/jalview/ws/WSClient.java | 2 +-
src/jalview/ws/WSClientI.java | 14 +-
src/vamsas/IMsaWS.java | 2 +-
src/vamsas/objects/simple/Alignment.java | 246 +-
src/vamsas/objects/simple/Alignment_Helper.java | 112 +-
src/vamsas/objects/simple/MsaResult.java | 154 +-
src/vamsas/objects/simple/MsaResult_Helper.java | 88 +-
src/vamsas/objects/simple/Object.java | 108 +-
src/vamsas/objects/simple/Object_Helper.java | 74 +-
src/vamsas/objects/simple/SequenceSet.java | 168 +-
src/vamsas/objects/simple/SequenceSet_Helper.java | 88 +-
src/vamsas/objects/simple/WsJobId.java | 180 +-
src/vamsas/objects/simple/WsJobId_Helper.java | 100 +-
198 files changed, 72674 insertions(+), 66191 deletions(-)
delete mode 100755 src/jalview/appletgui/ColumnSelection.java
delete mode 100755 src/jalview/gui/ColumnSelection.java
delete mode 100755 src/jalview/io/AnnotationReader.java
delete mode 100755 src/jalview/io/SequenceFeatureFetcher.java
diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java
index 107d98d..9689468 100755
--- a/src/MCview/AppletPDBCanvas.java
+++ b/src/MCview/AppletPDBCanvas.java
@@ -1,1003 +1,1003 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import jalview.analysis.AlignSeq;
-
-import jalview.datamodel.*;
-
-// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
-import java.awt.*;
-import java.awt.event.*;
-
-import java.io.*;
-
-import java.util.*;
-
-
-
-public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener
-{
-
- MCMatrix idmat = new MCMatrix(3, 3);
- MCMatrix objmat = new MCMatrix(3, 3);
- boolean redrawneeded = true;
- int omx = 0;
- int mx = 0;
- int omy = 0;
- int my = 0;
- public PDBfile pdb;
- int bsize;
- Image img;
- Graphics ig;
- Dimension prefsize;
- float[] centre = new float[3];
- float[] width = new float[3];
- float maxwidth;
- float scale;
- String inStr;
- String inType;
- boolean bysequence = true;
- boolean depthcue = true;
- boolean wire = false;
- boolean bymolecule = false;
- boolean zbuffer = true;
- boolean dragging;
- int xstart;
- int xend;
- int ystart;
- int yend;
- int xmid;
- int ymid;
- Font font = new Font("Helvetica", Font.PLAIN, 10);
- jalview.appletgui.SeqCanvas seqcanvas;
- public Sequence sequence;
- final StringBuffer mappingDetails = new StringBuffer();
- String appletToolTip = null;
- int toolx, tooly;
- PDBChain mainchain;
- Vector highlightRes;
- boolean pdbAction = false;
- Bond highlightBond1, highlightBond2;
- boolean errorLoading = false;
- boolean seqColoursReady = false;
- jalview.appletgui.FeatureRenderer fr;
-
- public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)
- {
- this.seqcanvas = seqcanvas;
- this.sequence = seq;
-
- seqcanvas.setPDBCanvas(this);
- addKeyListener(new KeyAdapter()
- {
-
- public void keyPressed(KeyEvent evt)
- {
- doKeyPressed(evt);
- }
- });
- }
-
-
- public void setPDBFile(PDBfile pdb)
- {
- int max = -10;
- int maxchain = -1;
- int pdbstart = 0;
- int pdbend = 0;
- int seqstart = 0;
- int seqend = 0;
- AlignSeq maxAlignseq = null;;
-
- for (int i = 0; i < pdb.chains.size(); i++)
- {
-
- mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());
- mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");
-
- // Now lets compare the sequences to get
- // the start and end points.
- // Align the sequence to the pdb
- AlignSeq as = new AlignSeq(sequence,
- ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");
- as.calcScoreMatrix();
- as.traceAlignment();
- PrintStream ps = new PrintStream(System.out)
- {
- public void print(String x) {
- mappingDetails.append(x);
- }
- public void println()
- {
- mappingDetails.append("\n");
- }
- };
-
- as.printAlignment(ps);
-
- if (as.maxscore > max) {
- max = as.maxscore;
- maxchain = i;
-
- pdbstart = as.seq2start;
- pdbend = as.seq2end;
- seqstart = as.seq1start + sequence.getStart()-1;
- seqend = as.seq1end + sequence.getEnd()-1;
- maxAlignseq = as;
- }
-
- mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
- mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);
- }
-
- mainchain = (PDBChain) pdb.chains.elementAt(maxchain);
-
- mainchain.pdbstart = pdbstart;
- mainchain.pdbend = pdbend;
- mainchain.seqstart = seqstart;
- mainchain.seqend = seqend;
- mainchain.isVisible = true;
- mainchain.makeExactMapping(maxAlignseq, sequence);
-
- this.pdb = pdb;
- this.prefsize = new Dimension(getSize().width, getSize().height);
-
- //Initialize the matrices to identity
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- if (i != j) {
- idmat.addElement(i, j, 0);
- objmat.addElement(i, j, 0);
- } else {
- idmat.addElement(i, j, 1);
- objmat.addElement(i, j, 1);
- }
- }
- }
-
- addMouseMotionListener(this);
- addMouseListener(this);
-
-
- findCentre();
- findWidth();
-
- setupBonds();
-
- scale = findScale();
- }
-
-
- Vector visiblebonds;
- void setupBonds()
- {
- seqColoursReady = false;
- // Sort the bonds by z coord
- visiblebonds = new Vector();
-
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)
- {
- Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < tmp.size(); i++)
- {
- visiblebonds.addElement(tmp.elementAt(i));
- }
- }
- }
- updateSeqColours();
- seqColoursReady = true;
- redrawneeded = true;
- repaint();
- }
-
-
- public void findWidth() {
- float[] max = new float[3];
- float[] min = new float[3];
-
- max[0] = (float) -1e30;
- max[1] = (float) -1e30;
- max[2] = (float) -1e30;
-
- min[0] = (float) 1e30;
- min[1] = (float) 1e30;
- min[2] = (float) 1e30;
-
- for (int ii = 0; ii < pdb.chains.size(); ii++) {
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++) {
- Bond tmp = (Bond) bonds.elementAt(i);
-
- if (tmp.start[0] >= max[0]) {
- max[0] = tmp.start[0];
- }
-
- if (tmp.start[1] >= max[1]) {
- max[1] = tmp.start[1];
- }
-
- if (tmp.start[2] >= max[2]) {
- max[2] = tmp.start[2];
- }
-
- if (tmp.start[0] <= min[0]) {
- min[0] = tmp.start[0];
- }
-
- if (tmp.start[1] <= min[1]) {
- min[1] = tmp.start[1];
- }
-
- if (tmp.start[2] <= min[2]) {
- min[2] = tmp.start[2];
- }
-
- if (tmp.end[0] >= max[0]) {
- max[0] = tmp.end[0];
- }
-
- if (tmp.end[1] >= max[1]) {
- max[1] = tmp.end[1];
- }
-
- if (tmp.end[2] >= max[2]) {
- max[2] = tmp.end[2];
- }
-
- if (tmp.end[0] <= min[0]) {
- min[0] = tmp.end[0];
- }
-
- if (tmp.end[1] <= min[1]) {
- min[1] = tmp.end[1];
- }
-
- if (tmp.end[2] <= min[2]) {
- min[2] = tmp.end[2];
- }
- }
- }
- }
-
- width[0] = (float) Math.abs(max[0] - min[0]);
- width[1] = (float) Math.abs(max[1] - min[1]);
- width[2] = (float) Math.abs(max[2] - min[2]);
-
- maxwidth = width[0];
-
- if (width[1] > width[0]) {
- maxwidth = width[1];
- }
-
- if (width[2] > width[1]) {
- maxwidth = width[2];
- }
-
- // System.out.println("Maxwidth = " + maxwidth);
- }
-
- public float findScale() {
- int dim;
- int width;
- int height;
-
- if (getSize().width != 0) {
- width = getSize().width;
- height = getSize().height;
- } else {
- width = prefsize.width;
- height = prefsize.height;
- }
-
- if (width < height) {
- dim = width;
- } else {
- dim = height;
- }
-
- return (float) (dim / (1.5d * maxwidth));
- }
-
- public void findCentre() {
- float xtot = 0;
- float ytot = 0;
- float ztot = 0;
-
- int bsize = 0;
-
- //Find centre coordinate
- for (int ii = 0; ii < pdb.chains.size(); ii++) {
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- bsize += bonds.size();
-
- for (int i = 0; i < bonds.size(); i++) {
- xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +
- ((Bond) bonds.elementAt(i)).end[0];
-
- ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +
- ((Bond) bonds.elementAt(i)).end[1];
-
- ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +
- ((Bond) bonds.elementAt(i)).end[2];
- }
- }
- }
-
- centre[0] = xtot / (2 * (float) bsize);
- centre[1] = ytot / (2 * (float) bsize);
- centre[2] = ztot / (2 * (float) bsize);
- }
-
- public void paint(Graphics g)
- {
-
- if(errorLoading)
- {
- g.setColor(Color.white);
- g.fillRect(0,0,getSize().width, getSize().height);
- g.setColor(Color.black);
- g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Error loading PDB data!!", 50, getSize().height/2);
- return;
- }
-
- if( !seqColoursReady )
- {
- g.setColor(Color.black);
- g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Fetching PDB data...", 50, getSize().height/2);
- return;
- }
-
-
-
- //Only create the image at the beginning -
- //this saves much memory usage
- if ((img == null) || (prefsize.width != getSize().width) ||
- (prefsize.height != getSize().height)) {
-
- try{ prefsize.width = getSize().width;
- prefsize.height = getSize().height;
-
- scale = findScale();
- img = createImage(prefsize.width, prefsize.height);
- ig = img.getGraphics();
-
- redrawneeded = true;
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
-
- if (redrawneeded)
- {
- drawAll(ig, prefsize.width, prefsize.height);
- redrawneeded = false;
- }
- if(appletToolTip!=null)
- {
- ig.setColor(Color.red);
- ig.drawString(appletToolTip, toolx, tooly);
- }
-
- g.drawImage(img, 0, 0, this);
-
- pdbAction = false;
- }
-
- public void drawAll(Graphics g, int width, int height)
- {
- ig.setColor(Color.black);
- ig.fillRect(0, 0, width, height);
- drawScene(ig);
- drawLabels(ig);
- }
-
- void setColours(jalview.schemes.ColourSchemeI cs)
- {
- bysequence = false;
- pdb.setColours(cs);
- redrawneeded = true;
- repaint();
- }
- public void updateSeqColours()
- {
- if (pdbAction)
- {
- return;
- }
-
- if(bysequence && pdb!=null)
- {
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- colourBySequence((PDBChain) pdb.chains.elementAt(ii));
- }
- }
-
- redrawneeded=true;
- repaint();
- }
-
-
- int findTrueIndex(int pos)
- {
- // returns the alignment position for a residue
- int j = sequence.getStart();
- int i = 0;
-
- while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))
- {
- if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
- {
- j++;
- }
-
- i++;
- }
-
- if(i>1)
- i--;
-
- if ( (j == sequence.getEnd()) && (j < pos))
- {
- return sequence.getEnd() + 1;
- }
- else
- {
- return i;
- }
- }
-
-
- // This method has been taken out of PDBChain to allow
- // Applet and Application specific sequence renderers to be used
- void colourBySequence(PDBChain chain)
- {
- boolean showFeatures = false;
-
- if(seqcanvas.getViewport().getShowSequenceFeatures())
- {
- if(fr==null)
- {
- fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport());
- }
- fr.transferSettings( seqcanvas.getFeatureRenderer());
- showFeatures = true;
- }
-
- for (int i = 0; i < chain.bonds.size(); i++)
- {
- Bond tmp = (Bond) chain.bonds.elementAt(i);
- tmp.startCol = Color.lightGray;
- tmp.endCol = Color.lightGray;
- if(chain!=mainchain)
- continue;
-
- if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
- (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
- {
-
- int index = findTrueIndex(tmp.at1.alignmentMapping);
- //sequence.findIndex(tmp.at1.alignmentMapping);
- if (index != -1)
- {
- tmp.startCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour( sequence, index);
-
- if(showFeatures)
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
- }
- }
-
- int index = findTrueIndex(tmp.at2.alignmentMapping);
- //sequence.findIndex( tmp.at2.alignmentMapping );
- if (index != -1)
- {
- tmp.endCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour( sequence, index);
-
- if(showFeatures)
- tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
- }
- }
- }
-
-
- Zsort zsort;
- public void drawScene(Graphics g)
- {
- if (zbuffer)
- {
- if(zsort ==null)
- zsort = new Zsort();
-
- zsort.Zsort(visiblebonds);
- }
-
-
- Bond tmpBond=null;
- for (int i = 0; i < visiblebonds.size(); i++)
- {
- tmpBond = (Bond) visiblebonds.elementAt(i);
-
-
- xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +
- (getSize().width / 2));
- ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +
- (getSize().height / 2));
-
- xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +
- (getSize().width / 2));
- yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +
- (getSize().height / 2));
-
- xmid = (xend + xstart) / 2;
- ymid = (yend + ystart) / 2;
-
- if (depthcue && !bymolecule)
- {
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {
- g.setColor(tmpBond.startCol.darker().darker());
- drawLine(g, xstart, ystart, xmid, ymid);
-
- g.setColor(tmpBond.endCol.darker().darker());
- drawLine(g, xmid, ymid, xend, yend);
- } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
- g.setColor(tmpBond.startCol.darker());
- drawLine(g, xstart, ystart, xmid, ymid);
-
- g.setColor(tmpBond.endCol.darker());
- drawLine(g, xmid, ymid, xend, yend);
- } else {
- g.setColor(tmpBond.startCol);
- drawLine(g, xstart, ystart, xmid, ymid);
-
- g.setColor(tmpBond.endCol);
- drawLine(g, xmid, ymid, xend, yend);
- }
-
- } else if (depthcue && bymolecule) {
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {
- g.setColor(Color.green.darker().darker());
- drawLine(g, xstart, ystart, xend, yend);
- } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
- g.setColor(Color.green.darker());
- drawLine(g, xstart, ystart, xend, yend);
- } else {
- g.setColor(Color.green);
- drawLine(g, xstart, ystart, xend, yend);
- }
- } else if (!depthcue && !bymolecule) {
- g.setColor(tmpBond.startCol);
- drawLine(g, xstart, ystart, xmid, ymid);
- g.setColor(tmpBond.endCol);
- drawLine(g, xmid, ymid, xend, yend);
- } else {
- drawLine(g, xstart, ystart, xend, yend);
- }
-
- if(highlightBond1!=null && highlightBond1==tmpBond)
- {
- g.setColor(Color.white);
- drawLine(g, xmid, ymid, xend, yend);
- }
-
- if(highlightBond2!=null && highlightBond2==tmpBond)
- {
- g.setColor(Color.white);
- drawLine(g, xstart, ystart, xmid, ymid);
- }
-
- }
- }
-
- public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {
- if (!wire) {
- if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {
- g.drawLine(x1, y1, x2, y2);
- g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
- g.drawLine(x1, y1 - 1, x2, y2 - 1);
- } else {
- g.setColor(g.getColor().brighter());
- g.drawLine(x1, y1, x2, y2);
- g.drawLine(x1 + 1, y1, x2 + 1, y2);
- g.drawLine(x1 - 1, y1, x2 - 1, y2);
- }
- } else {
- g.drawLine(x1, y1, x2, y2);
- }
- }
-
- public Dimension minimumsize() {
- return prefsize;
- }
-
- public Dimension preferredsize() {
- return prefsize;
- }
-
- public void doKeyPressed(KeyEvent evt)
- {
- if (evt.getKeyCode() == KeyEvent.VK_UP)
- {
- scale = (float) (scale * 1.1);
- redrawneeded = true;
- repaint();
- }
- else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
- {
- scale = (float) (scale * 0.9);
- redrawneeded = true;
- repaint();
- }
- }
-
- public void mousePressed(MouseEvent e) {
- pdbAction = true;
- Atom fatom = findAtom(e.getX(), e.getY());
- if(fatom!=null)
- {
- fatom.isSelected = !fatom.isSelected;
-
- redrawneeded = true;
- repaint();
- if (foundchain != -1)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
- if (chain == mainchain)
- {
- if (fatom.alignmentMapping != -1)
- {
- if (highlightRes == null)
- highlightRes = new Vector();
-
- if (highlightRes.contains(fatom.alignmentMapping+"" + ""))
- highlightRes.removeElement(fatom.alignmentMapping + "");
- else
- highlightRes.addElement(fatom.alignmentMapping + "");
- }
- }
- }
-
- }
- mx = e.getX();
- my = e.getY();
- omx = mx;
- omy = my;
- dragging = false;
- }
-
- public void mouseMoved(MouseEvent e) {
- pdbAction = true;
- if(highlightBond1!=null)
- {
- highlightBond1.at2.isSelected = false;
- highlightBond2.at1.isSelected = false;
- highlightBond1 = null;
- highlightBond2 = null;
- }
-
- Atom fatom = findAtom(e.getX(), e.getY());
-
- PDBChain chain = null;
- if(foundchain!=-1)
- {
- chain = (PDBChain) pdb.chains.elementAt(foundchain);
- if(chain == mainchain)
- {
- highlightSeqcanvas( fatom.alignmentMapping );
- }
- }
-
- if (fatom != null) {
- toolx = e.getX();
- tooly = e.getY();
-
- appletToolTip = chain.id+":"+ fatom.resNumber+" "+ fatom.resName;
- redrawneeded = true;
- repaint();
- } else {
- highlightSeqcanvas( -1);
- appletToolTip = null;
- redrawneeded = true;
- repaint();
- }
- }
-
-
- void highlightSeqcanvas(int pos)
- {
- SearchResults searchResults = new SearchResults();
- if(highlightRes!=null)
- {
- for (int i = 0; i < highlightRes.size(); i++)
- {
- int a = Integer.parseInt(highlightRes.elementAt(
- i).toString())+1;
-
- searchResults.addResult(sequence, a, a);
- }
- }
-
- if(pos!=-1)
- {
- searchResults.addResult(sequence, pos+1, pos+1);
- }
-
- seqcanvas.highlightSearchResults(searchResults);
- }
-
-
- public void mouseClicked(MouseEvent e) {
- }
-
- public void mouseEntered(MouseEvent e) {
- }
-
- public void mouseExited(MouseEvent e) {
- }
-
- public void mouseDragged(MouseEvent evt) {
- int x = evt.getX();
- int y = evt.getY();
- mx = x;
- my = y;
-
- MCMatrix objmat = new MCMatrix(3, 3);
- objmat.setIdentity();
-
- if ((evt.getModifiers() & Event.META_MASK) != 0) {
- objmat.rotatez((float) ((mx - omx)));
- } else {
- objmat.rotatex((float) ((my - omy)));
- objmat.rotatey((float) ((omx - mx)));
- }
-
- //Alter the bonds
- for (int ii = 0; ii < pdb.chains.size(); ii++) {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++) {
- Bond tmpBond = (Bond) bonds.elementAt(i);
-
- //Translate the bond so the centre is 0,0,0
- tmpBond.translate(-centre[0], -centre[1], -centre[2]);
-
- //Now apply the rotation matrix
- tmpBond.start = objmat.vectorMultiply(tmpBond.start);
- tmpBond.end = objmat.vectorMultiply(tmpBond.end);
-
- //Now translate back again
- tmpBond.translate(centre[0], centre[1], centre[2]);
- }
- }
-
- objmat = null;
-
- omx = mx;
- omy = my;
-
- dragging = true;
-
- redrawneeded = true;
-
- repaint();
- }
-
- public void mouseReleased(MouseEvent evt) {
- dragging = false;
- return;
- }
-
- void drawLabels(Graphics g) {
-
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
-
- if (chain.isVisible)
- {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++)
- {
- Bond tmpBond = (Bond) bonds.elementAt(i);
-
- if (tmpBond.at1.isSelected)
- {
- labelAtom(g, tmpBond, 1);
- }
-
- if (tmpBond.at2.isSelected)
- {
-
- labelAtom(g, tmpBond, 2);
- }
- }
- }
- }
- }
-
- public void labelAtom(Graphics g, Bond b, int n) {
- g.setFont(font);
-
- if (n == 1) {
- int xstart = (int) (((b.start[0] - centre[0]) * scale) +
- (getSize().width / 2));
- int ystart = (int) (((b.start[1] - centre[1]) * scale) +
- (getSize().height / 2));
-
- g.setColor(Color.red);
- g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);
- }
-
- if (n == 2) {
- int xstart = (int) (((b.end[0] - centre[0]) * scale) +
- (getSize().width / 2));
- int ystart = (int) (((b.end[1] - centre[1]) * scale) +
- (getSize().height / 2));
-
- g.setColor(Color.red);
- g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);
- }
- }
-
- int foundchain = -1;
- public Atom findAtom(int x, int y) {
- Atom fatom = null;
-
- foundchain = -1;
-
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
- int truex;
- Bond tmpBond=null;
-
- if (chain.isVisible)
- {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++)
- {
- tmpBond = (Bond) bonds.elementAt(i);
-
- truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +
- (getSize().width / 2));
-
- if (Math.abs(truex - x) <= 2)
- {
- int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +
- (getSize().height / 2));
-
- if (Math.abs(truey - y) <= 2)
- {
- fatom = tmpBond.at1;
- foundchain = ii;
- break;
- }
- }
- }
-
- // Still here? Maybe its the last bond
-
- truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
- (getSize().width / 2));
-
- if (Math.abs(truex - x) <= 2)
- {
- int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
- (getSize().height / 2));
-
- if (Math.abs(truey - y) <= 2)
- {
- fatom = tmpBond.at2;
- foundchain = ii;
- break;
- }
- }
-
- }
-
- if (fatom != null) //)&& chain.ds != null)
- {
- chain = (PDBChain) pdb.chains.elementAt(foundchain);
- }
- }
-
- return fatom;
- }
-
- public void update(Graphics g)
- {
- paint(g);
- }
-
- public void highlightRes(int ii)
- {
- if(!seqColoursReady)
- return;
-
- if (highlightRes != null
- && highlightRes.contains((ii-1) + ""))
- {
- return;
- }
-
- int index = -1;
- Bond tmpBond;
- for(index=0; index 0)
- {
- highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
- highlightBond1.at2.isSelected = true;
- }
-
- if (index != mainchain.bonds.size())
- {
- highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
- highlightBond2.at1.isSelected = true;
- }
-
- break;
- }
- }
-
- redrawneeded = true;
- repaint();
- }
-
-
- public void setAllchainsVisible(boolean b)
- {
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
- chain.isVisible = b;
- }
- mainchain.isVisible = true;
- findCentre();
- setupBonds();
- }
-
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+import jalview.analysis.AlignSeq;
+
+import jalview.datamodel.*;
+
+// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
+import java.awt.*;
+import java.awt.event.*;
+
+import java.io.*;
+
+import java.util.*;
+
+
+
+public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener
+{
+
+ MCMatrix idmat = new MCMatrix(3, 3);
+ MCMatrix objmat = new MCMatrix(3, 3);
+ boolean redrawneeded = true;
+ int omx = 0;
+ int mx = 0;
+ int omy = 0;
+ int my = 0;
+ public PDBfile pdb;
+ int bsize;
+ Image img;
+ Graphics ig;
+ Dimension prefsize;
+ float[] centre = new float[3];
+ float[] width = new float[3];
+ float maxwidth;
+ float scale;
+ String inStr;
+ String inType;
+ boolean bysequence = true;
+ boolean depthcue = true;
+ boolean wire = false;
+ boolean bymolecule = false;
+ boolean zbuffer = true;
+ boolean dragging;
+ int xstart;
+ int xend;
+ int ystart;
+ int yend;
+ int xmid;
+ int ymid;
+ Font font = new Font("Helvetica", Font.PLAIN, 10);
+ jalview.appletgui.SeqCanvas seqcanvas;
+ public Sequence sequence;
+ final StringBuffer mappingDetails = new StringBuffer();
+ String appletToolTip = null;
+ int toolx, tooly;
+ PDBChain mainchain;
+ Vector highlightRes;
+ boolean pdbAction = false;
+ Bond highlightBond1, highlightBond2;
+ boolean errorLoading = false;
+ boolean seqColoursReady = false;
+ jalview.appletgui.FeatureRenderer fr;
+
+ public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)
+ {
+ this.seqcanvas = seqcanvas;
+ this.sequence = seq;
+
+ seqcanvas.setPDBCanvas(this);
+ addKeyListener(new KeyAdapter()
+ {
+
+ public void keyPressed(KeyEvent evt)
+ {
+ doKeyPressed(evt);
+ }
+ });
+ }
+
+
+ public void setPDBFile(PDBfile pdb)
+ {
+ int max = -10;
+ int maxchain = -1;
+ int pdbstart = 0;
+ int pdbend = 0;
+ int seqstart = 0;
+ int seqend = 0;
+ AlignSeq maxAlignseq = null;;
+
+ for (int i = 0; i < pdb.chains.size(); i++)
+ {
+
+ mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());
+ mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");
+
+ // Now lets compare the sequences to get
+ // the start and end points.
+ // Align the sequence to the pdb
+ AlignSeq as = new AlignSeq(sequence,
+ ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");
+ as.calcScoreMatrix();
+ as.traceAlignment();
+ PrintStream ps = new PrintStream(System.out)
+ {
+ public void print(String x) {
+ mappingDetails.append(x);
+ }
+ public void println()
+ {
+ mappingDetails.append("\n");
+ }
+ };
+
+ as.printAlignment(ps);
+
+ if (as.maxscore > max) {
+ max = as.maxscore;
+ maxchain = i;
+
+ pdbstart = as.seq2start;
+ pdbend = as.seq2end;
+ seqstart = as.seq1start + sequence.getStart()-1;
+ seqend = as.seq1end + sequence.getEnd()-1;
+ maxAlignseq = as;
+ }
+
+ mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
+ mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);
+ }
+
+ mainchain = (PDBChain) pdb.chains.elementAt(maxchain);
+
+ mainchain.pdbstart = pdbstart;
+ mainchain.pdbend = pdbend;
+ mainchain.seqstart = seqstart;
+ mainchain.seqend = seqend;
+ mainchain.isVisible = true;
+ mainchain.makeExactMapping(maxAlignseq, sequence);
+
+ this.pdb = pdb;
+ this.prefsize = new Dimension(getSize().width, getSize().height);
+
+ //Initialize the matrices to identity
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ if (i != j) {
+ idmat.addElement(i, j, 0);
+ objmat.addElement(i, j, 0);
+ } else {
+ idmat.addElement(i, j, 1);
+ objmat.addElement(i, j, 1);
+ }
+ }
+ }
+
+ addMouseMotionListener(this);
+ addMouseListener(this);
+
+
+ findCentre();
+ findWidth();
+
+ setupBonds();
+
+ scale = findScale();
+ }
+
+
+ Vector visiblebonds;
+ void setupBonds()
+ {
+ seqColoursReady = false;
+ // Sort the bonds by z coord
+ visiblebonds = new Vector();
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)
+ {
+ Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < tmp.size(); i++)
+ {
+ visiblebonds.addElement(tmp.elementAt(i));
+ }
+ }
+ }
+ updateSeqColours();
+ seqColoursReady = true;
+ redrawneeded = true;
+ repaint();
+ }
+
+
+ public void findWidth() {
+ float[] max = new float[3];
+ float[] min = new float[3];
+
+ max[0] = (float) -1e30;
+ max[1] = (float) -1e30;
+ max[2] = (float) -1e30;
+
+ min[0] = (float) 1e30;
+ min[1] = (float) 1e30;
+ min[2] = (float) 1e30;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmp = (Bond) bonds.elementAt(i);
+
+ if (tmp.start[0] >= max[0]) {
+ max[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] >= max[1]) {
+ max[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] >= max[2]) {
+ max[2] = tmp.start[2];
+ }
+
+ if (tmp.start[0] <= min[0]) {
+ min[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] <= min[1]) {
+ min[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] <= min[2]) {
+ min[2] = tmp.start[2];
+ }
+
+ if (tmp.end[0] >= max[0]) {
+ max[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] >= max[1]) {
+ max[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] >= max[2]) {
+ max[2] = tmp.end[2];
+ }
+
+ if (tmp.end[0] <= min[0]) {
+ min[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] <= min[1]) {
+ min[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] <= min[2]) {
+ min[2] = tmp.end[2];
+ }
+ }
+ }
+ }
+
+ width[0] = (float) Math.abs(max[0] - min[0]);
+ width[1] = (float) Math.abs(max[1] - min[1]);
+ width[2] = (float) Math.abs(max[2] - min[2]);
+
+ maxwidth = width[0];
+
+ if (width[1] > width[0]) {
+ maxwidth = width[1];
+ }
+
+ if (width[2] > width[1]) {
+ maxwidth = width[2];
+ }
+
+ // System.out.println("Maxwidth = " + maxwidth);
+ }
+
+ public float findScale() {
+ int dim;
+ int width;
+ int height;
+
+ if (getSize().width != 0) {
+ width = getSize().width;
+ height = getSize().height;
+ } else {
+ width = prefsize.width;
+ height = prefsize.height;
+ }
+
+ if (width < height) {
+ dim = width;
+ } else {
+ dim = height;
+ }
+
+ return (float) (dim / (1.5d * maxwidth));
+ }
+
+ public void findCentre() {
+ float xtot = 0;
+ float ytot = 0;
+ float ztot = 0;
+
+ int bsize = 0;
+
+ //Find centre coordinate
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ bsize += bonds.size();
+
+ for (int i = 0; i < bonds.size(); i++) {
+ xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +
+ ((Bond) bonds.elementAt(i)).end[0];
+
+ ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +
+ ((Bond) bonds.elementAt(i)).end[1];
+
+ ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +
+ ((Bond) bonds.elementAt(i)).end[2];
+ }
+ }
+ }
+
+ centre[0] = xtot / (2 * (float) bsize);
+ centre[1] = ytot / (2 * (float) bsize);
+ centre[2] = ztot / (2 * (float) bsize);
+ }
+
+ public void paint(Graphics g)
+ {
+
+ if(errorLoading)
+ {
+ g.setColor(Color.white);
+ g.fillRect(0,0,getSize().width, getSize().height);
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString("Error loading PDB data!!", 50, getSize().height/2);
+ return;
+ }
+
+ if( !seqColoursReady )
+ {
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString("Fetching PDB data...", 50, getSize().height/2);
+ return;
+ }
+
+
+
+ //Only create the image at the beginning -
+ //this saves much memory usage
+ if ((img == null) || (prefsize.width != getSize().width) ||
+ (prefsize.height != getSize().height)) {
+
+ try{ prefsize.width = getSize().width;
+ prefsize.height = getSize().height;
+
+ scale = findScale();
+ img = createImage(prefsize.width, prefsize.height);
+ ig = img.getGraphics();
+
+ redrawneeded = true;
+ }catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+
+ if (redrawneeded)
+ {
+ drawAll(ig, prefsize.width, prefsize.height);
+ redrawneeded = false;
+ }
+ if(appletToolTip!=null)
+ {
+ ig.setColor(Color.red);
+ ig.drawString(appletToolTip, toolx, tooly);
+ }
+
+ g.drawImage(img, 0, 0, this);
+
+ pdbAction = false;
+ }
+
+ public void drawAll(Graphics g, int width, int height)
+ {
+ ig.setColor(Color.black);
+ ig.fillRect(0, 0, width, height);
+ drawScene(ig);
+ drawLabels(ig);
+ }
+
+ void setColours(jalview.schemes.ColourSchemeI cs)
+ {
+ bysequence = false;
+ pdb.setColours(cs);
+ redrawneeded = true;
+ repaint();
+ }
+ public void updateSeqColours()
+ {
+ if (pdbAction)
+ {
+ return;
+ }
+
+ if(bysequence && pdb!=null)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ colourBySequence((PDBChain) pdb.chains.elementAt(ii));
+ }
+ }
+
+ redrawneeded=true;
+ repaint();
+ }
+
+
+ int findTrueIndex(int pos)
+ {
+ // returns the alignment position for a residue
+ int j = sequence.getStart();
+ int i = 0;
+
+ while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))
+ {
+ if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
+ {
+ j++;
+ }
+
+ i++;
+ }
+
+ if(i>1)
+ i--;
+
+ if ( (j == sequence.getEnd()) && (j < pos))
+ {
+ return sequence.getEnd() + 1;
+ }
+ else
+ {
+ return i;
+ }
+ }
+
+
+ // This method has been taken out of PDBChain to allow
+ // Applet and Application specific sequence renderers to be used
+ void colourBySequence(PDBChain chain)
+ {
+ boolean showFeatures = false;
+
+ if(seqcanvas.getViewport().getShowSequenceFeatures())
+ {
+ if(fr==null)
+ {
+ fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport());
+ }
+ fr.transferSettings( seqcanvas.getFeatureRenderer());
+ showFeatures = true;
+ }
+
+ for (int i = 0; i < chain.bonds.size(); i++)
+ {
+ Bond tmp = (Bond) chain.bonds.elementAt(i);
+ tmp.startCol = Color.lightGray;
+ tmp.endCol = Color.lightGray;
+ if(chain!=mainchain)
+ continue;
+
+ if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
+ (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
+ {
+
+ int index = findTrueIndex(tmp.at1.alignmentMapping);
+ //sequence.findIndex(tmp.at1.alignmentMapping);
+ if (index != -1)
+ {
+ tmp.startCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
+ }
+ }
+
+ int index = findTrueIndex(tmp.at2.alignmentMapping);
+ //sequence.findIndex( tmp.at2.alignmentMapping );
+ if (index != -1)
+ {
+ tmp.endCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
+ }
+ }
+ }
+
+
+ Zsort zsort;
+ public void drawScene(Graphics g)
+ {
+ if (zbuffer)
+ {
+ if(zsort ==null)
+ zsort = new Zsort();
+
+ zsort.Zsort(visiblebonds);
+ }
+
+
+ Bond tmpBond=null;
+ for (int i = 0; i < visiblebonds.size(); i++)
+ {
+ tmpBond = (Bond) visiblebonds.elementAt(i);
+
+
+ xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ xmid = (xend + xstart) / 2;
+ ymid = (yend + ystart) / 2;
+
+ if (depthcue && !bymolecule)
+ {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {
+ g.setColor(tmpBond.startCol.darker().darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol.darker().darker());
+ drawLine(g, xmid, ymid, xend, yend);
+ } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
+ g.setColor(tmpBond.startCol.darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol.darker());
+ drawLine(g, xmid, ymid, xend, yend);
+ } else {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+
+ } else if (depthcue && bymolecule) {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {
+ g.setColor(Color.green.darker().darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
+ g.setColor(Color.green.darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ } else {
+ g.setColor(Color.green);
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ } else if (!depthcue && !bymolecule) {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ } else {
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+
+ if(highlightBond1!=null && highlightBond1==tmpBond)
+ {
+ g.setColor(Color.white);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+
+ if(highlightBond2!=null && highlightBond2==tmpBond)
+ {
+ g.setColor(Color.white);
+ drawLine(g, xstart, ystart, xmid, ymid);
+ }
+
+ }
+ }
+
+ public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {
+ if (!wire) {
+ if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
+ g.drawLine(x1, y1 - 1, x2, y2 - 1);
+ } else {
+ g.setColor(g.getColor().brighter());
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1, x2 + 1, y2);
+ g.drawLine(x1 - 1, y1, x2 - 1, y2);
+ }
+ } else {
+ g.drawLine(x1, y1, x2, y2);
+ }
+ }
+
+ public Dimension minimumsize() {
+ return prefsize;
+ }
+
+ public Dimension preferredsize() {
+ return prefsize;
+ }
+
+ public void doKeyPressed(KeyEvent evt)
+ {
+ if (evt.getKeyCode() == KeyEvent.VK_UP)
+ {
+ scale = (float) (scale * 1.1);
+ redrawneeded = true;
+ repaint();
+ }
+ else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+ {
+ scale = (float) (scale * 0.9);
+ redrawneeded = true;
+ repaint();
+ }
+ }
+
+ public void mousePressed(MouseEvent e) {
+ pdbAction = true;
+ Atom fatom = findAtom(e.getX(), e.getY());
+ if(fatom!=null)
+ {
+ fatom.isSelected = !fatom.isSelected;
+
+ redrawneeded = true;
+ repaint();
+ if (foundchain != -1)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if (chain == mainchain)
+ {
+ if (fatom.alignmentMapping != -1)
+ {
+ if (highlightRes == null)
+ highlightRes = new Vector();
+
+ if (highlightRes.contains(fatom.alignmentMapping+"" + ""))
+ highlightRes.removeElement(fatom.alignmentMapping + "");
+ else
+ highlightRes.addElement(fatom.alignmentMapping + "");
+ }
+ }
+ }
+
+ }
+ mx = e.getX();
+ my = e.getY();
+ omx = mx;
+ omy = my;
+ dragging = false;
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ pdbAction = true;
+ if(highlightBond1!=null)
+ {
+ highlightBond1.at2.isSelected = false;
+ highlightBond2.at1.isSelected = false;
+ highlightBond1 = null;
+ highlightBond2 = null;
+ }
+
+ Atom fatom = findAtom(e.getX(), e.getY());
+
+ PDBChain chain = null;
+ if(foundchain!=-1)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if(chain == mainchain)
+ {
+ highlightSeqcanvas( fatom.alignmentMapping );
+ }
+ }
+
+ if (fatom != null) {
+ toolx = e.getX();
+ tooly = e.getY();
+
+ appletToolTip = chain.id+":"+ fatom.resNumber+" "+ fatom.resName;
+ redrawneeded = true;
+ repaint();
+ } else {
+ highlightSeqcanvas( -1);
+ appletToolTip = null;
+ redrawneeded = true;
+ repaint();
+ }
+ }
+
+
+ void highlightSeqcanvas(int pos)
+ {
+ SearchResults searchResults = new SearchResults();
+ if(highlightRes!=null)
+ {
+ for (int i = 0; i < highlightRes.size(); i++)
+ {
+ int a = Integer.parseInt(highlightRes.elementAt(
+ i).toString())+1;
+
+ searchResults.addResult(sequence, a, a);
+ }
+ }
+
+ if(pos!=-1)
+ {
+ searchResults.addResult(sequence, pos+1, pos+1);
+ }
+
+ seqcanvas.highlightSearchResults(searchResults);
+ }
+
+
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+
+ public void mouseDragged(MouseEvent evt) {
+ int x = evt.getX();
+ int y = evt.getY();
+ mx = x;
+ my = y;
+
+ MCMatrix objmat = new MCMatrix(3, 3);
+ objmat.setIdentity();
+
+ if ((evt.getModifiers() & Event.META_MASK) != 0) {
+ objmat.rotatez((float) ((mx - omx)));
+ } else {
+ objmat.rotatex((float) ((my - omy)));
+ objmat.rotatey((float) ((omx - mx)));
+ }
+
+ //Alter the bonds
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ //Translate the bond so the centre is 0,0,0
+ tmpBond.translate(-centre[0], -centre[1], -centre[2]);
+
+ //Now apply the rotation matrix
+ tmpBond.start = objmat.vectorMultiply(tmpBond.start);
+ tmpBond.end = objmat.vectorMultiply(tmpBond.end);
+
+ //Now translate back again
+ tmpBond.translate(centre[0], centre[1], centre[2]);
+ }
+ }
+
+ objmat = null;
+
+ omx = mx;
+ omy = my;
+
+ dragging = true;
+
+ redrawneeded = true;
+
+ repaint();
+ }
+
+ public void mouseReleased(MouseEvent evt) {
+ dragging = false;
+ return;
+ }
+
+ void drawLabels(Graphics g) {
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ if (tmpBond.at1.isSelected)
+ {
+ labelAtom(g, tmpBond, 1);
+ }
+
+ if (tmpBond.at2.isSelected)
+ {
+
+ labelAtom(g, tmpBond, 2);
+ }
+ }
+ }
+ }
+ }
+
+ public void labelAtom(Graphics g, Bond b, int n) {
+ g.setFont(font);
+
+ if (n == 1) {
+ int xstart = (int) (((b.start[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ int ystart = (int) (((b.start[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ g.setColor(Color.red);
+ g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);
+ }
+
+ if (n == 2) {
+ int xstart = (int) (((b.end[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ int ystart = (int) (((b.end[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ g.setColor(Color.red);
+ g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);
+ }
+ }
+
+ int foundchain = -1;
+ public Atom findAtom(int x, int y) {
+ Atom fatom = null;
+
+ foundchain = -1;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ int truex;
+ Bond tmpBond=null;
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ tmpBond = (Bond) bonds.elementAt(i);
+
+ truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at1;
+ foundchain = ii;
+ break;
+ }
+ }
+ }
+
+ // Still here? Maybe its the last bond
+
+ truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at2;
+ foundchain = ii;
+ break;
+ }
+ }
+
+ }
+
+ if (fatom != null) //)&& chain.ds != null)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ }
+ }
+
+ return fatom;
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void highlightRes(int ii)
+ {
+ if(!seqColoursReady)
+ return;
+
+ if (highlightRes != null
+ && highlightRes.contains((ii-1) + ""))
+ {
+ return;
+ }
+
+ int index = -1;
+ Bond tmpBond;
+ for(index=0; index 0)
+ {
+ highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
+ highlightBond1.at2.isSelected = true;
+ }
+
+ if (index != mainchain.bonds.size())
+ {
+ highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
+ highlightBond2.at1.isSelected = true;
+ }
+
+ break;
+ }
+ }
+
+ redrawneeded = true;
+ repaint();
+ }
+
+
+ public void setAllchainsVisible(boolean b)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ chain.isVisible = b;
+ }
+ mainchain.isVisible = true;
+ findCentre();
+ setupBonds();
+ }
+
+}
diff --git a/src/MCview/AppletPDBViewer.java b/src/MCview/AppletPDBViewer.java
index e80178a..351de12 100755
--- a/src/MCview/AppletPDBViewer.java
+++ b/src/MCview/AppletPDBViewer.java
@@ -1,265 +1,266 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package MCview;
-
-import java.awt.*;
-
-import java.awt.event.*;
-import jalview.datamodel.*;
-import jalview.appletgui.*;
-import jalview.schemes.*;
-import java.awt.event.ActionListener;
-import java.awt.event.ActionEvent;
-
-
-public class AppletPDBViewer extends Frame implements ActionListener, ItemListener
-{
- AppletPDBCanvas pdbcanvas;
- public AppletPDBViewer(String pdbtext,String type,
- Sequence seq,
- SeqCanvas seqcanvas)
- {
-
- try
- {
- jbInit();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
-
- pdbcanvas = new AppletPDBCanvas(seqcanvas, seq);
-
- add(pdbcanvas, BorderLayout.CENTER);
-
- StringBuffer title = new StringBuffer(seq.getName() + ":");
-
- jalview.bin.JalviewLite.addFrame(this,title.toString(),400, 400);
-
- try{
- PDBfile pdbfile = new PDBfile(pdbtext, type);
- pdbcanvas.setPDBFile(pdbfile);
- }
- catch(Exception ex){
- pdbcanvas.errorLoading = true;
- pdbcanvas.repaint();
- }
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource()==mapping)
- mapping_actionPerformed();
- else if(evt.getSource()==wire)
- wire_actionPerformed();
- else if(evt.getSource()==depth)
- depth_actionPerformed();
- else if(evt.getSource()==zbuffer)
- zbuffer_actionPerformed();
- else if(evt.getSource()==charge)
- charge_actionPerformed();
-
- else if(evt.getSource()==chain)
- chain_actionPerformed();
- else if(evt.getSource()==seqButton)
- seqButton_actionPerformed();
- else if(evt.getSource()==zappo)
- pdbcanvas.setColours(new ZappoColourScheme());
- else if(evt.getSource()==taylor)
- pdbcanvas.setColours(new TaylorColourScheme());
- else if(evt.getSource()==hydro)
- pdbcanvas.setColours(new HydrophobicColourScheme());
- else if(evt.getSource()==helix)
- pdbcanvas.setColours(new HelixColourScheme());
- else if(evt.getSource()==strand)
- pdbcanvas.setColours(new StrandColourScheme());
- else if(evt.getSource()==turn)
- pdbcanvas.setColours(new TurnColourScheme());
- else if(evt.getSource()==buried)
- pdbcanvas.setColours(new BuriedColourScheme());
- else if(evt.getSource()==user)
- {
- pdbcanvas.bysequence = false;
- new jalview.appletgui.UserDefinedColours(pdbcanvas);
- }
- }
-
- public void itemStateChanged(ItemEvent evt)
- {
- if (evt.getSource() == allchains)
- allchains_itemStateChanged();
- else if (evt.getSource() == wire)
- wire_actionPerformed();
- else if (evt.getSource() == depth)
- depth_actionPerformed();
- else if (evt.getSource() == zbuffer)
- zbuffer_actionPerformed();
- }
-
-
- private void jbInit()
- throws Exception
- {
- setMenuBar(jMenuBar1);
- fileMenu.setLabel("File");
- coloursMenu.setLabel("Colours");
- mapping.setLabel("View Mapping");
- mapping.addActionListener(this);
- wire.setLabel("Wireframe");
- wire.addItemListener(this);
- depth.setState(true);
- depth.setLabel("Depthcue");
- depth.addItemListener(this);
- zbuffer.setState(true);
- zbuffer.setLabel("Z Buffering");
- zbuffer.addItemListener(this);
- charge.setLabel("Charge & Cysteine");
- charge.addActionListener(this);
- hydro.setLabel("Hydrophobicity");
- hydro.addActionListener(this);
- chain.setLabel("By Chain");
- chain.addActionListener(this);
- seqButton.setLabel("By Sequence");
- seqButton.addActionListener(this);
- allchains.setLabel("All Chains Visible");
- allchains.addItemListener(this);
- viewMenu.setLabel("View");
- zappo.setLabel("Zappo");
- zappo.addActionListener(this);
- taylor.setLabel("Taylor");
- taylor.addActionListener(this);
- helix.setLabel("Helix Propensity");
- helix.addActionListener(this);
- strand.setLabel("Strand Propensity");
- strand.addActionListener(this);
- turn.setLabel("Turn Propensity");
- turn.addActionListener(this);
- buried.setLabel("Buried Index");
- buried.addActionListener(this);
- user.setLabel("User Defined...");
- user.addActionListener(this);
- jMenuBar1.add(fileMenu);
- jMenuBar1.add(coloursMenu);
- jMenuBar1.add(viewMenu);
- fileMenu.add(mapping);;
-
- coloursMenu.add(seqButton);
- coloursMenu.add(chain);
- coloursMenu.add(charge);
- coloursMenu.add(zappo);
- coloursMenu.add(taylor);
- coloursMenu.add(hydro);
- coloursMenu.add(helix);
- coloursMenu.add(strand);
- coloursMenu.add(turn);
- coloursMenu.add(buried);
- coloursMenu.add(user);
- viewMenu.add(wire);
- viewMenu.add(depth);
- viewMenu.add(zbuffer);
- viewMenu.add(allchains);
- allchains.setState(true);
- }
-
- MenuBar jMenuBar1 = new MenuBar();
- Menu fileMenu = new Menu();
- Menu coloursMenu = new Menu();
- MenuItem mapping = new MenuItem();
- CheckboxGroup bg = new CheckboxGroup();
- CheckboxMenuItem wire = new CheckboxMenuItem();
- CheckboxMenuItem depth = new CheckboxMenuItem();
- CheckboxMenuItem zbuffer = new CheckboxMenuItem();
-
- MenuItem charge = new MenuItem();
- MenuItem hydro = new MenuItem();
- MenuItem chain = new MenuItem();
- MenuItem seqButton = new MenuItem();
-
- CheckboxMenuItem allchains = new CheckboxMenuItem();
- Menu viewMenu = new Menu();
- MenuItem turn = new MenuItem();
- MenuItem strand = new MenuItem();
- MenuItem helix = new MenuItem();
- MenuItem taylor = new MenuItem();
- MenuItem zappo = new MenuItem();
- MenuItem buried = new MenuItem();
- MenuItem user = new MenuItem();
-
- public void charge_actionPerformed()
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setChargeColours();
- pdbcanvas.redrawneeded=true;
- pdbcanvas.repaint();
- }
-
- public void chain_actionPerformed()
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setChainColours();
- pdbcanvas.redrawneeded=true;
- pdbcanvas.repaint();
- }
-
- public void zbuffer_actionPerformed()
- {
- pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;
- pdbcanvas.redrawneeded=true;
- pdbcanvas.repaint();
- }
-
- public void depth_actionPerformed()
- {
- pdbcanvas.depthcue = ! pdbcanvas.depthcue;
- pdbcanvas.redrawneeded=true;
- pdbcanvas.repaint();
- }
-
- public void wire_actionPerformed()
- {
- pdbcanvas.wire = ! pdbcanvas.wire;
- pdbcanvas.redrawneeded=true;
- pdbcanvas.repaint();
- }
-
- public void seqButton_actionPerformed()
- {
- pdbcanvas.bysequence = true;
- pdbcanvas.updateSeqColours();
- pdbcanvas.repaint();
- }
-
-
- public void mapping_actionPerformed()
- {
- jalview.appletgui.CutAndPasteTransfer cap
- = new jalview.appletgui.CutAndPasteTransfer(false, null);
- Frame frame = new Frame();
- frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", 500, 600);
- cap.setText(pdbcanvas.mappingDetails.toString());
- }
-
- public void allchains_itemStateChanged()
- {
- pdbcanvas.setAllchainsVisible(allchains.getState());
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package MCview;
+
+import java.awt.*;
+
+import java.awt.event.*;
+import jalview.datamodel.*;
+import jalview.appletgui.*;
+import jalview.schemes.*;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+
+public class AppletPDBViewer extends Frame implements ActionListener, ItemListener
+{
+ AppletPDBCanvas pdbcanvas;
+ public AppletPDBViewer(String pdbtext,String type,
+ Sequence seq,
+ SeqCanvas seqcanvas)
+ {
+
+ try
+ {
+ jbInit();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+
+ pdbcanvas = new AppletPDBCanvas(seqcanvas, seq);
+
+ add(pdbcanvas, BorderLayout.CENTER);
+
+ StringBuffer title = new StringBuffer(seq.getName() + ":");
+
+ jalview.bin.JalviewLite.addFrame(this,title.toString(),400, 400);
+
+ try{
+ PDBfile pdbfile = new PDBfile(pdbtext, type);
+ pdbcanvas.setPDBFile(pdbfile);
+ }
+ catch(Exception ex){
+ ex.printStackTrace();
+ pdbcanvas.errorLoading = true;
+ pdbcanvas.repaint();
+ }
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource()==mapping)
+ mapping_actionPerformed();
+ else if(evt.getSource()==wire)
+ wire_actionPerformed();
+ else if(evt.getSource()==depth)
+ depth_actionPerformed();
+ else if(evt.getSource()==zbuffer)
+ zbuffer_actionPerformed();
+ else if(evt.getSource()==charge)
+ charge_actionPerformed();
+
+ else if(evt.getSource()==chain)
+ chain_actionPerformed();
+ else if(evt.getSource()==seqButton)
+ seqButton_actionPerformed();
+ else if(evt.getSource()==zappo)
+ pdbcanvas.setColours(new ZappoColourScheme());
+ else if(evt.getSource()==taylor)
+ pdbcanvas.setColours(new TaylorColourScheme());
+ else if(evt.getSource()==hydro)
+ pdbcanvas.setColours(new HydrophobicColourScheme());
+ else if(evt.getSource()==helix)
+ pdbcanvas.setColours(new HelixColourScheme());
+ else if(evt.getSource()==strand)
+ pdbcanvas.setColours(new StrandColourScheme());
+ else if(evt.getSource()==turn)
+ pdbcanvas.setColours(new TurnColourScheme());
+ else if(evt.getSource()==buried)
+ pdbcanvas.setColours(new BuriedColourScheme());
+ else if(evt.getSource()==user)
+ {
+ pdbcanvas.bysequence = false;
+ new jalview.appletgui.UserDefinedColours(pdbcanvas);
+ }
+ }
+
+ public void itemStateChanged(ItemEvent evt)
+ {
+ if (evt.getSource() == allchains)
+ allchains_itemStateChanged();
+ else if (evt.getSource() == wire)
+ wire_actionPerformed();
+ else if (evt.getSource() == depth)
+ depth_actionPerformed();
+ else if (evt.getSource() == zbuffer)
+ zbuffer_actionPerformed();
+ }
+
+
+ private void jbInit()
+ throws Exception
+ {
+ setMenuBar(jMenuBar1);
+ fileMenu.setLabel("File");
+ coloursMenu.setLabel("Colours");
+ mapping.setLabel("View Mapping");
+ mapping.addActionListener(this);
+ wire.setLabel("Wireframe");
+ wire.addItemListener(this);
+ depth.setState(true);
+ depth.setLabel("Depthcue");
+ depth.addItemListener(this);
+ zbuffer.setState(true);
+ zbuffer.setLabel("Z Buffering");
+ zbuffer.addItemListener(this);
+ charge.setLabel("Charge & Cysteine");
+ charge.addActionListener(this);
+ hydro.setLabel("Hydrophobicity");
+ hydro.addActionListener(this);
+ chain.setLabel("By Chain");
+ chain.addActionListener(this);
+ seqButton.setLabel("By Sequence");
+ seqButton.addActionListener(this);
+ allchains.setLabel("All Chains Visible");
+ allchains.addItemListener(this);
+ viewMenu.setLabel("View");
+ zappo.setLabel("Zappo");
+ zappo.addActionListener(this);
+ taylor.setLabel("Taylor");
+ taylor.addActionListener(this);
+ helix.setLabel("Helix Propensity");
+ helix.addActionListener(this);
+ strand.setLabel("Strand Propensity");
+ strand.addActionListener(this);
+ turn.setLabel("Turn Propensity");
+ turn.addActionListener(this);
+ buried.setLabel("Buried Index");
+ buried.addActionListener(this);
+ user.setLabel("User Defined...");
+ user.addActionListener(this);
+ jMenuBar1.add(fileMenu);
+ jMenuBar1.add(coloursMenu);
+ jMenuBar1.add(viewMenu);
+ fileMenu.add(mapping);;
+
+ coloursMenu.add(seqButton);
+ coloursMenu.add(chain);
+ coloursMenu.add(charge);
+ coloursMenu.add(zappo);
+ coloursMenu.add(taylor);
+ coloursMenu.add(hydro);
+ coloursMenu.add(helix);
+ coloursMenu.add(strand);
+ coloursMenu.add(turn);
+ coloursMenu.add(buried);
+ coloursMenu.add(user);
+ viewMenu.add(wire);
+ viewMenu.add(depth);
+ viewMenu.add(zbuffer);
+ viewMenu.add(allchains);
+ allchains.setState(true);
+ }
+
+ MenuBar jMenuBar1 = new MenuBar();
+ Menu fileMenu = new Menu();
+ Menu coloursMenu = new Menu();
+ MenuItem mapping = new MenuItem();
+ CheckboxGroup bg = new CheckboxGroup();
+ CheckboxMenuItem wire = new CheckboxMenuItem();
+ CheckboxMenuItem depth = new CheckboxMenuItem();
+ CheckboxMenuItem zbuffer = new CheckboxMenuItem();
+
+ MenuItem charge = new MenuItem();
+ MenuItem hydro = new MenuItem();
+ MenuItem chain = new MenuItem();
+ MenuItem seqButton = new MenuItem();
+
+ CheckboxMenuItem allchains = new CheckboxMenuItem();
+ Menu viewMenu = new Menu();
+ MenuItem turn = new MenuItem();
+ MenuItem strand = new MenuItem();
+ MenuItem helix = new MenuItem();
+ MenuItem taylor = new MenuItem();
+ MenuItem zappo = new MenuItem();
+ MenuItem buried = new MenuItem();
+ MenuItem user = new MenuItem();
+
+ public void charge_actionPerformed()
+ {
+ pdbcanvas.bysequence = false;
+ pdbcanvas.pdb.setChargeColours();
+ pdbcanvas.redrawneeded=true;
+ pdbcanvas.repaint();
+ }
+
+ public void chain_actionPerformed()
+ {
+ pdbcanvas.bysequence = false;
+ pdbcanvas.pdb.setChainColours();
+ pdbcanvas.redrawneeded=true;
+ pdbcanvas.repaint();
+ }
+
+ public void zbuffer_actionPerformed()
+ {
+ pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;
+ pdbcanvas.redrawneeded=true;
+ pdbcanvas.repaint();
+ }
+
+ public void depth_actionPerformed()
+ {
+ pdbcanvas.depthcue = ! pdbcanvas.depthcue;
+ pdbcanvas.redrawneeded=true;
+ pdbcanvas.repaint();
+ }
+
+ public void wire_actionPerformed()
+ {
+ pdbcanvas.wire = ! pdbcanvas.wire;
+ pdbcanvas.redrawneeded=true;
+ pdbcanvas.repaint();
+ }
+
+ public void seqButton_actionPerformed()
+ {
+ pdbcanvas.bysequence = true;
+ pdbcanvas.updateSeqColours();
+ pdbcanvas.repaint();
+ }
+
+
+ public void mapping_actionPerformed()
+ {
+ jalview.appletgui.CutAndPasteTransfer cap
+ = new jalview.appletgui.CutAndPasteTransfer(false, null);
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", 500, 600);
+ cap.setText(pdbcanvas.mappingDetails.toString());
+ }
+
+ public void allchains_itemStateChanged()
+ {
+ pdbcanvas.setAllchainsVisible(allchains.getState());
+ }
+
+}
diff --git a/src/MCview/Atom.java b/src/MCview/Atom.java
index 51c4f01..269fbaa 100755
--- a/src/MCview/Atom.java
+++ b/src/MCview/Atom.java
@@ -1,58 +1,58 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import java.awt.*;
-
-
-public class Atom {
- float x;
- float y;
- float z;
- int number;
- String name;
- String resName;
- int resNumber;
- int type;
- Color color;
- String chain;
- int alignmentMapping=-1;
-
- public boolean isSelected = false;
-
- public Atom(String str)
- {
- name = str.substring(12,15).trim();
-
- resName = str.substring(17,20);
-
- chain = str.substring(21,22);
-
- resNumber = Integer.parseInt(str.substring(22,26).trim());
-
- this.x = (float) (new Float(str.substring(30,38).trim()).floatValue());
- this.y = (float) (new Float(str.substring(38,46).trim()).floatValue());
- this.z = (float) (new Float(str.substring(47,55).trim()).floatValue());
-
- }
-
- public void setColor(Color col) {
- this.color = col;
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+import java.awt.*;
+
+
+public class Atom {
+ float x;
+ float y;
+ float z;
+ int number;
+ String name;
+ String resName;
+ int resNumber;
+ int type;
+ Color color = Color.lightGray;
+ String chain;
+ int alignmentMapping=-1;
+
+ public boolean isSelected = false;
+
+ public Atom(String str)
+ {
+ name = str.substring(12,15).trim();
+
+ resName = str.substring(17,20);
+
+ chain = str.substring(21,22);
+
+ resNumber = Integer.parseInt(str.substring(22,26).trim());
+
+ this.x = (float) (new Float(str.substring(30,38).trim()).floatValue());
+ this.y = (float) (new Float(str.substring(38,46).trim()).floatValue());
+ this.z = (float) (new Float(str.substring(47,55).trim()).floatValue());
+
+ }
+
+ // public void setColor(Color col) {
+ // this.color = col;
+ // }
+}
diff --git a/src/MCview/Bond.java b/src/MCview/Bond.java
index 5f162b0..98edc45 100755
--- a/src/MCview/Bond.java
+++ b/src/MCview/Bond.java
@@ -1,78 +1,78 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import java.awt.*;
-
-
-public class Bond {
- float[] start;
- float[] end;
- Color startCol;
- Color endCol;
- public Atom at1;
- public Atom at2;
-
- public Bond(float[] start, float[] end, Atom at1, Atom at2) {
- this.start = start;
- this.end = end;
- this.startCol = at1.color;
- this.endCol = at2.color;
- this.at1 = at1;
- this.at2 = at2;
- }
-
- public Bond(Bond bond) {
- this.start = new float[3];
-
- this.start[0] = bond.start[0];
- this.start[1] = bond.start[1];
- this.start[2] = bond.start[2];
-
- this.end = new float[3];
-
- this.end[0] = bond.end[0];
- this.end[1] = bond.end[1];
- this.end[2] = bond.end[2];
-
- this.startCol = bond.startCol;
- this.endCol = bond.endCol;
- }
-
- public float length() {
- float len = ((end[0] - start[0]) * (end[0] - start[0])) +
- ((end[1] - start[1]) * (end[1] - start[1])) +
- ((end[2] - start[2]) * (end[2] - start[2]));
-
- len = (float) (Math.sqrt(len));
-
- return len;
- }
-
- public void translate(float x, float y, float z) {
- start[0] = (start[0] + x);
- end[0] = (end[0] + x);
-
- start[1] = (start[1] + y);
- end[1] = (end[1] + y);
-
- start[2] = (start[2] + z);
- end[2] = (end[2] + z);
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+import java.awt.*;
+
+
+public class Bond {
+ float[] start;
+ float[] end;
+ Color startCol = Color.lightGray;
+ Color endCol= Color.lightGray;
+ public Atom at1;
+ public Atom at2;
+
+ public Bond(float[] start, float[] end, Atom at1, Atom at2) {
+ this.start = start;
+ this.end = end;
+ this.startCol = at1.color;
+ this.endCol = at2.color;
+ this.at1 = at1;
+ this.at2 = at2;
+ }
+
+ /* public Bond(Bond bond) {
+ this.start = new float[3];
+
+ this.start[0] = bond.start[0];
+ this.start[1] = bond.start[1];
+ this.start[2] = bond.start[2];
+
+ this.end = new float[3];
+
+ this.end[0] = bond.end[0];
+ this.end[1] = bond.end[1];
+ this.end[2] = bond.end[2];
+
+ this.startCol = bond.startCol;
+ this.endCol = bond.endCol;
+ }
+
+ public float length() {
+ float len = ((end[0] - start[0]) * (end[0] - start[0])) +
+ ((end[1] - start[1]) * (end[1] - start[1])) +
+ ((end[2] - start[2]) * (end[2] - start[2]));
+
+ len = (float) (Math.sqrt(len));
+
+ return len;
+ }*/
+
+ public void translate(float x, float y, float z) {
+ start[0] = (start[0] + x);
+ end[0] = (end[0] + x);
+
+ start[1] = (start[1] + y);
+ end[1] = (end[1] + y);
+
+ start[2] = (start[2] + z);
+ end[2] = (end[2] + z);
+ }
+}
diff --git a/src/MCview/MCMatrix.java b/src/MCview/MCMatrix.java
index 66c3798..36aff78 100755
--- a/src/MCview/MCMatrix.java
+++ b/src/MCview/MCMatrix.java
@@ -1,152 +1,152 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-public class MCMatrix {
- float[][] matrix;
- float[][] tmp;
- float mycos;
- float mysin;
- float myconst = (float) (Math.PI / 180);
-
- public MCMatrix(int rows, int cols) {
- matrix = new float[rows][cols];
- tmp = new float[rows][cols];
- }
-
- public void addElement(int i, int j, float value) {
- matrix[i][j] = value;
- }
-
- public void rotatex(float degrees) {
- mycos = (float) (Math.cos(degrees * myconst));
- mysin = (float) (Math.sin(degrees * myconst));
-
- tmp[0][0] = 1;
- tmp[0][1] = 0;
- tmp[0][2] = 0;
- tmp[1][0] = 0;
- tmp[1][1] = mycos;
- tmp[1][2] = mysin;
- tmp[2][0] = 0;
- tmp[2][1] = -mysin;
- tmp[2][2] = mycos;
- preMultiply(tmp);
- }
-
- public void rotatez(float degrees) {
- mycos = (float) (Math.cos(degrees * myconst));
- mysin = (float) (Math.sin(degrees * myconst));
-
- tmp[0][0] = mycos;
- tmp[0][1] = -mysin;
- tmp[0][2] = 0;
- tmp[1][0] = mysin;
- tmp[1][1] = mycos;
- tmp[1][2] = 0;
- tmp[2][0] = 0;
- tmp[2][1] = 0;
- tmp[2][2] = 1;
-
- preMultiply(tmp);
- }
-
- public void rotatey(float degrees) {
- mycos = (float) (Math.cos(degrees * myconst));
- mysin = (float) (Math.sin(degrees * myconst));
-
- tmp[0][0] = mycos;
- tmp[0][1] = 0;
- tmp[0][2] = -mysin;
- tmp[1][0] = 0;
- tmp[1][1] = 1;
- tmp[1][2] = 0;
- tmp[2][0] = mysin;
- tmp[2][1] = 0;
- tmp[2][2] = mycos;
-
- preMultiply(tmp);
- }
-
- public float[] vectorMultiply(float[] vect) {
- float[] temp = new float[3];
-
- temp[0] = vect[0];
- temp[1] = vect[1];
- temp[2] = vect[2];
-
- for (int i = 0; i < 3; i++) {
- temp[i] = ((float) matrix[i][0] * vect[0]) +
- ((float) matrix[i][1] * vect[1]) +
- ((float) matrix[i][2] * vect[2]);
- }
-
- vect[0] = temp[0];
- vect[1] = temp[1];
- vect[2] = temp[2];
-
- return vect;
- }
-
- public void preMultiply(float[][] mat) {
- float[][] tmp = new float[3][3];
-
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- tmp[i][j] = (mat[i][0] * matrix[0][j]) +
- (mat[i][1] * matrix[1][j]) + (mat[i][2] * matrix[2][j]);
- }
- }
-
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- matrix[i][j] = tmp[i][j];
- }
- }
- }
-
- public void postMultiply(float[][] mat) {
- float[][] tmp = new float[3][3];
-
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- tmp[i][j] = (matrix[i][0] * mat[0][j]) +
- (matrix[i][1] * mat[1][j]) + (matrix[i][2] * mat[2][j]);
- }
- }
-
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- matrix[i][j] = tmp[i][j];
- }
- }
- }
-
- public void setIdentity() {
- matrix[0][0] = 1;
- matrix[1][1] = 1;
- matrix[2][2] = 1;
- matrix[0][1] = 0;
- matrix[0][2] = 0;
- matrix[1][0] = 0;
- matrix[1][2] = 0;
- matrix[2][0] = 0;
- matrix[2][1] = 0;
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+public class MCMatrix {
+ float[][] matrix;
+ float[][] tmp;
+ float mycos;
+ float mysin;
+ float myconst = (float) (Math.PI / 180);
+
+ public MCMatrix(int rows, int cols) {
+ matrix = new float[rows][cols];
+ tmp = new float[rows][cols];
+ }
+
+ public void addElement(int i, int j, float value) {
+ matrix[i][j] = value;
+ }
+
+ public void rotatex(float degrees) {
+ mycos = (float) (Math.cos(degrees * myconst));
+ mysin = (float) (Math.sin(degrees * myconst));
+
+ tmp[0][0] = 1;
+ tmp[0][1] = 0;
+ tmp[0][2] = 0;
+ tmp[1][0] = 0;
+ tmp[1][1] = mycos;
+ tmp[1][2] = mysin;
+ tmp[2][0] = 0;
+ tmp[2][1] = -mysin;
+ tmp[2][2] = mycos;
+ preMultiply(tmp);
+ }
+
+ public void rotatez(float degrees) {
+ mycos = (float) (Math.cos(degrees * myconst));
+ mysin = (float) (Math.sin(degrees * myconst));
+
+ tmp[0][0] = mycos;
+ tmp[0][1] = -mysin;
+ tmp[0][2] = 0;
+ tmp[1][0] = mysin;
+ tmp[1][1] = mycos;
+ tmp[1][2] = 0;
+ tmp[2][0] = 0;
+ tmp[2][1] = 0;
+ tmp[2][2] = 1;
+
+ preMultiply(tmp);
+ }
+
+ public void rotatey(float degrees) {
+ mycos = (float) (Math.cos(degrees * myconst));
+ mysin = (float) (Math.sin(degrees * myconst));
+
+ tmp[0][0] = mycos;
+ tmp[0][1] = 0;
+ tmp[0][2] = -mysin;
+ tmp[1][0] = 0;
+ tmp[1][1] = 1;
+ tmp[1][2] = 0;
+ tmp[2][0] = mysin;
+ tmp[2][1] = 0;
+ tmp[2][2] = mycos;
+
+ preMultiply(tmp);
+ }
+
+ public float[] vectorMultiply(float[] vect) {
+ float[] temp = new float[3];
+
+ temp[0] = vect[0];
+ temp[1] = vect[1];
+ temp[2] = vect[2];
+
+ for (int i = 0; i < 3; i++) {
+ temp[i] = ((float) matrix[i][0] * vect[0]) +
+ ((float) matrix[i][1] * vect[1]) +
+ ((float) matrix[i][2] * vect[2]);
+ }
+
+ vect[0] = temp[0];
+ vect[1] = temp[1];
+ vect[2] = temp[2];
+
+ return vect;
+ }
+
+ public void preMultiply(float[][] mat) {
+ float[][] tmp = new float[3][3];
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ tmp[i][j] = (mat[i][0] * matrix[0][j]) +
+ (mat[i][1] * matrix[1][j]) + (mat[i][2] * matrix[2][j]);
+ }
+ }
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ matrix[i][j] = tmp[i][j];
+ }
+ }
+ }
+
+ public void postMultiply(float[][] mat) {
+ float[][] tmp = new float[3][3];
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ tmp[i][j] = (matrix[i][0] * mat[0][j]) +
+ (matrix[i][1] * mat[1][j]) + (matrix[i][2] * mat[2][j]);
+ }
+ }
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ matrix[i][j] = tmp[i][j];
+ }
+ }
+ }
+
+ public void setIdentity() {
+ matrix[0][0] = 1;
+ matrix[1][1] = 1;
+ matrix[2][2] = 1;
+ matrix[0][1] = 0;
+ matrix[0][2] = 0;
+ matrix[1][0] = 0;
+ matrix[1][2] = 0;
+ matrix[2][0] = 0;
+ matrix[2][1] = 0;
+ }
+}
diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java
index d702264..ca4e5be 100755
--- a/src/MCview/PDBCanvas.java
+++ b/src/MCview/PDBCanvas.java
@@ -1,996 +1,1015 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import jalview.analysis.AlignSeq;
-
-import jalview.datamodel.*;
-
-// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
-import java.awt.*;
-import java.awt.event.*;
-
-import java.io.*;
-
-import java.util.*;
-
-import javax.swing.*;
-
-
-public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListener
-{
- MCMatrix idmat = new MCMatrix(3, 3);
- MCMatrix objmat = new MCMatrix(3, 3);
- boolean redrawneeded = true;
- int omx = 0;
- int mx = 0;
- int omy = 0;
- int my = 0;
- public PDBfile pdb;
- int bsize;
- Image img;
- Graphics ig;
- Dimension prefsize;
- float[] centre = new float[3];
- float[] width = new float[3];
- float maxwidth;
- float scale;
- String inStr;
- String inType;
- boolean bysequence = true;
- boolean depthcue = true;
- boolean wire = false;
- boolean bymolecule = false;
- boolean zbuffer = true;
- boolean dragging;
- int xstart;
- int xend;
- int ystart;
- int yend;
- int xmid;
- int ymid;
- Font font = new Font("Helvetica", Font.PLAIN, 10);
- jalview.gui.SeqCanvas seqcanvas;
- public Sequence sequence;
- final StringBuffer mappingDetails = new StringBuffer();
- PDBChain mainchain;
- Vector highlightRes;
- boolean pdbAction = false;
- boolean seqColoursReady = false;
- jalview.gui.FeatureRenderer fr;
-
- public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)
- {
- this.seqcanvas = seqcanvas;
- this.sequence = seq;
- seqcanvas.setPDBCanvas(this);
- }
-
- public void setPDBFile(PDBfile pdb)
- {
- int max = -10;
- int maxchain = -1;
- int pdbstart = 0;
- int pdbend = 0;
- int seqstart = 0;
- int seqend = 0;
- AlignSeq maxAlignseq = null;
-
- for (int i = 0; i < pdb.chains.size(); i++)
- {
-
- mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());
- mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");
-
- // Now lets compare the sequences to get
- // the start and end points.
- // Align the sequence to the pdb
- AlignSeq as = new AlignSeq(sequence,
- ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");
- as.calcScoreMatrix();
- as.traceAlignment();
- PrintStream ps = new PrintStream(System.out)
- {
- public void print(String x) {
- mappingDetails.append(x);
- }
- public void println()
- {
- mappingDetails.append("\n");
- }
- };
-
- as.printAlignment(ps);
-
-
-
- if (as.maxscore > max)
- {
- max = as.maxscore;
- maxchain = i;
- pdbstart = as.seq2start;
- pdbend = as.seq2end;
- seqstart = as.seq1start + sequence.getStart()-1;
- seqend = as.seq1end + sequence.getEnd()-1;
- maxAlignseq = as;
- }
-
- mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
- mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);
- }
-
- mainchain = (PDBChain) pdb.chains.elementAt(maxchain);
-
- mainchain.pdbstart = pdbstart;
- mainchain.pdbend = pdbend;
- mainchain.seqstart = seqstart;
- mainchain.seqend = seqend;
- mainchain.isVisible = true;
- mainchain.makeExactMapping(maxAlignseq, sequence);
-
- this.pdb = pdb;
- this.prefsize = new Dimension(getWidth(), getHeight());
-
- //Initialize the matrices to identity
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- if (i != j) {
- idmat.addElement(i, j, 0);
- objmat.addElement(i, j, 0);
- } else {
- idmat.addElement(i, j, 1);
- objmat.addElement(i, j, 1);
- }
- }
- }
-
- addMouseMotionListener(this);
- addMouseListener(this);
-
- addMouseWheelListener(new MouseWheelListener()
- {
- public void mouseWheelMoved(MouseWheelEvent e)
- {
- if (e.getWheelRotation() > 0)
- {
- scale = (float) (scale * 1.1);
- redrawneeded = true;
- repaint();
- }
-
- else
- {
- scale = (float) (scale * 0.9);
- redrawneeded = true;
- repaint();
- }
- }
- });
-
-
- findCentre();
- findWidth();
-
- setupBonds();
-
- scale = findScale();
-
- ToolTipManager.sharedInstance().registerComponent(this);
- ToolTipManager.sharedInstance().setInitialDelay(0);
- ToolTipManager.sharedInstance().setDismissDelay(10000);
- }
-
-
- Vector visiblebonds;
- void setupBonds()
- {
- seqColoursReady = false;
- // Sort the bonds by z coord
- visiblebonds = new Vector();
-
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)
- {
- Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < tmp.size(); i++)
- {
- visiblebonds.addElement(tmp.elementAt(i));
- }
- }
- }
-
- updateSeqColours();
- seqColoursReady = true;
- redrawneeded = true;
- repaint();
- }
-
-
- public void findWidth() {
- float[] max = new float[3];
- float[] min = new float[3];
-
- max[0] = (float) -1e30;
- max[1] = (float) -1e30;
- max[2] = (float) -1e30;
-
- min[0] = (float) 1e30;
- min[1] = (float) 1e30;
- min[2] = (float) 1e30;
-
- for (int ii = 0; ii < pdb.chains.size(); ii++) {
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++) {
- Bond tmp = (Bond) bonds.elementAt(i);
-
- if (tmp.start[0] >= max[0]) {
- max[0] = tmp.start[0];
- }
-
- if (tmp.start[1] >= max[1]) {
- max[1] = tmp.start[1];
- }
-
- if (tmp.start[2] >= max[2]) {
- max[2] = tmp.start[2];
- }
-
- if (tmp.start[0] <= min[0]) {
- min[0] = tmp.start[0];
- }
-
- if (tmp.start[1] <= min[1]) {
- min[1] = tmp.start[1];
- }
-
- if (tmp.start[2] <= min[2]) {
- min[2] = tmp.start[2];
- }
-
- if (tmp.end[0] >= max[0]) {
- max[0] = tmp.end[0];
- }
-
- if (tmp.end[1] >= max[1]) {
- max[1] = tmp.end[1];
- }
-
- if (tmp.end[2] >= max[2]) {
- max[2] = tmp.end[2];
- }
-
- if (tmp.end[0] <= min[0]) {
- min[0] = tmp.end[0];
- }
-
- if (tmp.end[1] <= min[1]) {
- min[1] = tmp.end[1];
- }
-
- if (tmp.end[2] <= min[2]) {
- min[2] = tmp.end[2];
- }
- }
- }
- }
- /*
- System.out.println("xmax " + max[0] + " min " + min[0]);
- System.out.println("ymax " + max[1] + " min " + min[1]);
- System.out.println("zmax " + max[2] + " min " + min[2]);*/
-
- width[0] = (float) Math.abs(max[0] - min[0]);
- width[1] = (float) Math.abs(max[1] - min[1]);
- width[2] = (float) Math.abs(max[2] - min[2]);
-
- maxwidth = width[0];
-
- if (width[1] > width[0]) {
- maxwidth = width[1];
- }
-
- if (width[2] > width[1]) {
- maxwidth = width[2];
- }
-
- // System.out.println("Maxwidth = " + maxwidth);
- }
-
- public float findScale() {
- int dim;
- int width;
- int height;
-
- if (getWidth() != 0) {
- width = getWidth();
- height = getHeight();
- } else {
- width = prefsize.width;
- height = prefsize.height;
- }
-
- if (width < height) {
- dim = width;
- } else {
- dim = height;
- }
-
- return (float) (dim / (1.5d * maxwidth));
- }
-
- public void findCentre() {
- float xtot = 0;
- float ytot = 0;
- float ztot = 0;
-
- int bsize = 0;
-
- //Find centre coordinate
- for (int ii = 0; ii < pdb.chains.size(); ii++) {
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- bsize += bonds.size();
-
- for (int i = 0; i < bonds.size(); i++) {
- xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +
- ((Bond) bonds.elementAt(i)).end[0];
-
- ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +
- ((Bond) bonds.elementAt(i)).end[1];
-
- ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +
- ((Bond) bonds.elementAt(i)).end[2];
- }
- }
- }
-
- centre[0] = xtot / (2 * (float) bsize);
- centre[1] = ytot / (2 * (float) bsize);
- centre[2] = ztot / (2 * (float) bsize);
- }
-
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
-
- if(!seqColoursReady)
- {
- g.setColor(Color.black);
- g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Retrieving PDB data....", 20, getHeight()/2);
- return;
- }
-
-
- //Only create the image at the beginning -
- //this saves much memory usage
- if ((img == null)
- || (prefsize.width != getWidth())
- || (prefsize.height != getHeight()))
-
- {
- prefsize.width = getWidth();
- prefsize.height = getHeight();
-
- scale = findScale();
- img = createImage(prefsize.width, prefsize.height);
- ig = img.getGraphics();
- Graphics2D ig2 = (Graphics2D) ig;
-
- ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
-
- redrawneeded = true;
- }
-
-
- if (redrawneeded)
- {
- drawAll(ig, prefsize.width, prefsize.height);
- redrawneeded = false;
- }
-
- g.drawImage(img, 0, 0, this);
-
- pdbAction = false;
- }
-
- public void drawAll(Graphics g, int width, int height)
- {
- g.setColor(Color.black);
- g.fillRect(0, 0, width, height);
- drawScene(g);
- drawLabels(g);
- }
-
-
- public void updateSeqColours()
- {
- if(pdbAction)
- {
- return;
- }
-
- // System.out.println("update seq colours");
- if(bysequence && pdb!=null)
- {
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- colourBySequence( (PDBChain) pdb.chains.elementAt(ii));
- }
- }
-
- redrawneeded=true;
- repaint();
- }
-
- int findTrueIndex(int pos)
- {
- // returns the alignment position for a residue
- int j = sequence.getStart();
- int i = 0;
-
- while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))
- {
- if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
- {
- j++;
- }
-
- i++;
- }
-
- if(i>1)
- i--;
-
- if ( (j == sequence.getEnd()) && (j < pos))
- {
- return sequence.getEnd() + 1;
- }
- else
- {
- return i;
- }
- }
-
- // This method has been taken out of PDBChain to allow
- // Applet and Application specific sequence renderers to be used
- void colourBySequence(PDBChain chain)
- {
- // System.out.println("colour by seq");
- boolean showFeatures = false;
- if(seqcanvas.getViewport().getShowSequenceFeatures())
- {
- showFeatures = true;
- if (fr == null)
- fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport());
-
- fr.transferSettings( seqcanvas.getFeatureRenderer() );
- }
-
- for (int i = 0; i < chain.bonds.size(); i++)
- {
- Bond tmp = (Bond) chain.bonds.elementAt(i);
- tmp.startCol = Color.lightGray;
- tmp.endCol = Color.lightGray;
-
- if(chain!=mainchain)
- continue;
-
- if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
- (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
- {
- int index = findTrueIndex(tmp.at1.alignmentMapping);
- //sequence.findIndex(tmp.at1.alignmentMapping);
- if (index != -1)
- {
- tmp.startCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour( sequence, index);
- if(tmp.startCol==null)
- tmp.startCol = Color.white;
-
- if(showFeatures)
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
- }
- }
-
- if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
- (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))
- {
-
- int index = findTrueIndex(tmp.at2.alignmentMapping);
- //sequence.findIndex( tmp.at2.alignmentMapping );
- if (index != -1)
- {
- tmp.endCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour( sequence, index);
- if(tmp.endCol==null)
- tmp.endCol = Color.white;
- if(showFeatures)
- tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
- }
- }
- }
- }
-
-
- Zsort zsort;
- public void drawScene(Graphics g)
- {
- if (zbuffer)
- {
- if(zsort==null)
- zsort = new Zsort();
-
- zsort.Zsort(visiblebonds);
- }
-
- Bond tmpBond=null;
- for (int i = 0; i < visiblebonds.size(); i++)
- {
- tmpBond = (Bond) visiblebonds.elementAt(i);
-
- xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +
- (getWidth() / 2));
- ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +
- (getHeight() / 2));
-
- xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +
- (getWidth() / 2));
- yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +
- (getHeight() / 2));
-
- xmid = (xend + xstart) / 2;
- ymid = (yend + ystart) / 2;
-
- if (depthcue && !bymolecule)
- {
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
- {
- g.setColor(tmpBond.startCol.darker().darker());
- drawLine(g, xstart, ystart, xmid, ymid);
- g.setColor(tmpBond.endCol.darker().darker());
- drawLine(g, xmid, ymid, xend, yend);
- } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
- g.setColor(tmpBond.startCol.darker());
- drawLine(g, xstart, ystart, xmid, ymid);
-
- g.setColor(tmpBond.endCol.darker());
- drawLine(g, xmid, ymid, xend, yend);
- } else {
- g.setColor(tmpBond.startCol);
- drawLine(g, xstart, ystart, xmid, ymid);
-
- g.setColor(tmpBond.endCol);
- drawLine(g, xmid, ymid, xend, yend);
- }
- } else if (depthcue && bymolecule) {
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {
- g.setColor(Color.green.darker().darker());
- drawLine(g, xstart, ystart, xend, yend);
- } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
- g.setColor(Color.green.darker());
- drawLine(g, xstart, ystart, xend, yend);
- } else {
- g.setColor(Color.green);
- drawLine(g, xstart, ystart, xend, yend);
- }
- } else if (!depthcue && !bymolecule) {
- g.setColor(tmpBond.startCol);
- drawLine(g, xstart, ystart, xmid, ymid);
- g.setColor(tmpBond.endCol);
- drawLine(g, xmid, ymid, xend, yend);
- } else {
- drawLine(g, xstart, ystart, xend, yend);
- }
-
- if(highlightBond1!=null && highlightBond1==tmpBond)
- {
- g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter());
- drawLine(g, xmid, ymid, xend, yend);
- }
-
- if(highlightBond2!=null && highlightBond2==tmpBond)
- {
- g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter());
- drawLine(g, xstart, ystart, xmid, ymid);
- }
-
- }
-
-
- }
-
- public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {
- if (!wire) {
- if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {
- g.drawLine(x1, y1, x2, y2);
- g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
- g.drawLine(x1, y1 - 1, x2, y2 - 1);
- } else {
- g.setColor(g.getColor().brighter());
- g.drawLine(x1, y1, x2, y2);
- g.drawLine(x1 + 1, y1, x2 + 1, y2);
- g.drawLine(x1 - 1, y1, x2 - 1, y2);
- }
- } else {
- g.drawLine(x1, y1, x2, y2);
- }
- }
-
- public Dimension minimumsize() {
- return prefsize;
- }
-
- public Dimension preferredsize() {
- return prefsize;
- }
-
- public void keyPressed(KeyEvent evt)
- {
- if (evt.getKeyCode() == KeyEvent.VK_UP)
- {
- scale = (float) (scale * 1.1);
- redrawneeded = true;
- repaint();
- }
- else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
- {
- scale = (float) (scale * 0.9);
- redrawneeded = true;
- repaint();
- }
- }
-
- public void mousePressed(MouseEvent e)
- {
- pdbAction = true;
- Atom fatom = findAtom(e.getX(), e.getY());
- if(fatom!=null)
- {
- fatom.isSelected = !fatom.isSelected;
-
- redrawneeded = true;
- repaint();
- if (foundchain != -1)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
- if (chain == mainchain)
- {
- if (fatom.alignmentMapping != -1)
- {
- if (highlightRes == null)
- highlightRes = new Vector();
-
- if (highlightRes.contains(fatom.alignmentMapping+""))
- highlightRes.remove(fatom.alignmentMapping + "");
- else
- highlightRes.add(fatom.alignmentMapping + "");
- }
- }
- }
-
- }
- mx = e.getX();
- my = e.getY();
- omx = mx;
- omy = my;
- dragging = false;
- }
-
- public void mouseMoved(MouseEvent e)
- {
- pdbAction = true;
- if(highlightBond1!=null)
- {
- highlightBond1.at2.isSelected = false;
- highlightBond2.at1.isSelected = false;
- highlightBond1 = null;
- highlightBond2 = null;
- }
-
- Atom fatom = findAtom(e.getX(), e.getY());
-
- PDBChain chain = null;
- if(foundchain!=-1)
- {
- chain = (PDBChain) pdb.chains.elementAt(foundchain);
- if(chain == mainchain)
- {
- highlightSeqcanvas( fatom.alignmentMapping );
- }
- }
-
- if (fatom != null)
- {
- this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName);
- } else
- {
- highlightSeqcanvas( -1);
- this.setToolTipText(null);
- }
- }
-
-
- void highlightSeqcanvas(int pos)
- {
- SearchResults searchResults = new SearchResults();
- if(highlightRes!=null)
- {
- for (int i = 0; i < highlightRes.size(); i++)
- {
- int a = Integer.parseInt(highlightRes.elementAt(
- i).toString())+1;
-
- searchResults.addResult(sequence, a, a);
- }
- }
-
- if(pos!=-1)
- {
- searchResults.addResult(sequence, pos+1, pos+1);
- }
-
- seqcanvas.highlightSearchResults(searchResults);
- }
-
-
- public void mouseClicked(MouseEvent e) { }
-
- public void mouseEntered(MouseEvent e) { }
-
- public void mouseExited(MouseEvent e) { }
-
- public void mouseDragged(MouseEvent evt)
- {
- int x = evt.getX();
- int y = evt.getY();
- mx = x;
- my = y;
-
-
- MCMatrix objmat = new MCMatrix(3, 3);
- objmat.setIdentity();
-
- if ((evt.getModifiers() & Event.META_MASK) != 0) {
- objmat.rotatez((float) ((mx - omx)));
- } else {
- objmat.rotatex((float) ((my - omy)));
- objmat.rotatey((float) ((omx - mx)));
- }
-
- //Alter the bonds
- for (int ii = 0; ii < pdb.chains.size(); ii++) {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++) {
- Bond tmpBond = (Bond) bonds.elementAt(i);
-
- //Translate the bond so the centre is 0,0,0
- tmpBond.translate(-centre[0], -centre[1], -centre[2]);
-
- //Now apply the rotation matrix
- tmpBond.start = objmat.vectorMultiply(tmpBond.start);
- tmpBond.end = objmat.vectorMultiply(tmpBond.end);
-
- //Now translate back again
- tmpBond.translate(centre[0], centre[1], centre[2]);
- }
- }
-
- objmat = null;
-
- omx = mx;
- omy = my;
-
- dragging = true;
-
- redrawneeded = true;
-
- repaint();
- }
-
- public void mouseReleased(MouseEvent evt)
- {
- dragging = false;
- return;
- }
-
- void drawLabels(Graphics g) {
-
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
-
- if (chain.isVisible)
- {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++)
- {
- Bond tmpBond = (Bond) bonds.elementAt(i);
-
- if (tmpBond.at1.isSelected)
- {
- labelAtom(g, tmpBond, 1);
- }
-
- if (tmpBond.at2.isSelected)
- {
-
- labelAtom(g, tmpBond, 2);
- }
- }
- }
- }
- }
-
- public void labelAtom(Graphics g, Bond b, int n) {
- g.setFont(font);
- g.setColor(Color.red);
- if (n == 1)
- {
- int xstart = (int) (((b.start[0] - centre[0]) * scale) +
- (getWidth() / 2));
- int ystart = (int) (((b.start[1] - centre[1]) * scale) +
- (getHeight() / 2));
-
- g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);
- }
-
- if (n == 2) {
- int xstart = (int) (((b.end[0] - centre[0]) * scale) +
- (getWidth() / 2));
- int ystart = (int) (((b.end[1] - centre[1]) * scale) +
- (getHeight() / 2));
-
- g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);
- }
- }
-
- int foundchain = -1;
- public Atom findAtom(int x, int y) {
- Atom fatom = null;
-
- foundchain = -1;
-
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
- int truex;
- Bond tmpBond=null;
-
- if (chain.isVisible)
- {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
-
- for (int i = 0; i < bonds.size(); i++)
- {
- tmpBond = (Bond) bonds.elementAt(i);
-
- truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +
- (getWidth() / 2));
-
- if (Math.abs(truex - x) <= 2)
- {
- int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +
- (getHeight() / 2));
-
- if (Math.abs(truey - y) <= 2)
- {
- fatom = tmpBond.at1;
- foundchain = ii;
- break;
- }
- }
- }
-
- // Still here? Maybe its the last bond
-
- truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
- (getWidth() / 2));
-
- if (Math.abs(truex - x) <= 2)
- {
- int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
- (getHeight() / 2));
-
- if (Math.abs(truey - y) <= 2)
- {
- fatom = tmpBond.at2;
- foundchain = ii;
- break;
- }
- }
-
- }
-
- if (fatom != null) //)&& chain.ds != null)
- {
- chain = (PDBChain) pdb.chains.elementAt(foundchain);
- }
- }
-
- return fatom;
- }
-
- Bond highlightBond1, highlightBond2;
- public void highlightRes(int ii)
- {
- if( !seqColoursReady )
- return;
-
- if (highlightRes != null
- && highlightRes.contains((ii-1) + ""))
- {
- return;
- }
-
- int index = -1;
- Bond tmpBond;
- for(index=0; index 0)
- {
- highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
- highlightBond1.at2.isSelected = true;
- }
-
- if (index != mainchain.bonds.size())
- {
- highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
- highlightBond2.at1.isSelected = true;
- }
-
- break;
- }
- }
-
- redrawneeded = true;
- repaint();
- }
-
- public void setAllchainsVisible(boolean b)
- {
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
- chain.isVisible = b;
- }
- mainchain.isVisible = true;
- findCentre();
- setupBonds();
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+import jalview.analysis.AlignSeq;
+
+import jalview.datamodel.*;
+
+// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
+import java.awt.*;
+import java.awt.event.*;
+
+import java.io.*;
+
+import java.util.*;
+
+import javax.swing.*;
+
+
+public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListener
+{
+ MCMatrix idmat = new MCMatrix(3, 3);
+ MCMatrix objmat = new MCMatrix(3, 3);
+ boolean redrawneeded = true;
+ int omx = 0;
+ int mx = 0;
+ int omy = 0;
+ int my = 0;
+ public PDBfile pdb;
+ int bsize;
+ Image img;
+ Graphics ig;
+ Dimension prefsize;
+ float[] centre = new float[3];
+ float[] width = new float[3];
+ float maxwidth;
+ float scale;
+ String inStr;
+ String inType;
+ boolean bysequence = true;
+ boolean depthcue = true;
+ boolean wire = false;
+ boolean bymolecule = false;
+ boolean zbuffer = true;
+ boolean dragging;
+ int xstart;
+ int xend;
+ int ystart;
+ int yend;
+ int xmid;
+ int ymid;
+ Font font = new Font("Helvetica", Font.PLAIN, 10);
+ jalview.gui.SeqCanvas seqcanvas;
+ public Sequence sequence;
+ final StringBuffer mappingDetails = new StringBuffer();
+ PDBChain mainchain;
+ Vector highlightRes;
+ boolean pdbAction = false;
+ boolean seqColoursReady = false;
+ jalview.gui.FeatureRenderer fr;
+ Color backgroundColour = Color.black;
+
+ public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)
+ {
+ this.seqcanvas = seqcanvas;
+ this.sequence = seq;
+ seqcanvas.setPDBCanvas(this);
+ }
+
+ public void setPDBFile(PDBfile pdb)
+ {
+ int max = -10;
+ int maxchain = -1;
+ int pdbstart = 0;
+ int pdbend = 0;
+ int seqstart = 0;
+ int seqend = 0;
+ AlignSeq maxAlignseq = null;
+
+ for (int i = 0; i < pdb.chains.size(); i++)
+ {
+
+ mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());
+ mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");
+
+ // Now lets compare the sequences to get
+ // the start and end points.
+ // Align the sequence to the pdb
+ AlignSeq as = new AlignSeq(sequence,
+ ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");
+ as.calcScoreMatrix();
+ as.traceAlignment();
+ PrintStream ps = new PrintStream(System.out)
+ {
+ public void print(String x) {
+ mappingDetails.append(x);
+ }
+ public void println()
+ {
+ mappingDetails.append("\n");
+ }
+ };
+
+ as.printAlignment(ps);
+
+
+
+ if (as.maxscore > max)
+ {
+ max = as.maxscore;
+ maxchain = i;
+ pdbstart = as.seq2start;
+ pdbend = as.seq2end;
+ seqstart = as.seq1start + sequence.getStart()-1;
+ seqend = as.seq1end + sequence.getEnd()-1;
+ maxAlignseq = as;
+ }
+
+ mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
+ mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);
+ }
+
+ mainchain = (PDBChain) pdb.chains.elementAt(maxchain);
+
+ mainchain.pdbstart = pdbstart;
+ mainchain.pdbend = pdbend;
+ mainchain.seqstart = seqstart;
+ mainchain.seqend = seqend;
+ mainchain.isVisible = true;
+ mainchain.makeExactMapping(maxAlignseq, sequence);
+
+ this.pdb = pdb;
+ this.prefsize = new Dimension(getWidth(), getHeight());
+
+ //Initialize the matrices to identity
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ if (i != j) {
+ idmat.addElement(i, j, 0);
+ objmat.addElement(i, j, 0);
+ } else {
+ idmat.addElement(i, j, 1);
+ objmat.addElement(i, j, 1);
+ }
+ }
+ }
+
+ addMouseMotionListener(this);
+ addMouseListener(this);
+
+ addMouseWheelListener(new MouseWheelListener()
+ {
+ public void mouseWheelMoved(MouseWheelEvent e)
+ {
+ if (e.getWheelRotation() > 0)
+ {
+ scale = (float) (scale * 1.1);
+ redrawneeded = true;
+ repaint();
+ }
+
+ else
+ {
+ scale = (float) (scale * 0.9);
+ redrawneeded = true;
+ repaint();
+ }
+ }
+ });
+
+
+ findCentre();
+ findWidth();
+
+ setupBonds();
+
+ scale = findScale();
+
+ ToolTipManager.sharedInstance().registerComponent(this);
+ ToolTipManager.sharedInstance().setInitialDelay(0);
+ ToolTipManager.sharedInstance().setDismissDelay(10000);
+ }
+
+
+ Vector visiblebonds;
+ void setupBonds()
+ {
+ seqColoursReady = false;
+ // Sort the bonds by z coord
+ visiblebonds = new Vector();
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)
+ {
+ Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < tmp.size(); i++)
+ {
+ visiblebonds.addElement(tmp.elementAt(i));
+ }
+ }
+ }
+
+ updateSeqColours();
+ seqColoursReady = true;
+ redrawneeded = true;
+ repaint();
+ }
+
+
+ public void findWidth() {
+ float[] max = new float[3];
+ float[] min = new float[3];
+
+ max[0] = (float) -1e30;
+ max[1] = (float) -1e30;
+ max[2] = (float) -1e30;
+
+ min[0] = (float) 1e30;
+ min[1] = (float) 1e30;
+ min[2] = (float) 1e30;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmp = (Bond) bonds.elementAt(i);
+
+ if (tmp.start[0] >= max[0]) {
+ max[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] >= max[1]) {
+ max[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] >= max[2]) {
+ max[2] = tmp.start[2];
+ }
+
+ if (tmp.start[0] <= min[0]) {
+ min[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] <= min[1]) {
+ min[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] <= min[2]) {
+ min[2] = tmp.start[2];
+ }
+
+ if (tmp.end[0] >= max[0]) {
+ max[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] >= max[1]) {
+ max[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] >= max[2]) {
+ max[2] = tmp.end[2];
+ }
+
+ if (tmp.end[0] <= min[0]) {
+ min[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] <= min[1]) {
+ min[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] <= min[2]) {
+ min[2] = tmp.end[2];
+ }
+ }
+ }
+ }
+ /*
+ System.out.println("xmax " + max[0] + " min " + min[0]);
+ System.out.println("ymax " + max[1] + " min " + min[1]);
+ System.out.println("zmax " + max[2] + " min " + min[2]);*/
+
+ width[0] = (float) Math.abs(max[0] - min[0]);
+ width[1] = (float) Math.abs(max[1] - min[1]);
+ width[2] = (float) Math.abs(max[2] - min[2]);
+
+ maxwidth = width[0];
+
+ if (width[1] > width[0]) {
+ maxwidth = width[1];
+ }
+
+ if (width[2] > width[1]) {
+ maxwidth = width[2];
+ }
+
+ // System.out.println("Maxwidth = " + maxwidth);
+ }
+
+ public float findScale() {
+ int dim;
+ int width;
+ int height;
+
+ if (getWidth() != 0) {
+ width = getWidth();
+ height = getHeight();
+ } else {
+ width = prefsize.width;
+ height = prefsize.height;
+ }
+
+ if (width < height) {
+ dim = width;
+ } else {
+ dim = height;
+ }
+
+ return (float) (dim / (1.5d * maxwidth));
+ }
+
+ public void findCentre() {
+ float xtot = 0;
+ float ytot = 0;
+ float ztot = 0;
+
+ int bsize = 0;
+
+ //Find centre coordinate
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ bsize += bonds.size();
+
+ for (int i = 0; i < bonds.size(); i++) {
+ xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +
+ ((Bond) bonds.elementAt(i)).end[0];
+
+ ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +
+ ((Bond) bonds.elementAt(i)).end[1];
+
+ ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +
+ ((Bond) bonds.elementAt(i)).end[2];
+ }
+ }
+ }
+
+ centre[0] = xtot / (2 * (float) bsize);
+ centre[1] = ytot / (2 * (float) bsize);
+ centre[2] = ztot / (2 * (float) bsize);
+ }
+
+ public void paintComponent(Graphics g)
+ {
+ super.paintComponent(g);
+
+ if(!seqColoursReady)
+ {
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString("Retrieving PDB data....", 20, getHeight()/2);
+ return;
+ }
+
+
+ //Only create the image at the beginning -
+ //this saves much memory usage
+ if ((img == null)
+ || (prefsize.width != getWidth())
+ || (prefsize.height != getHeight()))
+
+ {
+ prefsize.width = getWidth();
+ prefsize.height = getHeight();
+
+ scale = findScale();
+ img = createImage(prefsize.width, prefsize.height);
+ ig = img.getGraphics();
+ Graphics2D ig2 = (Graphics2D) ig;
+
+ ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ redrawneeded = true;
+ }
+
+
+ if (redrawneeded)
+ {
+ drawAll(ig, prefsize.width, prefsize.height);
+ redrawneeded = false;
+ }
+
+ g.drawImage(img, 0, 0, this);
+
+ pdbAction = false;
+ }
+
+ public void drawAll(Graphics g, int width, int height)
+ {
+ g.setColor(backgroundColour);
+ g.fillRect(0, 0, width, height);
+ drawScene(g);
+ drawLabels(g);
+ }
+
+
+ public void updateSeqColours()
+ {
+ if(pdbAction)
+ {
+ return;
+ }
+
+ // System.out.println("update seq colours");
+ if(bysequence && pdb!=null)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ colourBySequence( (PDBChain) pdb.chains.elementAt(ii));
+ }
+ }
+
+ redrawneeded=true;
+ repaint();
+ }
+
+ int findTrueIndex(int pos)
+ {
+ // returns the alignment position for a residue
+ int j = sequence.getStart();
+ int i = 0;
+
+ while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))
+ {
+ if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
+ {
+ j++;
+ }
+
+ i++;
+ }
+
+ if(i>1)
+ i--;
+
+ if ( (j == sequence.getEnd()) && (j < pos))
+ {
+ return sequence.getEnd() + 1;
+ }
+ else
+ {
+ return i;
+ }
+ }
+
+ // This method has been taken out of PDBChain to allow
+ // Applet and Application specific sequence renderers to be used
+ void colourBySequence(PDBChain chain)
+ {
+ // System.out.println("colour by seq");
+ boolean showFeatures = false;
+ if(seqcanvas.getViewport().getShowSequenceFeatures())
+ {
+ showFeatures = true;
+ if (fr == null)
+ fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport());
+
+ fr.transferSettings( seqcanvas.getFeatureRenderer() );
+ }
+
+ Bond tmp;
+ for (int i = 0; i < chain.bonds.size(); i++)
+ {
+ tmp = (Bond) chain.bonds.elementAt(i);
+
+ if(chain!=mainchain)
+ continue;
+
+ if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
+ (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
+ {
+ int index = findTrueIndex(tmp.at1.alignmentMapping);
+ //sequence.findIndex(tmp.at1.alignmentMapping);
+ if (index != -1)
+ {
+ tmp.startCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
+
+ if(tmp.startCol==null)
+ tmp.startCol = Color.white;
+ }
+ }
+
+ if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
+ (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))
+ {
+
+ int index = findTrueIndex(tmp.at2.alignmentMapping);
+ //sequence.findIndex( tmp.at2.alignmentMapping );
+ if (index != -1)
+ {
+ tmp.endCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
+
+ if(tmp.endCol==null)
+ tmp.endCol = Color.white;
+ }
+ }
+ }
+ }
+
+
+ Zsort zsort;
+ public void drawScene(Graphics g)
+ {
+ if (zbuffer)
+ {
+ if (zsort == null)
+ zsort = new Zsort();
+
+ zsort.Zsort(visiblebonds);
+ }
+
+ Bond tmpBond = null;
+ for (int i = 0; i < visiblebonds.size(); i++)
+ {
+ tmpBond = (Bond) visiblebonds.elementAt(i);
+
+ xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ xmid = (xend + xstart) / 2;
+ ymid = (yend + ystart) / 2;
+ if (depthcue && !bymolecule)
+ {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
+ {
+
+ g.setColor(tmpBond.startCol.darker().darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+ g.setColor(tmpBond.endCol.darker().darker());
+ drawLine(g, xmid, ymid, xend, yend);
+
+ }
+ else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
+ {
+ g.setColor(tmpBond.startCol.darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol.darker());
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+ else
+ {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+ }
+ else if (depthcue && bymolecule)
+ {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
+ {
+ g.setColor(Color.green.darker().darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
+ {
+ g.setColor(Color.green.darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ else
+ {
+ g.setColor(Color.green);
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ }
+ else if (!depthcue && !bymolecule)
+ {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+ else
+ {
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+
+ if (highlightBond1 != null && highlightBond1 == tmpBond)
+ {
+ g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter());
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+
+ if (highlightBond2 != null && highlightBond2 == tmpBond)
+ {
+ g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter());
+ drawLine(g, xstart, ystart, xmid, ymid);
+ }
+
+ }
+
+
+ }
+
+ public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {
+ if (!wire) {
+ if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
+ g.drawLine(x1, y1 - 1, x2, y2 - 1);
+ } else {
+ g.setColor(g.getColor().brighter());
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1, x2 + 1, y2);
+ g.drawLine(x1 - 1, y1, x2 - 1, y2);
+ }
+ } else {
+ g.drawLine(x1, y1, x2, y2);
+ }
+ }
+
+ public Dimension minimumsize() {
+ return prefsize;
+ }
+
+ public Dimension preferredsize() {
+ return prefsize;
+ }
+
+ public void keyPressed(KeyEvent evt)
+ {
+ if (evt.getKeyCode() == KeyEvent.VK_UP)
+ {
+ scale = (float) (scale * 1.1);
+ redrawneeded = true;
+ repaint();
+ }
+ else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+ {
+ scale = (float) (scale * 0.9);
+ redrawneeded = true;
+ repaint();
+ }
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ pdbAction = true;
+ Atom fatom = findAtom(e.getX(), e.getY());
+ if(fatom!=null)
+ {
+ fatom.isSelected = !fatom.isSelected;
+
+ redrawneeded = true;
+ repaint();
+ if (foundchain != -1)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if (chain == mainchain)
+ {
+ if (fatom.alignmentMapping != -1)
+ {
+ if (highlightRes == null)
+ highlightRes = new Vector();
+
+ if (highlightRes.contains(fatom.alignmentMapping+""))
+ highlightRes.remove(fatom.alignmentMapping + "");
+ else
+ highlightRes.add(fatom.alignmentMapping + "");
+ }
+ }
+ }
+
+ }
+ mx = e.getX();
+ my = e.getY();
+ omx = mx;
+ omy = my;
+ dragging = false;
+ }
+
+ public void mouseMoved(MouseEvent e)
+ {
+ pdbAction = true;
+ if(highlightBond1!=null)
+ {
+ highlightBond1.at2.isSelected = false;
+ highlightBond2.at1.isSelected = false;
+ highlightBond1 = null;
+ highlightBond2 = null;
+ }
+
+ Atom fatom = findAtom(e.getX(), e.getY());
+
+ PDBChain chain = null;
+ if(foundchain!=-1)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if(chain == mainchain)
+ {
+ highlightSeqcanvas( fatom.alignmentMapping );
+ }
+ }
+
+ if (fatom != null)
+ {
+ this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName);
+ } else
+ {
+ highlightSeqcanvas( -1);
+ this.setToolTipText(null);
+ }
+ }
+
+
+ void highlightSeqcanvas(int pos)
+ {
+ SearchResults searchResults = new SearchResults();
+ if(highlightRes!=null)
+ {
+ for (int i = 0; i < highlightRes.size(); i++)
+ {
+ int a = Integer.parseInt(highlightRes.elementAt(
+ i).toString())+1;
+
+ searchResults.addResult(sequence, a, a);
+ }
+ }
+
+ if(pos!=-1)
+ {
+ searchResults.addResult(sequence, pos+1, pos+1);
+ }
+
+ seqcanvas.highlightSearchResults(searchResults);
+ }
+
+
+ public void mouseClicked(MouseEvent e) { }
+
+ public void mouseEntered(MouseEvent e) { }
+
+ public void mouseExited(MouseEvent e) { }
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ int x = evt.getX();
+ int y = evt.getY();
+ mx = x;
+ my = y;
+
+
+ MCMatrix objmat = new MCMatrix(3, 3);
+ objmat.setIdentity();
+
+ if ((evt.getModifiers() & Event.META_MASK) != 0) {
+ objmat.rotatez((float) ((mx - omx)));
+ } else {
+ objmat.rotatex((float) ((my - omy)));
+ objmat.rotatey((float) ((omx - mx)));
+ }
+
+ //Alter the bonds
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ //Translate the bond so the centre is 0,0,0
+ tmpBond.translate(-centre[0], -centre[1], -centre[2]);
+
+ //Now apply the rotation matrix
+ tmpBond.start = objmat.vectorMultiply(tmpBond.start);
+ tmpBond.end = objmat.vectorMultiply(tmpBond.end);
+
+ //Now translate back again
+ tmpBond.translate(centre[0], centre[1], centre[2]);
+ }
+ }
+
+ objmat = null;
+
+ omx = mx;
+ omy = my;
+
+ dragging = true;
+
+ redrawneeded = true;
+
+ repaint();
+ }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ dragging = false;
+ return;
+ }
+
+ void drawLabels(Graphics g) {
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ if (tmpBond.at1.isSelected)
+ {
+ labelAtom(g, tmpBond, 1);
+ }
+
+ if (tmpBond.at2.isSelected)
+ {
+
+ labelAtom(g, tmpBond, 2);
+ }
+ }
+ }
+ }
+ }
+
+ public void labelAtom(Graphics g, Bond b, int n) {
+ g.setFont(font);
+ g.setColor(Color.red);
+ if (n == 1)
+ {
+ int xstart = (int) (((b.start[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ int ystart = (int) (((b.start[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);
+ }
+
+ if (n == 2) {
+ int xstart = (int) (((b.end[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ int ystart = (int) (((b.end[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);
+ }
+ }
+
+ int foundchain = -1;
+ public Atom findAtom(int x, int y) {
+ Atom fatom = null;
+
+ foundchain = -1;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ int truex;
+ Bond tmpBond=null;
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ tmpBond = (Bond) bonds.elementAt(i);
+
+ truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at1;
+ foundchain = ii;
+ break;
+ }
+ }
+ }
+
+ // Still here? Maybe its the last bond
+
+ truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at2;
+ foundchain = ii;
+ break;
+ }
+ }
+
+ }
+
+ if (fatom != null) //)&& chain.ds != null)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ }
+ }
+
+ return fatom;
+ }
+
+ Bond highlightBond1, highlightBond2;
+ public void highlightRes(int ii)
+ {
+ if( !seqColoursReady )
+ return;
+
+ if (highlightRes != null
+ && highlightRes.contains((ii-1) + ""))
+ {
+ return;
+ }
+
+ int index = -1;
+ Bond tmpBond;
+ for(index=0; index 0)
+ {
+ highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
+ highlightBond1.at2.isSelected = true;
+ }
+
+ if (index != mainchain.bonds.size())
+ {
+ highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
+ highlightBond2.at1.isSelected = true;
+ }
+
+ break;
+ }
+ }
+
+ redrawneeded = true;
+ repaint();
+ }
+
+ public void setAllchainsVisible(boolean b)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ chain.isVisible = b;
+ }
+ mainchain.isVisible = true;
+ findCentre();
+ setupBonds();
+ }
+}
diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java
index fa4bbf9..36681a1 100755
--- a/src/MCview/PDBChain.java
+++ b/src/MCview/PDBChain.java
@@ -1,269 +1,269 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import jalview.datamodel.*;
-
-import jalview.schemes.ResidueProperties;
-
-import java.awt.*;
-
-import java.util.*;
-import jalview.analysis.AlignSeq;
-
-
-public class PDBChain {
- public String id;
- public Vector bonds = new Vector();
- public Vector atoms = new Vector();
- public Vector residues = new Vector();
- public int offset;
- public Sequence sequence;
- public boolean isVisible = true;
- public int pdbstart = 0;
- public int pdbend = 0;
- public int seqstart = 0;
- public int seqend = 0;
-
- public PDBChain(String id) {
- this.id = id;
- }
-
- public String print() {
- String tmp = "";
-
- for (int i = 0; i < bonds.size(); i++) {
- tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " " +
- ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
- "\n";
- }
-
- return tmp;
- }
-
- void makeExactMapping(AlignSeq as, Sequence s1)
- {
- int pdbpos = as.getSeq2Start()-2;
- int alignpos = s1.getStart() + as.getSeq1Start()-3;
-
- for(int i=0; i") > -1 || data.indexOf("") > -1)
+ )
+ out.println(data);
+ }
+ out.close();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
}
diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java
index 63728ae..5824575 100755
--- a/src/MCview/PDBfile.java
+++ b/src/MCview/PDBfile.java
@@ -1,186 +1,171 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import java.io.*;
-
-import java.net.*;
-
-import java.util.*;
-import java.awt.Color;
-import jalview.io.AppletFormatAdapter;
-
-
-public class PDBfile extends jalview.io.FileParse {
- public Vector chains = new Vector();
- Vector lineArray = new Vector();
- public String id;
-
- public PDBfile(String[] lines) {
- for (int i = 0; i < lines.length; i++)
- lineArray.addElement(lines[i]);
-
- parse();
- }
-
- public PDBfile(String inFile, String inType) throws IOException {
- super(inFile, inType);
-
- String line;
- this.lineArray = new Vector();
-
- BufferedReader dataIn;
-
-
- if (inType.equals(AppletFormatAdapter.FILE)) {
- dataIn = new BufferedReader(new FileReader(inFile));
- }
- else if(inType.equals(AppletFormatAdapter.PASTE))
- {
- dataIn = new BufferedReader(new StringReader(inFile));
- }
- else if (inType.equalsIgnoreCase(AppletFormatAdapter.CLASSLOADER))
- {
- java.io.InputStream is = getClass().getResourceAsStream("/" +
- inFile);
-
- dataIn = new BufferedReader(new java.io.InputStreamReader(is));
- }
- else
- {
- URL url = new URL(inFile);
- dataIn = new BufferedReader(new InputStreamReader(url.openStream()));
- }
-
- while ((line = dataIn.readLine()) != null) {
- lineArray.addElement(line);
- }
-
-
- parse();
- lineArray = null;
- }
-
- public void parse()
- {
- PDBChain tmpchain;
- String line;
- boolean modelFlag = false;
- boolean terFlag = false;
-
-
- for (int i = 0; i < lineArray.size(); i++)
- {
-
- line = lineArray.elementAt(i).toString();
-
-
- if (line.indexOf("HEADER") == 0)
- {
- id = line.substring(62, 67).trim();
- continue;
- }
-
- if(line.indexOf("MODEL")==0)
- modelFlag = true;
-
- if(line.indexOf("TER")==0)
- terFlag = true;
-
- if(modelFlag && line.indexOf("ENDMDL")==0)
- break;
-
- if ( line.indexOf("ATOM")==0
- || (line.indexOf("HETATM")==0 && !terFlag)
- )
- {
- terFlag = false;
-
-
- //Jalview is only interested in CA bonds????
- if (!line.substring(12, 15).trim().equals("CA"))
- {
- continue;
- }
-
- Atom tmpatom = new Atom(line);
-
- tmpchain = findChain(tmpatom.chain);
- if (tmpchain != null)
- {
- tmpchain.atoms.addElement(tmpatom);
- }
- else
- {
- tmpchain = new PDBChain(tmpatom.chain);
- chains.addElement(tmpchain);
- tmpchain.atoms.addElement(tmpatom);
- }
-
- }
- }
-
- makeResidueList();
- makeCaBondList();
- }
-
- public void makeResidueList() {
- for (int i = 0; i < chains.size(); i++) {
- ((PDBChain) chains.elementAt(i)).makeResidueList();
- }
- }
-
- public void makeCaBondList() {
- for (int i = 0; i < chains.size(); i++) {
- ((PDBChain) chains.elementAt(i)).makeCaBondList();
- }
- }
-
- public PDBChain findChain(String id) {
- for (int i = 0; i < chains.size(); i++) {
- if (((PDBChain) chains.elementAt(i)).id.equals(id)) {
- return (PDBChain) chains.elementAt(i);
- }
- }
-
- return null;
- }
-
- public void setChargeColours() {
- for (int i = 0; i < chains.size(); i++) {
- ((PDBChain) chains.elementAt(i)).setChargeColours();
- }
- }
-
- public void setColours(jalview.schemes.ColourSchemeI cs) {
- for (int i = 0; i < chains.size(); i++) {
- ((PDBChain) chains.elementAt(i)).setChainColours(cs);
- }
- }
-
- public void setChainColours()
- {
- for (int i = 0; i < chains.size(); i++)
- {
- ((PDBChain) chains.elementAt(i)).setChainColours(
- Color.getHSBColor(1.0f / (float)i, .4f, 1.0f)
- );
- }
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+import jalview.datamodel.*;
+
+import java.io.*;
+
+import java.util.*;
+import java.awt.Color;
+
+
+public class PDBfile extends jalview.io.AlignFile {
+ public Vector chains;
+ public String id;
+
+ public PDBfile(String inFile, String inType) throws IOException
+ {
+ super(inFile, inType);
+ }
+
+ public String print()
+ {
+ return null;
+ }
+
+ public void parse() throws IOException
+ {
+ chains = new Vector();
+
+ PDBChain tmpchain;
+ String line;
+ boolean modelFlag = false;
+ boolean terFlag = false;
+
+
+ int index = 0;
+ while((line = nextLine())!=null)
+ {
+ if (line.indexOf("HEADER") == 0)
+ {
+ id = line.substring(62, 67).trim();
+ continue;
+ }
+
+ if(line.indexOf("MODEL")==0)
+ modelFlag = true;
+
+ if(line.indexOf("TER")==0)
+ terFlag = true;
+
+ if(modelFlag && line.indexOf("ENDMDL")==0)
+ break;
+
+ if ( line.indexOf("ATOM")==0
+ || (line.indexOf("HETATM")==0 && !terFlag)
+ )
+ {
+ terFlag = false;
+
+
+ //Jalview is only interested in CA bonds????
+ if (!line.substring(12, 15).trim().equals("CA"))
+ {
+ continue;
+ }
+
+ Atom tmpatom = new Atom(line);
+ tmpchain = findChain(tmpatom.chain);
+ if (tmpchain != null)
+ {
+ tmpchain.atoms.addElement(tmpatom);
+ }
+ else
+ {
+ tmpchain = new PDBChain(tmpatom.chain);
+ chains.addElement(tmpchain);
+ tmpchain.atoms.addElement(tmpatom);
+ }
+ }
+ index ++;
+ }
+
+ makeResidueList();
+ makeCaBondList();
+
+ if(id==null)
+ {
+ id = inFile.getName();
+ }
+ for (int i = 0; i < chains.size(); i++)
+ {
+ SequenceI seq = ( (PDBChain) chains.elementAt(i)).
+ sequence;
+ seq.setName(id + "|" + seq.getName());
+ Sequence dataset = new Sequence(seq.
+ getName(),
+ seq.getSequence().toString(), seq.getStart(), seq.getEnd());
+
+ PDBEntry entry = new PDBEntry();
+ entry.setId(id);
+ if(inFile!=null)
+ entry.setFile(inFile.getAbsolutePath());
+
+ seq.setDatasetSequence(dataset);
+ dataset.addPDBId(entry);
+
+ getSeqs().addElement(seq);
+ }
+ }
+
+ public void makeResidueList() {
+ for (int i = 0; i < chains.size(); i++) {
+ ((PDBChain) chains.elementAt(i)).makeResidueList();
+ }
+ }
+
+ public void makeCaBondList() {
+ for (int i = 0; i < chains.size(); i++) {
+ ((PDBChain) chains.elementAt(i)).makeCaBondList();
+ }
+ }
+
+ public PDBChain findChain(String id) {
+ for (int i = 0; i < chains.size(); i++) {
+ if (((PDBChain) chains.elementAt(i)).id.equals(id)) {
+ return (PDBChain) chains.elementAt(i);
+ }
+ }
+
+ return null;
+ }
+
+ public void setChargeColours() {
+ for (int i = 0; i < chains.size(); i++) {
+ ((PDBChain) chains.elementAt(i)).setChargeColours();
+ }
+ }
+
+ public void setColours(jalview.schemes.ColourSchemeI cs) {
+ for (int i = 0; i < chains.size(); i++) {
+ ((PDBChain) chains.elementAt(i)).setChainColours(cs);
+ }
+ }
+
+ public void setChainColours()
+ {
+ for (int i = 0; i < chains.size(); i++)
+ {
+ ((PDBChain) chains.elementAt(i)).setChainColours(
+ Color.getHSBColor(1.0f / (float)i, .4f, 1.0f)
+ );
+ }
+ }
+}
diff --git a/src/MCview/Residue.java b/src/MCview/Residue.java
index 0f24137..39e7112 100755
--- a/src/MCview/Residue.java
+++ b/src/MCview/Residue.java
@@ -1,48 +1,48 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import java.util.*;
-
-
-public class Residue {
- Vector atoms = new Vector();
- int number;
- int count;
- int seqnumber;
-
- public Residue(Vector atoms, int number, int count) {
- this.atoms = atoms;
- this.number = number;
- this.count = count;
- }
-
- public Atom findAtom(String name)
- {
- for (int i = 0; i < atoms.size(); i++)
- {
- if (((Atom) atoms.elementAt(i)).name.equals(name))
- {
- return (Atom) atoms.elementAt(i);
- }
- }
-
- return null;
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+import java.util.*;
+
+
+public class Residue {
+ Vector atoms = new Vector();
+ int number;
+ int count;
+ int seqnumber;
+
+ public Residue(Vector atoms, int number, int count) {
+ this.atoms = atoms;
+ this.number = number;
+ this.count = count;
+ }
+
+ public Atom findAtom(String name)
+ {
+ for (int i = 0; i < atoms.size(); i++)
+ {
+ if (((Atom) atoms.elementAt(i)).name.equals(name))
+ {
+ return (Atom) atoms.elementAt(i);
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/src/MCview/Zsort.java b/src/MCview/Zsort.java
index c54a3ff..383958d 100755
--- a/src/MCview/Zsort.java
+++ b/src/MCview/Zsort.java
@@ -1,63 +1,63 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package MCview;
-
-import java.util.*;
-
-
-public class Zsort {
- public void Zsort(Vector bonds) {
- sort(bonds, 0, bonds.size() - 1);
- }
-
- public void sort(Vector bonds, int p, int r) {
- int q;
-
- if (p < r) {
- q = partition(bonds, p, r);
- sort(bonds, p, q);
- sort(bonds, q + 1, r);
- }
- }
-
- private int partition(Vector bonds, int p, int r) {
- float x = ((Bond) bonds.elementAt(p)).start[2];
- int i = p - 1;
- int j = r + 1;
- Bond tmp;
- while (true) {
- do {
- j = j - 1;
- } while ((j >= 0) && (((Bond) bonds.elementAt(j)).start[2] > x));
-
- do {
- i = i + 1;
- } while ((i < bonds.size()) &&
- (((Bond) bonds.elementAt(i)).start[2] < x));
-
- if (i < j) {
- tmp = (Bond) bonds.elementAt(i);
- bonds.setElementAt(bonds.elementAt(j), i);
- bonds.setElementAt(tmp, j);
- } else {
- return j;
- }
- }
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package MCview;
+
+import java.util.*;
+
+
+public class Zsort {
+ public void Zsort(Vector bonds) {
+ sort(bonds, 0, bonds.size() - 1);
+ }
+
+ public void sort(Vector bonds, int p, int r) {
+ int q;
+
+ if (p < r) {
+ q = partition(bonds, p, r);
+ sort(bonds, p, q);
+ sort(bonds, q + 1, r);
+ }
+ }
+
+ private int partition(Vector bonds, int p, int r) {
+ float x = ((Bond) bonds.elementAt(p)).start[2];
+ int i = p - 1;
+ int j = r + 1;
+ Bond tmp;
+ while (true) {
+ do {
+ j --;
+ } while ((j >= 0) && (((Bond) bonds.elementAt(j)).start[2] > x));
+
+ do {
+ i ++;
+ } while ((i < bonds.size()) &&
+ (((Bond) bonds.elementAt(i)).start[2] < x));
+
+ if (i < j) {
+ tmp = (Bond) bonds.elementAt(i);
+ bonds.setElementAt(bonds.elementAt(j), i);
+ bonds.setElementAt(tmp, j);
+ } else {
+ return j;
+ }
+ }
+ }
+}
diff --git a/src/ext/vamsas/MuscleWS.java b/src/ext/vamsas/MuscleWS.java
index ffbe5cb..2b9d19b 100755
--- a/src/ext/vamsas/MuscleWS.java
+++ b/src/ext/vamsas/MuscleWS.java
@@ -3,11 +3,11 @@
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.2RC2 Nov 16, 2004 (12:19:44 EST) WSDL2Java emitter.
- */
-
+ */
+
/*
* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+* Copyright (C) 2006 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
@@ -22,20 +22,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package ext.vamsas;
-
-public interface MuscleWS extends java.rmi.Remote {
- public vamsas.objects.simple.WsJobId align(
- vamsas.objects.simple.SequenceSet seqSet)
- throws java.rmi.RemoteException;
-
- public vamsas.objects.simple.Alignment getalign(java.lang.String job_id)
- throws java.rmi.RemoteException;
-
- public vamsas.objects.simple.MsaResult getResult(java.lang.String job_id)
- throws java.rmi.RemoteException;
-
- public vamsas.objects.simple.WsJobId cancel(java.lang.String jobId)
- throws java.rmi.RemoteException;
-}
+*/
+package ext.vamsas;
+
+public interface MuscleWS extends java.rmi.Remote {
+ public vamsas.objects.simple.WsJobId align(
+ vamsas.objects.simple.SequenceSet seqSet)
+ throws java.rmi.RemoteException;
+
+ public vamsas.objects.simple.Alignment getalign(java.lang.String job_id)
+ throws java.rmi.RemoteException;
+
+ public vamsas.objects.simple.MsaResult getResult(java.lang.String job_id)
+ throws java.rmi.RemoteException;
+
+ public vamsas.objects.simple.WsJobId cancel(java.lang.String jobId)
+ throws java.rmi.RemoteException;
+}
diff --git a/src/ext/vamsas/MuscleWSService.java b/src/ext/vamsas/MuscleWSService.java
index ffc4abc..f4984e3 100755
--- a/src/ext/vamsas/MuscleWSService.java
+++ b/src/ext/vamsas/MuscleWSService.java
@@ -3,11 +3,11 @@
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.2RC2 Nov 16, 2004 (12:19:44 EST) WSDL2Java emitter.
- */
-
+ */
+
/*
* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+* Copyright (C) 2006 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
@@ -22,15 +22,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package ext.vamsas;
-
-public interface MuscleWSService extends javax.xml.rpc.Service {
- public java.lang.String getMuscleWSAddress();
-
- public ext.vamsas.MuscleWS getMuscleWS()
- throws javax.xml.rpc.ServiceException;
-
- public ext.vamsas.MuscleWS getMuscleWS(java.net.URL portAddress)
- throws javax.xml.rpc.ServiceException;
-}
+*/
+package ext.vamsas;
+
+public interface MuscleWSService extends javax.xml.rpc.Service {
+ public java.lang.String getMuscleWSAddress();
+
+ public ext.vamsas.MuscleWS getMuscleWS()
+ throws javax.xml.rpc.ServiceException;
+
+ public ext.vamsas.MuscleWS getMuscleWS(java.net.URL portAddress)
+ throws javax.xml.rpc.ServiceException;
+}
diff --git a/src/ext/vamsas/MuscleWSServiceLocator.java b/src/ext/vamsas/MuscleWSServiceLocator.java
index 96ef074..565b73e 100755
--- a/src/ext/vamsas/MuscleWSServiceLocator.java
+++ b/src/ext/vamsas/MuscleWSServiceLocator.java
@@ -3,11 +3,11 @@
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.2RC2 Nov 16, 2004 (12:19:44 EST) WSDL2Java emitter.
- */
-
+ */
+
/*
* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+* Copyright (C) 2006 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
@@ -22,147 +22,147 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package ext.vamsas;
-
-public class MuscleWSServiceLocator extends org.apache.axis.client.Service
- implements ext.vamsas.MuscleWSService {
- // Use to get a proxy class for MuscleWS
- private java.lang.String MuscleWS_address = "http://anaplog.compbio.dundee.ac.uk:8080/axis/services/MuscleWS";
-
- // The WSDD service name defaults to the port name.
- private java.lang.String MuscleWSWSDDServiceName = "MuscleWS";
- private java.util.HashSet ports = null;
-
- public MuscleWSServiceLocator() {
- }
-
- public MuscleWSServiceLocator(org.apache.axis.EngineConfiguration config) {
- super(config);
- }
-
- public java.lang.String getMuscleWSAddress() {
- return MuscleWS_address;
- }
-
- public java.lang.String getMuscleWSWSDDServiceName() {
- return MuscleWSWSDDServiceName;
- }
-
- public void setMuscleWSWSDDServiceName(java.lang.String name) {
- MuscleWSWSDDServiceName = name;
- }
-
- public ext.vamsas.MuscleWS getMuscleWS()
- throws javax.xml.rpc.ServiceException {
- java.net.URL endpoint;
-
- try {
- endpoint = new java.net.URL(MuscleWS_address);
- } catch (java.net.MalformedURLException e) {
- throw new javax.xml.rpc.ServiceException(e);
- }
-
- return getMuscleWS(endpoint);
- }
-
- public ext.vamsas.MuscleWS getMuscleWS(java.net.URL portAddress)
- throws javax.xml.rpc.ServiceException {
- try {
- ext.vamsas.MuscleWSSoapBindingStub _stub = new ext.vamsas.MuscleWSSoapBindingStub(portAddress,
- this);
- _stub.setPortName(getMuscleWSWSDDServiceName());
-
- return _stub;
- } catch (org.apache.axis.AxisFault e) {
- return null;
- }
- }
-
- public void setMuscleWSEndpointAddress(java.lang.String address) {
- MuscleWS_address = address;
- }
-
+*/
+package ext.vamsas;
+
+public class MuscleWSServiceLocator extends org.apache.axis.client.Service
+ implements ext.vamsas.MuscleWSService {
+ // Use to get a proxy class for MuscleWS
+ private java.lang.String MuscleWS_address = "http://anaplog.compbio.dundee.ac.uk:8080/axis/services/MuscleWS";
+
+ // The WSDD service name defaults to the port name.
+ private java.lang.String MuscleWSWSDDServiceName = "MuscleWS";
+ private java.util.HashSet ports = null;
+
+ public MuscleWSServiceLocator() {
+ }
+
+ public MuscleWSServiceLocator(org.apache.axis.EngineConfiguration config) {
+ super(config);
+ }
+
+ public java.lang.String getMuscleWSAddress() {
+ return MuscleWS_address;
+ }
+
+ public java.lang.String getMuscleWSWSDDServiceName() {
+ return MuscleWSWSDDServiceName;
+ }
+
+ public void setMuscleWSWSDDServiceName(java.lang.String name) {
+ MuscleWSWSDDServiceName = name;
+ }
+
+ public ext.vamsas.MuscleWS getMuscleWS()
+ throws javax.xml.rpc.ServiceException {
+ java.net.URL endpoint;
+
+ try {
+ endpoint = new java.net.URL(MuscleWS_address);
+ } catch (java.net.MalformedURLException e) {
+ throw new javax.xml.rpc.ServiceException(e);
+ }
+
+ return getMuscleWS(endpoint);
+ }
+
+ public ext.vamsas.MuscleWS getMuscleWS(java.net.URL portAddress)
+ throws javax.xml.rpc.ServiceException {
+ try {
+ ext.vamsas.MuscleWSSoapBindingStub _stub = new ext.vamsas.MuscleWSSoapBindingStub(portAddress,
+ this);
+ _stub.setPortName(getMuscleWSWSDDServiceName());
+
+ return _stub;
+ } catch (org.apache.axis.AxisFault e) {
+ return null;
+ }
+ }
+
+ public void setMuscleWSEndpointAddress(java.lang.String address) {
+ MuscleWS_address = address;
+ }
+
/**
* For the given interface, get the stub implementation.
* If this service has no port for the given interface,
* then ServiceException is thrown.
- */
- public java.rmi.Remote getPort(Class serviceEndpointInterface)
- throws javax.xml.rpc.ServiceException {
- try {
- if (ext.vamsas.MuscleWS.class.isAssignableFrom(
- serviceEndpointInterface)) {
- ext.vamsas.MuscleWSSoapBindingStub _stub = new ext.vamsas.MuscleWSSoapBindingStub(new java.net.URL(
- MuscleWS_address), this);
- _stub.setPortName(getMuscleWSWSDDServiceName());
-
- return _stub;
- }
- } catch (java.lang.Throwable t) {
- throw new javax.xml.rpc.ServiceException(t);
- }
-
- throw new javax.xml.rpc.ServiceException(
- "There is no stub implementation for the interface: " +
- ((serviceEndpointInterface == null) ? "null"
- : serviceEndpointInterface.getName()));
- }
-
+ */
+ public java.rmi.Remote getPort(Class serviceEndpointInterface)
+ throws javax.xml.rpc.ServiceException {
+ try {
+ if (ext.vamsas.MuscleWS.class.isAssignableFrom(
+ serviceEndpointInterface)) {
+ ext.vamsas.MuscleWSSoapBindingStub _stub = new ext.vamsas.MuscleWSSoapBindingStub(new java.net.URL(
+ MuscleWS_address), this);
+ _stub.setPortName(getMuscleWSWSDDServiceName());
+
+ return _stub;
+ }
+ } catch (java.lang.Throwable t) {
+ throw new javax.xml.rpc.ServiceException(t);
+ }
+
+ throw new javax.xml.rpc.ServiceException(
+ "There is no stub implementation for the interface: " +
+ ((serviceEndpointInterface == null) ? "null"
+ : serviceEndpointInterface.getName()));
+ }
+
/**
* For the given interface, get the stub implementation.
* If this service has no port for the given interface,
* then ServiceException is thrown.
- */
- public java.rmi.Remote getPort(javax.xml.namespace.QName portName,
- Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
- if (portName == null) {
- return getPort(serviceEndpointInterface);
- }
-
- java.lang.String inputPortName = portName.getLocalPart();
-
- if ("MuscleWS".equals(inputPortName)) {
- return getMuscleWS();
- } else {
- java.rmi.Remote _stub = getPort(serviceEndpointInterface);
- ((org.apache.axis.client.Stub) _stub).setPortName(portName);
-
- return _stub;
- }
- }
-
- public javax.xml.namespace.QName getServiceName() {
- return new javax.xml.namespace.QName("vamsas", "MuscleWSService");
- }
-
- public java.util.Iterator getPorts() {
- if (ports == null) {
- ports = new java.util.HashSet();
- ports.add(new javax.xml.namespace.QName("vamsas", "MuscleWS"));
- }
-
- return ports.iterator();
- }
-
+ */
+ public java.rmi.Remote getPort(javax.xml.namespace.QName portName,
+ Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
+ if (portName == null) {
+ return getPort(serviceEndpointInterface);
+ }
+
+ java.lang.String inputPortName = portName.getLocalPart();
+
+ if ("MuscleWS".equals(inputPortName)) {
+ return getMuscleWS();
+ } else {
+ java.rmi.Remote _stub = getPort(serviceEndpointInterface);
+ ((org.apache.axis.client.Stub) _stub).setPortName(portName);
+
+ return _stub;
+ }
+ }
+
+ public javax.xml.namespace.QName getServiceName() {
+ return new javax.xml.namespace.QName("vamsas", "MuscleWSService");
+ }
+
+ public java.util.Iterator getPorts() {
+ if (ports == null) {
+ ports = new java.util.HashSet();
+ ports.add(new javax.xml.namespace.QName("vamsas", "MuscleWS"));
+ }
+
+ return ports.iterator();
+ }
+
/**
* Set the endpoint address for the specified port name.
-*/
- public void setEndpointAddress(java.lang.String portName,
- java.lang.String address) throws javax.xml.rpc.ServiceException {
- if ("MuscleWS".equals(portName)) {
- setMuscleWSEndpointAddress(address);
- } else { // Unknown Port Name
- throw new javax.xml.rpc.ServiceException(
- " Cannot set Endpoint Address for Unknown Port" + portName);
- }
- }
-
+*/
+ public void setEndpointAddress(java.lang.String portName,
+ java.lang.String address) throws javax.xml.rpc.ServiceException {
+ if ("MuscleWS".equals(portName)) {
+ setMuscleWSEndpointAddress(address);
+ } else { // Unknown Port Name
+ throw new javax.xml.rpc.ServiceException(
+ " Cannot set Endpoint Address for Unknown Port" + portName);
+ }
+ }
+
/**
* Set the endpoint address for the specified port name.
-*/
- public void setEndpointAddress(javax.xml.namespace.QName portName,
- java.lang.String address) throws javax.xml.rpc.ServiceException {
- setEndpointAddress(portName.getLocalPart(), address);
- }
-}
+*/
+ public void setEndpointAddress(javax.xml.namespace.QName portName,
+ java.lang.String address) throws javax.xml.rpc.ServiceException {
+ setEndpointAddress(portName.getLocalPart(), address);
+ }
+}
diff --git a/src/ext/vamsas/MuscleWSSoapBindingStub.java b/src/ext/vamsas/MuscleWSSoapBindingStub.java
index c56432d..b1f8065 100755
--- a/src/ext/vamsas/MuscleWSSoapBindingStub.java
+++ b/src/ext/vamsas/MuscleWSSoapBindingStub.java
@@ -3,11 +3,11 @@
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.2RC2 Nov 16, 2004 (12:19:44 EST) WSDL2Java emitter.
- */
-
+ */
+
/*
* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+* Copyright (C) 2006 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
@@ -22,373 +22,373 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package ext.vamsas;
-
-public class MuscleWSSoapBindingStub extends org.apache.axis.client.Stub
- implements ext.vamsas.MuscleWS {
- static org.apache.axis.description.OperationDesc[] _operations;
-
- static {
- _operations = new org.apache.axis.description.OperationDesc[4];
- _initOperationDesc1();
- }
-
- private java.util.Vector cachedSerClasses = new java.util.Vector();
- private java.util.Vector cachedSerQNames = new java.util.Vector();
- private java.util.Vector cachedSerFactories = new java.util.Vector();
- private java.util.Vector cachedDeserFactories = new java.util.Vector();
-
- public MuscleWSSoapBindingStub() throws org.apache.axis.AxisFault {
- this(null);
- }
-
- public MuscleWSSoapBindingStub(java.net.URL endpointURL,
- javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {
- this(service);
- super.cachedEndpoint = endpointURL;
- }
-
- public MuscleWSSoapBindingStub(javax.xml.rpc.Service service)
- throws org.apache.axis.AxisFault {
- if (service == null) {
- super.service = new org.apache.axis.client.Service();
- } else {
- super.service = service;
- }
-
- java.lang.Class cls;
- javax.xml.namespace.QName qName;
- java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;
- java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;
- //java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;
- //java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;
- java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;
- java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;
- //java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;
- // java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;
- //java.lang.Class simplelistsf = org.apache.axis.encoding.ser.SimpleListSerializerFactory.class;
- //java.lang.Class simplelistdf = org.apache.axis.encoding.ser.SimpleListDeserializerFactory.class;
- qName = new javax.xml.namespace.QName("simple.objects.vamsas",
- "Sequence");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.Sequence.class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(beansf);
- cachedDeserFactories.add(beandf);
-
- qName = new javax.xml.namespace.QName("vamsas", "ArrayOf_tns1_Sequence");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.Sequence[].class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(arraysf);
- cachedDeserFactories.add(arraydf);
-
- qName = new javax.xml.namespace.QName("simple.objects.vamsas",
- "MsaResult");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.MsaResult.class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(beansf);
- cachedDeserFactories.add(beandf);
-
- qName = new javax.xml.namespace.QName("simple.objects.vamsas",
- "SequenceSet");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.SequenceSet.class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(beansf);
- cachedDeserFactories.add(beandf);
-
- qName = new javax.xml.namespace.QName("http://simple.objects.vamsas",
- "Object");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.Object.class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(beansf);
- cachedDeserFactories.add(beandf);
-
- qName = new javax.xml.namespace.QName("simple.objects.vamsas",
- "Alignment");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.Alignment.class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(beansf);
- cachedDeserFactories.add(beandf);
-
- qName = new javax.xml.namespace.QName("simple.objects.vamsas", "WsJobId");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.WsJobId.class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(beansf);
- cachedDeserFactories.add(beandf);
-
- qName = new javax.xml.namespace.QName("vamsas", "ArrayOf_xsd_string");
- cachedSerQNames.add(qName);
- cls = java.lang.String[].class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(arraysf);
- cachedDeserFactories.add(arraydf);
-
- qName = new javax.xml.namespace.QName("simple.objects.vamsas", "Result");
- cachedSerQNames.add(qName);
- cls = vamsas.objects.simple.Result.class;
- cachedSerClasses.add(cls);
- cachedSerFactories.add(beansf);
- cachedDeserFactories.add(beandf);
- }
-
- private static void _initOperationDesc1() {
- org.apache.axis.description.OperationDesc oper;
- oper = new org.apache.axis.description.OperationDesc();
- oper.setName("align");
- oper.addParameter(new javax.xml.namespace.QName("", "seqSet"),
- new javax.xml.namespace.QName("simple.objects.vamsas", "SequenceSet"),
- vamsas.objects.simple.SequenceSet.class,
- org.apache.axis.description.ParameterDesc.IN, false, false);
- oper.setReturnType(new javax.xml.namespace.QName(
- "simple.objects.vamsas", "WsJobId"));
- oper.setReturnClass(vamsas.objects.simple.WsJobId.class);
- oper.setReturnQName(new javax.xml.namespace.QName("", "alignReturn"));
- oper.setStyle(org.apache.axis.constants.Style.RPC);
- oper.setUse(org.apache.axis.constants.Use.ENCODED);
- _operations[0] = oper;
-
- oper = new org.apache.axis.description.OperationDesc();
- oper.setName("getalign");
- oper.addParameter(new javax.xml.namespace.QName("", "job_id"),
- new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
- "string"), java.lang.String.class,
- org.apache.axis.description.ParameterDesc.IN, false, false);
- oper.setReturnType(new javax.xml.namespace.QName(
- "simple.objects.vamsas", "Alignment"));
- oper.setReturnClass(vamsas.objects.simple.Alignment.class);
- oper.setReturnQName(new javax.xml.namespace.QName("", "getalignReturn"));
- oper.setStyle(org.apache.axis.constants.Style.RPC);
- oper.setUse(org.apache.axis.constants.Use.ENCODED);
- _operations[1] = oper;
-
- oper = new org.apache.axis.description.OperationDesc();
- oper.setName("getResult");
- oper.addParameter(new javax.xml.namespace.QName("", "job_id"),
- new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
- "string"), java.lang.String.class,
- org.apache.axis.description.ParameterDesc.IN, false, false);
- oper.setReturnType(new javax.xml.namespace.QName(
- "simple.objects.vamsas", "MsaResult"));
- oper.setReturnClass(vamsas.objects.simple.MsaResult.class);
- oper.setReturnQName(new javax.xml.namespace.QName("", "getResultReturn"));
- oper.setStyle(org.apache.axis.constants.Style.RPC);
- oper.setUse(org.apache.axis.constants.Use.ENCODED);
- _operations[2] = oper;
-
- oper = new org.apache.axis.description.OperationDesc();
- oper.setName("cancel");
- oper.addParameter(new javax.xml.namespace.QName("", "jobId"),
- new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
- "string"), java.lang.String.class,
- org.apache.axis.description.ParameterDesc.IN, false, false);
- oper.setReturnType(new javax.xml.namespace.QName(
- "simple.objects.vamsas", "WsJobId"));
- oper.setReturnClass(vamsas.objects.simple.WsJobId.class);
- oper.setReturnQName(new javax.xml.namespace.QName("", "cancelReturn"));
- oper.setStyle(org.apache.axis.constants.Style.RPC);
- oper.setUse(org.apache.axis.constants.Use.ENCODED);
- _operations[3] = oper;
- }
-
- protected org.apache.axis.client.Call createCall()
- throws java.rmi.RemoteException {
- try {
- org.apache.axis.client.Call _call = (org.apache.axis.client.Call) super.service.createCall();
-
- if (super.maintainSessionSet) {
- _call.setMaintainSession(super.maintainSession);
- }
-
- if (super.cachedUsername != null) {
- _call.setUsername(super.cachedUsername);
- }
-
- if (super.cachedPassword != null) {
- _call.setPassword(super.cachedPassword);
- }
-
- if (super.cachedEndpoint != null) {
- _call.setTargetEndpointAddress(super.cachedEndpoint);
- }
-
- if (super.cachedTimeout != null) {
- _call.setTimeout(super.cachedTimeout);
- }
-
- if (super.cachedPortName != null) {
- _call.setPortName(super.cachedPortName);
- }
-
- java.util.Enumeration keys = super.cachedProperties.keys();
-
- while (keys.hasMoreElements()) {
- java.lang.String key = (java.lang.String) keys.nextElement();
- _call.setProperty(key, super.cachedProperties.get(key));
- }
-
- // All the type mapping information is registered
- // when the first call is made.
- // The type mapping information is actually registered in
- // the TypeMappingRegistry of the service, which
- // is the reason why registration is only needed for the first call.
- synchronized (this) {
- if (firstCall()) {
- // must set encoding style before registering serializers
- _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
- _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);
-
- for (int i = 0; i < cachedSerFactories.size(); ++i) {
- java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);
- javax.xml.namespace.QName qName = (javax.xml.namespace.QName) cachedSerQNames.get(i);
- java.lang.Class sf = (java.lang.Class) cachedSerFactories.get(i);
- java.lang.Class df = (java.lang.Class) cachedDeserFactories.get(i);
- _call.registerTypeMapping(cls, qName, sf, df, false);
- }
- }
- }
-
- return _call;
- } catch (java.lang.Throwable _t) {
- throw new org.apache.axis.AxisFault("Failure trying to get the Call object",
- _t);
- }
- }
-
- public vamsas.objects.simple.WsJobId align(
- vamsas.objects.simple.SequenceSet seqSet)
- throws java.rmi.RemoteException {
- if (super.cachedEndpoint == null) {
- throw new org.apache.axis.NoEndPointException();
- }
-
- org.apache.axis.client.Call _call = createCall();
- _call.setOperation(_operations[0]);
- _call.setUseSOAPAction(true);
- _call.setSOAPActionURI("");
- _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
- _call.setOperationName(new javax.xml.namespace.QName("vamsas", "align"));
-
- setRequestHeaders(_call);
- setAttachments(_call);
-
- java.lang.Object _resp = _call.invoke(new java.lang.Object[] { seqSet });
-
- if (_resp instanceof java.rmi.RemoteException) {
- throw (java.rmi.RemoteException) _resp;
- } else {
- extractAttachments(_call);
-
- try {
- return (vamsas.objects.simple.WsJobId) _resp;
- } catch (java.lang.Exception _exception) {
- return (vamsas.objects.simple.WsJobId) org.apache.axis.utils.JavaUtils.convert(_resp,
- vamsas.objects.simple.WsJobId.class);
- }
- }
- }
-
- public vamsas.objects.simple.Alignment getalign(java.lang.String job_id)
- throws java.rmi.RemoteException {
- if (super.cachedEndpoint == null) {
- throw new org.apache.axis.NoEndPointException();
- }
-
- org.apache.axis.client.Call _call = createCall();
- _call.setOperation(_operations[1]);
- _call.setUseSOAPAction(true);
- _call.setSOAPActionURI("");
- _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
- _call.setOperationName(new javax.xml.namespace.QName("vamsas",
- "getalign"));
-
- setRequestHeaders(_call);
- setAttachments(_call);
-
- java.lang.Object _resp = _call.invoke(new java.lang.Object[] { job_id });
-
- if (_resp instanceof java.rmi.RemoteException) {
- throw (java.rmi.RemoteException) _resp;
- } else {
- extractAttachments(_call);
-
- try {
- return (vamsas.objects.simple.Alignment) _resp;
- } catch (java.lang.Exception _exception) {
- return (vamsas.objects.simple.Alignment) org.apache.axis.utils.JavaUtils.convert(_resp,
- vamsas.objects.simple.Alignment.class);
- }
- }
- }
-
- public vamsas.objects.simple.MsaResult getResult(java.lang.String job_id)
- throws java.rmi.RemoteException {
- if (super.cachedEndpoint == null) {
- throw new org.apache.axis.NoEndPointException();
- }
-
- org.apache.axis.client.Call _call = createCall();
- _call.setOperation(_operations[2]);
- _call.setUseSOAPAction(true);
- _call.setSOAPActionURI("");
- _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
- _call.setOperationName(new javax.xml.namespace.QName("vamsas",
- "getResult"));
-
- setRequestHeaders(_call);
- setAttachments(_call);
-
- java.lang.Object _resp = _call.invoke(new java.lang.Object[] { job_id });
-
- if (_resp instanceof java.rmi.RemoteException) {
- throw (java.rmi.RemoteException) _resp;
- } else {
- extractAttachments(_call);
-
- try {
- return (vamsas.objects.simple.MsaResult) _resp;
- } catch (java.lang.Exception _exception) {
- return (vamsas.objects.simple.MsaResult) org.apache.axis.utils.JavaUtils.convert(_resp,
- vamsas.objects.simple.MsaResult.class);
- }
- }
- }
-
- public vamsas.objects.simple.WsJobId cancel(java.lang.String jobId)
- throws java.rmi.RemoteException {
- if (super.cachedEndpoint == null) {
- throw new org.apache.axis.NoEndPointException();
- }
-
- org.apache.axis.client.Call _call = createCall();
- _call.setOperation(_operations[3]);
- _call.setUseSOAPAction(true);
- _call.setSOAPActionURI("");
- _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
- _call.setOperationName(new javax.xml.namespace.QName("vamsas", "cancel"));
-
- setRequestHeaders(_call);
- setAttachments(_call);
-
- java.lang.Object _resp = _call.invoke(new java.lang.Object[] { jobId });
-
- if (_resp instanceof java.rmi.RemoteException) {
- throw (java.rmi.RemoteException) _resp;
- } else {
- extractAttachments(_call);
-
- try {
- return (vamsas.objects.simple.WsJobId) _resp;
- } catch (java.lang.Exception _exception) {
- return (vamsas.objects.simple.WsJobId) org.apache.axis.utils.JavaUtils.convert(_resp,
- vamsas.objects.simple.WsJobId.class);
- }
- }
- }
-}
+*/
+package ext.vamsas;
+
+public class MuscleWSSoapBindingStub extends org.apache.axis.client.Stub
+ implements ext.vamsas.MuscleWS {
+ static org.apache.axis.description.OperationDesc[] _operations;
+
+ static {
+ _operations = new org.apache.axis.description.OperationDesc[4];
+ _initOperationDesc1();
+ }
+
+ private java.util.Vector cachedSerClasses = new java.util.Vector();
+ private java.util.Vector cachedSerQNames = new java.util.Vector();
+ private java.util.Vector cachedSerFactories = new java.util.Vector();
+ private java.util.Vector cachedDeserFactories = new java.util.Vector();
+
+ public MuscleWSSoapBindingStub() throws org.apache.axis.AxisFault {
+ this(null);
+ }
+
+ public MuscleWSSoapBindingStub(java.net.URL endpointURL,
+ javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {
+ this(service);
+ super.cachedEndpoint = endpointURL;
+ }
+
+ public MuscleWSSoapBindingStub(javax.xml.rpc.Service service)
+ throws org.apache.axis.AxisFault {
+ if (service == null) {
+ super.service = new org.apache.axis.client.Service();
+ } else {
+ super.service = service;
+ }
+
+ java.lang.Class cls;
+ javax.xml.namespace.QName qName;
+ java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;
+ java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;
+ //java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;
+ //java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;
+ java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;
+ java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;
+ //java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;
+ // java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;
+ //java.lang.Class simplelistsf = org.apache.axis.encoding.ser.SimpleListSerializerFactory.class;
+ //java.lang.Class simplelistdf = org.apache.axis.encoding.ser.SimpleListDeserializerFactory.class;
+ qName = new javax.xml.namespace.QName("simple.objects.vamsas",
+ "Sequence");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.Sequence.class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(beansf);
+ cachedDeserFactories.add(beandf);
+
+ qName = new javax.xml.namespace.QName("vamsas", "ArrayOf_tns1_Sequence");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.Sequence[].class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(arraysf);
+ cachedDeserFactories.add(arraydf);
+
+ qName = new javax.xml.namespace.QName("simple.objects.vamsas",
+ "MsaResult");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.MsaResult.class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(beansf);
+ cachedDeserFactories.add(beandf);
+
+ qName = new javax.xml.namespace.QName("simple.objects.vamsas",
+ "SequenceSet");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.SequenceSet.class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(beansf);
+ cachedDeserFactories.add(beandf);
+
+ qName = new javax.xml.namespace.QName("http://simple.objects.vamsas",
+ "Object");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.Object.class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(beansf);
+ cachedDeserFactories.add(beandf);
+
+ qName = new javax.xml.namespace.QName("simple.objects.vamsas",
+ "Alignment");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.Alignment.class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(beansf);
+ cachedDeserFactories.add(beandf);
+
+ qName = new javax.xml.namespace.QName("simple.objects.vamsas", "WsJobId");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.WsJobId.class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(beansf);
+ cachedDeserFactories.add(beandf);
+
+ qName = new javax.xml.namespace.QName("vamsas", "ArrayOf_xsd_string");
+ cachedSerQNames.add(qName);
+ cls = java.lang.String[].class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(arraysf);
+ cachedDeserFactories.add(arraydf);
+
+ qName = new javax.xml.namespace.QName("simple.objects.vamsas", "Result");
+ cachedSerQNames.add(qName);
+ cls = vamsas.objects.simple.Result.class;
+ cachedSerClasses.add(cls);
+ cachedSerFactories.add(beansf);
+ cachedDeserFactories.add(beandf);
+ }
+
+ private static void _initOperationDesc1() {
+ org.apache.axis.description.OperationDesc oper;
+ oper = new org.apache.axis.description.OperationDesc();
+ oper.setName("align");
+ oper.addParameter(new javax.xml.namespace.QName("", "seqSet"),
+ new javax.xml.namespace.QName("simple.objects.vamsas", "SequenceSet"),
+ vamsas.objects.simple.SequenceSet.class,
+ org.apache.axis.description.ParameterDesc.IN, false, false);
+ oper.setReturnType(new javax.xml.namespace.QName(
+ "simple.objects.vamsas", "WsJobId"));
+ oper.setReturnClass(vamsas.objects.simple.WsJobId.class);
+ oper.setReturnQName(new javax.xml.namespace.QName("", "alignReturn"));
+ oper.setStyle(org.apache.axis.constants.Style.RPC);
+ oper.setUse(org.apache.axis.constants.Use.ENCODED);
+ _operations[0] = oper;
+
+ oper = new org.apache.axis.description.OperationDesc();
+ oper.setName("getalign");
+ oper.addParameter(new javax.xml.namespace.QName("", "job_id"),
+ new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
+ "string"), java.lang.String.class,
+ org.apache.axis.description.ParameterDesc.IN, false, false);
+ oper.setReturnType(new javax.xml.namespace.QName(
+ "simple.objects.vamsas", "Alignment"));
+ oper.setReturnClass(vamsas.objects.simple.Alignment.class);
+ oper.setReturnQName(new javax.xml.namespace.QName("", "getalignReturn"));
+ oper.setStyle(org.apache.axis.constants.Style.RPC);
+ oper.setUse(org.apache.axis.constants.Use.ENCODED);
+ _operations[1] = oper;
+
+ oper = new org.apache.axis.description.OperationDesc();
+ oper.setName("getResult");
+ oper.addParameter(new javax.xml.namespace.QName("", "job_id"),
+ new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
+ "string"), java.lang.String.class,
+ org.apache.axis.description.ParameterDesc.IN, false, false);
+ oper.setReturnType(new javax.xml.namespace.QName(
+ "simple.objects.vamsas", "MsaResult"));
+ oper.setReturnClass(vamsas.objects.simple.MsaResult.class);
+ oper.setReturnQName(new javax.xml.namespace.QName("", "getResultReturn"));
+ oper.setStyle(org.apache.axis.constants.Style.RPC);
+ oper.setUse(org.apache.axis.constants.Use.ENCODED);
+ _operations[2] = oper;
+
+ oper = new org.apache.axis.description.OperationDesc();
+ oper.setName("cancel");
+ oper.addParameter(new javax.xml.namespace.QName("", "jobId"),
+ new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
+ "string"), java.lang.String.class,
+ org.apache.axis.description.ParameterDesc.IN, false, false);
+ oper.setReturnType(new javax.xml.namespace.QName(
+ "simple.objects.vamsas", "WsJobId"));
+ oper.setReturnClass(vamsas.objects.simple.WsJobId.class);
+ oper.setReturnQName(new javax.xml.namespace.QName("", "cancelReturn"));
+ oper.setStyle(org.apache.axis.constants.Style.RPC);
+ oper.setUse(org.apache.axis.constants.Use.ENCODED);
+ _operations[3] = oper;
+ }
+
+ protected org.apache.axis.client.Call createCall()
+ throws java.rmi.RemoteException {
+ try {
+ org.apache.axis.client.Call _call = (org.apache.axis.client.Call) super.service.createCall();
+
+ if (super.maintainSessionSet) {
+ _call.setMaintainSession(super.maintainSession);
+ }
+
+ if (super.cachedUsername != null) {
+ _call.setUsername(super.cachedUsername);
+ }
+
+ if (super.cachedPassword != null) {
+ _call.setPassword(super.cachedPassword);
+ }
+
+ if (super.cachedEndpoint != null) {
+ _call.setTargetEndpointAddress(super.cachedEndpoint);
+ }
+
+ if (super.cachedTimeout != null) {
+ _call.setTimeout(super.cachedTimeout);
+ }
+
+ if (super.cachedPortName != null) {
+ _call.setPortName(super.cachedPortName);
+ }
+
+ java.util.Enumeration keys = super.cachedProperties.keys();
+
+ while (keys.hasMoreElements()) {
+ java.lang.String key = (java.lang.String) keys.nextElement();
+ _call.setProperty(key, super.cachedProperties.get(key));
+ }
+
+ // All the type mapping information is registered
+ // when the first call is made.
+ // The type mapping information is actually registered in
+ // the TypeMappingRegistry of the service, which
+ // is the reason why registration is only needed for the first call.
+ synchronized (this) {
+ if (firstCall()) {
+ // must set encoding style before registering serializers
+ _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
+ _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);
+
+ for (int i = 0; i < cachedSerFactories.size(); ++i) {
+ java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);
+ javax.xml.namespace.QName qName = (javax.xml.namespace.QName) cachedSerQNames.get(i);
+ java.lang.Class sf = (java.lang.Class) cachedSerFactories.get(i);
+ java.lang.Class df = (java.lang.Class) cachedDeserFactories.get(i);
+ _call.registerTypeMapping(cls, qName, sf, df, false);
+ }
+ }
+ }
+
+ return _call;
+ } catch (java.lang.Throwable _t) {
+ throw new org.apache.axis.AxisFault("Failure trying to get the Call object",
+ _t);
+ }
+ }
+
+ public vamsas.objects.simple.WsJobId align(
+ vamsas.objects.simple.SequenceSet seqSet)
+ throws java.rmi.RemoteException {
+ if (super.cachedEndpoint == null) {
+ throw new org.apache.axis.NoEndPointException();
+ }
+
+ org.apache.axis.client.Call _call = createCall();
+ _call.setOperation(_operations[0]);
+ _call.setUseSOAPAction(true);
+ _call.setSOAPActionURI("");
+ _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
+ _call.setOperationName(new javax.xml.namespace.QName("vamsas", "align"));
+
+ setRequestHeaders(_call);
+ setAttachments(_call);
+
+ java.lang.Object _resp = _call.invoke(new java.lang.Object[] { seqSet });
+
+ if (_resp instanceof java.rmi.RemoteException) {
+ throw (java.rmi.RemoteException) _resp;
+ } else {
+ extractAttachments(_call);
+
+ try {
+ return (vamsas.objects.simple.WsJobId) _resp;
+ } catch (java.lang.Exception _exception) {
+ return (vamsas.objects.simple.WsJobId) org.apache.axis.utils.JavaUtils.convert(_resp,
+ vamsas.objects.simple.WsJobId.class);
+ }
+ }
+ }
+
+ public vamsas.objects.simple.Alignment getalign(java.lang.String job_id)
+ throws java.rmi.RemoteException {
+ if (super.cachedEndpoint == null) {
+ throw new org.apache.axis.NoEndPointException();
+ }
+
+ org.apache.axis.client.Call _call = createCall();
+ _call.setOperation(_operations[1]);
+ _call.setUseSOAPAction(true);
+ _call.setSOAPActionURI("");
+ _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
+ _call.setOperationName(new javax.xml.namespace.QName("vamsas",
+ "getalign"));
+
+ setRequestHeaders(_call);
+ setAttachments(_call);
+
+ java.lang.Object _resp = _call.invoke(new java.lang.Object[] { job_id });
+
+ if (_resp instanceof java.rmi.RemoteException) {
+ throw (java.rmi.RemoteException) _resp;
+ } else {
+ extractAttachments(_call);
+
+ try {
+ return (vamsas.objects.simple.Alignment) _resp;
+ } catch (java.lang.Exception _exception) {
+ return (vamsas.objects.simple.Alignment) org.apache.axis.utils.JavaUtils.convert(_resp,
+ vamsas.objects.simple.Alignment.class);
+ }
+ }
+ }
+
+ public vamsas.objects.simple.MsaResult getResult(java.lang.String job_id)
+ throws java.rmi.RemoteException {
+ if (super.cachedEndpoint == null) {
+ throw new org.apache.axis.NoEndPointException();
+ }
+
+ org.apache.axis.client.Call _call = createCall();
+ _call.setOperation(_operations[2]);
+ _call.setUseSOAPAction(true);
+ _call.setSOAPActionURI("");
+ _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
+ _call.setOperationName(new javax.xml.namespace.QName("vamsas",
+ "getResult"));
+
+ setRequestHeaders(_call);
+ setAttachments(_call);
+
+ java.lang.Object _resp = _call.invoke(new java.lang.Object[] { job_id });
+
+ if (_resp instanceof java.rmi.RemoteException) {
+ throw (java.rmi.RemoteException) _resp;
+ } else {
+ extractAttachments(_call);
+
+ try {
+ return (vamsas.objects.simple.MsaResult) _resp;
+ } catch (java.lang.Exception _exception) {
+ return (vamsas.objects.simple.MsaResult) org.apache.axis.utils.JavaUtils.convert(_resp,
+ vamsas.objects.simple.MsaResult.class);
+ }
+ }
+ }
+
+ public vamsas.objects.simple.WsJobId cancel(java.lang.String jobId)
+ throws java.rmi.RemoteException {
+ if (super.cachedEndpoint == null) {
+ throw new org.apache.axis.NoEndPointException();
+ }
+
+ org.apache.axis.client.Call _call = createCall();
+ _call.setOperation(_operations[3]);
+ _call.setUseSOAPAction(true);
+ _call.setSOAPActionURI("");
+ _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
+ _call.setOperationName(new javax.xml.namespace.QName("vamsas", "cancel"));
+
+ setRequestHeaders(_call);
+ setAttachments(_call);
+
+ java.lang.Object _resp = _call.invoke(new java.lang.Object[] { jobId });
+
+ if (_resp instanceof java.rmi.RemoteException) {
+ throw (java.rmi.RemoteException) _resp;
+ } else {
+ extractAttachments(_call);
+
+ try {
+ return (vamsas.objects.simple.WsJobId) _resp;
+ } catch (java.lang.Exception _exception) {
+ return (vamsas.objects.simple.WsJobId) org.apache.axis.utils.JavaUtils.convert(_resp,
+ vamsas.objects.simple.WsJobId.class);
+ }
+ }
+ }
+}
diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java
index ad1fe4e..1f43788 100755
--- a/src/jalview/analysis/AAFrequency.java
+++ b/src/jalview/analysis/AAFrequency.java
@@ -1,139 +1,139 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.analysis;
-
-import jalview.datamodel.*;
-
-import java.util.*;
-
-
-/**
- * Takes in a vector of sequences and column start and column end
- * and returns a vector of size (end-start+1). Each element of the
- * vector contains a hashtable with the keys being residues and
- * the values being the count of each residue in that column.
- * This class is used extensively in calculating alignment colourschemes
- * that depend on the amount of conservation in each alignment column.
- * @author $author$
- * @version $Revision$
- */
-public class AAFrequency
-{
- /** Takes in a vector of sequences and column start and column end
- * and returns a vector of size (end-start+1). Each element of the
- * vector contains a hashtable with the keys being residues and
- * the values being the count of each residue in that column.
- * This class is used extensively in calculating alignment colourschemes
- * that depend on the amount of conservation in each alignment column. */
- public static final Vector calculate(Vector sequences, int start, int end)
- {
- Vector result = new Vector();
- Hashtable residueHash;
- int count, maxCount, nongap, i, j, jSize = sequences.size();
- String maxResidue, sequence, res;
- float percentage;
-
- for (i = start; i <= end; i++)
- {
- residueHash = new Hashtable();
- maxCount = 0;
- maxResidue = "-";
- nongap = 0;
-
- for (j = 0; j < jSize; j++)
- {
- if (sequences.elementAt(j) instanceof Sequence)
- {
- sequence = ((Sequence) sequences.elementAt(j)).getSequence();
-
- if (sequence.length() > i)
- {
- res = String.valueOf(Character.toUpperCase(sequence.charAt(i)));
-
- if (jalview.util.Comparison.isGap(res.charAt(0)))
- {
- res = "-"; // we always use this for gaps in the property vectors
- }
- else
- { nongap++; }
-
- if (residueHash.containsKey(res))
- {
- count = ((Integer) residueHash.get(res)).intValue();
- count++;
-
- if (!jalview.util.Comparison.isGap(res.charAt(0)) &&
- (count >= maxCount))
- {
- if (count > maxCount)
- {
- maxResidue = res;
- }
- else if (maxResidue.indexOf(res) == -1)
- {
- maxResidue += res;
- }
-
- maxCount = count;
- }
-
- residueHash.put(res, new Integer(count));
- }
- else
- {
- residueHash.put(res, new Integer(1));
- }
- }
- else
- {
- if (residueHash.containsKey("-"))
- {
- count = ((Integer) residueHash.get("-")).intValue();
- count++;
- residueHash.put("-", new Integer(count));
- }
- else
- {
- residueHash.put("-", new Integer(1));
- }
- }
- }
- }
-
- residueHash.put("maxCount", new Integer(maxCount));
- residueHash.put("maxResidue", maxResidue);
-
-
- //Size is redundant at present if we calculate percentage here
- //residueHash.put("size", new Integer(jSize));
- //residueHash.put("nogaps", new Integer(nongap));
-
- percentage = ((float)maxCount*100) / (float)jSize;
- residueHash.put("pid_gaps", new Float(percentage) );
-
- percentage = ((float)maxCount*100) / (float)nongap;
- residueHash.put("pid_nogaps", new Float(percentage) );
- result.addElement(residueHash);
- }
-
-
-
- return result;
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.analysis;
+
+import jalview.datamodel.*;
+
+import java.util.*;
+
+
+/**
+ * Takes in a vector of sequences and column start and column end
+ * and returns a vector of size (end-start+1). Each element of the
+ * vector contains a hashtable with the keys being residues and
+ * the values being the count of each residue in that column.
+ * This class is used extensively in calculating alignment colourschemes
+ * that depend on the amount of conservation in each alignment column.
+ * @author $author$
+ * @version $Revision$
+ */
+public class AAFrequency
+{
+ /** Takes in a vector of sequences and column start and column end
+ * and returns a vector of size (end-start+1). Each element of the
+ * vector contains a hashtable with the keys being residues and
+ * the values being the count of each residue in that column.
+ * This class is used extensively in calculating alignment colourschemes
+ * that depend on the amount of conservation in each alignment column. */
+ public static final Vector calculate(Vector sequences, int start, int end)
+ {
+ Vector result = new Vector();
+ Hashtable residueHash;
+ int count, maxCount, nongap, i, j, jSize = sequences.size();
+ String maxResidue, sequence, res;
+ float percentage;
+
+ for (i = start; i <= end; i++)
+ {
+ residueHash = new Hashtable();
+ maxCount = 0;
+ maxResidue = "-";
+ nongap = 0;
+
+ for (j = 0; j < jSize; j++)
+ {
+ if (sequences.elementAt(j) instanceof Sequence)
+ {
+ sequence = ((Sequence) sequences.elementAt(j)).getSequence();
+
+ if (sequence.length() > i)
+ {
+ res = String.valueOf(Character.toUpperCase(sequence.charAt(i)));
+
+ if (jalview.util.Comparison.isGap(res.charAt(0)))
+ {
+ res = "-"; // we always use this for gaps in the property vectors
+ }
+ else
+ { nongap++; }
+
+ if (residueHash.containsKey(res))
+ {
+ count = ((Integer) residueHash.get(res)).intValue();
+ count++;
+
+ if (!jalview.util.Comparison.isGap(res.charAt(0)) &&
+ (count >= maxCount))
+ {
+ if (count > maxCount)
+ {
+ maxResidue = res;
+ }
+ else if (maxResidue.indexOf(res) == -1)
+ {
+ maxResidue += res;
+ }
+
+ maxCount = count;
+ }
+
+ residueHash.put(res, new Integer(count));
+ }
+ else
+ {
+ residueHash.put(res, new Integer(1));
+ }
+ }
+ else
+ {
+ if (residueHash.containsKey("-"))
+ {
+ count = ((Integer) residueHash.get("-")).intValue();
+ count++;
+ residueHash.put("-", new Integer(count));
+ }
+ else
+ {
+ residueHash.put("-", new Integer(1));
+ }
+ }
+ }
+ }
+
+ residueHash.put("maxCount", new Integer(maxCount));
+ residueHash.put("maxResidue", maxResidue);
+
+
+ //Size is redundant at present if we calculate percentage here
+ //residueHash.put("size", new Integer(jSize));
+ //residueHash.put("nogaps", new Integer(nongap));
+
+ percentage = ((float)maxCount*100) / (float)jSize;
+ residueHash.put("pid_gaps", new Float(percentage) );
+
+ percentage = ((float)maxCount*100) / (float)nongap;
+ residueHash.put("pid_nogaps", new Float(percentage) );
+ result.addElement(residueHash);
+ }
+
+
+
+ return result;
+ }
+}
diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java
index 401ad01..f743dd2 100755
--- a/src/jalview/analysis/AlignSeq.java
+++ b/src/jalview/analysis/AlignSeq.java
@@ -1,811 +1,837 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.analysis;
-
-import jalview.datamodel.SequenceI;
-
-import jalview.schemes.*;
-
-import jalview.util.*;
-
-import java.awt.*;
-
-import java.util.*;
-
-
-/**
- *
- *
- * @author $author$
- * @version $Revision$
- */
-public class AlignSeq
-{
- /** DOCUMENT ME!! */
- public static java.util.Hashtable dnaHash = new java.util.Hashtable();
-
- static
- {
- dnaHash.put("C", new Integer(0));
- dnaHash.put("T", new Integer(1));
- dnaHash.put("A", new Integer(2));
- dnaHash.put("G", new Integer(3));
- dnaHash.put("-", new Integer(4));
- }
-
- static String[] dna = { "C", "T", "A", "G", "-" };
- static String[] pep =
- {
- "A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F",
- "P", "S", "T", "W", "Y", "V", "B", "Z", "X", "-"
- };
- int[][] score;
- int[][] E;
- int[][] F;
- int[][] traceback;
- int[] seq1;
- int[] seq2;
- SequenceI s1;
- SequenceI s2;
- String s1str;
- String s2str;
- int maxi;
- int maxj;
- int[] aseq1;
- int[] aseq2;
- public String astr1 = "";
- public String astr2 = "";
-
- /** DOCUMENT ME!! */
- public int seq1start;
-
- /** DOCUMENT ME!! */
- public int seq1end;
-
- /** DOCUMENT ME!! */
- public int seq2start;
-
- /** DOCUMENT ME!! */
- public int seq2end;
- int count;
-
- /** DOCUMENT ME!! */
- public int maxscore;
- float pid;
- int prev = 0;
- int gapOpen = 120;
- int gapExtend = 20;
- int[][] lookup = ResidueProperties.getBLOSUM62();
- String[] intToStr = pep;
- int defInt = 23;
- StringBuffer output = new StringBuffer();
- String type;
- Runtime rt;
-
-
- /**
- * Creates a new AlignSeq object.
- *
- * @param s1 DOCUMENT ME!
- * @param s2 DOCUMENT ME!
- * @param type DOCUMENT ME!
- */
- public AlignSeq(SequenceI s1, SequenceI s2, String type)
- {
- rt = Runtime.getRuntime();
- SeqInit(s1, s2, type);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getMaxScore()
- {
- return maxscore;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getSeq2Start()
- {
- return seq2start;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getSeq2End()
- {
- return seq2end;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getSeq1Start()
- {
- return seq1start;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getSeq1End()
- {
- return seq1end;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getOutput()
- {
- return output.toString();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getAStr1()
- {
- return astr1;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getAStr2()
- {
- return astr2;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int[] getASeq1()
- {
- return aseq1;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int[] getASeq2()
- {
- return aseq2;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceI getS1()
- {
- return s1;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceI getS2()
- {
- return s2;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param s1 DOCUMENT ME!
- * @param s2 DOCUMENT ME!
- * @param type DOCUMENT ME!
- */
- public void SeqInit(SequenceI s1, SequenceI s2, String type)
- {
- s1str = extractGaps(jalview.util.Comparison.GapChars, s1.getSequence());
- s2str = extractGaps(jalview.util.Comparison.GapChars, s2.getSequence());
-
- this.s1 = s1;
- this.s2 = s2;
-
- this.type = type;
-
- if (type.equals("pep"))
- {
- lookup = ResidueProperties.getBLOSUM62();
- intToStr = pep;
- defInt = 23;
- }
- else if (type.equals("dna"))
- {
- lookup = ResidueProperties.getDNA();
- intToStr = dna;
- defInt = 4;
- }
- else
- {
- output.append("Wrong type = dna or pep only");
- System.exit(0);
- }
-
- //System.out.println("lookuip " + rt.freeMemory() + " "+ rt.totalMemory());
- seq1 = new int[s1str.length()];
-
- //System.out.println("seq1 " + rt.freeMemory() +" " + rt.totalMemory());
- seq2 = new int[s2str.length()];
-
- //System.out.println("seq2 " + rt.freeMemory() + " " + rt.totalMemory());
- score = new int[s1str.length()][s2str.length()];
-
- //System.out.println("score " + rt.freeMemory() + " " + rt.totalMemory());
- E = new int[s1str.length()][s2str.length()];
-
- //System.out.println("E " + rt.freeMemory() + " " + rt.totalMemory());
- F = new int[s1str.length()][s2str.length()];
- traceback = new int[s1str.length()][s2str.length()];
-
- //System.out.println("F " + rt.freeMemory() + " " + rt.totalMemory());
- seq1 = stringToInt(s1str, type);
-
- //System.out.println("seq1 " + rt.freeMemory() + " " + rt.totalMemory());
- seq2 = stringToInt(s2str, type);
-
- //System.out.println("Seq2 " + rt.freeMemory() + " " + rt.totalMemory());
- // long tstart = System.currentTimeMillis();
- // calcScoreMatrix();
- //long tend = System.currentTimeMillis();
- //System.out.println("Time take to calculate score matrix = " + (tend-tstart) + " ms");
- // printScoreMatrix(score);
- //System.out.println();
- //printScoreMatrix(traceback);
- //System.out.println();
- // printScoreMatrix(E);
- //System.out.println();
- ///printScoreMatrix(F);
- //System.out.println();
- // tstart = System.currentTimeMillis();
- //traceAlignment();
- //tend = System.currentTimeMillis();
- //System.out.println("Time take to traceback alignment = " + (tend-tstart) + " ms");
- }
-
- /**
- * DOCUMENT ME!
- */
- public void traceAlignment()
- {
- // Find the maximum score along the rhs or bottom row
- int max = -9999;
-
- for (int i = 0; i < seq1.length; i++)
- {
- if (score[i][seq2.length - 1] > max)
- {
- max = score[i][seq2.length - 1];
- maxi = i;
- maxj = seq2.length - 1;
- }
- }
-
- for (int j = 0; j < seq2.length; j++)
- {
- if (score[seq1.length - 1][j] > max)
- {
- max = score[seq1.length - 1][j];
- maxi = seq1.length - 1;
- maxj = j;
- }
- }
-
- // System.out.println(maxi + " " + maxj + " " + score[maxi][maxj]);
- int i = maxi;
- int j = maxj;
- int trace;
- maxscore = score[i][j] / 10;
-
- seq1end = maxi + 1;
- seq2end = maxj + 1;
-
- aseq1 = new int[seq1.length + seq2.length];
- aseq2 = new int[seq1.length + seq2.length];
-
- count = (seq1.length + seq2.length) - 1;
-
- while ((i > 0) && (j > 0))
- {
- if ((aseq1[count] != defInt) && (i >= 0))
- {
- aseq1[count] = seq1[i];
- astr1 = intToStr[seq1[i]] + astr1;
- }
-
- if ((aseq2[count] != defInt) && (j > 0))
- {
- aseq2[count] = seq2[j];
- astr2 = intToStr[seq2[j]] + astr2;
- }
-
- trace = findTrace(i, j);
-
- if (trace == 0)
- {
- i--;
- j--;
- }
- else if (trace == 1)
- {
- j--;
- aseq1[count] = defInt;
- astr1 = "-" + astr1.substring(1);
- }
- else if (trace == -1)
- {
- i--;
- aseq2[count] = defInt;
- astr2 = "-" + astr2.substring(1);
- }
-
- count--;
- }
-
- seq1start = i + 1;
- seq2start = j + 1;
-
- if (aseq1[count] != defInt)
- {
- aseq1[count] = seq1[i];
- astr1 = intToStr[seq1[i]] + astr1;
- }
-
- if (aseq2[count] != defInt)
- {
- aseq2[count] = seq2[j];
- astr2 = intToStr[seq2[j]] + astr2;
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- public void printAlignment(java.io.PrintStream os)
- {
- // Find the biggest id length for formatting purposes
- int maxid = s1.getName().length();
-
- if (s2.getName().length() > maxid)
- {
- maxid = s2.getName().length();
- }
-
- int len = 72 - maxid - 1;
- int nochunks = ((aseq1.length - count) / len) + 1;
- pid = 0;
-
- output.append("Score = " + score[maxi][maxj] + "\n");
- output.append("Length of alignment = " + (aseq1.length - count) + "\n");
- output.append("Sequence ");
- output.append(new Format("%" + maxid + "s").form(s1.getName()));
- output.append(" : " + seq1start + " - " + seq1end + " (Sequence length = " +
- s1str.length() + ")\n");
- output .append("Sequence ");
- output.append(new Format("%" + maxid + "s").form(s2.getName()));
- output .append(" : " + seq2start + " - " + seq2end + " (Sequence length = " +
- s2str.length() + ")\n\n");
-
- for (int j = 0; j < nochunks; j++)
- {
- // Print the first aligned sequence
- output.append(new Format("%" + (maxid) + "s").form(s1.getName()) + " ");
-
- for (int i = 0; i < len; i++)
- {
- if ((count + i + (j * len)) < aseq1.length)
- {
- output.append(new Format("%s").form(intToStr[aseq1[count + i +
- (j * len)]]));
- }
- }
-
- output.append("\n");
- output.append(new Format("%" + (maxid) + "s").form(" ") + " ");
-
- // Print out the matching chars
- for (int i = 0; i < len; i++)
- {
- if ((count + i + (j * len)) < aseq1.length)
- {
- if (intToStr[aseq1[count + i + (j * len)]].equals(
- intToStr[aseq2[count + i + (j * len)]]) &&
- !intToStr[aseq1[count + i + (j * len)]].equals("-"))
- {
- pid++;
- output.append("|");
- }
- else if (type.equals("pep"))
- {
- if (ResidueProperties.getPAM250(
- intToStr[aseq1[count + i + (j * len)]],
- intToStr[aseq2[count + i + (j * len)]]) > 0)
- {
- output.append(".");
- }
- else
- {
- output.append(" ");
- }
- }
- else
- {
- output.append(" ");
- }
- }
- }
-
- // Now print the second aligned sequence
- output = output.append("\n");
- output = output.append(new Format("%" + (maxid) + "s").form(s2.getName()) + " ");
-
- for (int i = 0; i < len; i++)
- {
- if ((count + i + (j * len)) < aseq1.length)
- {
- output .append(new Format("%s").form(intToStr[aseq2[count + i +
- (j * len)]]));
- }
- }
-
- output = output .append("\n\n");
- }
-
- pid = pid / (float) (aseq1.length - count) * 100;
- output = output.append(new Format("Percentage ID = %2.2f\n\n").form(pid));
-
- try{
- os.print(output.toString());
- }catch(Exception ex){}
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param mat DOCUMENT ME!
- */
- public void printScoreMatrix(int[][] mat)
- {
- int n = seq1.length;
- int m = seq2.length;
-
- for (int i = 0; i < n; i++)
- {
- // Print the top sequence
- if (i == 0)
- {
- Format.print(System.out, "%8s", s2str.substring(0, 1));
-
- for (int jj = 1; jj < m; jj++)
- {
- Format.print(System.out, "%5s", s2str.substring(jj, jj + 1));
- }
-
- System.out.println();
- }
-
- for (int j = 0; j < m; j++)
- {
- if (j == 0)
- {
- Format.print(System.out, "%3s", s1str.substring(i, i + 1));
- }
-
- Format.print(System.out, "%3d ", mat[i][j] / 10);
- }
-
- System.out.println();
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param j DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int findTrace(int i, int j)
- {
- int t = 0;
- int max = score[i - 1][j - 1] + (lookup[seq1[i]][seq2[j]] * 10);
-
- if (F[i][j] > max)
- {
- max = F[i][j];
- t = -1;
- }
- else if (F[i][j] == max)
- {
- if (prev == -1)
- {
- max = F[i][j];
- t = -1;
- }
- }
-
- if (E[i][j] >= max)
- {
- max = E[i][j];
- t = 1;
- }
- else if (E[i][j] == max)
- {
- if (prev == 1)
- {
- max = E[i][j];
- t = 1;
- }
- }
-
- prev = t;
-
- return t;
- }
-
- /**
- * DOCUMENT ME!
- */
- public void calcScoreMatrix()
- {
- int n = seq1.length;
- int m = seq2.length;
-
- // top left hand element
- score[0][0] = lookup[seq1[0]][seq2[0]] * 10;
- E[0][0] = -gapExtend;
- F[0][0] = 0;
-
- // Calculate the top row first
- for (int j = 1; j < m; j++)
- {
- // What should these values be? 0 maybe
- E[0][j] = max(score[0][j - 1] - gapOpen, E[0][j - 1] - gapExtend);
- F[0][j] = -gapExtend;
-
- score[0][j] = max(lookup[seq1[0]][seq2[j]] * 10, -gapOpen,
- -gapExtend);
-
- traceback[0][j] = 1;
- }
-
- // Now do the left hand column
- for (int i = 1; i < n; i++)
- {
- E[i][0] = -gapOpen;
- F[i][0] = max(score[i - 1][0] - gapOpen, F[i - 1][0] - gapExtend);
-
- score[i][0] = max(lookup[seq1[i]][seq2[0]] * 10, E[i][0], F[i][0]);
- traceback[i][0] = -1;
- }
-
- // Now do all the other rows
- for (int i = 1; i < n; i++)
- {
- for (int j = 1; j < m; j++)
- {
- E[i][j] = max(score[i][j - 1] - gapOpen, E[i][j - 1] -
- gapExtend);
- F[i][j] = max(score[i - 1][j] - gapOpen, F[i - 1][j] -
- gapExtend);
-
- score[i][j] = max(score[i - 1][j - 1] +
- (lookup[seq1[i]][seq2[j]] * 10), E[i][j], F[i][j]);
- traceback[i][j] = findTrace(i, j);
- }
- }
- }
-
-
-
- /**
- * DOCUMENT ME!
- *
- * @param gapChar DOCUMENT ME!
- * @param seq DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static String extractGaps(String gapChar, String seq)
- {
- StringTokenizer str = new StringTokenizer(seq, gapChar);
- StringBuffer newString = new StringBuffer();
-
- while (str.hasMoreTokens())
- {
- newString.append( str.nextToken() );
- }
-
- return newString.toString();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i1 DOCUMENT ME!
- * @param i2 DOCUMENT ME!
- * @param i3 DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int max(int i1, int i2, int i3)
- {
- int max = i1;
-
- if (i2 > i1)
- {
- max = i2;
- }
-
- if (i3 > max)
- {
- max = i3;
- }
-
- return max;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i1 DOCUMENT ME!
- * @param i2 DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int max(int i1, int i2)
- {
- int max = i1;
-
- if (i2 > i1)
- {
- max = i2;
- }
-
- return max;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param s DOCUMENT ME!
- * @param type DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int[] stringToInt(String s, String type)
- {
- int[] seq1 = new int[s.length()];
-
- for (int i = 0; i < s.length(); i++)
- {
- String ss = s.substring(i, i + 1).toUpperCase();
-
- try
- {
- if (type.equals("pep"))
- {
- seq1[i] = ((Integer) ResidueProperties.aaHash.get(ss)).intValue();
- }
- else if (type.equals("dna"))
- {
- seq1[i] = ((Integer) dnaHash.get(ss)).intValue();
- }
-
- if (seq1[i] > 23)
- {
- seq1[i] = 23;
- }
- }
- catch (Exception e)
- {
- if (type.equals("dna"))
- {
- seq1[i] = 4;
- }
- else
- {
- seq1[i] = 23;
- }
- }
- }
-
- return seq1;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param g DOCUMENT ME!
- * @param mat DOCUMENT ME!
- * @param n DOCUMENT ME!
- * @param m DOCUMENT ME!
- * @param psize DOCUMENT ME!
- */
- public static void displayMatrix(Graphics g, int[][] mat, int n, int m,
- int psize)
- {
- int max = -1000;
- int min = 1000;
-
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if (mat[i][j] >= max)
- {
- max = mat[i][j];
- }
-
- if (mat[i][j] <= min)
- {
- min = mat[i][j];
- }
- }
- }
-
- System.out.println(max + " " + min);
-
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- int x = psize * i;
- int y = psize * j;
-
- // System.out.println(mat[i][j]);
- float score = (float) (mat[i][j] - min) / (float) (max - min);
- g.setColor(new Color(score, 0, 0));
- g.fillRect(x, y, psize, psize);
-
- // System.out.println(x + " " + y + " " + score);
- }
- }
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.analysis;
+
+import jalview.datamodel.SequenceI;
+
+import jalview.schemes.*;
+
+import jalview.util.*;
+
+import java.awt.*;
+
+import java.util.*;
+
+
+/**
+ *
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AlignSeq
+{
+ /** DOCUMENT ME!! */
+ public static java.util.Hashtable dnaHash = new java.util.Hashtable();
+
+ static
+ {
+ dnaHash.put("C", new Integer(0));
+ dnaHash.put("T", new Integer(1));
+ dnaHash.put("A", new Integer(2));
+ dnaHash.put("G", new Integer(3));
+ dnaHash.put("-", new Integer(4));
+ }
+
+ static String[] dna = { "C", "T", "A", "G", "-" };
+ static String[] pep =
+ {
+ "A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F",
+ "P", "S", "T", "W", "Y", "V", "B", "Z", "X", "-"
+ };
+ int[][] score;
+ int[][] E;
+ int[][] F;
+ int[][] traceback;
+ int[] seq1;
+ int[] seq2;
+ SequenceI s1;
+ SequenceI s2;
+ public String s1str;
+ public String s2str;
+ int maxi;
+ int maxj;
+ int[] aseq1;
+ int[] aseq2;
+ public String astr1="";
+ public String astr2="";
+
+ /** DOCUMENT ME!! */
+ public int seq1start;
+
+ /** DOCUMENT ME!! */
+ public int seq1end;
+
+ /** DOCUMENT ME!! */
+ public int seq2start;
+
+ /** DOCUMENT ME!! */
+ public int seq2end;
+ int count;
+
+ /** DOCUMENT ME!! */
+ public int maxscore;
+ float pid;
+ int prev = 0;
+ int gapOpen = 120;
+ int gapExtend = 20;
+ int[][] lookup = ResidueProperties.getBLOSUM62();
+ String[] intToStr = pep;
+ int defInt = 23;
+ StringBuffer output = new StringBuffer();
+ String type;
+
+ /**
+ * Creates a new AlignSeq object.
+ *
+ * @param s1 DOCUMENT ME!
+ * @param s2 DOCUMENT ME!
+ * @param type DOCUMENT ME!
+ */
+ public AlignSeq(SequenceI s1, SequenceI s2, String type)
+ {
+ SeqInit(s1, s1.getSequence(), s2, s2.getSequence(), type);
+ }
+
+ /**
+ * Creates a new AlignSeq object.
+ *
+ * @param s1 DOCUMENT ME!
+ * @param s2 DOCUMENT ME!
+ * @param type DOCUMENT ME!
+ */
+ public AlignSeq(SequenceI s1,
+ String string1,
+ SequenceI s2,
+ String string2,
+ String type)
+ {
+ SeqInit(s1, string1, s2, string2, type);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getMaxScore()
+ {
+ return maxscore;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getSeq2Start()
+ {
+ return seq2start;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getSeq2End()
+ {
+ return seq2end;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getSeq1Start()
+ {
+ return seq1start;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getSeq1End()
+ {
+ return seq1end;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getOutput()
+ {
+ return output.toString();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getAStr1()
+ {
+ return astr1;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getAStr2()
+ {
+ return astr2;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int[] getASeq1()
+ {
+ return aseq1;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int[] getASeq2()
+ {
+ return aseq2;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceI getS1()
+ {
+ return s1;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceI getS2()
+ {
+ return s2;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param s1 DOCUMENT ME!
+ * @param s2 DOCUMENT ME!
+ * @param type DOCUMENT ME!
+ */
+ public void SeqInit(SequenceI s1,
+ String string1,
+ SequenceI s2,
+ String string2,
+ String type)
+ {
+
+ s1str = extractGaps(jalview.util.Comparison.GapChars, string1);
+ s2str = extractGaps(jalview.util.Comparison.GapChars, string2);
+
+ if(s1str.length()==0 || s2str.length()==0)
+ {
+ System.out.println("ALL GAPS: " +
+ (s1str.length()==0?s1.getName():" ")
+ +(s2str.length()==0?s2.getName():""));
+ return;
+ }
+
+ this.s1 = s1;
+ this.s2 = s2;
+
+ this.type = type;
+
+ if (type.equals("pep"))
+ {
+ lookup = ResidueProperties.getBLOSUM62();
+ intToStr = pep;
+ defInt = 23;
+ }
+ else if (type.equals("dna"))
+ {
+ lookup = ResidueProperties.getDNA();
+ intToStr = dna;
+ defInt = 4;
+ }
+ else
+ {
+ output.append("Wrong type = dna or pep only");
+ System.exit(0);
+ }
+
+ //System.out.println("lookuip " + rt.freeMemory() + " "+ rt.totalMemory());
+ seq1 = new int[s1str.length()];
+
+ //System.out.println("seq1 " + rt.freeMemory() +" " + rt.totalMemory());
+ seq2 = new int[s2str.length()];
+
+ //System.out.println("seq2 " + rt.freeMemory() + " " + rt.totalMemory());
+ score = new int[s1str.length()][s2str.length()];
+
+ //System.out.println("score " + rt.freeMemory() + " " + rt.totalMemory());
+ E = new int[s1str.length()][s2str.length()];
+
+ //System.out.println("E " + rt.freeMemory() + " " + rt.totalMemory());
+ F = new int[s1str.length()][s2str.length()];
+ traceback = new int[s1str.length()][s2str.length()];
+
+ //System.out.println("F " + rt.freeMemory() + " " + rt.totalMemory());
+ seq1 = stringToInt(s1str, type);
+
+ //System.out.println("seq1 " + rt.freeMemory() + " " + rt.totalMemory());
+ seq2 = stringToInt(s2str, type);
+
+ //System.out.println("Seq2 " + rt.freeMemory() + " " + rt.totalMemory());
+ // long tstart = System.currentTimeMillis();
+ // calcScoreMatrix();
+ //long tend = System.currentTimeMillis();
+ //System.out.println("Time take to calculate score matrix = " + (tend-tstart) + " ms");
+ // printScoreMatrix(score);
+ //System.out.println();
+ //printScoreMatrix(traceback);
+ //System.out.println();
+ // printScoreMatrix(E);
+ //System.out.println();
+ ///printScoreMatrix(F);
+ //System.out.println();
+ // tstart = System.currentTimeMillis();
+ //traceAlignment();
+ //tend = System.currentTimeMillis();
+ //System.out.println("Time take to traceback alignment = " + (tend-tstart) + " ms");
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void traceAlignment()
+ {
+ // Find the maximum score along the rhs or bottom row
+ int max = -9999;
+
+ for (int i = 0; i < seq1.length; i++)
+ {
+ if (score[i][seq2.length - 1] > max)
+ {
+ max = score[i][seq2.length - 1];
+ maxi = i;
+ maxj = seq2.length - 1;
+ }
+ }
+
+ for (int j = 0; j < seq2.length; j++)
+ {
+ if (score[seq1.length - 1][j] > max)
+ {
+ max = score[seq1.length - 1][j];
+ maxi = seq1.length - 1;
+ maxj = j;
+ }
+ }
+
+ // System.out.println(maxi + " " + maxj + " " + score[maxi][maxj]);
+ int i = maxi;
+ int j = maxj;
+ int trace;
+ maxscore = score[i][j] / 10;
+
+ seq1end = maxi + 1;
+ seq2end = maxj + 1;
+
+ aseq1 = new int[seq1.length + seq2.length];
+ aseq2 = new int[seq1.length + seq2.length];
+
+ count = (seq1.length + seq2.length) - 1;
+
+ while ((i > 0) && (j > 0))
+ {
+ if ((aseq1[count] != defInt) && (i >= 0))
+ {
+ aseq1[count] = seq1[i];
+ astr1 = intToStr[seq1[i]] + astr1;
+ }
+
+ if ((aseq2[count] != defInt) && (j > 0))
+ {
+ aseq2[count] = seq2[j];
+ astr2 = intToStr[seq2[j]] + astr2;
+ }
+
+ trace = findTrace(i, j);
+
+ if (trace == 0)
+ {
+ i--;
+ j--;
+ }
+ else if (trace == 1)
+ {
+ j--;
+ aseq1[count] = defInt;
+ astr1 = "-" + astr1.substring(1);
+ }
+ else if (trace == -1)
+ {
+ i--;
+ aseq2[count] = defInt;
+ astr2 = "-" + astr2.substring(1);
+ }
+
+ count--;
+ }
+
+ seq1start = i + 1;
+ seq2start = j + 1;
+
+ if (aseq1[count] != defInt)
+ {
+ aseq1[count] = seq1[i];
+ astr1 = intToStr[seq1[i]] + astr1;
+ }
+
+ if (aseq2[count] != defInt)
+ {
+ aseq2[count] = seq2[j];
+ astr2 = intToStr[seq2[j]] + astr2;
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void printAlignment(java.io.PrintStream os)
+ {
+ // Find the biggest id length for formatting purposes
+ int maxid = s1.getName().length();
+
+ if (s2.getName().length() > maxid)
+ {
+ maxid = s2.getName().length();
+ }
+
+ int len = 72 - maxid - 1;
+ int nochunks = ((aseq1.length - count) / len) + 1;
+ pid = 0;
+
+ output.append("Score = " + score[maxi][maxj] + "\n");
+ output.append("Length of alignment = " + (aseq1.length - count) + "\n");
+ output.append("Sequence ");
+ output.append(new Format("%" + maxid + "s").form(s1.getName()));
+ output.append(" : " + s1.getStart() + " - " + s1.getEnd() + " (Sequence length = " +
+ s1str.length() + ")\n");
+ output .append("Sequence ");
+ output.append(new Format("%" + maxid + "s").form(s2.getName()));
+ output.append(" : " + s2.getStart() + " - " + s2.getEnd() + " (Sequence length = " +
+ s2str.length() + ")\n\n");
+
+ for (int j = 0; j < nochunks; j++)
+ {
+ // Print the first aligned sequence
+ output.append(new Format("%" + (maxid) + "s").form(s1.getName()) + " ");
+
+ for (int i = 0; i < len; i++)
+ {
+ if ((count + i + (j * len)) < aseq1.length)
+ {
+ output.append(new Format("%s").form(intToStr[aseq1[count + i +
+ (j * len)]]));
+ }
+ }
+
+ output.append("\n");
+ output.append(new Format("%" + (maxid) + "s").form(" ") + " ");
+
+ // Print out the matching chars
+ for (int i = 0; i < len; i++)
+ {
+ if ((count + i + (j * len)) < aseq1.length)
+ {
+ if (intToStr[aseq1[count + i + (j * len)]].equals(
+ intToStr[aseq2[count + i + (j * len)]]) &&
+ !intToStr[aseq1[count + i + (j * len)]].equals("-"))
+ {
+ pid++;
+ output.append("|");
+ }
+ else if (type.equals("pep"))
+ {
+ if (ResidueProperties.getPAM250(
+ intToStr[aseq1[count + i + (j * len)]],
+ intToStr[aseq2[count + i + (j * len)]]) > 0)
+ {
+ output.append(".");
+ }
+ else
+ {
+ output.append(" ");
+ }
+ }
+ else
+ {
+ output.append(" ");
+ }
+ }
+ }
+
+ // Now print the second aligned sequence
+ output = output.append("\n");
+ output = output.append(new Format("%" + (maxid) + "s").form(s2.getName()) + " ");
+
+ for (int i = 0; i < len; i++)
+ {
+ if ((count + i + (j * len)) < aseq1.length)
+ {
+ output .append(new Format("%s").form(intToStr[aseq2[count + i +
+ (j * len)]]));
+ }
+ }
+
+ output = output .append("\n\n");
+ }
+
+ pid = pid / (float) (aseq1.length - count) * 100;
+ output = output.append(new Format("Percentage ID = %2.2f\n\n").form(pid));
+
+ try{
+ os.print(output.toString());
+ }catch(Exception ex){}
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param mat DOCUMENT ME!
+ */
+ public void printScoreMatrix(int[][] mat)
+ {
+ int n = seq1.length;
+ int m = seq2.length;
+
+ for (int i = 0; i < n; i++)
+ {
+ // Print the top sequence
+ if (i == 0)
+ {
+ Format.print(System.out, "%8s", s2str.substring(0, 1));
+
+ for (int jj = 1; jj < m; jj++)
+ {
+ Format.print(System.out, "%5s", s2str.substring(jj, jj + 1));
+ }
+
+ System.out.println();
+ }
+
+ for (int j = 0; j < m; j++)
+ {
+ if (j == 0)
+ {
+ Format.print(System.out, "%3s", s1str.substring(i, i + 1));
+ }
+
+ Format.print(System.out, "%3d ", mat[i][j] / 10);
+ }
+
+ System.out.println();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int findTrace(int i, int j)
+ {
+ int t = 0;
+ int max = score[i - 1][j - 1] + (lookup[seq1[i]][seq2[j]] * 10);
+
+ if (F[i][j] > max)
+ {
+ max = F[i][j];
+ t = -1;
+ }
+ else if (F[i][j] == max)
+ {
+ if (prev == -1)
+ {
+ max = F[i][j];
+ t = -1;
+ }
+ }
+
+ if (E[i][j] >= max)
+ {
+ max = E[i][j];
+ t = 1;
+ }
+ else if (E[i][j] == max)
+ {
+ if (prev == 1)
+ {
+ max = E[i][j];
+ t = 1;
+ }
+ }
+
+ prev = t;
+
+ return t;
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void calcScoreMatrix()
+ {
+ int n = seq1.length;
+ int m = seq2.length;
+
+ // top left hand element
+ score[0][0] = lookup[seq1[0]][seq2[0]] * 10;
+ E[0][0] = -gapExtend;
+ F[0][0] = 0;
+
+ // Calculate the top row first
+ for (int j = 1; j < m; j++)
+ {
+ // What should these values be? 0 maybe
+ E[0][j] = max(score[0][j - 1] - gapOpen, E[0][j - 1] - gapExtend);
+ F[0][j] = -gapExtend;
+
+ score[0][j] = max(lookup[seq1[0]][seq2[j]] * 10, -gapOpen,
+ -gapExtend);
+
+ traceback[0][j] = 1;
+ }
+
+ // Now do the left hand column
+ for (int i = 1; i < n; i++)
+ {
+ E[i][0] = -gapOpen;
+ F[i][0] = max(score[i - 1][0] - gapOpen, F[i - 1][0] - gapExtend);
+
+ score[i][0] = max(lookup[seq1[i]][seq2[0]] * 10, E[i][0], F[i][0]);
+ traceback[i][0] = -1;
+ }
+
+ // Now do all the other rows
+ for (int i = 1; i < n; i++)
+ {
+ for (int j = 1; j < m; j++)
+ {
+ E[i][j] = max(score[i][j - 1] - gapOpen, E[i][j - 1] -
+ gapExtend);
+ F[i][j] = max(score[i - 1][j] - gapOpen, F[i - 1][j] -
+ gapExtend);
+
+ score[i][j] = max(score[i - 1][j - 1] +
+ (lookup[seq1[i]][seq2[j]] * 10), E[i][j], F[i][j]);
+ traceback[i][j] = findTrace(i, j);
+ }
+ }
+ }
+
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param gapChar DOCUMENT ME!
+ * @param seq DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static String extractGaps(String gapChar, String seq)
+ {
+ StringTokenizer str = new StringTokenizer(seq, gapChar);
+ StringBuffer newString = new StringBuffer();
+
+ while (str.hasMoreTokens())
+ {
+ newString.append( str.nextToken() );
+ }
+
+ return newString.toString();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i1 DOCUMENT ME!
+ * @param i2 DOCUMENT ME!
+ * @param i3 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int max(int i1, int i2, int i3)
+ {
+ int max = i1;
+
+ if (i2 > i1)
+ {
+ max = i2;
+ }
+
+ if (i3 > max)
+ {
+ max = i3;
+ }
+
+ return max;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i1 DOCUMENT ME!
+ * @param i2 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int max(int i1, int i2)
+ {
+ int max = i1;
+
+ if (i2 > i1)
+ {
+ max = i2;
+ }
+
+ return max;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param s DOCUMENT ME!
+ * @param type DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int[] stringToInt(String s, String type)
+ {
+ int[] seq1 = new int[s.length()];
+
+ for (int i = 0; i < s.length(); i++)
+ {
+ String ss = s.substring(i, i + 1).toUpperCase();
+
+ try
+ {
+ if (type.equals("pep"))
+ {
+ seq1[i] = ((Integer) ResidueProperties.aaHash.get(ss)).intValue();
+ }
+ else if (type.equals("dna"))
+ {
+ seq1[i] = ((Integer) dnaHash.get(ss)).intValue();
+ }
+
+ if (seq1[i] > 23)
+ {
+ seq1[i] = 23;
+ }
+ }
+ catch (Exception e)
+ {
+ if (type.equals("dna"))
+ {
+ seq1[i] = 4;
+ }
+ else
+ {
+ seq1[i] = 23;
+ }
+ }
+ }
+
+ return seq1;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param g DOCUMENT ME!
+ * @param mat DOCUMENT ME!
+ * @param n DOCUMENT ME!
+ * @param m DOCUMENT ME!
+ * @param psize DOCUMENT ME!
+ */
+ public static void displayMatrix(Graphics g, int[][] mat, int n, int m,
+ int psize)
+ {
+ int max = -1000;
+ int min = 1000;
+
+ for (int i = 0; i < n; i++)
+ {
+ for (int j = 0; j < m; j++)
+ {
+ if (mat[i][j] >= max)
+ {
+ max = mat[i][j];
+ }
+
+ if (mat[i][j] <= min)
+ {
+ min = mat[i][j];
+ }
+ }
+ }
+
+ System.out.println(max + " " + min);
+
+ for (int i = 0; i < n; i++)
+ {
+ for (int j = 0; j < m; j++)
+ {
+ int x = psize * i;
+ int y = psize * j;
+
+ // System.out.println(mat[i][j]);
+ float score = (float) (mat[i][j] - min) / (float) (max - min);
+ g.setColor(new Color(score, 0, 0));
+ g.fillRect(x, y, psize, psize);
+
+ // System.out.println(x + " " + y + " " + score);
+ }
+ }
+ }
+}
diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java
index 20101dc..507d38b 100755
--- a/src/jalview/analysis/AlignmentSorter.java
+++ b/src/jalview/analysis/AlignmentSorter.java
@@ -1,469 +1,470 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.analysis;
-
-import jalview.datamodel.*;
-
-import jalview.util.*;
-
-import java.util.*;
-
-
-/** Data structure to hold and manipulate a multiple sequence alignment
- */
-public class AlignmentSorter
-{
- static boolean sortIdAscending = true;
- static int lastGroupHash = 0;
- static boolean sortGroupAscending = true;
- static AlignmentOrder lastOrder = null;
- static boolean sortOrderAscending = true;
- static NJTree lastTree = null;
- static boolean sortTreeAscending = true;
-
- /**
- * Sort by Percentage Identity
- *
- * @param align AlignmentI
- * @param s SequenceI
- */
- public static void sortByPID(AlignmentI align, SequenceI s)
- {
- int nSeq = align.getHeight();
-
- float[] scores = new float[nSeq];
- SequenceI[] seqs = new SequenceI[nSeq];
-
- for (int i = 0; i < nSeq; i++)
- {
- scores[i] = Comparison.PID(align.getSequenceAt(i), s);
- seqs[i] = align.getSequenceAt(i);
- }
-
- QuickSort.sort(scores, 0, scores.length - 1, seqs);
-
- setReverseOrder(align, seqs);
- }
-
- /**
- * Reverse the order of the sort
- *
- * @param align DOCUMENT ME!
- * @param seqs DOCUMENT ME!
- */
- private static void setReverseOrder(AlignmentI align, SequenceI[] seqs)
- {
- int nSeq = seqs.length;
-
- int len = 0;
-
- if ((nSeq % 2) == 0)
- {
- len = nSeq / 2;
- }
- else
- {
- len = (nSeq + 1) / 2;
- }
-
- // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
- for (int i = 0; i < len; i++)
- {
- //SequenceI tmp = seqs[i];
- align.getSequences().setElementAt(seqs[nSeq - i - 1], i);
- align.getSequences().setElementAt(seqs[i], nSeq - i - 1);
- }
- }
-
- /**
- * Sets the Alignment object with the given sequences
- *
- * @param align Alignment object to be updated
- * @param tmp sequences as a vector
- */
- private static void setOrder(AlignmentI align, Vector tmp)
- {
- setOrder(align, vectorSubsetToArray(tmp, align.getSequences()));
- }
-
- /**
- * Sets the Alignment object with the given sequences
- *
- * @param align DOCUMENT ME!
- * @param seqs sequences as an array
- */
- private static void setOrder(AlignmentI align, SequenceI[] seqs)
- {
- // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
- Vector algn = align.getSequences();
-
- for (int i = 0; i < seqs.length; i++)
- {
- algn.setElementAt(seqs[i], i);
- }
- }
-
- /**
- * Sorts by ID. Numbers are sorted before letters.
- *
- * @param align The alignment object to sort
- */
- public static void sortByID(AlignmentI align)
- {
- int nSeq = align.getHeight();
-
- String[] ids = new String[nSeq];
- SequenceI[] seqs = new SequenceI[nSeq];
-
- for (int i = 0; i < nSeq; i++)
- {
- ids[i] = align.getSequenceAt(i).getName();
- seqs[i] = align.getSequenceAt(i);
- }
-
- QuickSort.sort(ids, seqs);
-
- if (sortIdAscending)
- {
- setReverseOrder(align, seqs);
- }
- else
- {
- setOrder(align, seqs);
- }
-
- sortIdAscending = !sortIdAscending;
- }
-
- /**
- * Sorts the alignment by size of group.
- *
Maintains the order of sequences in each group
- * by order in given alignment object.
- *
- * @param align sorts the given alignment object by group
- */
- public static void sortByGroup(AlignmentI align)
- {
- //MAINTAINS ORIGNAL SEQUENCE ORDER,
- //ORDERS BY GROUP SIZE
- Vector groups = new Vector();
-
- if (groups.hashCode() != lastGroupHash)
- {
- sortGroupAscending = true;
- lastGroupHash = groups.hashCode();
- }
- else
- {
- sortGroupAscending = !sortGroupAscending;
- }
-
- //SORTS GROUPS BY SIZE
- //////////////////////
- for (int i = 0; i < align.getGroups().size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) align.getGroups().elementAt(i);
-
- for (int j = 0; j < groups.size(); j++)
- {
- SequenceGroup sg2 = (SequenceGroup) groups.elementAt(j);
-
- if (sg.getSize() > sg2.getSize())
- {
- groups.insertElementAt(sg, j);
-
- break;
- }
- }
-
- if (!groups.contains(sg))
- {
- groups.addElement(sg);
- }
- }
-
- //NOW ADD SEQUENCES MAINTAINING ALIGNMENT ORDER
- ///////////////////////////////////////////////
- Vector seqs = new Vector();
-
- for (int i = 0; i < groups.size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
- SequenceI[] orderedseqs = sg.getSequencesInOrder(align);
-
- for (int j = 0; j < orderedseqs.length; j++)
- {
- seqs.addElement(orderedseqs[j]);
- }
- }
-
- if (sortGroupAscending)
- {
- setOrder(align, seqs);
- }
- else
- {
- setReverseOrder(align,
- vectorSubsetToArray(seqs, align.getSequences()));
- }
- }
-
- /**
- * Converts Vector to array.
- * java 1.18 does not have Vector.toArray()
- *
- * @param tmp Vector of SequenceI objects
- *
- * @return array of Sequence[]
- */
- private static SequenceI[] vectorToArray(Vector tmp)
- {
- SequenceI[] seqs = new SequenceI[tmp.size()];
-
- for (int i = 0; i < tmp.size(); i++)
- {
- seqs[i] = (SequenceI) tmp.elementAt(i);
- }
-
- return seqs;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param tmp DOCUMENT ME!
- * @param mask DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- private static SequenceI[] vectorSubsetToArray(Vector tmp, Vector mask)
- {
- Vector seqs = new Vector();
- int i;
- boolean[] tmask = new boolean[mask.size()];
-
- for (i = 0; i < mask.size(); i++)
- tmask[i] = true;
-
- for (i = 0; i < tmp.size(); i++)
- {
- Object sq = tmp.elementAt(i);
-
- if (mask.contains(sq) && tmask[mask.indexOf(sq)])
- {
- tmask[mask.indexOf(sq)] = false;
- seqs.addElement(sq);
- }
- }
-
- for (i = 0; i < tmask.length; i++)
- if (tmask[i])
- {
- seqs.addElement(mask.elementAt(i));
- }
-
- return vectorToArray(seqs);
- }
-
- /**
- * Sorts by a given AlignmentOrder object
- *
- * @param align Alignment to order
- * @param order specified order for alignment
- */
- public static void sortBy(AlignmentI align, AlignmentOrder order)
- {
- // Get an ordered vector of sequences which may also be present in align
- Vector tmp = order.getOrder();
-
- if (lastOrder == order)
- {
- sortOrderAscending = !sortOrderAscending;
- }
- else
- {
- sortOrderAscending = true;
- }
-
- if (sortOrderAscending)
- {
- setOrder(align, tmp);
- }
- else
- {
- setReverseOrder(align,
- vectorSubsetToArray(tmp, align.getSequences()));
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param align alignment to order
- * @param tree tree which has
- *
- * @return DOCUMENT ME!
- */
- private static Vector getOrderByTree(AlignmentI align, NJTree tree)
- {
- int nSeq = align.getHeight();
-
- Vector tmp = new Vector();
-
- tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences());
-
- if (tmp.size() != nSeq)
- {
- // TODO: JBPNote - decide if this is always an error
- // (eg. not when a tree is associated to another alignment which has more
- // sequences)
- if (tmp.size() < nSeq)
- {
- addStrays(align, tmp);
- }
-
- if (tmp.size() != nSeq)
- {
- System.err.println("ERROR: tmp.size()=" + tmp.size() +
- " != nseq=" + nSeq + " in getOrderByTree");
- }
- }
-
- return tmp;
- }
-
- /**
- * Sorts the alignment by a given tree
- *
- * @param align alignment to order
- * @param tree tree which has
- */
- public static void sortByTree(AlignmentI align, NJTree tree)
- {
- Vector tmp = getOrderByTree(align, tree);
-
- // tmp should properly permute align with tree.
- if (lastTree != tree)
- {
- sortTreeAscending = true;
- lastTree = tree;
- }
- else
- {
- sortTreeAscending = !sortTreeAscending;
- }
-
- if (sortTreeAscending)
- {
- setOrder(align, tmp);
- }
- else
- {
- setReverseOrder(align,
- vectorSubsetToArray(tmp, align.getSequences()));
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param align DOCUMENT ME!
- * @param seqs DOCUMENT ME!
- */
- private static void addStrays(AlignmentI align, Vector seqs)
- {
- int nSeq = align.getHeight();
-
- for (int i = 0; i < nSeq; i++)
- {
- if (!seqs.contains(align.getSequenceAt(i)))
- {
- seqs.addElement(align.getSequenceAt(i));
- }
- }
-
- if (nSeq != seqs.size())
- {
- System.err.println(
- "ERROR: Size still not right even after addStrays");
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- * @param tmp DOCUMENT ME!
- * @param seqset DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- private static Vector _sortByTree(SequenceNode node, Vector tmp,
- Vector seqset)
- {
- if (node == null)
- {
- return tmp;
- }
-
- SequenceNode left = (SequenceNode) node.left();
- SequenceNode right = (SequenceNode) node.right();
-
- if ((left == null) && (right == null))
- {
- if (!node.isPlaceholder() && (node.element() != null))
- {
- if (node.element() instanceof SequenceI)
- {
- if (!tmp.contains(node.element()))
- {
- tmp.addElement((SequenceI) node.element());
- }
- }
- }
-
- return tmp;
- }
- else
- {
- _sortByTree(left, tmp, seqset);
- _sortByTree(right, tmp, seqset);
- }
-
- return tmp;
- }
-
- // Ordering Objects
- // Alignment.sortBy(OrderObj) - sequence of sequence pointer refs in appropriate order
- //
-
- /**
- * recover the order of sequences given by the safe numbering scheme introducd
- * SeqsetUtils.uniquify.
- */
- public static void recoverOrder(SequenceI[] alignment)
- {
- float[] ids = new float[alignment.length];
-
- for (int i = 0; i < alignment.length; i++)
- ids[i] = (new Float(alignment[i].getName().substring(8))).floatValue();
-
- jalview.util.QuickSort.sort(ids, alignment);
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.analysis;
+
+import jalview.datamodel.*;
+
+import jalview.util.*;
+
+import java.util.*;
+
+
+/** Data structure to hold and manipulate a multiple sequence alignment
+ */
+public class AlignmentSorter
+{
+ static boolean sortIdAscending = true;
+ static int lastGroupHash = 0;
+ static boolean sortGroupAscending = true;
+ static AlignmentOrder lastOrder = null;
+ static boolean sortOrderAscending = true;
+ static NJTree lastTree = null;
+ static boolean sortTreeAscending = true;
+
+ /**
+ * Sort by Percentage Identity
+ *
+ * @param align AlignmentI
+ * @param s SequenceI
+ */
+ public static void sortByPID(AlignmentI align, SequenceI s)
+ {
+ int nSeq = align.getHeight();
+
+ float[] scores = new float[nSeq];
+ SequenceI[] seqs = new SequenceI[nSeq];
+
+ for (int i = 0; i < nSeq; i++)
+ {
+ scores[i] = Comparison.PID(align.getSequenceAt(i).getSequence(),
+ s.getSequence());
+ seqs[i] = align.getSequenceAt(i);
+ }
+
+ QuickSort.sort(scores, 0, scores.length - 1, seqs);
+
+ setReverseOrder(align, seqs);
+ }
+
+ /**
+ * Reverse the order of the sort
+ *
+ * @param align DOCUMENT ME!
+ * @param seqs DOCUMENT ME!
+ */
+ private static void setReverseOrder(AlignmentI align, SequenceI[] seqs)
+ {
+ int nSeq = seqs.length;
+
+ int len = 0;
+
+ if ((nSeq % 2) == 0)
+ {
+ len = nSeq / 2;
+ }
+ else
+ {
+ len = (nSeq + 1) / 2;
+ }
+
+ // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
+ for (int i = 0; i < len; i++)
+ {
+ //SequenceI tmp = seqs[i];
+ align.getSequences().setElementAt(seqs[nSeq - i - 1], i);
+ align.getSequences().setElementAt(seqs[i], nSeq - i - 1);
+ }
+ }
+
+ /**
+ * Sets the Alignment object with the given sequences
+ *
+ * @param align Alignment object to be updated
+ * @param tmp sequences as a vector
+ */
+ private static void setOrder(AlignmentI align, Vector tmp)
+ {
+ setOrder(align, vectorSubsetToArray(tmp, align.getSequences()));
+ }
+
+ /**
+ * Sets the Alignment object with the given sequences
+ *
+ * @param align DOCUMENT ME!
+ * @param seqs sequences as an array
+ */
+ private static void setOrder(AlignmentI align, SequenceI[] seqs)
+ {
+ // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
+ Vector algn = align.getSequences();
+
+ for (int i = 0; i < seqs.length; i++)
+ {
+ algn.setElementAt(seqs[i], i);
+ }
+ }
+
+ /**
+ * Sorts by ID. Numbers are sorted before letters.
+ *
+ * @param align The alignment object to sort
+ */
+ public static void sortByID(AlignmentI align)
+ {
+ int nSeq = align.getHeight();
+
+ String[] ids = new String[nSeq];
+ SequenceI[] seqs = new SequenceI[nSeq];
+
+ for (int i = 0; i < nSeq; i++)
+ {
+ ids[i] = align.getSequenceAt(i).getName();
+ seqs[i] = align.getSequenceAt(i);
+ }
+
+ QuickSort.sort(ids, seqs);
+
+ if (sortIdAscending)
+ {
+ setReverseOrder(align, seqs);
+ }
+ else
+ {
+ setOrder(align, seqs);
+ }
+
+ sortIdAscending = !sortIdAscending;
+ }
+
+ /**
+ * Sorts the alignment by size of group.
+ *
Maintains the order of sequences in each group
+ * by order in given alignment object.
+ *
+ * @param align sorts the given alignment object by group
+ */
+ public static void sortByGroup(AlignmentI align)
+ {
+ //MAINTAINS ORIGNAL SEQUENCE ORDER,
+ //ORDERS BY GROUP SIZE
+ Vector groups = new Vector();
+
+ if (groups.hashCode() != lastGroupHash)
+ {
+ sortGroupAscending = true;
+ lastGroupHash = groups.hashCode();
+ }
+ else
+ {
+ sortGroupAscending = !sortGroupAscending;
+ }
+
+ //SORTS GROUPS BY SIZE
+ //////////////////////
+ for (int i = 0; i < align.getGroups().size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) align.getGroups().elementAt(i);
+
+ for (int j = 0; j < groups.size(); j++)
+ {
+ SequenceGroup sg2 = (SequenceGroup) groups.elementAt(j);
+
+ if (sg.getSize(false) > sg2.getSize(false))
+ {
+ groups.insertElementAt(sg, j);
+
+ break;
+ }
+ }
+
+ if (!groups.contains(sg))
+ {
+ groups.addElement(sg);
+ }
+ }
+
+ //NOW ADD SEQUENCES MAINTAINING ALIGNMENT ORDER
+ ///////////////////////////////////////////////
+ Vector seqs = new Vector();
+
+ for (int i = 0; i < groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
+ SequenceI[] orderedseqs = sg.getSequencesInOrder(align);
+
+ for (int j = 0; j < orderedseqs.length; j++)
+ {
+ seqs.addElement(orderedseqs[j]);
+ }
+ }
+
+ if (sortGroupAscending)
+ {
+ setOrder(align, seqs);
+ }
+ else
+ {
+ setReverseOrder(align,
+ vectorSubsetToArray(seqs, align.getSequences()));
+ }
+ }
+
+ /**
+ * Converts Vector to array.
+ * java 1.18 does not have Vector.toArray()
+ *
+ * @param tmp Vector of SequenceI objects
+ *
+ * @return array of Sequence[]
+ */
+ private static SequenceI[] vectorToArray(Vector tmp)
+ {
+ SequenceI[] seqs = new SequenceI[tmp.size()];
+
+ for (int i = 0; i < tmp.size(); i++)
+ {
+ seqs[i] = (SequenceI) tmp.elementAt(i);
+ }
+
+ return seqs;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param tmp DOCUMENT ME!
+ * @param mask DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ private static SequenceI[] vectorSubsetToArray(Vector tmp, Vector mask)
+ {
+ Vector seqs = new Vector();
+ int i;
+ boolean[] tmask = new boolean[mask.size()];
+
+ for (i = 0; i < mask.size(); i++)
+ tmask[i] = true;
+
+ for (i = 0; i < tmp.size(); i++)
+ {
+ Object sq = tmp.elementAt(i);
+
+ if (mask.contains(sq) && tmask[mask.indexOf(sq)])
+ {
+ tmask[mask.indexOf(sq)] = false;
+ seqs.addElement(sq);
+ }
+ }
+
+ for (i = 0; i < tmask.length; i++)
+ if (tmask[i])
+ {
+ seqs.addElement(mask.elementAt(i));
+ }
+
+ return vectorToArray(seqs);
+ }
+
+ /**
+ * Sorts by a given AlignmentOrder object
+ *
+ * @param align Alignment to order
+ * @param order specified order for alignment
+ */
+ public static void sortBy(AlignmentI align, AlignmentOrder order)
+ {
+ // Get an ordered vector of sequences which may also be present in align
+ Vector tmp = order.getOrder();
+
+ if (lastOrder == order)
+ {
+ sortOrderAscending = !sortOrderAscending;
+ }
+ else
+ {
+ sortOrderAscending = true;
+ }
+
+ if (sortOrderAscending)
+ {
+ setOrder(align, tmp);
+ }
+ else
+ {
+ setReverseOrder(align,
+ vectorSubsetToArray(tmp, align.getSequences()));
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param align alignment to order
+ * @param tree tree which has
+ *
+ * @return DOCUMENT ME!
+ */
+ private static Vector getOrderByTree(AlignmentI align, NJTree tree)
+ {
+ int nSeq = align.getHeight();
+
+ Vector tmp = new Vector();
+
+ tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences());
+
+ if (tmp.size() != nSeq)
+ {
+ // TODO: JBPNote - decide if this is always an error
+ // (eg. not when a tree is associated to another alignment which has more
+ // sequences)
+ if (tmp.size() < nSeq)
+ {
+ addStrays(align, tmp);
+ }
+
+ if (tmp.size() != nSeq)
+ {
+ System.err.println("ERROR: tmp.size()=" + tmp.size() +
+ " != nseq=" + nSeq + " in getOrderByTree");
+ }
+ }
+
+ return tmp;
+ }
+
+ /**
+ * Sorts the alignment by a given tree
+ *
+ * @param align alignment to order
+ * @param tree tree which has
+ */
+ public static void sortByTree(AlignmentI align, NJTree tree)
+ {
+ Vector tmp = getOrderByTree(align, tree);
+
+ // tmp should properly permute align with tree.
+ if (lastTree != tree)
+ {
+ sortTreeAscending = true;
+ lastTree = tree;
+ }
+ else
+ {
+ sortTreeAscending = !sortTreeAscending;
+ }
+
+ if (sortTreeAscending)
+ {
+ setOrder(align, tmp);
+ }
+ else
+ {
+ setReverseOrder(align,
+ vectorSubsetToArray(tmp, align.getSequences()));
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param align DOCUMENT ME!
+ * @param seqs DOCUMENT ME!
+ */
+ private static void addStrays(AlignmentI align, Vector seqs)
+ {
+ int nSeq = align.getHeight();
+
+ for (int i = 0; i < nSeq; i++)
+ {
+ if (!seqs.contains(align.getSequenceAt(i)))
+ {
+ seqs.addElement(align.getSequenceAt(i));
+ }
+ }
+
+ if (nSeq != seqs.size())
+ {
+ System.err.println(
+ "ERROR: Size still not right even after addStrays");
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ * @param tmp DOCUMENT ME!
+ * @param seqset DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ private static Vector _sortByTree(SequenceNode node, Vector tmp,
+ Vector seqset)
+ {
+ if (node == null)
+ {
+ return tmp;
+ }
+
+ SequenceNode left = (SequenceNode) node.left();
+ SequenceNode right = (SequenceNode) node.right();
+
+ if ((left == null) && (right == null))
+ {
+ if (!node.isPlaceholder() && (node.element() != null))
+ {
+ if (node.element() instanceof SequenceI)
+ {
+ if (!tmp.contains(node.element()))
+ {
+ tmp.addElement((SequenceI) node.element());
+ }
+ }
+ }
+
+ return tmp;
+ }
+ else
+ {
+ _sortByTree(left, tmp, seqset);
+ _sortByTree(right, tmp, seqset);
+ }
+
+ return tmp;
+ }
+
+ // Ordering Objects
+ // Alignment.sortBy(OrderObj) - sequence of sequence pointer refs in appropriate order
+ //
+
+ /**
+ * recover the order of sequences given by the safe numbering scheme introducd
+ * SeqsetUtils.uniquify.
+ */
+ public static void recoverOrder(SequenceI[] alignment)
+ {
+ float[] ids = new float[alignment.length];
+
+ for (int i = 0; i < alignment.length; i++)
+ ids[i] = (new Float(alignment[i].getName().substring(8))).floatValue();
+
+ jalview.util.QuickSort.sort(ids, alignment);
+ }
+}
diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java
index b9b68ce..7d831e8 100755
--- a/src/jalview/analysis/Conservation.java
+++ b/src/jalview/analysis/Conservation.java
@@ -1,563 +1,576 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.analysis;
-
-import jalview.datamodel.*;
-
-import java.util.*;
-
-
-/**
- * Calculates conservation values for a given set of sequences
- *
- * @author $author$
- * @version $Revision$
- */
-public class Conservation
-{
- Vector sequences;
- int start;
- int end;
- Vector seqNums; // vector of int vectors where first is sequence checksum
- int maxLength = 0; // used by quality calcs
- boolean seqNumsChanged = false; // updated after any change via calcSeqNum;
- Vector total = new Vector();
-
- /** Stores calculated quality values */
- public Vector quality;
-
- /** Stores maximum and minimum values of quality values */
- public Double[] qualityRange = new Double[2];
- String consString = "";
- Sequence consSequence;
- Hashtable propHash;
- int threshold;
- String name = "";
- int[][] cons2;
-
- /**
- * Creates a new Conservation object.
- *
- * @param name Name of conservation
- * @param propHash DOCUMENT ME!
- * @param threshold to count the residues in residueHash(). commonly used value is 3
- * @param sequences sequences to be used in calculation
- * @param start start residue position
- * @param end end residue position
- */
- public Conservation(String name, Hashtable propHash, int threshold,
- Vector sequences, int start, int end)
- {
- this.name = name;
- this.propHash = propHash;
- this.threshold = threshold;
- this.sequences = sequences;
- this.start = start;
- this.end = end;
- seqNums = new Vector(sequences.size());
- calcSeqNums();
- }
-
- /**
- * DOCUMENT ME!
- */
- private void calcSeqNums()
- {
- int i=0, iSize=sequences.size();
- for (i=0; i < iSize; i++)
- {
- calcSeqNum(i);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- private void calcSeqNum(int i)
- {
- String sq = null; // for dumb jbuilder not-inited exception warning
- int[] sqnum = null;
-
- if ((i > -1) && (i < sequences.size()))
- {
- sq = ((SequenceI) sequences.elementAt(i)).getSequence();
-
- if (seqNums.size() <= i)
- {
- seqNums.addElement(new int[sq.length() + 1]);
- }
-
- if (sq.hashCode() != ((int[]) seqNums.elementAt(i))[0])
- {
- int j;
- int len;
- seqNumsChanged = true;
- sq = ((SequenceI) sequences.elementAt(i)).getSequence();
- len = sq.length();
-
- if (maxLength < len)
- {
- maxLength = len;
- }
-
- sqnum = new int[len + 1]; // better to always make a new array - sequence can change its length
- sqnum[0] = sq.hashCode();
-
- for (j = 1; j <= len; j++)
- {
- sqnum[j] = ((Integer) jalview.schemes.ResidueProperties.aaHash.get(String.valueOf(
- sq.charAt(j - 1)))).intValue(); // yuk - JBPNote - case taken care of in aaHash
- }
-
- seqNums.setElementAt(sqnum, i);
- }
- }
- else
- {
- // JBPNote INFO level debug
- System.err.println(
- "ERROR: calcSeqNum called with out of range sequence index for Alignment\n");
- }
- }
-
- /**
- * Calculates the conservation values for given set of sequences
- */
- public void calculate()
- {
- Hashtable resultHash, residueHash, ht;
- int count, thresh, j, jSize = sequences.size();
- String sequence, res, type;
- Enumeration enumeration, enumeration2;
-
- for (int i = start; i <= end; i++)
- {
- resultHash = new Hashtable();
- residueHash = new Hashtable();
-
- for (j = 0; j < jSize; j++)
- {
- // JBPNote - have to make sure elements of the sequences vector
- // are tested like this everywhere...
- if (sequences.elementAt(j) instanceof Sequence)
- {
- sequence = ((Sequence) sequences.elementAt(j)).getSequence();
-
- if (sequence.length() > i)
- {
- res = String.valueOf(Character.toUpperCase(sequence.charAt(i)));
-
- if (residueHash.containsKey(res))
- {
- count = ((Integer) residueHash.get(res)).intValue();
- count++;
- residueHash.put(res, new Integer(count));
- }
- else
- {
- residueHash.put(res, new Integer(1));
- }
- }
- else
- {
- if (residueHash.containsKey("-"))
- {
- count = ((Integer) residueHash.get("-")).intValue();
- count++;
- residueHash.put("-", new Integer(count));
- }
- else
- {
- residueHash.put("-", new Integer(1));
- }
- }
- }
- }
-
- //What is the count threshold to count the residues in residueHash()
- thresh = (threshold * (sequences.size())) / 100;
-
- //loop over all the found residues
- enumeration = residueHash.keys();
-
- while (enumeration.hasMoreElements())
- {
- res = (String) enumeration.nextElement();
-
- if (((Integer) residueHash.get(res)).intValue() > thresh)
- {
- //Now loop over the properties
- enumeration2 = propHash.keys();
-
- while (enumeration2.hasMoreElements())
- {
- type = (String) enumeration2.nextElement();
- ht = (Hashtable) propHash.get(type);
-
- //Have we ticked this before?
- if (!resultHash.containsKey(type))
- {
- if (ht.containsKey(res))
- {
- resultHash.put(type, ht.get(res));
- }
- else
- {
- resultHash.put(type, ht.get("-"));
- }
- }
- else if (((Integer) resultHash.get(type)).equals(
- (Integer) ht.get(res)) == false)
- {
- resultHash.put(type, new Integer(-1));
- }
- }
- }
- }
-
- total.addElement(resultHash);
- }
- }
-
-
- /***
- * countConsNGaps
- * returns gap count in int[0], and conserved residue count in int[1]
- */
- public int[] countConsNGaps(int j)
- {
- int count = 0;
- int cons = 0;
- int nres = 0;
- int[] r = new int[2];
- char f = '$';
- int i, iSize = sequences.size();
- char c;
-
- for (i = 0; i < iSize; i++)
- {
- if (j >= ((Sequence) sequences.elementAt(i)).getLength())
- {
- count++;
- continue;
- }
-
- c = ((Sequence) sequences.elementAt(i)).getCharAt(j); // gaps do not have upper/lower case
-
- if (jalview.util.Comparison.isGap((c)))
- {
- count++;
- }
- else
- {
- nres++;
-
- if (nres == 1)
- {
- f = c;
- cons++;
- }
- else if (f == c)
- {
- cons++;
- }
- }
- }
-
- r[0] = (nres == cons) ? 1 : 0;
- r[1] = count;
-
- return r;
- }
-
- /**
- * Calculates the conservation sequence
- *
- * @param consflag if true, poitiveve conservation; false calculates negative conservation
- * @param percentageGaps commonly used value is 25
- */
- public void verdict(boolean consflag, float percentageGaps)
- {
- StringBuffer consString = new StringBuffer();
- String type;
- Integer result;
- int[] gapcons;
- int totGaps, count;
- float pgaps;
- Hashtable resultHash ;
- Enumeration enumeration;
-
-
- for (int i = start; i <= end; i++)
- {
- gapcons = countConsNGaps(i);
- totGaps = gapcons[1];
- pgaps = ((float) totGaps * 100) / (float) sequences.size();
-
- if (percentageGaps > pgaps)
- {
- resultHash = (Hashtable) total.elementAt(i - start);
-
- //Now find the verdict
- count = 0;
- enumeration = resultHash.keys();
-
- while (enumeration.hasMoreElements())
- {
- type = (String) enumeration.nextElement();
- result = (Integer) resultHash.get(type);
-
- //Do we want to count +ve conservation or +ve and -ve cons.?
- if (consflag)
- {
- if (result.intValue() == 1)
- {
- count++;
- }
- }
- else
- {
- if (result.intValue() != -1)
- {
- count++;
- }
- }
- }
-
- if (count < 10)
- {
- consString.append(count); // Conserved props!=Identity
- }
- else
- {
- consString.append((gapcons[0] == 1) ? "*" : "+");
- }
- }
- else
- {
- consString.append("-");
- }
- }
-
- consSequence = new Sequence(name, consString.toString(), start, end);
- }
-
- /**
- *
- *
- * @return Conservation sequence
- */
- public Sequence getConsSequence()
- {
- return consSequence;
- }
-
- // From Alignment.java in jalview118
- public void findQuality()
- {
- findQuality(0, maxLength - 1);
- }
-
- /**
- * DOCUMENT ME!
- */
- private void percentIdentity2()
- {
- calcSeqNums(); // updates maxLength, too.
-
- if ((cons2 == null) || seqNumsChanged)
- {
- cons2 = new int[maxLength][24];
-
- // Initialize the array
- for (int j = 0; j < 24; j++)
- {
- for (int i = 0; i < maxLength; i++)
- {
- cons2[i][j] = 0;
- }
- }
-
- int[] sqnum;
- int j = 0;
-
- while (j < sequences.size())
- {
- sqnum = (int[]) seqNums.elementAt(j);
-
- for (int i = 1; i < sqnum.length; i++)
- {
- cons2[i - 1][sqnum[i]]++;
- }
-
- for (int i = sqnum.length - 1; i < maxLength; i++)
- {
- cons2[i][23]++; // gap count
- }
-
- j++;
- }
-
- // unnecessary ?
-
- /* for (int i=start; i <= end; i++) {
- int max = -1000;
- int maxi = -1;
- int maxj = -1;
-
- for (int j=0;j<24;j++) {
- if (cons2[i][j] > max) {
- max = cons2[i][j];
- maxi = i;
- maxj = j;
- }
-
- }
- } */
- }
- }
-
- /**
- * Calculates the quality of the set of sequences
- *
- * @param start Start residue
- * @param end End residue
- */
- public void findQuality(int start, int end)
- {
- quality = new Vector();
-
- double max = -10000;
- int[][] BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62();
-
- //Loop over columns // JBPNote Profiling info
- // long ts = System.currentTimeMillis();
- //long te = System.currentTimeMillis();
- percentIdentity2();
-
- int size = seqNums.size();
- int[] lengths = new int[size];
- double tot, bigtot, sr, tmp;
- double [] x, xx;
- int l, j, i, ii, seqNum;
-
- for (l = 0; l < size; l++)
- lengths[l] = ((int[]) seqNums.elementAt(l)).length - 1;
-
-
- for (j = start; j <= end; j++)
- {
- bigtot = 0;
-
- // First Xr = depends on column only
- x = new double[24];
-
- for (ii = 0; ii < 24; ii++)
- {
- x[ii] = 0;
-
- try
- {
- for (int i2 = 0; i2 < 24; i2++)
- {
- x[ii] += (((double) cons2[j][i2] * BLOSUM62[ii][i2]) +
- 4);
- }
- }
- catch (Exception e)
- {
- System.err.println("Exception during quality calculation.");
- e.printStackTrace();
- }
-
- //System.out.println("X " + ii + " " + x[ii]);
- x[ii] /= (size);
-
- //System.out.println("X " + ii + " " + x[ii]);
- }
-
- // Now calculate D for each position and sum
- for (int k = 0; k < size; k++)
- {
- tot = 0;
- xx = new double[24];
- seqNum = (j < lengths[k])
- ? ((int[]) seqNums.elementAt(k))[j + 1] : 23; // Sequence, or gap at the end
-
- // This is a loop over r
- for (i = 0; i < 23; i++)
- {
- sr = 0;
-
- try
- {
- sr = (double) BLOSUM62[i][seqNum] + 4;
- }
- catch (Exception e)
- {
- System.out.println("Exception in sr: " + e);
- e.printStackTrace();
- }
-
- //Calculate X with another loop over residues
- // System.out.println("Xi " + i + " " + x[i] + " " + sr);
- xx[i] = x[i] - sr;
-
- tot += (xx[i] * xx[i]);
- }
-
- bigtot += Math.sqrt(tot);
- }
-
- // This is the quality for one column
- if (max < bigtot)
- {
- max = bigtot;
- }
-
- // bigtot = bigtot * (size-cons2[j][23])/size;
- quality.addElement(new Double(bigtot));
-
-
- // Need to normalize by gaps
- }
-
- double newmax = -10000;
-
- for (j = start; j <= end; j++)
- {
- tmp = ((Double) quality.elementAt(j)).doubleValue();
- tmp = ((max - tmp) * (size - cons2[j][23])) / size;
-
- // System.out.println(tmp+ " " + j);
- quality.setElementAt(new Double(tmp), j);
-
- if (tmp > newmax)
- {
- newmax = tmp;
- }
- }
-
- // System.out.println("Quality " + s);
- qualityRange[0] = new Double(0);
- qualityRange[1] = new Double(newmax);
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.analysis;
+
+import jalview.datamodel.*;
+
+import java.util.*;
+
+
+/**
+ * Calculates conservation values for a given set of sequences
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Conservation
+{
+ Vector sequences;
+ int start;
+ int end;
+ Vector seqNums; // vector of int vectors where first is sequence checksum
+ int maxLength = 0; // used by quality calcs
+ boolean seqNumsChanged = false; // updated after any change via calcSeqNum;
+ Vector total = new Vector();
+
+ /** Stores calculated quality values */
+ public Vector quality;
+
+ /** Stores maximum and minimum values of quality values */
+ public Double[] qualityRange = new Double[2];
+ String consString = "";
+ Sequence consSequence;
+ Hashtable propHash;
+ int threshold;
+ String name = "";
+ int[][] cons2;
+
+ /**
+ * Creates a new Conservation object.
+ *
+ * @param name Name of conservation
+ * @param propHash DOCUMENT ME!
+ * @param threshold to count the residues in residueHash(). commonly used value is 3
+ * @param sequences sequences to be used in calculation
+ * @param start start residue position
+ * @param end end residue position
+ */
+ public Conservation(String name, Hashtable propHash, int threshold,
+ Vector sequences, int start, int end)
+ {
+ this.name = name;
+ this.propHash = propHash;
+ this.threshold = threshold;
+ this.sequences = sequences;
+ this.start = start;
+ this.end = end;
+ seqNums = new Vector(sequences.size());
+ calcSeqNums();
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ private void calcSeqNums()
+ {
+ int i=0, iSize=sequences.size();
+ for (i=0; i < iSize; i++)
+ {
+ calcSeqNum(i);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ private void calcSeqNum(int i)
+ {
+ String sq = null; // for dumb jbuilder not-inited exception warning
+ int[] sqnum = null;
+
+ if ((i > -1) && (i < sequences.size()))
+ {
+ sq = ((SequenceI) sequences.elementAt(i)).getSequence();
+
+ if (seqNums.size() <= i)
+ {
+ seqNums.addElement(new int[sq.length() + 1]);
+ }
+
+ if (sq.hashCode() != ((int[]) seqNums.elementAt(i))[0])
+ {
+ int j;
+ int len;
+ seqNumsChanged = true;
+ sq = ((SequenceI) sequences.elementAt(i)).getSequence();
+ len = sq.length();
+
+ if (maxLength < len)
+ {
+ maxLength = len;
+ }
+
+ sqnum = new int[len + 1]; // better to always make a new array - sequence can change its length
+ sqnum[0] = sq.hashCode();
+
+ for (j = 1; j <= len; j++)
+ {
+ sqnum[j] = ((Integer) jalview.schemes.ResidueProperties.aaHash.get(String.valueOf(
+ sq.charAt(j - 1)))).intValue(); // yuk - JBPNote - case taken care of in aaHash
+ }
+
+ seqNums.setElementAt(sqnum, i);
+ }
+ }
+ else
+ {
+ // JBPNote INFO level debug
+ System.err.println(
+ "ERROR: calcSeqNum called with out of range sequence index for Alignment\n");
+ }
+ }
+
+ /**
+ * Calculates the conservation values for given set of sequences
+ */
+ public void calculate()
+ {
+ Hashtable resultHash, residueHash, ht;
+ int count, thresh, j, jSize = sequences.size();
+ String type, res=null;
+ SequenceI sequence;
+ char c;
+ Enumeration enumeration, enumeration2;
+
+ for (int i = start; i <= end; i++)
+ {
+ resultHash = new Hashtable();
+ residueHash = new Hashtable();
+
+ for (j = 0; j < jSize; j++)
+ {
+ // JBPNote - have to make sure elements of the sequences vector
+ // are tested like this everywhere...
+ sequence = (Sequence) sequences.elementAt(j);
+
+ if (sequence.getLength() > i)
+ {
+ c = sequence.getCharAt(i);
+
+ // No need to check if its a '-'
+ if(c == '.' || c==' ')
+ c = '-';
+
+ if ('a' <= c && c <= 'z')
+ {
+ // TO UPPERCASE !!!
+ //Faster than toUpperCase
+ c -= ('a' - 'A') ;
+ }
+
+ res = String.valueOf( c );
+
+
+ if (residueHash.containsKey(res))
+ {
+ count = ((Integer) residueHash.get(res)).intValue();
+ count++;
+ residueHash.put(res, new Integer(count));
+ }
+ else
+ {
+ residueHash.put(res, new Integer(1));
+ }
+ }
+ else
+ {
+ if (residueHash.containsKey("-"))
+ {
+ count = ((Integer) residueHash.get("-")).intValue();
+ count++;
+ residueHash.put("-", new Integer(count));
+ }
+ else
+ {
+ residueHash.put("-", new Integer(1));
+ }
+ }
+ }
+
+ //What is the count threshold to count the residues in residueHash()
+ thresh = (threshold * (sequences.size())) / 100;
+
+ //loop over all the found residues
+ enumeration = residueHash.keys();
+
+ while (enumeration.hasMoreElements())
+ {
+ res = (String) enumeration.nextElement();
+
+ if (((Integer) residueHash.get(res)).intValue() > thresh)
+ {
+ //Now loop over the properties
+ enumeration2 = propHash.keys();
+
+ while (enumeration2.hasMoreElements())
+ {
+ type = (String) enumeration2.nextElement();
+ ht = (Hashtable) propHash.get(type);
+
+ //Have we ticked this before?
+ if (!resultHash.containsKey(type))
+ {
+ if (ht.containsKey(res))
+ {
+ resultHash.put(type, ht.get(res));
+ }
+ else
+ {
+ resultHash.put(type, ht.get("-"));
+ }
+ }
+ else if (((Integer) resultHash.get(type)).equals(
+ (Integer) ht.get(res)) == false)
+ {
+ resultHash.put(type, new Integer(-1));
+ }
+ }
+ }
+ }
+
+ total.addElement(resultHash);
+ }
+ }
+
+
+ /***
+ * countConsNGaps
+ * returns gap count in int[0], and conserved residue count in int[1]
+ */
+ public int[] countConsNGaps(int j)
+ {
+ int count = 0;
+ int cons = 0;
+ int nres = 0;
+ int[] r = new int[2];
+ char f = '$';
+ int i, iSize = sequences.size();
+ char c;
+
+ for (i = 0; i < iSize; i++)
+ {
+ if (j >= ((Sequence) sequences.elementAt(i)).getLength())
+ {
+ count++;
+ continue;
+ }
+
+ c = ((Sequence) sequences.elementAt(i)).getCharAt(j); // gaps do not have upper/lower case
+
+ if (jalview.util.Comparison.isGap((c)))
+ {
+ count++;
+ }
+ else
+ {
+ nres++;
+
+ if (nres == 1)
+ {
+ f = c;
+ cons++;
+ }
+ else if (f == c)
+ {
+ cons++;
+ }
+ }
+ }
+
+ r[0] = (nres == cons) ? 1 : 0;
+ r[1] = count;
+
+ return r;
+ }
+
+ /**
+ * Calculates the conservation sequence
+ *
+ * @param consflag if true, poitiveve conservation; false calculates negative conservation
+ * @param percentageGaps commonly used value is 25
+ */
+ public void verdict(boolean consflag, float percentageGaps)
+ {
+ StringBuffer consString = new StringBuffer();
+ String type;
+ Integer result;
+ int[] gapcons;
+ int totGaps, count;
+ float pgaps;
+ Hashtable resultHash ;
+ Enumeration enumeration;
+
+
+ for (int i = start; i <= end; i++)
+ {
+ gapcons = countConsNGaps(i);
+ totGaps = gapcons[1];
+ pgaps = ((float) totGaps * 100) / (float) sequences.size();
+
+ if (percentageGaps > pgaps)
+ {
+ resultHash = (Hashtable) total.elementAt(i - start);
+
+ //Now find the verdict
+ count = 0;
+ enumeration = resultHash.keys();
+
+ while (enumeration.hasMoreElements())
+ {
+ type = (String) enumeration.nextElement();
+ result = (Integer) resultHash.get(type);
+
+ //Do we want to count +ve conservation or +ve and -ve cons.?
+ if (consflag)
+ {
+ if (result.intValue() == 1)
+ {
+ count++;
+ }
+ }
+ else
+ {
+ if (result.intValue() != -1)
+ {
+ count++;
+ }
+ }
+ }
+
+ if (count < 10)
+ {
+ consString.append(count); // Conserved props!=Identity
+ }
+ else
+ {
+ consString.append((gapcons[0] == 1) ? "*" : "+");
+ }
+ }
+ else
+ {
+ consString.append("-");
+ }
+ }
+
+ consSequence = new Sequence(name, consString.toString(), start, end);
+ }
+
+ /**
+ *
+ *
+ * @return Conservation sequence
+ */
+ public Sequence getConsSequence()
+ {
+ return consSequence;
+ }
+
+ // From Alignment.java in jalview118
+ public void findQuality()
+ {
+ findQuality(0, maxLength - 1);
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ private void percentIdentity2()
+ {
+ calcSeqNums(); // updates maxLength, too.
+
+ if ((cons2 == null) || seqNumsChanged)
+ {
+ cons2 = new int[maxLength][24];
+
+ // Initialize the array
+ for (int j = 0; j < 24; j++)
+ {
+ for (int i = 0; i < maxLength; i++)
+ {
+ cons2[i][j] = 0;
+ }
+ }
+
+ int[] sqnum;
+ int j = 0;
+
+ while (j < sequences.size())
+ {
+ sqnum = (int[]) seqNums.elementAt(j);
+
+ for (int i = 1; i < sqnum.length; i++)
+ {
+ cons2[i - 1][sqnum[i]]++;
+ }
+
+ for (int i = sqnum.length - 1; i < maxLength; i++)
+ {
+ cons2[i][23]++; // gap count
+ }
+
+ j++;
+ }
+
+ // unnecessary ?
+
+ /* for (int i=start; i <= end; i++) {
+ int max = -1000;
+ int maxi = -1;
+ int maxj = -1;
+
+ for (int j=0;j<24;j++) {
+ if (cons2[i][j] > max) {
+ max = cons2[i][j];
+ maxi = i;
+ maxj = j;
+ }
+
+ }
+ } */
+ }
+ }
+
+ /**
+ * Calculates the quality of the set of sequences
+ *
+ * @param start Start residue
+ * @param end End residue
+ */
+ public void findQuality(int start, int end)
+ {
+ quality = new Vector();
+
+ double max = -10000;
+ int[][] BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62();
+
+ //Loop over columns // JBPNote Profiling info
+ // long ts = System.currentTimeMillis();
+ //long te = System.currentTimeMillis();
+ percentIdentity2();
+
+ int size = seqNums.size();
+ int[] lengths = new int[size];
+ double tot, bigtot, sr, tmp;
+ double [] x, xx;
+ int l, j, i, ii, seqNum;
+
+ for (l = 0; l < size; l++)
+ lengths[l] = ((int[]) seqNums.elementAt(l)).length - 1;
+
+
+ for (j = start; j <= end; j++)
+ {
+ bigtot = 0;
+
+ // First Xr = depends on column only
+ x = new double[24];
+
+ for (ii = 0; ii < 24; ii++)
+ {
+ x[ii] = 0;
+
+ try
+ {
+ for (int i2 = 0; i2 < 24; i2++)
+ {
+ x[ii] += (((double) cons2[j][i2] * BLOSUM62[ii][i2]) +
+ 4);
+ }
+ }
+ catch (Exception e)
+ {
+ System.err.println("Exception during quality calculation.");
+ e.printStackTrace();
+ }
+
+ //System.out.println("X " + ii + " " + x[ii]);
+ x[ii] /= (size);
+
+ //System.out.println("X " + ii + " " + x[ii]);
+ }
+
+ // Now calculate D for each position and sum
+ for (int k = 0; k < size; k++)
+ {
+ tot = 0;
+ xx = new double[24];
+ seqNum = (j < lengths[k])
+ ? ((int[]) seqNums.elementAt(k))[j + 1] : 23; // Sequence, or gap at the end
+
+ // This is a loop over r
+ for (i = 0; i < 23; i++)
+ {
+ sr = 0;
+
+ try
+ {
+ sr = (double) BLOSUM62[i][seqNum] + 4;
+ }
+ catch (Exception e)
+ {
+ System.out.println("Exception in sr: " + e);
+ e.printStackTrace();
+ }
+
+ //Calculate X with another loop over residues
+ // System.out.println("Xi " + i + " " + x[i] + " " + sr);
+ xx[i] = x[i] - sr;
+
+ tot += (xx[i] * xx[i]);
+ }
+
+ bigtot += Math.sqrt(tot);
+ }
+
+ // This is the quality for one column
+ if (max < bigtot)
+ {
+ max = bigtot;
+ }
+
+ // bigtot = bigtot * (size-cons2[j][23])/size;
+ quality.addElement(new Double(bigtot));
+
+
+ // Need to normalize by gaps
+ }
+
+ double newmax = -10000;
+
+ for (j = start; j <= end; j++)
+ {
+ tmp = ((Double) quality.elementAt(j)).doubleValue();
+ tmp = ((max - tmp) * (size - cons2[j][23])) / size;
+
+ // System.out.println(tmp+ " " + j);
+ quality.setElementAt(new Double(tmp), j);
+
+ if (tmp > newmax)
+ {
+ newmax = tmp;
+ }
+ }
+
+ // System.out.println("Quality " + s);
+ qualityRange[0] = new Double(0);
+ qualityRange[1] = new Double(newmax);
+ }
+}
diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java
index 40dfc9b..e029771 100755
--- a/src/jalview/analysis/NJTree.java
+++ b/src/jalview/analysis/NJTree.java
@@ -1,1190 +1,1248 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.analysis;
-
-import jalview.datamodel.*;
-
-import jalview.io.NewickFile;
-
-import jalview.schemes.ResidueProperties;
-
-import jalview.util.*;
-
-import java.util.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class NJTree
-{
- Vector cluster;
- SequenceI[] sequence;
- int[] done;
- int noseqs;
- int noClus;
- float[][] distance;
- int mini;
- int minj;
- float ri;
- float rj;
- Vector groups = new Vector();
- SequenceNode maxdist;
- SequenceNode top;
- float maxDistValue;
- float maxheight;
- int ycount;
- Vector node;
- String type;
- String pwtype;
- Object found = null;
- Object leaves = null;
- int start;
- int end;
- boolean hasDistances = true; // normal case for jalview trees
- boolean hasBootstrap = false; // normal case for jalview trees
-
- private boolean hasRootDistance = true;
-
- /**
- * Creates a new NJTree object.
- *
- * @param node DOCUMENT ME!
- */
- public NJTree(SequenceNode node)
- {
- top = node;
- maxheight = findHeight(top);
- }
-
- /**
- * Creates a new NJTree object.
- *
- * @param seqs DOCUMENT ME!
- * @param treefile DOCUMENT ME!
- */
- public NJTree(SequenceI[] seqs, NewickFile treefile)
- {
- top = treefile.getTree();
-
- hasDistances = treefile.HasDistances();
- hasBootstrap = treefile.HasBootstrap();
- hasRootDistance = treefile.HasRootDistance();
-
- maxheight = findHeight(top);
-
- SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);
-
- Vector leaves = new Vector();
- findLeaves(top, leaves);
-
- int i = 0;
- int namesleft = seqs.length;
-
- SequenceNode j;
- SequenceI nam;
- String realnam;
-
- while (i < leaves.size())
- {
- j = (SequenceNode) leaves.elementAt(i++);
- realnam = j.getName();
- nam = null;
-
- if (namesleft > -1)
- {
- nam = algnIds.findIdMatch(realnam);
- }
-
- if (nam != null)
- {
- j.setElement(nam);
- namesleft--;
- }
- else
- {
- j.setElement(new Sequence(realnam, "THISISAPLACEHLDER"));
- j.setPlaceholder(true);
- }
- }
- }
-
- /**
- * Creates a new NJTree object.
- *
- * @param sequence DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- */
- public NJTree(SequenceI[] sequence, int start, int end)
- {
- this(sequence, "NJ", "BL", start, end);
- }
-
- /**
- * Creates a new NJTree object.
- *
- * @param sequence DOCUMENT ME!
- * @param type DOCUMENT ME!
- * @param pwtype DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- */
- public NJTree(SequenceI[] sequence, String type, String pwtype, int start,
- int end)
- {
- this.sequence = sequence;
- this.node = new Vector();
- this.type = type;
- this.pwtype = pwtype;
- this.start = start;
- this.end = end;
-
- if (!(type.equals("NJ")))
- {
- type = "AV";
- }
-
- if (!(pwtype.equals("PID")))
- {
- type = "BL";
- }
-
- int i = 0;
-
- done = new int[sequence.length];
-
- while ((i < sequence.length) && (sequence[i] != null))
- {
- done[i] = 0;
- i++;
- }
-
- noseqs = i++;
-
- distance = findDistances();
-
- makeLeaves();
-
- noClus = cluster.size();
-
- cluster();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String toString()
- {
- jalview.io.NewickFile fout = new jalview.io.NewickFile(getTopNode());
-
- return fout.print(false, true); // distances only
- }
-
- /**
- *
- * used when the alignment associated to a tree has changed.
- *
- * @param alignment Vector
- */
- public void UpdatePlaceHolders(Vector alignment)
- {
- Vector leaves = new Vector();
- findLeaves(top, leaves);
-
- int sz = leaves.size();
- SequenceIdMatcher seqmatcher = null;
- int i = 0;
-
- while (i < sz)
- {
- SequenceNode leaf = (SequenceNode) leaves.elementAt(i++);
-
- if (alignment.contains(leaf.element()))
- {
- leaf.setPlaceholder(false);
- }
- else
- {
- if (seqmatcher == null)
- {
- // Only create this the first time we need it
- SequenceI[] seqs = new SequenceI[alignment.size()];
-
- for (int j = 0; j < seqs.length; j++)
- seqs[j] = (SequenceI) alignment.elementAt(j);
-
- seqmatcher = new SequenceIdMatcher(seqs);
- }
-
- SequenceI nam = seqmatcher.findIdMatch(leaf.getName());
-
- if (nam != null)
- {
- leaf.setPlaceholder(false);
- leaf.setElement(nam);
- }
- else
- {
- leaf.setPlaceholder(true);
- }
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- public void cluster()
- {
- while (noClus > 2)
- {
- if (type.equals("NJ"))
- {
- findMinNJDistance();
- }
- else
- {
- findMinDistance();
- }
-
- Cluster c = joinClusters(mini, minj);
-
- done[minj] = 1;
-
- cluster.setElementAt(null, minj);
- cluster.setElementAt(c, mini);
-
- noClus--;
- }
-
- boolean onefound = false;
-
- int one = -1;
- int two = -1;
-
- for (int i = 0; i < noseqs; i++)
- {
- if (done[i] != 1)
- {
- if (onefound == false)
- {
- two = i;
- onefound = true;
- }
- else
- {
- one = i;
- }
- }
- }
-
- joinClusters(one, two);
- top = (SequenceNode) (node.elementAt(one));
-
- reCount(top);
- findHeight(top);
- findMaxDist(top);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param j DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Cluster joinClusters(int i, int j)
- {
- float dist = distance[i][j];
-
- int noi = ((Cluster) cluster.elementAt(i)).value.length;
- int noj = ((Cluster) cluster.elementAt(j)).value.length;
-
- int[] value = new int[noi + noj];
-
- for (int ii = 0; ii < noi; ii++)
- {
- value[ii] = ((Cluster) cluster.elementAt(i)).value[ii];
- }
-
- for (int ii = noi; ii < (noi + noj); ii++)
- {
- value[ii] = ((Cluster) cluster.elementAt(j)).value[ii - noi];
- }
-
- Cluster c = new Cluster(value);
-
- ri = findr(i, j);
- rj = findr(j, i);
-
- if (type.equals("NJ"))
- {
- findClusterNJDistance(i, j);
- }
- else
- {
- findClusterDistance(i, j);
- }
-
- SequenceNode sn = new SequenceNode();
-
- sn.setLeft((SequenceNode) (node.elementAt(i)));
- sn.setRight((SequenceNode) (node.elementAt(j)));
-
- SequenceNode tmpi = (SequenceNode) (node.elementAt(i));
- SequenceNode tmpj = (SequenceNode) (node.elementAt(j));
-
- if (type.equals("NJ"))
- {
- findNewNJDistances(tmpi, tmpj, dist);
- }
- else
- {
- findNewDistances(tmpi, tmpj, dist);
- }
-
- tmpi.setParent(sn);
- tmpj.setParent(sn);
-
- node.setElementAt(sn, i);
-
- return c;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param tmpi DOCUMENT ME!
- * @param tmpj DOCUMENT ME!
- * @param dist DOCUMENT ME!
- */
- public void findNewNJDistances(SequenceNode tmpi, SequenceNode tmpj,
- float dist)
- {
-
- tmpi.dist = ((dist + ri) - rj) / 2;
- tmpj.dist = (dist - tmpi.dist);
-
- if (tmpi.dist < 0)
- {
- tmpi.dist = 0;
- }
-
- if (tmpj.dist < 0)
- {
- tmpj.dist = 0;
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param tmpi DOCUMENT ME!
- * @param tmpj DOCUMENT ME!
- * @param dist DOCUMENT ME!
- */
- public void findNewDistances(SequenceNode tmpi, SequenceNode tmpj,
- float dist)
- {
- float ih = 0;
- float jh = 0;
-
- SequenceNode sni = tmpi;
- SequenceNode snj = tmpj;
-
- while (sni != null)
- {
- ih = ih + sni.dist;
- sni = (SequenceNode) sni.left();
- }
-
- while (snj != null)
- {
- jh = jh + snj.dist;
- snj = (SequenceNode) snj.left();
- }
-
- tmpi.dist = ((dist / 2) - ih);
- tmpj.dist = ((dist / 2) - jh);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param j DOCUMENT ME!
- */
- public void findClusterDistance(int i, int j)
- {
- int noi = ((Cluster) cluster.elementAt(i)).value.length;
- int noj = ((Cluster) cluster.elementAt(j)).value.length;
-
- // New distances from cluster to others
- float[] newdist = new float[noseqs];
-
- for (int l = 0; l < noseqs; l++)
- {
- if ((l != i) && (l != j))
- {
- newdist[l] = ((distance[i][l] * noi) + (distance[j][l] * noj)) / (noi +
- noj);
- }
- else
- {
- newdist[l] = 0;
- }
- }
-
- for (int ii = 0; ii < noseqs; ii++)
- {
- distance[i][ii] = newdist[ii];
- distance[ii][i] = newdist[ii];
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param j DOCUMENT ME!
- */
- public void findClusterNJDistance(int i, int j)
- {
-
- // New distances from cluster to others
- float[] newdist = new float[noseqs];
-
- for (int l = 0; l < noseqs; l++)
- {
- if ((l != i) && (l != j))
- {
- newdist[l] = ((distance[i][l] + distance[j][l]) -
- distance[i][j]) / 2;
- }
- else
- {
- newdist[l] = 0;
- }
- }
-
- for (int ii = 0; ii < noseqs; ii++)
- {
- distance[i][ii] = newdist[ii];
- distance[ii][i] = newdist[ii];
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param j DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public float findr(int i, int j)
- {
- float tmp = 1;
-
- for (int k = 0; k < noseqs; k++)
- {
- if ((k != i) && (k != j) && (done[k] != 1))
- {
- tmp = tmp + distance[i][k];
- }
- }
-
- if (noClus > 2)
- {
- tmp = tmp / (noClus - 2);
- }
-
- return tmp;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public float findMinNJDistance()
- {
- float min = 100000;
-
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i + 1; j < noseqs; j++)
- {
- if ((done[i] != 1) && (done[j] != 1))
- {
- float tmp = distance[i][j] - (findr(i, j) + findr(j, i));
-
- if (tmp < min)
- {
- mini = i;
- minj = j;
-
- min = tmp;
- }
- }
- }
- }
-
- return min;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public float findMinDistance()
- {
- float min = 100000;
-
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i + 1; j < noseqs; j++)
- {
- if ((done[i] != 1) && (done[j] != 1))
- {
- if (distance[i][j] < min)
- {
- mini = i;
- minj = j;
-
- min = distance[i][j];
- }
- }
- }
- }
-
- return min;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public float[][] findDistances()
- {
- float[][] distance = new float[noseqs][noseqs];
-
- if (pwtype.equals("PID"))
- {
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i; j < noseqs; j++)
- {
- if (j == i)
- {
- distance[i][i] = 0;
- }
- else
- {
- distance[i][j] = 100 -
- Comparison.PID(sequence[i], sequence[j], start, end);
- distance[j][i] = distance[i][j];
- }
- }
- }
- }
- else if (pwtype.equals("BL"))
- {
- int maxscore = 0;
-
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i; j < noseqs; j++)
- {
- int score = 0;
-
- for (int k = start; k < end; k++)
- {
- try
- {
- score += ResidueProperties.getBLOSUM62(sequence[i].getSequence(
- k, k + 1), sequence[j].getSequence(k, k +
- 1));
- }
- catch (Exception ex)
- {
- System.err.println("err creating BLOSUM62 tree");
- ex.printStackTrace();
- }
- }
-
- distance[i][j] = (float) score;
-
- if (score > maxscore)
- {
- maxscore = score;
- }
- }
- }
-
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i; j < noseqs; j++)
- {
- distance[i][j] = (float) maxscore - distance[i][j];
- distance[j][i] = distance[i][j];
- }
- }
- }
- else if (pwtype.equals("SW"))
- {
- float max = -1;
-
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i; j < noseqs; j++)
- {
- AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep");
- as.calcScoreMatrix();
- as.traceAlignment();
- as.printAlignment(System.out);
- distance[i][j] = (float) as.maxscore;
-
- if (max < distance[i][j])
- {
- max = distance[i][j];
- }
- }
- }
-
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i; j < noseqs; j++)
- {
- distance[i][j] = max - distance[i][j];
- distance[j][i] = distance[i][j];
- }
- }
- }
-
- return distance;
- }
-
- /**
- * DOCUMENT ME!
- */
- public void makeLeaves()
- {
- cluster = new Vector();
-
- for (int i = 0; i < noseqs; i++)
- {
- SequenceNode sn = new SequenceNode();
-
- sn.setElement(sequence[i]);
- sn.setName(sequence[i].getName());
- node.addElement(sn);
-
- int[] value = new int[1];
- value[0] = i;
-
- Cluster c = new Cluster(value);
- cluster.addElement(c);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- * @param leaves DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector findLeaves(SequenceNode node, Vector leaves)
- {
- if (node == null)
- {
- return leaves;
- }
-
- if ((node.left() == null) && (node.right() == null))
- {
- leaves.addElement(node);
-
- return leaves;
- }
- else
- {
- findLeaves((SequenceNode) node.left(), leaves);
- findLeaves((SequenceNode) node.right(), leaves);
- }
-
- return leaves;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- * @param count DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Object findLeaf(SequenceNode node, int count)
- {
- found = _findLeaf(node, count);
-
- return found;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- * @param count DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Object _findLeaf(SequenceNode node, int count)
- {
- if (node == null)
- {
- return null;
- }
-
- if (node.ycount == count)
- {
- found = node.element();
-
- return found;
- }
- else
- {
- _findLeaf((SequenceNode) node.left(), count);
- _findLeaf((SequenceNode) node.right(), count);
- }
-
- return found;
- }
-
- /**
- * printNode is mainly for debugging purposes.
- *
- * @param node SequenceNode
- */
- public void printNode(SequenceNode node)
- {
- if (node == null)
- {
- return;
- }
-
- if ((node.left() == null) && (node.right() == null))
- {
- System.out.println("Leaf = " +
- ((SequenceI) node.element()).getName());
- System.out.println("Dist " + ((SequenceNode) node).dist);
- System.out.println("Boot " + node.getBootstrap());
- }
- else
- {
- System.out.println("Dist " + ((SequenceNode) node).dist);
- printNode((SequenceNode) node.left());
- printNode((SequenceNode) node.right());
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- */
- public void findMaxDist(SequenceNode node)
- {
- if (node == null)
- {
- return;
- }
-
- if ((node.left() == null) && (node.right() == null))
- {
- float dist = ((SequenceNode) node).dist;
-
- if (dist > maxDistValue)
- {
- maxdist = (SequenceNode) node;
- maxDistValue = dist;
- }
- }
- else
- {
- findMaxDist((SequenceNode) node.left());
- findMaxDist((SequenceNode) node.right());
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector getGroups()
- {
- return groups;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public float getMaxHeight()
- {
- return maxheight;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- * @param threshold DOCUMENT ME!
- */
- public void groupNodes(SequenceNode node, float threshold)
- {
- if (node == null)
- {
- return;
- }
-
- if ((node.height / maxheight) > threshold)
- {
- groups.addElement(node);
- }
- else
- {
- groupNodes((SequenceNode) node.left(), threshold);
- groupNodes((SequenceNode) node.right(), threshold);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public float findHeight(SequenceNode node)
- {
- if (node == null)
- {
- return maxheight;
- }
-
- if ((node.left() == null) && (node.right() == null))
- {
- node.height = ((SequenceNode) node.parent()).height + node.dist;
-
- if (node.height > maxheight)
- {
- return node.height;
- }
- else
- {
- return maxheight;
- }
- }
- else
- {
- if (node.parent() != null)
- {
- node.height = ((SequenceNode) node.parent()).height +
- node.dist;
- }
- else
- {
- maxheight = 0;
- node.height = (float) 0.0;
- }
-
- maxheight = findHeight((SequenceNode) (node.left()));
- maxheight = findHeight((SequenceNode) (node.right()));
- }
-
- return maxheight;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceNode reRoot()
- {
- if (maxdist != null)
- {
- ycount = 0;
-
- float tmpdist = maxdist.dist;
-
- // New top
- SequenceNode sn = new SequenceNode();
- sn.setParent(null);
-
- // New right hand of top
- SequenceNode snr = (SequenceNode) maxdist.parent();
- changeDirection(snr, maxdist);
- System.out.println("Printing reversed tree");
- printN(snr);
- snr.dist = tmpdist / 2;
- maxdist.dist = tmpdist / 2;
-
- snr.setParent(sn);
- maxdist.setParent(sn);
-
- sn.setRight(snr);
- sn.setLeft(maxdist);
-
- top = sn;
-
- ycount = 0;
- reCount(top);
- findHeight(top);
- }
-
- return top;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- */
- public static void printN(SequenceNode node)
- {
- if (node == null)
- {
- return;
- }
-
- if ((node.left() != null) && (node.right() != null))
- {
- printN((SequenceNode) node.left());
- printN((SequenceNode) node.right());
- }
- else
- {
- System.out.println(" name = " +
- ((SequenceI) node.element()).getName());
- }
-
- System.out.println(" dist = " + ((SequenceNode) node).dist + " " +
- ((SequenceNode) node).count + " " + ((SequenceNode) node).height);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- */
- public void reCount(SequenceNode node)
- {
- ycount = 0;
- _reCount(node);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- */
- public void _reCount(SequenceNode node)
- {
- if (node == null)
- {
- return;
- }
-
- if ((node.left() != null) && (node.right() != null))
- {
- _reCount((SequenceNode) node.left());
- _reCount((SequenceNode) node.right());
-
- SequenceNode l = (SequenceNode) node.left();
- SequenceNode r = (SequenceNode) node.right();
-
- ((SequenceNode) node).count = l.count + r.count;
- ((SequenceNode) node).ycount = (l.ycount + r.ycount) / 2;
- }
- else
- {
- ((SequenceNode) node).count = 1;
- ((SequenceNode) node).ycount = ycount++;
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- */
- public void swapNodes(SequenceNode node)
- {
- if (node == null)
- {
- return;
- }
-
- SequenceNode tmp = (SequenceNode) node.left();
-
- node.setLeft(node.right());
- node.setRight(tmp);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node DOCUMENT ME!
- * @param dir DOCUMENT ME!
- */
- public void changeDirection(SequenceNode node, SequenceNode dir)
- {
- if (node == null)
- {
- return;
- }
-
- if (node.parent() != top)
- {
- changeDirection((SequenceNode) node.parent(), node);
-
- SequenceNode tmp = (SequenceNode) node.parent();
-
- if (dir == node.left())
- {
- node.setParent(dir);
- node.setLeft(tmp);
- }
- else if (dir == node.right())
- {
- node.setParent(dir);
- node.setRight(tmp);
- }
- }
- else
- {
- if (dir == node.left())
- {
- node.setParent(node.left());
-
- if (top.left() == node)
- {
- node.setRight(top.right());
- }
- else
- {
- node.setRight(top.left());
- }
- }
- else
- {
- node.setParent(node.right());
-
- if (top.left() == node)
- {
- node.setLeft(top.right());
- }
- else
- {
- node.setLeft(top.left());
- }
- }
- }
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceNode getMaxDist()
- {
- return maxdist;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceNode getTopNode()
- {
- return top;
- }
- /**
- *
- * @return true if tree has real distances
- */
- public boolean isHasDistances() {
- return hasDistances;
- }
-
- /**
- *
- * @return true if tree has real bootstrap values
- */
- public boolean isHasBootstrap() {
- return hasBootstrap;
- }
-
- public boolean isHasRootDistance()
- {
- return hasRootDistance;
- }
-
-}
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-class Cluster
-{
- int[] value;
-
- /**
- * Creates a new Cluster object.
- *
- * @param value DOCUMENT ME!
- */
- public Cluster(int[] value)
- {
- this.value = value;
- }
-}
-
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.analysis;
+
+import jalview.datamodel.*;
+
+import jalview.io.NewickFile;
+
+import jalview.schemes.ResidueProperties;
+
+import jalview.util.*;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class NJTree
+{
+ Vector cluster;
+ SequenceI[] sequence;
+
+ //SequenceData is a string representation of what the user
+ //sees. The display may contain hidden columns.
+ public AlignmentView seqData=null;
+
+ int[] done;
+ int noseqs;
+ int noClus;
+ float[][] distance;
+ int mini;
+ int minj;
+ float ri;
+ float rj;
+ Vector groups = new Vector();
+ SequenceNode maxdist;
+ SequenceNode top;
+ float maxDistValue;
+ float maxheight;
+ int ycount;
+ Vector node;
+ String type;
+ String pwtype;
+ Object found = null;
+ Object leaves = null;
+
+ boolean hasDistances = true; // normal case for jalview trees
+ boolean hasBootstrap = false; // normal case for jalview trees
+
+ private boolean hasRootDistance = true;
+
+ /**
+ * Create a new NJTree object with leaves associated with sequences in seqs,
+ * and original alignment data represented by Cigar strings.
+ * @param seqs SequenceI[]
+ * @param odata Cigar[]
+ * @param treefile NewickFile
+ */
+ public NJTree(SequenceI[] seqs, AlignmentView odata, NewickFile treefile) {
+ this(seqs, treefile);
+ if (odata!=null)
+ seqData = odata;
+ /*
+ sequenceString = new String[odata.length];
+ char gapChar = jalview.util.Comparison.GapChars.charAt(0);
+ for (int i = 0; i < odata.length; i++)
+ {
+ SequenceI oseq_aligned = odata[i].getSeq(gapChar);
+ sequenceString[i] = oseq_aligned.getSequence();
+ } */
+ }
+
+ /**
+ * Creates a new NJTree object from a tree from an external source
+ *
+ * @param seqs SequenceI which should be associated with leafs of treefile
+ * @param treefile A parsed tree
+ */
+ public NJTree(SequenceI[] seqs, NewickFile treefile)
+ {
+ this.sequence = seqs;
+ top = treefile.getTree();
+
+ /**
+ * There is no dependent alignment to be recovered from an
+ * imported tree.
+ *
+ if (sequenceString == null)
+ {
+ sequenceString = new String[seqs.length];
+ for (int i = 0; i < seqs.length; i++)
+ {
+ sequenceString[i] = seqs[i].getSequence();
+ }
+ }
+ */
+
+ hasDistances = treefile.HasDistances();
+ hasBootstrap = treefile.HasBootstrap();
+ hasRootDistance = treefile.HasRootDistance();
+
+ maxheight = findHeight(top);
+
+ SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);
+
+ Vector leaves = new Vector();
+ findLeaves(top, leaves);
+
+ int i = 0;
+ int namesleft = seqs.length;
+
+ SequenceNode j;
+ SequenceI nam;
+ String realnam;
+
+ while (i < leaves.size())
+ {
+ j = (SequenceNode) leaves.elementAt(i++);
+ realnam = j.getName();
+ nam = null;
+
+ if (namesleft > -1)
+ {
+ nam = algnIds.findIdMatch(realnam);
+ }
+
+ if (nam != null)
+ {
+ j.setElement(nam);
+ namesleft--;
+ }
+ else
+ {
+ j.setElement(new Sequence(realnam, "THISISAPLACEHLDER"));
+ j.setPlaceholder(true);
+ }
+ }
+ }
+
+ /**
+ * Creates a new NJTree object.
+ *
+ * @param sequence DOCUMENT ME!
+ * @param type DOCUMENT ME!
+ * @param pwtype DOCUMENT ME!
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ */
+ public NJTree(SequenceI[] sequence,
+ AlignmentView seqData,
+ String type,
+ String pwtype,
+ int start, int end)
+ {
+ this.sequence = sequence;
+ this.node = new Vector();
+ this.type = type;
+ this.pwtype = pwtype;
+ if (seqData!=null) {
+ this.seqData = seqData;
+ } else {
+ SeqCigar[] seqs = new SeqCigar[sequence.length];
+ for(int i=0; i 2)
+ {
+ if (type.equals("NJ"))
+ {
+ findMinNJDistance();
+ }
+ else
+ {
+ findMinDistance();
+ }
+
+ Cluster c = joinClusters(mini, minj);
+
+ done[minj] = 1;
+
+ cluster.setElementAt(null, minj);
+ cluster.setElementAt(c, mini);
+
+ noClus--;
+ }
+
+ boolean onefound = false;
+
+ int one = -1;
+ int two = -1;
+
+ for (int i = 0; i < noseqs; i++)
+ {
+ if (done[i] != 1)
+ {
+ if (onefound == false)
+ {
+ two = i;
+ onefound = true;
+ }
+ else
+ {
+ one = i;
+ }
+ }
+ }
+
+ joinClusters(one, two);
+ top = (SequenceNode) (node.elementAt(one));
+
+ reCount(top);
+ findHeight(top);
+ findMaxDist(top);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Cluster joinClusters(int i, int j)
+ {
+ float dist = distance[i][j];
+
+ int noi = ((Cluster) cluster.elementAt(i)).value.length;
+ int noj = ((Cluster) cluster.elementAt(j)).value.length;
+
+ int[] value = new int[noi + noj];
+
+ for (int ii = 0; ii < noi; ii++)
+ {
+ value[ii] = ((Cluster) cluster.elementAt(i)).value[ii];
+ }
+
+ for (int ii = noi; ii < (noi + noj); ii++)
+ {
+ value[ii] = ((Cluster) cluster.elementAt(j)).value[ii - noi];
+ }
+
+ Cluster c = new Cluster(value);
+
+ ri = findr(i, j);
+ rj = findr(j, i);
+
+ if (type.equals("NJ"))
+ {
+ findClusterNJDistance(i, j);
+ }
+ else
+ {
+ findClusterDistance(i, j);
+ }
+
+ SequenceNode sn = new SequenceNode();
+
+ sn.setLeft((SequenceNode) (node.elementAt(i)));
+ sn.setRight((SequenceNode) (node.elementAt(j)));
+
+ SequenceNode tmpi = (SequenceNode) (node.elementAt(i));
+ SequenceNode tmpj = (SequenceNode) (node.elementAt(j));
+
+ if (type.equals("NJ"))
+ {
+ findNewNJDistances(tmpi, tmpj, dist);
+ }
+ else
+ {
+ findNewDistances(tmpi, tmpj, dist);
+ }
+
+ tmpi.setParent(sn);
+ tmpj.setParent(sn);
+
+ node.setElementAt(sn, i);
+
+ return c;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param tmpi DOCUMENT ME!
+ * @param tmpj DOCUMENT ME!
+ * @param dist DOCUMENT ME!
+ */
+ public void findNewNJDistances(SequenceNode tmpi, SequenceNode tmpj,
+ float dist)
+ {
+
+ tmpi.dist = ((dist + ri) - rj) / 2;
+ tmpj.dist = (dist - tmpi.dist);
+
+ if (tmpi.dist < 0)
+ {
+ tmpi.dist = 0;
+ }
+
+ if (tmpj.dist < 0)
+ {
+ tmpj.dist = 0;
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param tmpi DOCUMENT ME!
+ * @param tmpj DOCUMENT ME!
+ * @param dist DOCUMENT ME!
+ */
+ public void findNewDistances(SequenceNode tmpi, SequenceNode tmpj,
+ float dist)
+ {
+ float ih = 0;
+ float jh = 0;
+
+ SequenceNode sni = tmpi;
+ SequenceNode snj = tmpj;
+
+ while (sni != null)
+ {
+ ih = ih + sni.dist;
+ sni = (SequenceNode) sni.left();
+ }
+
+ while (snj != null)
+ {
+ jh = jh + snj.dist;
+ snj = (SequenceNode) snj.left();
+ }
+
+ tmpi.dist = ((dist / 2) - ih);
+ tmpj.dist = ((dist / 2) - jh);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ */
+ public void findClusterDistance(int i, int j)
+ {
+ int noi = ((Cluster) cluster.elementAt(i)).value.length;
+ int noj = ((Cluster) cluster.elementAt(j)).value.length;
+
+ // New distances from cluster to others
+ float[] newdist = new float[noseqs];
+
+ for (int l = 0; l < noseqs; l++)
+ {
+ if ((l != i) && (l != j))
+ {
+ newdist[l] = ((distance[i][l] * noi) + (distance[j][l] * noj)) / (noi +
+ noj);
+ }
+ else
+ {
+ newdist[l] = 0;
+ }
+ }
+
+ for (int ii = 0; ii < noseqs; ii++)
+ {
+ distance[i][ii] = newdist[ii];
+ distance[ii][i] = newdist[ii];
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ */
+ public void findClusterNJDistance(int i, int j)
+ {
+
+ // New distances from cluster to others
+ float[] newdist = new float[noseqs];
+
+ for (int l = 0; l < noseqs; l++)
+ {
+ if ((l != i) && (l != j))
+ {
+ newdist[l] = ((distance[i][l] + distance[j][l]) -
+ distance[i][j]) / 2;
+ }
+ else
+ {
+ newdist[l] = 0;
+ }
+ }
+
+ for (int ii = 0; ii < noseqs; ii++)
+ {
+ distance[i][ii] = newdist[ii];
+ distance[ii][i] = newdist[ii];
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public float findr(int i, int j)
+ {
+ float tmp = 1;
+
+ for (int k = 0; k < noseqs; k++)
+ {
+ if ((k != i) && (k != j) && (done[k] != 1))
+ {
+ tmp = tmp + distance[i][k];
+ }
+ }
+
+ if (noClus > 2)
+ {
+ tmp = tmp / (noClus - 2);
+ }
+
+ return tmp;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public float findMinNJDistance()
+ {
+ float min = 100000;
+
+ for (int i = 0; i < (noseqs - 1); i++)
+ {
+ for (int j = i + 1; j < noseqs; j++)
+ {
+ if ((done[i] != 1) && (done[j] != 1))
+ {
+ float tmp = distance[i][j] - (findr(i, j) + findr(j, i));
+
+ if (tmp < min)
+ {
+ mini = i;
+ minj = j;
+
+ min = tmp;
+ }
+ }
+ }
+ }
+
+ return min;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public float findMinDistance()
+ {
+ float min = 100000;
+
+ for (int i = 0; i < (noseqs - 1); i++)
+ {
+ for (int j = i + 1; j < noseqs; j++)
+ {
+ if ((done[i] != 1) && (done[j] != 1))
+ {
+ if (distance[i][j] < min)
+ {
+ mini = i;
+ minj = j;
+
+ min = distance[i][j];
+ }
+ }
+ }
+ }
+
+ return min;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public float[][] findDistances(String[] sequenceString)
+ {
+ float[][] distance = new float[noseqs][noseqs];
+
+ if (pwtype.equals("PID"))
+ {
+ for (int i = 0; i < (noseqs - 1); i++)
+ {
+ for (int j = i; j < noseqs; j++)
+ {
+ if (j == i)
+ {
+ distance[i][i] = 0;
+ }
+ else
+ {
+ distance[i][j] = 100 -
+ Comparison.PID(sequenceString[i], sequenceString[j]);
+
+ distance[j][i] = distance[i][j];
+ }
+ }
+ }
+ }
+ else if (pwtype.equals("BL"))
+ {
+ int maxscore = 0;
+ int end = sequenceString[0].length();
+ for (int i = 0; i < (noseqs - 1); i++)
+ {
+ for (int j = i; j < noseqs; j++)
+ {
+ int score = 0;
+
+ for (int k = 0; k < end; k++)
+ {
+ try
+ {
+ score += ResidueProperties.getBLOSUM62(
+ sequenceString[i].substring(k, k + 1),
+ sequenceString[j].substring(k, k + 1));
+ }
+ catch (Exception ex)
+ {
+ System.err.println("err creating BLOSUM62 tree");
+ ex.printStackTrace();
+ }
+ }
+
+ distance[i][j] = (float) score;
+
+ if (score > maxscore)
+ {
+ maxscore = score;
+ }
+ }
+ }
+
+ for (int i = 0; i < (noseqs - 1); i++)
+ {
+ for (int j = i; j < noseqs; j++)
+ {
+ distance[i][j] = (float) maxscore - distance[i][j];
+ distance[j][i] = distance[i][j];
+ }
+ }
+ }
+ /* else if (pwtype.equals("SW"))
+ {
+ float max = -1;
+
+ for (int i = 0; i < (noseqs - 1); i++)
+ {
+ for (int j = i; j < noseqs; j++)
+ {
+ AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep");
+ as.calcScoreMatrix();
+ as.traceAlignment();
+ as.printAlignment(System.out);
+ distance[i][j] = (float) as.maxscore;
+
+ if (max < distance[i][j])
+ {
+ max = distance[i][j];
+ }
+ }
+ }
+
+ for (int i = 0; i < (noseqs - 1); i++)
+ {
+ for (int j = i; j < noseqs; j++)
+ {
+ distance[i][j] = max - distance[i][j];
+ distance[j][i] = distance[i][j];
+ }
+ }
+ }/*/
+
+ return distance;
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void makeLeaves()
+ {
+ cluster = new Vector();
+
+ for (int i = 0; i < noseqs; i++)
+ {
+ SequenceNode sn = new SequenceNode();
+
+ sn.setElement(sequence[i]);
+ sn.setName(sequence[i].getName());
+ node.addElement(sn);
+
+ int[] value = new int[1];
+ value[0] = i;
+
+ Cluster c = new Cluster(value);
+ cluster.addElement(c);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ * @param leaves DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Vector findLeaves(SequenceNode node, Vector leaves)
+ {
+ if (node == null)
+ {
+ return leaves;
+ }
+
+ if ((node.left() == null) && (node.right() == null))
+ {
+ leaves.addElement(node);
+
+ return leaves;
+ }
+ else
+ {
+ findLeaves((SequenceNode) node.left(), leaves);
+ findLeaves((SequenceNode) node.right(), leaves);
+ }
+
+ return leaves;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ * @param count DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Object findLeaf(SequenceNode node, int count)
+ {
+ found = _findLeaf(node, count);
+
+ return found;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ * @param count DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Object _findLeaf(SequenceNode node, int count)
+ {
+ if (node == null)
+ {
+ return null;
+ }
+
+ if (node.ycount == count)
+ {
+ found = node.element();
+
+ return found;
+ }
+ else
+ {
+ _findLeaf((SequenceNode) node.left(), count);
+ _findLeaf((SequenceNode) node.right(), count);
+ }
+
+ return found;
+ }
+
+ /**
+ * printNode is mainly for debugging purposes.
+ *
+ * @param node SequenceNode
+ */
+ public void printNode(SequenceNode node)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ if ((node.left() == null) && (node.right() == null))
+ {
+ System.out.println("Leaf = " +
+ ((SequenceI) node.element()).getName());
+ System.out.println("Dist " + ((SequenceNode) node).dist);
+ System.out.println("Boot " + node.getBootstrap());
+ }
+ else
+ {
+ System.out.println("Dist " + ((SequenceNode) node).dist);
+ printNode((SequenceNode) node.left());
+ printNode((SequenceNode) node.right());
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ */
+ public void findMaxDist(SequenceNode node)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ if ((node.left() == null) && (node.right() == null))
+ {
+ float dist = ((SequenceNode) node).dist;
+
+ if (dist > maxDistValue)
+ {
+ maxdist = (SequenceNode) node;
+ maxDistValue = dist;
+ }
+ }
+ else
+ {
+ findMaxDist((SequenceNode) node.left());
+ findMaxDist((SequenceNode) node.right());
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Vector getGroups()
+ {
+ return groups;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public float getMaxHeight()
+ {
+ return maxheight;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ * @param threshold DOCUMENT ME!
+ */
+ public void groupNodes(SequenceNode node, float threshold)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ if ((node.height / maxheight) > threshold)
+ {
+ groups.addElement(node);
+ }
+ else
+ {
+ groupNodes((SequenceNode) node.left(), threshold);
+ groupNodes((SequenceNode) node.right(), threshold);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public float findHeight(SequenceNode node)
+ {
+ if (node == null)
+ {
+ return maxheight;
+ }
+
+ if ((node.left() == null) && (node.right() == null))
+ {
+ node.height = ((SequenceNode) node.parent()).height + node.dist;
+
+ if (node.height > maxheight)
+ {
+ return node.height;
+ }
+ else
+ {
+ return maxheight;
+ }
+ }
+ else
+ {
+ if (node.parent() != null)
+ {
+ node.height = ((SequenceNode) node.parent()).height +
+ node.dist;
+ }
+ else
+ {
+ maxheight = 0;
+ node.height = (float) 0.0;
+ }
+
+ maxheight = findHeight((SequenceNode) (node.left()));
+ maxheight = findHeight((SequenceNode) (node.right()));
+ }
+
+ return maxheight;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceNode reRoot()
+ {
+ if (maxdist != null)
+ {
+ ycount = 0;
+
+ float tmpdist = maxdist.dist;
+
+ // New top
+ SequenceNode sn = new SequenceNode();
+ sn.setParent(null);
+
+ // New right hand of top
+ SequenceNode snr = (SequenceNode) maxdist.parent();
+ changeDirection(snr, maxdist);
+ System.out.println("Printing reversed tree");
+ printN(snr);
+ snr.dist = tmpdist / 2;
+ maxdist.dist = tmpdist / 2;
+
+ snr.setParent(sn);
+ maxdist.setParent(sn);
+
+ sn.setRight(snr);
+ sn.setLeft(maxdist);
+
+ top = sn;
+
+ ycount = 0;
+ reCount(top);
+ findHeight(top);
+ }
+
+ return top;
+ }
+ /**
+ *
+ * @return true if original sequence data can be recovered
+ */
+ public boolean hasOriginalSequenceData() {
+ return seqData!=null;
+ }
+ /**
+ * Returns original alignment data used for calculation - or null where
+ * not available.
+ *
+ * @return null or cut'n'pasteable alignment
+ */
+ public String printOriginalSequenceData(char gapChar)
+ {
+ if (seqData==null)
+ return null;
+
+ StringBuffer sb = new StringBuffer();
+ String[] seqdatas = seqData.getSequenceStrings(gapChar);
+ for(int i=0; i0) {
- for (int i=0;i0)
- {
- sq.setPDBId(pdbid);
- }
-
- if ( (start != null) && (end != null))
- {
- sq.setStart(start.intValue());
- sq.setEnd(end.intValue());
- }
-
- if ((sfeatures != null) && (sfeatures.size()>0))
- {
- SequenceFeature[] sfarray = (SequenceFeature[]) sfeatures.toArray();
- sq.setSequenceFeatures(sfarray);
- }
-
- if ((seqds!=null) && !(seqds.getName().equals("THISISAPLACEHOLDER") && seqds.getLength()==0)) {
- sq.setDatasetSequence(seqds);
- }
-
- return namePresent;
- }
-
- /**
- * Form of the unique name used in uniquify for the i'th sequence in an ordered vector of sequences.
- * @param i int
- * @return String
- */
- public static String unique_name(int i)
- {
- return new String("Sequence" + i);
- }
-
- /**
- * Generates a hash of SeqCharacterHash properties for each sequence
- * in a sequence set, and optionally renames the sequences to an
- * unambiguous 'safe' name.
- * @param sequences SequenceI[]
- * @param write_names boolean set this to rename each of the sequences to its unique_name(index) name
- * @return Hashtable to be passed to @see deuniquify to recover original names (and properties) for renamed sequences
- */
- public static Hashtable uniquify(SequenceI[] sequences, boolean write_names)
- {
- // Generate a safely named sequence set and a hash to recover the sequence names
- Hashtable map = new Hashtable();
- //String[] un_names = new String[sequences.length];
-
- for (int i = 0; i < sequences.length; i++)
- {
- String safename = unique_name(i);
- map.put(safename, SeqCharacterHash(sequences[i]));
-
- if (write_names)
- {
- sequences[i].setName(safename);
- }
- }
-
-
- return map;
- }
- /**
- * recover unsafe sequence names and original properties for a sequence
- * set using a map generated by @see uniquify(sequences,true)
- * @param map Hashtable
- * @param sequences SequenceI[]
- * @return boolean
- */
- public static boolean deuniquify(Hashtable map, SequenceI[] sequences)
- {
- jalview.analysis.SequenceIdMatcher matcher = new SequenceIdMatcher(sequences);
- SequenceI msq = null;
- Enumeration keys = map.keys();
- Vector unmatched = new Vector();
- for (int i=0, j=sequences.length; i0) {
- System.err.println("Did not find matches for :");
- for (Enumeration i = unmatched.elements(); i.hasMoreElements(); System.out.println(((SequenceI) i.nextElement()).getName()))
- ;
- return false;
- }
-
- return true;
- }
- /**
- * returns a subset of the sequenceI seuqences,
- * including only those that contain at least one residue.
- * @param sequences SequenceI[]
- * @return SequenceI[]
- */
- public static SequenceI[] getNonEmptySequenceSet(SequenceI[] sequences) {
- // Identify first row of alignment with residues for prediction
- boolean ungapped[] = new boolean[sequences.length];
- int msflen=0;
- for (int i=0,j=sequences.length; iTitle:
+ *
+ * Description:
+ *
+ * Copyright: Copyright (c) 2004
+ *
+ * Company: Dundee University
+ *
+ * @author not attributable
+ * @version 1.0
+ */
+public class SeqsetUtils
+{
+
+ /**
+ * Store essential properties of a sequence in a hashtable for later recovery
+ * Keys are Name, Start, End, SeqFeatures, PdbId
+ * @param seq SequenceI
+ * @return Hashtable
+ */
+ public static Hashtable SeqCharacterHash(SequenceI seq)
+ {
+ Hashtable sqinfo = new Hashtable();
+ sqinfo.put("Name", seq.getName());
+ sqinfo.put("Start", new Integer(seq.getStart()));
+ sqinfo.put("End", new Integer(seq.getEnd()));
+ Vector sfeat = new Vector();
+ jalview.datamodel.SequenceFeature[] sfarray=seq.getSequenceFeatures();
+ if (sfarray!=null && sfarray.length>0) {
+ for (int i=0;i0)
+ {
+ sq.setPDBId(pdbid);
+ }
+
+ if ( (start != null) && (end != null))
+ {
+ sq.setStart(start.intValue());
+ sq.setEnd(end.intValue());
+ }
+
+ if ((sfeatures != null) && (sfeatures.size()>0))
+ {
+ SequenceFeature[] sfarray = (SequenceFeature[]) sfeatures.toArray();
+ sq.setSequenceFeatures(sfarray);
+ }
+
+ if ((seqds!=null) && !(seqds.getName().equals("THISISAPLACEHOLDER") && seqds.getLength()==0)) {
+ sq.setDatasetSequence(seqds);
+ }
+
+ return namePresent;
+ }
+
+ /**
+ * Form of the unique name used in uniquify for the i'th sequence in an ordered vector of sequences.
+ * @param i int
+ * @return String
+ */
+ public static String unique_name(int i)
+ {
+ return new String("Sequence" + i);
+ }
+
+ /**
+ * Generates a hash of SeqCharacterHash properties for each sequence
+ * in a sequence set, and optionally renames the sequences to an
+ * unambiguous 'safe' name.
+ * @param sequences SequenceI[]
+ * @param write_names boolean set this to rename each of the sequences to its unique_name(index) name
+ * @return Hashtable to be passed to @see deuniquify to recover original names (and properties) for renamed sequences
+ */
+ public static Hashtable uniquify(SequenceI[] sequences, boolean write_names)
+ {
+ // Generate a safely named sequence set and a hash to recover the sequence names
+ Hashtable map = new Hashtable();
+ //String[] un_names = new String[sequences.length];
+
+ for (int i = 0; i < sequences.length; i++)
+ {
+ String safename = unique_name(i);
+ map.put(safename, SeqCharacterHash(sequences[i]));
+
+ if (write_names)
+ {
+ sequences[i].setName(safename);
+ }
+ }
+
+
+ return map;
+ }
+ /**
+ * recover unsafe sequence names and original properties for a sequence
+ * set using a map generated by @see uniquify(sequences,true)
+ * @param map Hashtable
+ * @param sequences SequenceI[]
+ * @return boolean
+ */
+ public static boolean deuniquify(Hashtable map, SequenceI[] sequences)
+ {
+ jalview.analysis.SequenceIdMatcher matcher = new SequenceIdMatcher(sequences);
+ SequenceI msq = null;
+ Enumeration keys = map.keys();
+ Vector unmatched = new Vector();
+ for (int i=0, j=sequences.length; i0) {
+ System.err.println("Did not find matches for :");
+ for (Enumeration i = unmatched.elements(); i.hasMoreElements(); System.out.println(((SequenceI) i.nextElement()).getName()))
+ ;
+ return false;
+ }
+
+ return true;
+ }
+ /**
+ * returns a subset of the sequenceI seuqences,
+ * including only those that contain at least one residue.
+ * @param sequences SequenceI[]
+ * @return SequenceI[]
+ */
+ public static SequenceI[] getNonEmptySequenceSet(SequenceI[] sequences) {
+ // Identify first row of alignment with residues for prediction
+ boolean ungapped[] = new boolean[sequences.length];
+ int msflen=0;
+ for (int i=0,j=sequences.length; iTitle:
- * SequenceIdMatcher
- * Description:
- * Routine which does approximate Sequence Id resolution by name using
- * string containment (on word boundaries) rather than equivalence
- * Copyright: Copyright (c) 2004
- *
- * Company: Dundee University
- *
- * @author not attributable
- * @version 1.0
- */
-public class SequenceIdMatcher
-{
- private Hashtable names;
-
- public SequenceIdMatcher(SequenceI[] seqs)
- {
- names = new Hashtable();
- for (int i = 0; i < seqs.length; i++)
- {
- names.put(new SeqIdName(seqs[i].getName()), seqs[i]);
- }
- }
-
- SequenceI findIdMatch(SequenceI seq)
- {
- SeqIdName nam = new SeqIdName(seq.getName());
-
- if (names.containsKey(nam))
- {
- return (SequenceI) names.get(nam);
- }
-
- return null;
- }
-
- SequenceI findIdMatch(String seqnam)
- {
- SeqIdName nam = new SeqIdName(seqnam);
-
- if (names.containsKey(nam))
- {
- return (SequenceI) names.get(nam);
- }
-
- return null;
- }
-
- /**
- * findIdMatch
- *
- * Return pointers to sequences (or sequence object containers)
- * which have same Id as a given set of different sequence objects
- *
- * @param seqs SequenceI[]
- * @return SequenceI[]
- */
- SequenceI[] findIdMatch(SequenceI[] seqs)
- {
- SequenceI[] namedseqs = null;
- int i = 0;
- SeqIdName nam;
-
- if (seqs.length > 0)
- {
- namedseqs = new SequenceI[seqs.length];
- do
- {
- nam = new SeqIdName(seqs[i].getName());
-
- if (names.containsKey(nam))
- {
- namedseqs[i] = (SequenceI) names.get(nam);
- }
- else
- {
- namedseqs[i] = null;
- }
- }
- while (++i < seqs.length);
- }
-
- return namedseqs;
- }
-
- private class SeqIdName
- {
- String id;
-
- SeqIdName(String s)
- {
- if (s!=null)
- id = new String(s);
- else
- id = "";
- }
-
- public int hashCode()
- {
- return ((id.length()>=4) ? id.substring(0, 4).hashCode() : id.hashCode());
- }
-
- public boolean equals(Object s)
- {
- if (s instanceof SeqIdName)
- {
- return this.equals( (SeqIdName) s);
- }
- else
- {
- if (s instanceof String)
- {
- return this.equals( (String) s);
- }
- }
-
- return false;
- }
-
- /**
- * Characters that define the end of a unique sequence ID at
- * the beginning of an arbitrary ID string
- * JBPNote: This is a heuristic that will fail for arbritrarily extended sequence id's
- * (like portions of an aligned set of repeats from one sequence)
- */
- private String WORD_SEP="~. |#\\/<>!\"£$%^*)}[@',?";
-
- /**
- * matches if one ID properly contains another at a whitespace boundary.
- * TODO: (JBPNote) These are not efficient. should use char[] for speed
- * todo: (JBPNote) Set separator characters appropriately
- * @param s SeqIdName
- * @return boolean
- */
- public boolean equals(SeqIdName s)
- {
- if (id.length()>s.id.length()) {
- return id.startsWith(s.id) ?
- (WORD_SEP.indexOf(id.charAt(s.id.length()))>-1)
- : false;
- } else
- return s.id.startsWith(id) ?
- (s.id.equals(id) ? true :
- (WORD_SEP.indexOf(s.id.charAt(id.length()))>-1))
- : false;
- }
-
- public boolean equals(String s)
- {
- if (id.length()>s.length()) {
- return id.startsWith(s) ?
- (WORD_SEP.indexOf(id.charAt(s.length()))>-1)
- : false;
- } else
- return s.startsWith(id) ?
- (s.equals(id) ? true :
- (WORD_SEP.indexOf(s.charAt(id.length()))>-1))
- : false;
- }
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.analysis;
+
+import java.util.*;
+
+import jalview.datamodel.*;
+
+/**
+ * Title:
+ * SequenceIdMatcher
+ * Description:
+ * Routine which does approximate Sequence Id resolution by name using
+ * string containment (on word boundaries) rather than equivalence
+ * Copyright: Copyright (c) 2004
+ *
+ * Company: Dundee University
+ *
+ * @author not attributable
+ * @version 1.0
+ */
+public class SequenceIdMatcher
+{
+ private Hashtable names;
+
+ public SequenceIdMatcher(SequenceI[] seqs)
+ {
+ names = new Hashtable();
+ for (int i = 0; i < seqs.length; i++)
+ {
+ names.put(new SeqIdName(seqs[i].getName()), seqs[i]);
+ }
+ }
+
+ SequenceI findIdMatch(SequenceI seq)
+ {
+ SeqIdName nam = new SeqIdName(seq.getName());
+
+ if (names.containsKey(nam))
+ {
+ return (SequenceI) names.get(nam);
+ }
+
+ return null;
+ }
+
+ SequenceI findIdMatch(String seqnam)
+ {
+ SeqIdName nam = new SeqIdName(seqnam);
+
+ if (names.containsKey(nam))
+ {
+ return (SequenceI) names.get(nam);
+ }
+
+ return null;
+ }
+
+ /**
+ * findIdMatch
+ *
+ * Return pointers to sequences (or sequence object containers)
+ * which have same Id as a given set of different sequence objects
+ *
+ * @param seqs SequenceI[]
+ * @return SequenceI[]
+ */
+ SequenceI[] findIdMatch(SequenceI[] seqs)
+ {
+ SequenceI[] namedseqs = null;
+ int i = 0;
+ SeqIdName nam;
+
+ if (seqs.length > 0)
+ {
+ namedseqs = new SequenceI[seqs.length];
+ do
+ {
+ nam = new SeqIdName(seqs[i].getName());
+
+ if (names.containsKey(nam))
+ {
+ namedseqs[i] = (SequenceI) names.get(nam);
+ }
+ else
+ {
+ namedseqs[i] = null;
+ }
+ }
+ while (++i < seqs.length);
+ }
+
+ return namedseqs;
+ }
+
+ private class SeqIdName
+ {
+ String id;
+
+ SeqIdName(String s)
+ {
+ if (s!=null)
+ id = new String(s);
+ else
+ id = "";
+ }
+
+ public int hashCode()
+ {
+ return ((id.length()>=4) ? id.substring(0, 4).hashCode() : id.hashCode());
+ }
+
+ public boolean equals(Object s)
+ {
+ if (s instanceof SeqIdName)
+ {
+ return this.equals( (SeqIdName) s);
+ }
+ else
+ {
+ if (s instanceof String)
+ {
+ return this.equals( (String) s);
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Characters that define the end of a unique sequence ID at
+ * the beginning of an arbitrary ID string
+ * JBPNote: This is a heuristic that will fail for arbritrarily extended sequence id's
+ * (like portions of an aligned set of repeats from one sequence)
+ */
+ private String WORD_SEP="~. |#\\/<>!\"£$%^*)}[@',?";
+
+ /**
+ * matches if one ID properly contains another at a whitespace boundary.
+ * TODO: (JBPNote) These are not efficient. should use char[] for speed
+ * todo: (JBPNote) Set separator characters appropriately
+ * @param s SeqIdName
+ * @return boolean
+ */
+ public boolean equals(SeqIdName s)
+ {
+ if (id.length()>s.id.length()) {
+ return id.startsWith(s.id) ?
+ (WORD_SEP.indexOf(id.charAt(s.id.length()))>-1)
+ : false;
+ } else
+ return s.id.startsWith(id) ?
+ (s.id.equals(id) ? true :
+ (WORD_SEP.indexOf(s.id.charAt(id.length()))>-1))
+ : false;
+ }
+
+ public boolean equals(String s)
+ {
+ if (id.length()>s.length()) {
+ return id.startsWith(s) ?
+ (WORD_SEP.indexOf(id.charAt(s.length()))>-1)
+ : false;
+ } else
+ return s.startsWith(id) ?
+ (s.equals(id) ? true :
+ (WORD_SEP.indexOf(s.charAt(id.length()))>-1))
+ : false;
+ }
+ }
+}
diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java
index b85c7d2..3e25d44 100755
--- a/src/jalview/appletgui/APopupMenu.java
+++ b/src/jalview/appletgui/APopupMenu.java
@@ -1,459 +1,645 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.util.Vector;
-
-import jalview.analysis.*;
-import jalview.datamodel.*;
-import jalview.schemes.*;
-
-public class APopupMenu
- extends java.awt.PopupMenu implements ActionListener, ItemListener
-{
- Menu groupMenu = new Menu();
- protected MenuItem clustalColour = new MenuItem();
- protected MenuItem zappoColour = new MenuItem();
- protected MenuItem taylorColour = new MenuItem();
- protected MenuItem hydrophobicityColour = new MenuItem();
- protected MenuItem helixColour = new MenuItem();
- protected MenuItem strandColour = new MenuItem();
- protected MenuItem turnColour = new MenuItem();
- protected MenuItem buriedColour = new MenuItem();
- protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
- protected MenuItem userDefinedColour = new MenuItem();
- protected MenuItem PIDColour = new MenuItem();
- protected MenuItem BLOSUM62Colour = new MenuItem();
- MenuItem noColourmenuItem = new MenuItem();
- protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
-
- final AlignmentPanel ap;
- MenuItem unGroupMenuItem = new MenuItem();
- MenuItem nucleotideMenuItem = new MenuItem();
- Menu colourMenu = new Menu();
- CheckboxMenuItem showBoxes = new CheckboxMenuItem();
- CheckboxMenuItem showText = new CheckboxMenuItem();
- CheckboxMenuItem showColourText = new CheckboxMenuItem();
-
- public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
- {
- ///////////////////////////////////////////////////////////
- // If this is activated from the sequence panel, the user may want to
- // edit or annotate a particular residue. Therefore display the residue menu
- //
- // If from the IDPanel, we must display the sequence menu
- //////////////////////////////////////////////////////////
-
- this.ap = apanel;
-
- try
- {
- jbInit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- SequenceGroup sg = ap.av.getSelectionGroup();
- if (sg != null)
- {
- showText.setState(sg.getDisplayText());
- showColourText.setState(sg.getColourText());
- showBoxes.setState(sg.getDisplayBoxes());
- }
-
- if (!ap.av.alignment.getGroups().contains(sg))
- {
- groupMenu.remove(unGroupMenuItem);
- }
-
- if (seq != null && links!=null)
- {
- Menu linkMenu = new Menu("Link");
- MenuItem item;
- String link;
- for(int i=0; i-1)
- id = id.substring(id.lastIndexOf("|")+1);
-
- final String url = link.substring(link.indexOf("|")+1, link.indexOf("$SEQUENCE_ID$"))
- + id +
- link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
-
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- ap.alignFrame.showURL(url, target);
- }
- });
- linkMenu.add(item);
- }
- add(linkMenu);
-
- item = new MenuItem("Show PDB Structure");
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- addPDB(seq);
- }
- });
-
- add(item);
-
-
- }
- }
-
- public void itemStateChanged(ItemEvent evt)
- {
- if(evt.getSource()==abovePIDColour)
- abovePIDColour_itemStateChanged();
- else if(evt.getSource()==showColourText)
- showColourText_itemStateChanged();
- else if(evt.getSource()==showText)
- showText_itemStateChanged();
- else if(evt.getSource()==showBoxes)
- showBoxes_itemStateChanged() ;
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource()==clustalColour)
- clustalColour_actionPerformed();
- else if(evt.getSource()==zappoColour)
- zappoColour_actionPerformed();
- else if(evt.getSource()==taylorColour)
- taylorColour_actionPerformed();
- else if(evt.getSource()==hydrophobicityColour)
- hydrophobicityColour_actionPerformed();
- else if(evt.getSource()==helixColour)
- helixColour_actionPerformed();
- else if(evt.getSource()==strandColour)
- strandColour_actionPerformed();
- else if(evt.getSource()==clustalColour)
- turnColour_actionPerformed();
- else if(evt.getSource()==buriedColour)
- buriedColour_actionPerformed();
- else if(evt.getSource()==nucleotideMenuItem)
- nucleotideMenuItem_actionPerformed();
-
- else if(evt.getSource()==userDefinedColour)
- userDefinedColour_actionPerformed();
- else if(evt.getSource()==PIDColour)
- PIDColour_actionPerformed();
- else if(evt.getSource()==BLOSUM62Colour)
- BLOSUM62Colour_actionPerformed();
- else if(evt.getSource()==noColourmenuItem)
- noColourmenuItem_actionPerformed();
- else if(evt.getSource()==conservationMenuItem)
- conservationMenuItem_itemStateChanged();
- else if(evt.getSource()==unGroupMenuItem)
- unGroupMenuItem_actionPerformed();
-
- }
-
- void addPDB(Sequence seq)
- {
- CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
- cap.setText("Paste your PDB file here.");
- cap.setPDBImport(seq);
- Frame frame = new Frame();
- frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);
- }
-
- private void jbInit()
- throws Exception
- {
- groupMenu.setLabel("Group");
- groupMenu.setLabel("Define");
-
- unGroupMenuItem.setLabel("Remove Group");
- unGroupMenuItem.addActionListener(this);
-
- nucleotideMenuItem.setLabel("Nucleotide");
- nucleotideMenuItem.addActionListener(this);
- conservationMenuItem.addItemListener(this);
- abovePIDColour.addItemListener(this);
- colourMenu.setLabel("Group Colour");
- showBoxes.setLabel("Boxes");
- showBoxes.setState(true);
- showBoxes.addItemListener(this);
-
- showText.setLabel("Text");
- showText.addItemListener(this);
- showColourText.setLabel("Colour Text");
- showColourText.addItemListener(this);
-
- add(groupMenu);
- groupMenu.add(unGroupMenuItem);
- groupMenu.add(colourMenu);
- groupMenu.addSeparator();
- groupMenu.add(showBoxes);
- groupMenu.add(showText);
- groupMenu.add(showColourText);
- colourMenu.add(noColourmenuItem);
- colourMenu.add(clustalColour);
- colourMenu.add(BLOSUM62Colour);
- colourMenu.add(PIDColour);
- colourMenu.add(zappoColour);
- colourMenu.add(taylorColour);
- colourMenu.add(hydrophobicityColour);
- colourMenu.add(helixColour);
- colourMenu.add(strandColour);
- colourMenu.add(turnColour);
- colourMenu.add(buriedColour);
- colourMenu.add(nucleotideMenuItem);
- colourMenu.add(userDefinedColour);
- colourMenu.addSeparator();
- colourMenu.add(abovePIDColour);
- colourMenu.add(conservationMenuItem);
-
- noColourmenuItem.setLabel("None");
- noColourmenuItem.addActionListener(this);
-
- clustalColour.setLabel("Clustalx colours");
- clustalColour.addActionListener(this);
- zappoColour.setLabel("Zappo");
- zappoColour.addActionListener(this);
- taylorColour.setLabel("Taylor");
- taylorColour.addActionListener(this);
- hydrophobicityColour.setLabel("Hydrophobicity");
- hydrophobicityColour.addActionListener(this);
- helixColour.setLabel("Helix propensity");
- helixColour.addActionListener(this);
- strandColour.setLabel("Strand propensity");
- strandColour.addActionListener(this);
- turnColour.setLabel("Turn propensity");
- turnColour.addActionListener(this);
- buriedColour.setLabel("Buried Index");
- buriedColour.addActionListener(this);
- abovePIDColour.setLabel("Above % Identity");
-
- userDefinedColour.setLabel("User Defined");
- userDefinedColour.addActionListener(this);
- PIDColour.setLabel("Percentage Identity");
- PIDColour.addActionListener(this);
- BLOSUM62Colour.setLabel("BLOSUM62");
- BLOSUM62Colour.addActionListener(this);
- conservationMenuItem.setLabel("Conservation");
-
- }
-
- void refresh()
- {
- ap.seqPanel.seqCanvas.repaint();
- if(ap.overviewPanel!=null)
- ap.overviewPanel.updateOverviewImage();
- }
-
- protected void clustalColour_actionPerformed()
- {
- SequenceGroup sg = getGroup();
- sg.cs = new ClustalxColourScheme(sg.sequences, ap.av.alignment.getWidth());
- refresh();
- }
-
- protected void zappoColour_actionPerformed()
- {
- getGroup().cs = new ZappoColourScheme();
- refresh();
- }
-
- protected void taylorColour_actionPerformed()
- {
- getGroup().cs = new TaylorColourScheme();
- refresh();
- }
-
- protected void hydrophobicityColour_actionPerformed()
- {
- getGroup().cs = new HydrophobicColourScheme();
- refresh();
- }
-
- protected void helixColour_actionPerformed()
- {
- getGroup().cs = new HelixColourScheme();
- refresh();
- }
-
- protected void strandColour_actionPerformed()
- {
- getGroup().cs = new StrandColourScheme();
- refresh();
- }
-
- protected void turnColour_actionPerformed()
- {
- getGroup().cs = new TurnColourScheme();
- refresh();
- }
-
- protected void buriedColour_actionPerformed()
- {
- getGroup().cs = new BuriedColourScheme();
- refresh();
- }
-
- public void nucleotideMenuItem_actionPerformed()
- {
- getGroup().cs = new NucleotideColourScheme();
- refresh();
- }
-
- protected void abovePIDColour_itemStateChanged()
- {
- SequenceGroup sg = getGroup();
- if(sg.cs==null)
- return;
-
- if (abovePIDColour.getState())
- {
- sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,
- ap.av.alignment.getWidth()));
- int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
- getGroup().getName());
-
- sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
-
- SliderPanel.showPIDSlider();
-
- }
- else // remove PIDColouring
- {
- sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
- }
-
- refresh();
-
- }
-
- protected void userDefinedColour_actionPerformed()
- {
- new UserDefinedColours(ap, getGroup());
- }
-
- protected void PIDColour_actionPerformed()
- {
- SequenceGroup sg = getGroup();
- sg.cs = new PIDColourScheme();
- sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,
- ap.av.alignment.getWidth()));
- refresh();
- }
-
- protected void BLOSUM62Colour_actionPerformed()
- {
- SequenceGroup sg = getGroup();
-
- sg.cs = new Blosum62ColourScheme();
-
- sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,
- ap.av.alignment.getWidth()));
-
- refresh();
- }
-
- protected void noColourmenuItem_actionPerformed()
- {
- getGroup().cs = null;
- refresh();
- }
-
- protected void conservationMenuItem_itemStateChanged()
- {
- SequenceGroup sg = getGroup();
- if(sg.cs==null)
- return;
-
- if (conservationMenuItem.getState())
- {
-
- Conservation c = new Conservation("Group",
- ResidueProperties.propHash, 3,
- sg.sequences, 0,
- ap.av.alignment.getWidth());
-
- c.calculate();
- c.verdict(false, ap.av.ConsPercGaps);
-
- sg.cs.setConservation(c);
-
- SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
- SliderPanel.showConservationSlider();
- }
- else // remove ConservationColouring
- {
- sg.cs.setConservation(null);
- }
-
- refresh();
- }
-
-
- SequenceGroup getGroup()
- {
- SequenceGroup sg = ap.av.getSelectionGroup();
-
- // this method won't add a new group if it already exists
- if(sg!=null)
- ap.av.alignment.addGroup(sg);
-
- return sg;
- }
-
- void unGroupMenuItem_actionPerformed()
- {
- SequenceGroup sg = ap.av.getSelectionGroup();
- ap.av.alignment.deleteGroup(sg);
- ap.av.setSelectionGroup(null);
- ap.repaint();
- }
-
- public void showColourText_itemStateChanged()
- {
- getGroup().setColourText(showColourText.getState());
- refresh();
- }
-
- public void showText_itemStateChanged()
- {
- getGroup().setDisplayText(showText.getState());
- refresh();
- }
-
- public void showBoxes_itemStateChanged()
- {
- getGroup().setDisplayBoxes(showBoxes.getState());
- refresh();
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.Vector;
+
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import jalview.schemes.*;
+
+public class APopupMenu
+ extends java.awt.PopupMenu implements ActionListener, ItemListener
+{
+ Menu groupMenu = new Menu();
+ protected MenuItem clustalColour = new MenuItem();
+ protected MenuItem zappoColour = new MenuItem();
+ protected MenuItem taylorColour = new MenuItem();
+ protected MenuItem hydrophobicityColour = new MenuItem();
+ protected MenuItem helixColour = new MenuItem();
+ protected MenuItem strandColour = new MenuItem();
+ protected MenuItem turnColour = new MenuItem();
+ protected MenuItem buriedColour = new MenuItem();
+ protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
+ protected MenuItem userDefinedColour = new MenuItem();
+ protected MenuItem PIDColour = new MenuItem();
+ protected MenuItem BLOSUM62Colour = new MenuItem();
+ MenuItem noColourmenuItem = new MenuItem();
+ protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
+
+ final AlignmentPanel ap;
+ MenuItem unGroupMenuItem = new MenuItem();
+ MenuItem nucleotideMenuItem = new MenuItem();
+ Menu colourMenu = new Menu();
+ CheckboxMenuItem showBoxes = new CheckboxMenuItem();
+ CheckboxMenuItem showText = new CheckboxMenuItem();
+ CheckboxMenuItem showColourText = new CheckboxMenuItem();
+ Menu editMenu = new Menu("Edit");
+ MenuItem copy = new MenuItem("Copy (Jalview Only)");
+ MenuItem cut = new MenuItem("Cut (Jalview Only)");
+ MenuItem toUpper = new MenuItem("To Upper Case");
+ MenuItem toLower = new MenuItem("To Lower Case");
+ MenuItem toggleCase = new MenuItem("Toggle Case");
+ Menu outputmenu = new Menu();
+ Menu seqMenu = new Menu();
+ MenuItem pdb = new MenuItem();
+ MenuItem hideSeqs = new MenuItem();
+ MenuItem repGroup = new MenuItem();
+
+ Sequence seq;
+ MenuItem revealAll = new MenuItem();
+
+ public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
+ {
+ ///////////////////////////////////////////////////////////
+ // If this is activated from the sequence panel, the user may want to
+ // edit or annotate a particular residue. Therefore display the residue menu
+ //
+ // If from the IDPanel, we must display the sequence menu
+ //////////////////////////////////////////////////////////
+
+ this.ap = apanel;
+ this.seq = seq;
+
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
+ {
+ MenuItem item = new MenuItem( jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i] );
+
+ item.addActionListener(this);
+ outputmenu.add(item);
+ }
+
+ SequenceGroup sg = ap.av.getSelectionGroup();
+
+ if (sg != null && sg.getSize(false)>0)
+ {
+ showText.setState(sg.getDisplayText());
+ showColourText.setState(sg.getColourText());
+ showBoxes.setState(sg.getDisplayBoxes());
+ if (!ap.av.alignment.getGroups().contains(sg))
+ {
+ groupMenu.remove(unGroupMenuItem);
+ }
+
+ }
+ else
+ {
+ remove(hideSeqs);
+ remove(groupMenu);
+ }
+
+ if (links!=null)
+ {
+ Menu linkMenu = new Menu("Link");
+ MenuItem item;
+ String link;
+ for(int i=0; i -1)
+ {
+ String id = seq.getName();
+ if (id.indexOf("|") > -1)
+ id = id.substring(id.lastIndexOf("|") + 1);
+
+ url = link.substring(link.indexOf("|") + 1,
+ link.indexOf("$SEQUENCE_ID$"))
+ + id +
+ link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
+ }
+ else
+ url = link.substring(link.lastIndexOf("|")+1);
+
+ System.out.println("add "+url +" "+target);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ ap.alignFrame.showURL(url, target);
+ }
+ });
+ linkMenu.add(item);
+ }
+ if(seq!=null)
+ seqMenu.add(linkMenu);
+ else
+ add(linkMenu);
+ }
+ if(seq!=null)
+ {
+ seqMenu.setLabel(seq.getName());
+ repGroup.setLabel("Represent Group with " + seq.getName());
+ }
+ else
+ remove(seqMenu);
+
+ if(!ap.av.hasHiddenRows)
+ remove(revealAll);
+ }
+
+ public void itemStateChanged(ItemEvent evt)
+ {
+ if(evt.getSource()==abovePIDColour)
+ abovePIDColour_itemStateChanged();
+ else if(evt.getSource()==showColourText)
+ showColourText_itemStateChanged();
+ else if(evt.getSource()==showText)
+ showText_itemStateChanged();
+ else if(evt.getSource()==showBoxes)
+ showBoxes_itemStateChanged() ;
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ Object source = evt.getSource();
+ if(source==clustalColour)
+ clustalColour_actionPerformed();
+ else if(source==zappoColour)
+ zappoColour_actionPerformed();
+ else if(source==taylorColour)
+ taylorColour_actionPerformed();
+ else if(source==hydrophobicityColour)
+ hydrophobicityColour_actionPerformed();
+ else if(source==helixColour)
+ helixColour_actionPerformed();
+ else if(source==strandColour)
+ strandColour_actionPerformed();
+ else if(source==clustalColour)
+ turnColour_actionPerformed();
+ else if(source==buriedColour)
+ buriedColour_actionPerformed();
+ else if(source==nucleotideMenuItem)
+ nucleotideMenuItem_actionPerformed();
+
+ else if (source == userDefinedColour)
+ userDefinedColour_actionPerformed();
+ else if (source == PIDColour)
+ PIDColour_actionPerformed();
+ else if (source == BLOSUM62Colour)
+ BLOSUM62Colour_actionPerformed();
+ else if (source == noColourmenuItem)
+ noColourmenuItem_actionPerformed();
+ else if (source == conservationMenuItem)
+ conservationMenuItem_itemStateChanged();
+ else if (source == unGroupMenuItem)
+ unGroupMenuItem_actionPerformed();
+
+ else if(source == pdb)
+ addPDB();
+ else if(source == hideSeqs)
+ hideSequences(false);
+ else if(source == repGroup)
+ hideSequences(true);
+ else if(source == revealAll)
+ {
+ ap.av.showAllHiddenSeqs();
+ }
+
+ else if(source==copy)
+ ap.alignFrame.copy_actionPerformed();
+ else if(source==cut)
+ ap.alignFrame.cut_actionPerformed();
+ else if(source==toUpper || source==toLower || source==toggleCase)
+ {
+ SequenceGroup sg = ap.av.getSelectionGroup();
+ if (sg != null)
+ {
+ for (int g = 0; g < sg.getSize(true); g++)
+ {
+ int start = sg.getStartRes();
+ int end = sg.getEndRes() + 1;
+
+ do
+ {
+ if (ap.av.hasHiddenColumns)
+ {
+ end = ap.av.colSel.getHiddenBoundaryRight(start);
+ if (start == end)
+ end = sg.getEndRes() + 1;
+ if (end > sg.getEndRes())
+ end = sg.getEndRes() + 1;
+ }
+
+ if (source == toggleCase)
+ ( (SequenceI) sg.getSequences(true).elementAt(g))
+ .toggleCase(start, end);
+ else
+ ( (SequenceI) sg.getSequences(true).elementAt(g))
+ .changeCase(source == toUpper, start, end);
+
+ if (ap.av.hasHiddenColumns)
+ {
+ start = ap.av.colSel.adjustForHiddenColumns(end);
+ start = ap.av.colSel.getHiddenBoundaryLeft(start) + 1;
+ }
+
+ }
+ while (end < sg.getEndRes());
+ }
+ ap.seqPanel.seqCanvas.repaint();
+ }
+ }
+ else
+ outputText(evt);
+
+ }
+
+ void outputText(ActionEvent e)
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
+ Vector vseqs = new Vector();
+
+ String [] selection = ap.av.getViewAsString(true);
+ SequenceI [] seqs = ap.av.getSelectionAsNewSequence();
+ if (selection != null)
+ {
+ for (int i = 0; i < selection.length; i++)
+ {
+ Sequence seq = new Sequence(
+ seqs[i].getName(),
+ selection[i],
+ seqs[i].getStart(), seqs[i].getEnd());
+ seq.setDescription(seqs[i].getDescription());
+ vseqs.addElement( seq );
+ }
+ }
+
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame,
+ "Selection output - " + e.getActionCommand(),
+ 600, 500);
+
+ cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
+ e.getActionCommand(),
+ vseqs,
+ ap.av.showJVSuffix));
+
+ }
+
+ void addPDB()
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
+ cap.setText("Paste your PDB file here.");
+ cap.setPDBImport(seq);
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);
+ }
+
+ private void jbInit()
+ throws Exception
+ {
+ groupMenu.setLabel("Group");
+ groupMenu.setLabel("Selection");
+
+ unGroupMenuItem.setLabel("Remove Group");
+ unGroupMenuItem.addActionListener(this);
+
+ nucleotideMenuItem.setLabel("Nucleotide");
+ nucleotideMenuItem.addActionListener(this);
+ conservationMenuItem.addItemListener(this);
+ abovePIDColour.addItemListener(this);
+ colourMenu.setLabel("Group Colour");
+ showBoxes.setLabel("Boxes");
+ showBoxes.setState(true);
+ showBoxes.addItemListener(this);
+
+ showText.setLabel("Text");
+ showText.addItemListener(this);
+ showColourText.setLabel("Colour Text");
+ showColourText.addItemListener(this);
+ outputmenu.setLabel("Output to Textbox...");
+ seqMenu.setLabel("Sequence");
+ pdb.setLabel("View PDB Structure");
+ hideSeqs.setLabel("Hide Sequences");
+ repGroup.setLabel("Represent Group with");
+ revealAll.setLabel("Reveal All");
+
+ add(groupMenu);
+ this.add(seqMenu);
+ this.add(hideSeqs);
+ this.add(revealAll);
+ groupMenu.add(editMenu);
+ groupMenu.add(outputmenu);
+ groupMenu.addSeparator();
+ groupMenu.add(unGroupMenuItem);
+ groupMenu.add(colourMenu);
+ groupMenu.add(showBoxes);
+ groupMenu.add(showText);
+ groupMenu.add(showColourText);
+ colourMenu.add(noColourmenuItem);
+ colourMenu.add(clustalColour);
+ colourMenu.add(BLOSUM62Colour);
+ colourMenu.add(PIDColour);
+ colourMenu.add(zappoColour);
+ colourMenu.add(taylorColour);
+ colourMenu.add(hydrophobicityColour);
+ colourMenu.add(helixColour);
+ colourMenu.add(strandColour);
+ colourMenu.add(turnColour);
+ colourMenu.add(buriedColour);
+ colourMenu.add(nucleotideMenuItem);
+ colourMenu.add(userDefinedColour);
+ colourMenu.addSeparator();
+ colourMenu.add(abovePIDColour);
+ colourMenu.add(conservationMenuItem);
+
+ noColourmenuItem.setLabel("None");
+ noColourmenuItem.addActionListener(this);
+
+ clustalColour.setLabel("Clustalx colours");
+ clustalColour.addActionListener(this);
+ zappoColour.setLabel("Zappo");
+ zappoColour.addActionListener(this);
+ taylorColour.setLabel("Taylor");
+ taylorColour.addActionListener(this);
+ hydrophobicityColour.setLabel("Hydrophobicity");
+ hydrophobicityColour.addActionListener(this);
+ helixColour.setLabel("Helix propensity");
+ helixColour.addActionListener(this);
+ strandColour.setLabel("Strand propensity");
+ strandColour.addActionListener(this);
+ turnColour.setLabel("Turn propensity");
+ turnColour.addActionListener(this);
+ buriedColour.setLabel("Buried Index");
+ buriedColour.addActionListener(this);
+ abovePIDColour.setLabel("Above % Identity");
+
+ userDefinedColour.setLabel("User Defined");
+ userDefinedColour.addActionListener(this);
+ PIDColour.setLabel("Percentage Identity");
+ PIDColour.addActionListener(this);
+ BLOSUM62Colour.setLabel("BLOSUM62");
+ BLOSUM62Colour.addActionListener(this);
+ conservationMenuItem.setLabel("Conservation");
+
+ editMenu.add(copy);
+ copy.addActionListener(this);
+ editMenu.add(cut);
+ cut.addActionListener(this);
+ editMenu.add(toUpper);
+ toUpper.addActionListener(this);
+ editMenu.add(toLower);
+ toLower.addActionListener(this);
+ editMenu.add(toggleCase);
+ seqMenu.add(pdb);
+ seqMenu.add(repGroup);
+ toggleCase.addActionListener(this);
+ pdb.addActionListener(this);
+ hideSeqs.addActionListener(this);
+ repGroup.addActionListener(this);
+ revealAll.addActionListener(this);
+
+ }
+
+ void refresh()
+ {
+ ap.seqPanel.seqCanvas.repaint();
+ if(ap.overviewPanel!=null)
+ ap.overviewPanel.updateOverviewImage();
+ }
+
+ protected void clustalColour_actionPerformed()
+ {
+ SequenceGroup sg = getGroup();
+ sg.cs = new ClustalxColourScheme(sg.getSequences(true), ap.av.alignment.getWidth());
+ refresh();
+ }
+
+ protected void zappoColour_actionPerformed()
+ {
+ getGroup().cs = new ZappoColourScheme();
+ refresh();
+ }
+
+ protected void taylorColour_actionPerformed()
+ {
+ getGroup().cs = new TaylorColourScheme();
+ refresh();
+ }
+
+ protected void hydrophobicityColour_actionPerformed()
+ {
+ getGroup().cs = new HydrophobicColourScheme();
+ refresh();
+ }
+
+ protected void helixColour_actionPerformed()
+ {
+ getGroup().cs = new HelixColourScheme();
+ refresh();
+ }
+
+ protected void strandColour_actionPerformed()
+ {
+ getGroup().cs = new StrandColourScheme();
+ refresh();
+ }
+
+ protected void turnColour_actionPerformed()
+ {
+ getGroup().cs = new TurnColourScheme();
+ refresh();
+ }
+
+ protected void buriedColour_actionPerformed()
+ {
+ getGroup().cs = new BuriedColourScheme();
+ refresh();
+ }
+
+ public void nucleotideMenuItem_actionPerformed()
+ {
+ getGroup().cs = new NucleotideColourScheme();
+ refresh();
+ }
+
+ protected void abovePIDColour_itemStateChanged()
+ {
+ SequenceGroup sg = getGroup();
+ if(sg.cs==null)
+ return;
+
+ if (abovePIDColour.getState())
+ {
+ sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
+ ap.av.alignment.getWidth()));
+ int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
+ getGroup().getName());
+
+ sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
+
+ SliderPanel.showPIDSlider();
+
+ }
+ else // remove PIDColouring
+ {
+ sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
+ }
+
+ refresh();
+
+ }
+
+ protected void userDefinedColour_actionPerformed()
+ {
+ new UserDefinedColours(ap, getGroup());
+ }
+
+ protected void PIDColour_actionPerformed()
+ {
+ SequenceGroup sg = getGroup();
+ sg.cs = new PIDColourScheme();
+ sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
+ ap.av.alignment.getWidth()));
+ refresh();
+ }
+
+ protected void BLOSUM62Colour_actionPerformed()
+ {
+ SequenceGroup sg = getGroup();
+
+ sg.cs = new Blosum62ColourScheme();
+
+ sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
+ ap.av.alignment.getWidth()));
+
+ refresh();
+ }
+
+ protected void noColourmenuItem_actionPerformed()
+ {
+ getGroup().cs = null;
+ refresh();
+ }
+
+ protected void conservationMenuItem_itemStateChanged()
+ {
+ SequenceGroup sg = getGroup();
+ if(sg.cs==null)
+ return;
+
+ if (conservationMenuItem.getState())
+ {
+
+ Conservation c = new Conservation("Group",
+ ResidueProperties.propHash, 3,
+ sg.getSequences(true), 0,
+ ap.av.alignment.getWidth());
+
+ c.calculate();
+ c.verdict(false, ap.av.ConsPercGaps);
+
+ sg.cs.setConservation(c);
+
+ SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
+ SliderPanel.showConservationSlider();
+ }
+ else // remove ConservationColouring
+ {
+ sg.cs.setConservation(null);
+ }
+
+ refresh();
+ }
+
+
+ SequenceGroup getGroup()
+ {
+ SequenceGroup sg = ap.av.getSelectionGroup();
+
+ // this method won't add a new group if it already exists
+ if(sg!=null)
+ ap.av.alignment.addGroup(sg);
+
+ return sg;
+ }
+
+ void unGroupMenuItem_actionPerformed()
+ {
+ SequenceGroup sg = ap.av.getSelectionGroup();
+ ap.av.alignment.deleteGroup(sg);
+ ap.av.setSelectionGroup(null);
+ ap.repaint();
+ }
+
+ public void showColourText_itemStateChanged()
+ {
+ getGroup().setColourText(showColourText.getState());
+ refresh();
+ }
+
+ public void showText_itemStateChanged()
+ {
+ getGroup().setDisplayText(showText.getState());
+ refresh();
+ }
+
+ public void showBoxes_itemStateChanged()
+ {
+ getGroup().setDisplayBoxes(showBoxes.getState());
+ refresh();
+ }
+
+ void hideSequences(boolean representGroup)
+ {
+ SequenceGroup sg = ap.av.getSelectionGroup();
+ if(sg==null || sg.getSize(false)<1)
+ {
+ ap.av.hideSequence(seq);
+ return;
+ }
+
+ int index = 0;
+ while(index < sg.getSize(false))
+ {
+ if(representGroup && sg.getSequenceAt(index)!=seq)
+ {
+ seq.addHiddenSequence(sg.getSequenceAt(index));
+ ap.av.hideSequence(sg.getSequenceAt(index));
+ }
+ else if(!representGroup)
+ {
+ ap.av.hideSequence(sg.getSequenceAt(index));
+ }
+ index ++;
+ }
+
+ ap.av.setSelectionGroup(null);
+ }
+
+}
diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java
index 189a36d..e37061a 100755
--- a/src/jalview/appletgui/AlignFrame.java
+++ b/src/jalview/appletgui/AlignFrame.java
@@ -1,2176 +1,2406 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import jalview.schemes.*;
-import jalview.datamodel.*;
-import jalview.analysis.*;
-import jalview.io.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import java.io.InputStreamReader;
-import java.io.BufferedReader;
-import java.net.URL;
-
-
-public class AlignFrame extends Frame implements ActionListener,
- ItemListener, KeyListener, MouseListener
-{
- public AlignmentPanel alignPanel;
- public AlignViewport viewport;
- int NEW_WINDOW_WIDTH = 700;
- int NEW_WINDOW_HEIGHT = 500;
- jalview.bin.JalviewLite applet;
-
-
- public AlignFrame(AlignmentI al,
- jalview.bin.JalviewLite applet,
- String title,
- boolean embedded)
- {
- try{
- jbInit();
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
-
- this.applet = applet;
- viewport = new AlignViewport(al, applet);
- alignPanel = new AlignmentPanel(this, viewport);
-
- annotationPanelMenuItem.setState(viewport.showAnnotation);
-
- if(applet!=null)
- {
- String param = applet.getParameter("sortBy");
- if (param != null)
- {
- if (param.equalsIgnoreCase("Id"))
- sortIDMenuItem_actionPerformed();
- else if (param.equalsIgnoreCase("Pairwise Identity"))
- sortPairwiseMenuItem_actionPerformed();
- }
-
- param = applet.getParameter("wrap");
- if (param != null)
- {
- if (param.equalsIgnoreCase("true"))
- {
- wrapMenuItem.setState(true);
- wrapMenuItem_actionPerformed();
- }
- }
-
- try
- {
- param = applet.getParameter("windowWidth");
- if (param != null)
- {
- int width = Integer.parseInt(param);
- NEW_WINDOW_WIDTH = width;
- }
- param = applet.getParameter("windowHeight");
- if (param != null)
- {
- int height = Integer.parseInt(param);
- NEW_WINDOW_HEIGHT = height;
- }
- }
- catch (Exception ex)
- {}
-
- }
-
- //Some JVMS send keyevents to Top frame or lowest panel,
- //Havent worked out why yet. So add to both this frame and seqCanvas for now
- this.addKeyListener(this);
- alignPanel.seqPanel.seqCanvas.addKeyListener(this);
- alignPanel.idPanel.idCanvas.addKeyListener(this);
-
- viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener()
- {
- public void propertyChange(java.beans.PropertyChangeEvent evt)
- {
- if (evt.getPropertyName().equals("alignment"))
- {
- alignmentChanged();
- }
- }
- });
-
-
- if(embedded)
- {
- setEmbedded();
- }
- else
- {
- add(alignPanel, BorderLayout.CENTER);
- jalview.bin.JalviewLite.addFrame(this, title, NEW_WINDOW_WIDTH,
- NEW_WINDOW_HEIGHT);
- }
- alignPanel.validate();
- alignPanel.repaint();
- }
- public AlignViewport getAlignViewport()
- {
- return viewport;
- }
-
- public SeqCanvas getSeqcanvas()
- {
- return alignPanel.seqPanel.seqCanvas;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param String DOCUMENT ME!
- */
-
- public void parseFeaturesFile(String file)
- {
- String line = null;
- try
- {
- BufferedReader in = null;
- java.io.InputStream is = getClass().getResourceAsStream("/" + file);
- if (is != null)
- {
- in = new BufferedReader(new java.io.InputStreamReader(is));
- }
- else
- {
- URL url = new URL(file);
- in = new BufferedReader(new InputStreamReader(url.openStream()));
- }
-
- SequenceI seq = null;
- String type, desc, token;
-
- int index, start, end;
- StringTokenizer st;
- SequenceFeature sf;
- FeatureRenderer fr = alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
- int lineNo = 0;
- String featureGroup = null;
- while ( (line = in.readLine()) != null)
- {
- lineNo++;
- st = new StringTokenizer(line, "\t");
- if (st.countTokens() == 2)
- {
- type = st.nextToken();
- if(type.equalsIgnoreCase("startgroup"))
- {
- featureGroup = st.nextToken();
- }
- else if(type.equalsIgnoreCase("endgroup"))
- {
- //We should check whether this is the current group,
- //but at present theres no way of showing more than 1 group
- st.nextToken();
- featureGroup = null;
- }
- else
- {
- 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);
-
- 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, featureGroup);
-
- seq.addSequenceFeature(sf);
- }
- }
-
- viewport.showSequenceFeatures = true;
- sequenceFeatures.setState(true);
-
- alignPanel.repaint();
-
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- System.out.println("Error parsing groups file: " + ex +"\n"+line);
- }
- }
-
- public void keyPressed(KeyEvent evt)
- {
- switch (evt.getKeyCode())
- {
- case 27: // escape key
- deselectAllSequenceMenuItem_actionPerformed();
- break;
- case KeyEvent.VK_X:
- if (evt.isControlDown() || evt.isMetaDown())
- {
- cut_actionPerformed();
- }
- break;
- case KeyEvent.VK_C:
- if (evt.isControlDown() || evt.isMetaDown())
- {
- copy_actionPerformed();
- }
- break;
- case KeyEvent.VK_V:
- if (evt.isControlDown() || evt.isMetaDown())
- {
- paste(true);
- }
- break;
- case KeyEvent.VK_A:
- if (evt.isControlDown() || evt.isMetaDown())
- {
- selectAllSequenceMenuItem_actionPerformed();
- }
- break;
- case KeyEvent.VK_DOWN:
- moveSelectedSequences(false);
- break;
- case KeyEvent.VK_UP:
- moveSelectedSequences(true);
- break;
- case KeyEvent.VK_F:
- if (evt.isControlDown())
- {
- findMenuItem_actionPerformed();
- }
- break;
- case KeyEvent.VK_BACK_SPACE:
- case KeyEvent.VK_DELETE:
- cut_actionPerformed();
- break;
- }
- }
- public void keyReleased(KeyEvent evt)
- {}
- public void keyTyped(KeyEvent evt)
- {}
-
-public void itemStateChanged(ItemEvent evt)
- {
- if(evt.getSource()==colourTextMenuItem)
- colourTextMenuItem_actionPerformed();
- else if(evt.getSource()==wrapMenuItem)
- wrapMenuItem_actionPerformed();
- else if(evt.getSource()==scaleAbove)
- scaleAbove_actionPerformed();
- else if(evt.getSource()==scaleLeft)
- scaleLeft_actionPerformed();
- else if(evt.getSource()==scaleRight)
- scaleRight_actionPerformed();
- else if(evt.getSource()==seqLimits)
- seqLimits_itemStateChanged();
- else if(evt.getSource()==viewBoxesMenuItem)
- viewBoxesMenuItem_actionPerformed();
- else if(evt.getSource()==viewTextMenuItem)
- viewTextMenuItem_actionPerformed();
- else if(evt.getSource()==renderGapsMenuItem)
- renderGapsMenuItem_actionPerformed();
- else if(evt.getSource()==annotationPanelMenuItem)
- annotationPanelMenuItem_actionPerformed();
- else if(evt.getSource()==sequenceFeatures)
- {
- viewport.showSequenceFeatures(sequenceFeatures.getState());
- alignPanel.seqPanel.seqCanvas.repaint();
- }
- else if(evt.getSource()==conservationMenuItem)
- conservationMenuItem_actionPerformed();
- else if(evt.getSource()==abovePIDThreshold)
- abovePIDThreshold_actionPerformed();
- else if(evt.getSource()==applyToAllGroups)
- applyToAllGroups_actionPerformed();
- }
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource()==inputText)
- inputText_actionPerformed();
- else if(evt.getSource()==loadTree)
- loadTree_actionPerformed();
- else if(evt.getSource()==closeMenuItem)
- closeMenuItem_actionPerformed();
- else if(evt.getSource()==copy)
- copy_actionPerformed();
- else if(evt.getSource()==undoMenuItem)
- undoMenuItem_actionPerformed();
- else if(evt.getSource()==redoMenuItem)
- redoMenuItem_actionPerformed();
- else if(evt.getSource()==inputText)
- inputText_actionPerformed();
- else if(evt.getSource()==closeMenuItem)
- closeMenuItem_actionPerformed();
- else if(evt.getSource()==undoMenuItem)
- undoMenuItem_actionPerformed();
- else if(evt.getSource()==redoMenuItem)
- redoMenuItem_actionPerformed();
- else if(evt.getSource()==copy)
- copy_actionPerformed();
- else if(evt.getSource()==pasteNew)
- pasteNew_actionPerformed();
- else if(evt.getSource()==pasteThis)
- pasteThis_actionPerformed();
- else if(evt.getSource()==cut)
- cut_actionPerformed();
- else if(evt.getSource()==delete)
- delete_actionPerformed();
- else if(evt.getSource()==deleteGroups)
- deleteGroups_actionPerformed();
- else if(evt.getSource()==selectAllSequenceMenuItem)
- selectAllSequenceMenuItem_actionPerformed();
- else if(evt.getSource()==deselectAllSequenceMenuItem)
- deselectAllSequenceMenuItem_actionPerformed();
- else if(evt.getSource()==invertSequenceMenuItem)
- invertSequenceMenuItem_actionPerformed();
- else if(evt.getSource()==remove2LeftMenuItem)
- remove2LeftMenuItem_actionPerformed();
- else if(evt.getSource()==remove2RightMenuItem)
- remove2RightMenuItem_actionPerformed();
- else if(evt.getSource()==removeGappedColumnMenuItem)
- removeGappedColumnMenuItem_actionPerformed();
- else if(evt.getSource()==removeAllGapsMenuItem)
- removeAllGapsMenuItem_actionPerformed();
- else if(evt.getSource()==findMenuItem)
- findMenuItem_actionPerformed();
- else if(evt.getSource()==font)
- font_actionPerformed();
- else if(evt.getSource()==featureSettings)
- featureSettings_actionPerformed();
- else if(evt.getSource()==overviewMenuItem)
- overviewMenuItem_actionPerformed();
- else if(evt.getSource()==noColourmenuItem)
- noColourmenuItem_actionPerformed();
- else if(evt.getSource()==clustalColour)
- clustalColour_actionPerformed();
- else if(evt.getSource()==zappoColour)
- zappoColour_actionPerformed();
- else if(evt.getSource()==taylorColour)
- taylorColour_actionPerformed();
- else if(evt.getSource()==hydrophobicityColour)
- hydrophobicityColour_actionPerformed();
- else if(evt.getSource()==helixColour)
- helixColour_actionPerformed();
- else if(evt.getSource()==strandColour)
- strandColour_actionPerformed();
- else if(evt.getSource()==turnColour)
- turnColour_actionPerformed();
- else if(evt.getSource()==buriedColour)
- buriedColour_actionPerformed();
- else if(evt.getSource()==nucleotideColour)
- nucleotideColour_actionPerformed();
- else if(evt.getSource()==modifyPID)
- modifyPID_actionPerformed();
- else if(evt.getSource()==modifyConservation)
- modifyConservation_actionPerformed();
- else if(evt.getSource()==userDefinedColour)
- userDefinedColour_actionPerformed();
- else if(evt.getSource()==PIDColour)
- PIDColour_actionPerformed();
- else if(evt.getSource()==BLOSUM62Colour)
- BLOSUM62Colour_actionPerformed();
- else if(evt.getSource()==annotationColour)
- new AnnotationColourChooser(viewport, alignPanel);
- else if(evt.getSource()==sortPairwiseMenuItem)
- sortPairwiseMenuItem_actionPerformed();
- else if(evt.getSource()==sortIDMenuItem)
- sortIDMenuItem_actionPerformed();
- else if(evt.getSource()==sortGroupMenuItem)
- sortGroupMenuItem_actionPerformed();
- else if(evt.getSource()==removeRedundancyMenuItem)
- removeRedundancyMenuItem_actionPerformed();
- else if(evt.getSource()==pairwiseAlignmentMenuItem)
- pairwiseAlignmentMenuItem_actionPerformed();
- else if(evt.getSource()==PCAMenuItem)
- PCAMenuItem_actionPerformed();
- else if(evt.getSource()==averageDistanceTreeMenuItem)
- averageDistanceTreeMenuItem_actionPerformed();
- else if(evt.getSource()==neighbourTreeMenuItem)
- neighbourTreeMenuItem_actionPerformed();
- else if(evt.getSource()==njTreeBlosumMenuItem)
- njTreeBlosumMenuItem_actionPerformed();
- else if(evt.getSource()==avDistanceTreeBlosumMenuItem)
- avTreeBlosumMenuItem_actionPerformed();
- else if(evt.getSource()==documentation)
- documentation_actionPerformed();
- else if(evt.getSource()==about)
- about_actionPerformed();
-
- }
-
- public void inputText_actionPerformed()
- {
- CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
- Frame frame = new Frame();
- frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame, "Cut & Paste Input", 500, 500);
- }
-
- protected void outputText_actionPerformed(ActionEvent e)
- {
- CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
- Frame frame = new Frame();
- frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame,
- "Alignment output - " + e.getActionCommand(),
- 600, 500);
- cap.setText(new AppletFormatAdapter().formatSequences(e.getActionCommand(),
- viewport.getAlignment().getSequences(),
- viewport.showJVSuffix));
- }
-
- public void closeMenuItem_actionPerformed()
- {
- PaintRefresher.components.remove(viewport.alignment);
- if(PaintRefresher.components.size()==0 && applet==null)
- System.exit(0);
-
- this.dispose();
- }
-
- Stack historyList = new Stack();
- Stack redoList = new Stack();
-
- void updateEditMenuBar()
- {
- if (historyList.size() > 0)
- {
- undoMenuItem.setEnabled(true);
- HistoryItem hi = (HistoryItem) historyList.peek();
- undoMenuItem.setLabel("Undo " + hi.getDescription());
- }
- else
- {
- undoMenuItem.setEnabled(false);
- undoMenuItem.setLabel("Undo");
- }
-
- if (redoList.size() > 0)
- {
- redoMenuItem.setEnabled(true);
- HistoryItem hi = (HistoryItem) redoList.peek();
- redoMenuItem.setLabel("Redo " + hi.getDescription());
- }
- else
- {
- redoMenuItem.setEnabled(false);
- redoMenuItem.setLabel("Redo");
- }
- }
-
- public void addHistoryItem(HistoryItem hi)
- {
- historyList.push(hi);
- updateEditMenuBar();
- }
-
- protected void undoMenuItem_actionPerformed()
- {
- HistoryItem hi = (HistoryItem) historyList.pop();
- redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment,
- HistoryItem.HIDE));
- restoreHistoryItem(hi);
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- protected void redoMenuItem_actionPerformed()
- {
- HistoryItem hi = (HistoryItem) redoList.pop();
- restoreHistoryItem(hi);
- updateEditMenuBar();
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- // used by undo and redo
- void restoreHistoryItem(HistoryItem hi)
- {
- hi.restore();
-
- updateEditMenuBar();
-
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- public void moveSelectedSequences(boolean up)
- {
- SequenceGroup sg = viewport.getSelectionGroup();
- if (sg == null)
- {
- return;
- }
-
- if (up)
- {
- for (int i = 1; i < viewport.alignment.getHeight(); i++)
- {
- SequenceI seq = viewport.alignment.getSequenceAt(i);
- if (!sg.sequences.contains(seq))
- {
- continue;
- }
-
- SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
- if (sg.sequences.contains(temp))
- {
- continue;
- }
-
- viewport.alignment.getSequences().setElementAt(temp, i);
- viewport.alignment.getSequences().setElementAt(seq, i - 1);
- }
- }
- else
- {
- for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
- {
- SequenceI seq = viewport.alignment.getSequenceAt(i);
- if (!sg.sequences.contains(seq))
- {
- continue;
- }
-
- SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
- if (sg.sequences.contains(temp))
- {
- continue;
- }
-
- viewport.alignment.getSequences().setElementAt(temp, i);
- viewport.alignment.getSequences().setElementAt(seq, i + 1);
- }
- }
-
- alignPanel.repaint();
- }
-
- StringBuffer copiedSequences;
- protected void copy_actionPerformed()
- {
- if (viewport.getSelectionGroup() == null)
- {
- return;
- }
-
- SequenceGroup sg = viewport.getSelectionGroup();
- copiedSequences = new StringBuffer();
- Hashtable orderedSeqs = new Hashtable();
- for (int i = 0; i < sg.getSize(); i++)
- {
- SequenceI seq = sg.getSequenceAt(i);
- int index = viewport.alignment.findIndex(seq);
- orderedSeqs.put(index + "", seq);
- }
-
- int index = 0, startRes, endRes;
- char ch;
-
- for (int i = 0; i < sg.getSize(); i++)
- {
- SequenceI seq = null;
-
- while (seq == null)
- {
- if (orderedSeqs.containsKey(index + ""))
- {
- seq = (SequenceI) orderedSeqs.get(index + "");
- index++;
-
- break;
- }
- else
- {
- index++;
- }
- }
-
- //FIND START RES
- //Returns residue following index if gap
- startRes = seq.findPosition(sg.getStartRes());
-
- //FIND END RES
- //Need to find the residue preceeding index if gap
- endRes = 0;
-
- for (int j = 0; j < sg.getEndRes()+1 && j < seq.getLength(); j++)
- {
- ch = seq.getCharAt(j);
- if (!jalview.util.Comparison.isGap( (ch)))
- {
- endRes++;
- }
- }
-
- if(endRes>0)
- {
- endRes += seq.getStart() -1;
- }
-
- copiedSequences.append(seq.getName() + "\t" +
- startRes + "\t" +
- endRes + "\t" +
- seq.getSequence(sg.getStartRes(),
- sg.getEndRes() + 1) + "\n");
- }
-
- }
-
- protected void pasteNew_actionPerformed()
- {
- paste(true);
- }
-
- protected void pasteThis_actionPerformed()
- {
- addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
- HistoryItem.PASTE));
- paste(false);
- }
-
- void paste(boolean newAlignment)
- {
- try
- {
- if (copiedSequences == null)
- {
- return;
- }
-
- StringTokenizer st = new StringTokenizer(copiedSequences.toString());
- Vector seqs = new Vector();
- while (st.hasMoreElements())
- {
- String name = st.nextToken();
- int start = Integer.parseInt(st.nextToken());
- int end = Integer.parseInt(st.nextToken());
- Sequence sequence = new Sequence(name, st.nextToken(), start, end);
-
- if (!newAlignment)
- {
- viewport.alignment.addSequence(sequence);
- }
- else
- {
- seqs.addElement(sequence);
- }
- }
-
- if (newAlignment)
- {
- SequenceI[] newSeqs = new SequenceI[seqs.size()];
- for (int i = 0; i < seqs.size(); i++)
- {
- newSeqs[i] = (SequenceI) seqs.elementAt(i);
- }
-
- String newtitle = new String("Copied sequences");
- if (getTitle().startsWith("Copied sequences"))
- {
- newtitle = getTitle();
- }
- else
- {
- newtitle = newtitle.concat("- from " + getTitle());
- }
- AlignFrame af = new AlignFrame(new Alignment(newSeqs),
- applet,
- newtitle,
- false);
-
- jalview.bin.JalviewLite.addFrame(af, newtitle, NEW_WINDOW_WIDTH,
- NEW_WINDOW_HEIGHT);
- }
- else
- {
- viewport.setEndSeq(viewport.alignment.getHeight());
- viewport.alignment.getWidth();
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- }
- catch (Exception ex)
- {} // could be anything being pasted in here
-
- }
-
- protected void cut_actionPerformed()
- {
- copy_actionPerformed();
- delete_actionPerformed();
- }
-
- protected void delete_actionPerformed()
- {
- addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
- HistoryItem.HIDE));
- if (viewport.getSelectionGroup() == null)
- {
- return;
- }
-
-
- SequenceGroup sg = viewport.getSelectionGroup();
- boolean allSequences = false;
- if(sg.sequences.size()==viewport.alignment.getHeight())
- allSequences = true;
-
- 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)
- {
- viewport.getColumnSelection().removeElements(sg.getStartRes(),
- sg.getEndRes() + 1);
- }
-
-
- if (seq.getSequence().length() < 1)
- {
- viewport.getAlignment().deleteSequence(seq);
- }
- else
- {
- viewport.getAlignment().getSequences().setElementAt(seq, index);
- }
- }
-
- viewport.setSelectionGroup(null);
- viewport.alignment.deleteGroup(sg);
- viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getSize().height);
- if (viewport.getAlignment().getHeight() < 1)
- {
- try
- {
- this.setVisible(false);
- }
- catch (Exception ex)
- {}
- }
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
-
- }
-
- protected void deleteGroups_actionPerformed()
- {
- viewport.alignment.deleteAllGroups();
- viewport.setSelectionGroup(null);
-
- alignPanel.repaint();
- }
-
- public void selectAllSequenceMenuItem_actionPerformed()
- {
- SequenceGroup sg = new SequenceGroup();
- for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
- {
- sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
- }
- sg.setEndRes(viewport.alignment.getWidth()-1);
- viewport.setSelectionGroup(sg);
- alignPanel.repaint();
- PaintRefresher.Refresh(null, viewport.alignment);
- }
-
- public void deselectAllSequenceMenuItem_actionPerformed()
- {
- viewport.setSelectionGroup(null);
- viewport.getColumnSelection().clear();
- viewport.setSelectionGroup(null);
- alignPanel.idPanel.idCanvas.searchResults = null;
- alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
- alignPanel.repaint();
- PaintRefresher.Refresh(null, viewport.alignment);
- }
-
- public void invertSequenceMenuItem_actionPerformed()
- {
- SequenceGroup sg = viewport.getSelectionGroup();
- for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
- {
- sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
- }
-
- PaintRefresher.Refresh(null, viewport.alignment);
- }
-
- public void remove2LeftMenuItem_actionPerformed()
- {
- ColumnSelection colSel = viewport.getColumnSelection();
- if (colSel.size() > 0)
- {
- addHistoryItem(new HistoryItem("Remove Left", viewport.alignment,
- HistoryItem.HIDE));
- int min = colSel.getMin();
- viewport.getAlignment().trimLeft(min);
- colSel.compensateForEdit(0, min);
-
- if (viewport.getSelectionGroup() != null)
- {
- viewport.getSelectionGroup().adjustForRemoveLeft(min);
- }
-
- Vector groups = viewport.alignment.getGroups();
- for (int i = 0; i < groups.size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
- if (!sg.adjustForRemoveLeft(min))
- {
- viewport.alignment.deleteGroup(sg);
- }
- }
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
- }
-
- public void remove2RightMenuItem_actionPerformed()
- {
- ColumnSelection colSel = viewport.getColumnSelection();
- if (colSel.size() > 0)
- {
- addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
- HistoryItem.HIDE));
- int max = colSel.getMax();
- viewport.getAlignment().trimRight(max);
- if (viewport.getSelectionGroup() != null)
- {
- viewport.getSelectionGroup().adjustForRemoveRight(max);
- }
-
- Vector groups = viewport.alignment.getGroups();
- for (int i = 0; i < groups.size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
- if (!sg.adjustForRemoveRight(max))
- {
- viewport.alignment.deleteGroup(sg);
- }
- }
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- }
-
- public void removeGappedColumnMenuItem_actionPerformed()
- {
- addHistoryItem(new HistoryItem("Remove Gapped Columns",
- viewport.alignment,
- HistoryItem.HIDE));
-
- //This is to maintain viewport position on first residue
- //of first sequence
- SequenceI seq = viewport.alignment.getSequenceAt(0);
- int startRes = seq.findPosition(viewport.startRes);
-
- viewport.getAlignment().removeGaps();
-
- viewport.setStartRes(seq.findIndex(startRes)-1);
-
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- public void removeAllGapsMenuItem_actionPerformed()
- {
- addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
- HistoryItem.HIDE));
-
- //This is to maintain viewport position on first residue
- //of first sequence
- SequenceI seq = viewport.alignment.getSequenceAt(0);
- int startRes = seq.findPosition(viewport.startRes);
-
- SequenceI current;
- int jSize;
-
- Vector seqs=null;
-
- int start=0, end = viewport.alignment.getWidth();
-
- if (viewport.getSelectionGroup() != null
- && viewport.getSelectionGroup().sequences != null
- && viewport.getSelectionGroup().sequences.size()>0)
- {
- seqs = viewport.getSelectionGroup().sequences;
- start = viewport.getSelectionGroup().getStartRes();
- end = viewport.getSelectionGroup().getEndRes()+1;
- }
- else
- seqs = viewport.alignment.getSequences();
-
- for (int i = 0; i < seqs.size(); i++)
- {
- current = (SequenceI) seqs.elementAt(i);
- jSize = current.getLength();
-
- // Removing a range is much quicker than removing gaps
- // one by one for long sequences
- int j = start;
- int rangeStart=-1, rangeEnd=-1;
-
- do
- {
- if (jalview.util.Comparison.isGap(current.getCharAt(j)))
- {
- if(rangeStart==-1)
- {
- rangeStart = j;
- rangeEnd = j+1;
- }
- else
- {
- rangeEnd++;
- }
- j++;
- }
- else
- {
- if(rangeStart>-1)
- {
- current.deleteChars(rangeStart, rangeEnd);
- j-=rangeEnd-rangeStart;
- jSize-=rangeEnd-rangeStart;
- rangeStart = -1;
- rangeEnd = -1;
- }
- else
- j++;
- }
- }
- while (j < end && j < jSize);
- if(rangeStart>-1)
- {
- current.deleteChars(rangeStart, rangeEnd);
- }
- }
- viewport.setStartRes(seq.findIndex(startRes)-1);
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- public void alignmentChanged()
- {
- viewport.updateConsensus();
- viewport.updateConservation ();
- resetAllColourSchemes();
- if(alignPanel.overviewPanel!=null)
- alignPanel.overviewPanel.updateOverviewImage();
-
- viewport.alignment.adjustSequenceAnnotations();
- alignPanel.repaint();
- }
-
- void resetAllColourSchemes()
- {
- ColourSchemeI cs = viewport.globalColourScheme;
- if(cs!=null)
- {
- if (cs instanceof ClustalxColourScheme)
- {
- ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
- resetClustalX(viewport.alignment.getSequences(),
- viewport.alignment.getWidth());
- }
-
- cs.setConsensus(viewport.vconsensus);
- if (cs.conservationApplied())
- {
- Alignment al = (Alignment) viewport.alignment;
- Conservation c = new Conservation("All",
- ResidueProperties.propHash, 3,
- al.getSequences(), 0,
- al.getWidth() - 1);
- c.calculate();
- c.verdict(false, viewport.ConsPercGaps);
-
- cs.setConservation(c);
- }
- }
-
- int s, sSize = viewport.alignment.getGroups().size();
- for(s=0; s 1)
- {
- Frame frame = new Frame();
- frame.add(new PairwiseAlignPanel(alignPanel));
- jalview.bin.JalviewLite.addFrame(frame, "Pairwise Alignment", 600, 500);
- }
- }
-
- public void PCAMenuItem_actionPerformed()
- {
- //are the sequences aligned?
- if (!viewport.alignment.isAligned())
- {
- SequenceI current;
- int Width = viewport.getAlignment().getWidth();
-
- for (int i = 0; i < viewport.getAlignment().getSequences().size();
- i++)
- {
- current = viewport.getAlignment().getSequenceAt(i);
-
- if (current.getLength() < Width)
- {
- current.insertCharAt(Width - 1, viewport.getGapCharacter());
- }
- }
- alignPanel.repaint();
- }
-
- if ( (viewport.getSelectionGroup() != null &&
- viewport.getSelectionGroup().getSize() < 4 &&
- viewport.getSelectionGroup().getSize() > 0)
- || viewport.getAlignment().getHeight() < 4)
- {
- return;
- }
-
- try
- {
- new PCAPanel(viewport);
- }
- catch (java.lang.OutOfMemoryError ex)
- {
- }
-
- }
-
- public void averageDistanceTreeMenuItem_actionPerformed()
- {
- NewTreePanel("AV", "PID", "Average distance tree using PID");
- }
-
- public void neighbourTreeMenuItem_actionPerformed()
- {
- NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
- }
-
- protected void njTreeBlosumMenuItem_actionPerformed()
- {
- NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
- }
-
- protected void avTreeBlosumMenuItem_actionPerformed()
- {
- NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID");
- }
-
- void NewTreePanel(String type, String pwType, String title)
- {
- //are the sequences aligned?
- if (!viewport.alignment.isAligned())
- {
- SequenceI current;
- int Width = viewport.getAlignment().getWidth();
-
- for (int i = 0; i < viewport.getAlignment().getSequences().size();
- i++)
- {
- current = viewport.getAlignment().getSequenceAt(i);
-
- if (current.getLength() < Width)
- {
- current.insertCharAt(Width - 1, viewport.getGapCharacter());
- }
- }
- alignPanel.repaint();
-
- }
-
- final TreePanel tp;
- if (viewport.getSelectionGroup() != null &&
- viewport.getSelectionGroup().getSize() > 3)
- {
- tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
- pwType,
- 0, viewport.alignment.getWidth());
- }
- else
- {
- tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
- type, pwType, 0, viewport.alignment.getWidth());
- }
-
- addTreeMenuItem(tp, title);
-
- jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
- }
-
- void loadTree_actionPerformed()
- {
- TreePanel tp = null;
-
- CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
- cap.setText("Paste your Newick tree file here.");
- cap.treeImport = true;
- Frame frame = new Frame();
- frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame, "Paste Newick file ", 400, 300);
- }
-
- public void loadTree(jalview.io.NewickFile tree, String treeFile)
- {
- TreePanel tp = new TreePanel(viewport,
- viewport.getAlignment().getSequences(),
- tree, "From File - ", treeFile);
- jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
- addTreeMenuItem(tp, treeFile);
- }
-
- void addTreeMenuItem(final TreePanel treePanel, String title)
- {
- final MenuItem item = new MenuItem(title);
- sortByTreeMenu.add(item);
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent evt)
- {
- addHistoryItem(new HistoryItem("Sort", viewport.alignment,
- HistoryItem.SORT));
- AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());
- alignPanel.repaint();
- }
- });
-
- treePanel.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- sortByTreeMenu.remove(item);
- };
- });
- }
-
- protected void documentation_actionPerformed()
- {
- showURL("http://www.jalview.org/help.html", "HELP");
- }
-
- protected void about_actionPerformed()
- {
-
- class AboutPanel extends Canvas
- {
- String version;
- public AboutPanel(String version)
- { this.version = version; }
-
- public void paint(Graphics g)
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, getSize().width, getSize().height);
- g.setFont(new Font("Helvetica", Font.PLAIN, 12));
- FontMetrics fm = g.getFontMetrics();
- int fh = fm.getHeight();
- int y = 5, x = 7;
- g.setColor(Color.black);
- g.setFont(new Font("Helvetica", Font.BOLD, 14));
- g.drawString("Jalview - Release "+version, 200, y += fh);
- g.setFont(new Font("Helvetica", Font.PLAIN, 12));
- g.drawString("Authors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton.",
- x, y += fh * 2);
- g.drawString("Current development managed by Andrew Waterhouse; Barton Group, University of Dundee.",
- x, y += fh);
- g.drawString(
- "For any issues relating to Jalview, email help@jalview.org", x,
- y += fh);
- g.drawString("If you use JalView, please cite:", x, y += fh + 8);
- g.drawString("\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",
- x, y += fh);
- g.drawString("Bioinformatics, 2004 12;426-7.", x, y += fh);
- }
- }
-
- String version = "test";
- java.net.URL url = getClass().getResource("/.build_properties");
- if (url != null)
- {
- try
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- url.openStream()));
- String line;
- while ( (line = reader.readLine()) != null)
- {
- if (line.indexOf("VERSION") > -1)
- {
- version = line.substring(line.indexOf("=") + 1);
- }
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
-
- Frame frame = new Frame();
- frame.add(new AboutPanel(version));
- jalview.bin.JalviewLite.addFrame(frame, "Jalview", 580, 200);
-
- }
-
- public void showURL(String url, String target)
- {
- if (applet == null)
- {
- System.out.println("Not running as applet - no browser available.");
- }
- else
- {
- try
- {
- applet.getAppletContext().showDocument(new java.net.URL(url),
- target);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }
-
-
- //////////////////////////////////////////////////////////////////////////////////
- //JBuilder Graphics here
-
- protected MenuBar alignFrameMenuBar = new MenuBar();
- protected Menu fileMenu = new Menu("File");
- protected MenuItem loadTree = new MenuItem("Load Associated Tree");
- protected MenuItem closeMenuItem = new MenuItem("Close");
- protected Menu editMenu = new Menu("Edit");
- protected Menu viewMenu = new Menu("View");
- protected Menu colourMenu = new Menu("Colour");
- protected Menu calculateMenu = new Menu("Calculate");
- protected MenuItem selectAllSequenceMenuItem = new MenuItem("Select all");
- protected MenuItem deselectAllSequenceMenuItem = new MenuItem("Deselect All");
- protected MenuItem invertSequenceMenuItem = new MenuItem("Invert Selection");
- protected MenuItem remove2LeftMenuItem = new MenuItem();
- protected MenuItem remove2RightMenuItem = new MenuItem();
- protected MenuItem removeGappedColumnMenuItem = new MenuItem();
- protected MenuItem removeAllGapsMenuItem = new MenuItem();
- protected CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
- protected CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
- protected MenuItem sortPairwiseMenuItem = new MenuItem();
- protected MenuItem sortIDMenuItem = new MenuItem();
- protected MenuItem sortGroupMenuItem = new MenuItem();
- protected MenuItem removeRedundancyMenuItem = new MenuItem();
- protected MenuItem pairwiseAlignmentMenuItem = new MenuItem();
- protected MenuItem PCAMenuItem = new MenuItem();
- protected MenuItem averageDistanceTreeMenuItem = new MenuItem();
- protected MenuItem neighbourTreeMenuItem = new MenuItem();
- BorderLayout borderLayout1 = new BorderLayout();
- public Label statusBar = new Label();
- protected Menu outputTextboxMenu = new Menu();
- protected MenuItem clustalColour = new MenuItem();
- protected MenuItem zappoColour = new MenuItem();
- protected MenuItem taylorColour = new MenuItem();
- protected MenuItem hydrophobicityColour = new MenuItem();
- protected MenuItem helixColour = new MenuItem();
- protected MenuItem strandColour = new MenuItem();
- protected MenuItem turnColour = new MenuItem();
- protected MenuItem buriedColour = new MenuItem();
- protected MenuItem userDefinedColour = new MenuItem();
- protected MenuItem PIDColour = new MenuItem();
- protected MenuItem BLOSUM62Colour = new MenuItem();
- MenuItem njTreeBlosumMenuItem = new MenuItem();
- MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
- protected CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
- protected CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
- MenuItem overviewMenuItem = new MenuItem();
- protected MenuItem undoMenuItem = new MenuItem();
- protected MenuItem redoMenuItem = new MenuItem();
- protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
- MenuItem noColourmenuItem = new MenuItem();
- protected CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
- protected CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
- MenuItem findMenuItem = new MenuItem();
- Menu searchMenu = new Menu();
- protected CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
- protected MenuItem nucleotideColour = new MenuItem();
- MenuItem deleteGroups = new MenuItem();
- MenuItem delete = new MenuItem();
- MenuItem copy = new MenuItem();
- MenuItem cut = new MenuItem();
- Menu pasteMenu = new Menu();
- MenuItem pasteNew = new MenuItem();
- MenuItem pasteThis = new MenuItem();
- protected CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
- protected MenuItem font = new MenuItem();
- protected CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
- protected CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
- protected CheckboxMenuItem scaleRight = new CheckboxMenuItem();
- MenuItem modifyPID = new MenuItem();
- MenuItem modifyConservation = new MenuItem();
- protected Menu sortByTreeMenu = new Menu();
- Menu sort = new Menu();
- Menu calculate = new Menu();
- MenuItem inputText = new MenuItem();
- Menu helpMenu = new Menu();
- MenuItem documentation = new MenuItem();
- MenuItem about = new MenuItem();
- protected CheckboxMenuItem seqLimits = new CheckboxMenuItem();
- Panel embeddedMenu;
- Label embeddedEdit;
- Label embeddedSearch;
- Label embeddedView;
- Label embeddedColour;
- Label embeddedFile;
- Label embeddedHelp;
- Label embeddedCalculate;
- FlowLayout flowLayout1;
-
- private void jbInit() throws Exception {
-
- setMenuBar(alignFrameMenuBar);
-
- MenuItem item;
-
- // dynamically fill save as menu with available formats
- for (int i = 0; i < jalview.io.AppletFormatAdapter.formats.size(); i++)
- {
-
- item = new MenuItem( (String) jalview.io.AppletFormatAdapter.formats.
- elementAt(
- i));
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- outputText_actionPerformed(e);
- }
- });
-
- outputTextboxMenu.add(item);
- }
- closeMenuItem.addActionListener(this);
-
- loadTree.addActionListener(this);
- selectAllSequenceMenuItem.addActionListener(this);
- deselectAllSequenceMenuItem.addActionListener(this);
- invertSequenceMenuItem.addActionListener(this);
- remove2LeftMenuItem.setLabel("Remove Left");
- remove2LeftMenuItem.addActionListener(this);
- remove2RightMenuItem.setLabel("Remove Right");
- remove2RightMenuItem.addActionListener(this);
- removeGappedColumnMenuItem.setLabel("Remove Empty Columns");
- removeGappedColumnMenuItem.addActionListener(this);
- removeAllGapsMenuItem.setLabel("Remove All Gaps");
- removeAllGapsMenuItem.addActionListener(this);
- viewBoxesMenuItem.setLabel("Boxes");
- viewBoxesMenuItem.setState(true);
- viewBoxesMenuItem.addItemListener(this);
- viewTextMenuItem.setLabel("Text");
- viewTextMenuItem.setState(true);
- viewTextMenuItem.addItemListener(this);
- sortPairwiseMenuItem.setLabel("by Pairwise Identity");
- sortPairwiseMenuItem.addActionListener(this);
- sortIDMenuItem.setLabel("by ID");
- sortIDMenuItem.addActionListener(this);
- sortGroupMenuItem.setLabel("by Group");
- sortGroupMenuItem.addActionListener(this);
- removeRedundancyMenuItem.setLabel("Remove Redundancy...");
- removeRedundancyMenuItem.addActionListener(this);
- pairwiseAlignmentMenuItem.setLabel("Pairwise Alignments...");
- pairwiseAlignmentMenuItem.addActionListener(this);
- PCAMenuItem.setLabel("Principal Component Analysis");
- PCAMenuItem.addActionListener(this);
- averageDistanceTreeMenuItem.setLabel(
- "Average Distance Using % Identity");
- averageDistanceTreeMenuItem.addActionListener(this);
- neighbourTreeMenuItem.setLabel("Neighbour Joining Using % Identity");
- neighbourTreeMenuItem.addActionListener(this);
- alignFrameMenuBar.setFont(new java.awt.Font("Verdana", 0, 11));
- statusBar.setBackground(Color.white);
- statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
- statusBar.setText("Status bar");
- outputTextboxMenu.setLabel("Output to Textbox");
- clustalColour.setLabel("Clustalx");
-
- clustalColour.addActionListener(this);
- zappoColour.setLabel("Zappo");
- zappoColour.addActionListener(this);
- taylorColour.setLabel("Taylor");
- taylorColour.addActionListener(this);
- hydrophobicityColour.setLabel("Hydrophobicity");
- hydrophobicityColour.addActionListener(this);
- helixColour.setLabel("Helix Propensity");
- helixColour.addActionListener(this);
- strandColour.setLabel("Strand Propensity");
- strandColour.addActionListener(this);
- turnColour.setLabel("Turn Propensity");
- turnColour.addActionListener(this);
- buriedColour.setLabel("Buried Index");
- buriedColour.addActionListener(this);
- userDefinedColour.setLabel("User Defined...");
- userDefinedColour.addActionListener(this);
- PIDColour.setLabel("Percentage Identity");
- PIDColour.addActionListener(this);
- BLOSUM62Colour.setLabel("BLOSUM62 Score");
- BLOSUM62Colour.addActionListener(this);
- avDistanceTreeBlosumMenuItem.setLabel(
- "Average Distance Using BLOSUM62");
- avDistanceTreeBlosumMenuItem.addActionListener(this);
- njTreeBlosumMenuItem.setLabel("Neighbour Joining Using BLOSUM62");
- njTreeBlosumMenuItem.addActionListener(this);
- annotationPanelMenuItem.setLabel("Show Annotations");
- annotationPanelMenuItem.addItemListener(this);
- colourTextMenuItem.setLabel("Colour Text");
- colourTextMenuItem.addItemListener(this);
- overviewMenuItem.setLabel("Overview Window");
- overviewMenuItem.addActionListener(this);
- undoMenuItem.setEnabled(false);
- undoMenuItem.setLabel("Undo");
- undoMenuItem.addActionListener(this);
- redoMenuItem.setEnabled(false);
- redoMenuItem.setLabel("Redo");
- redoMenuItem.addActionListener(this);
- conservationMenuItem.setLabel("by Conservation");
- conservationMenuItem.addItemListener(this);
- noColourmenuItem.setLabel("None");
- noColourmenuItem.addActionListener(this);
- wrapMenuItem.setLabel("Wrap");
- wrapMenuItem.addItemListener(this);
- renderGapsMenuItem.setLabel("Show Gaps");
- renderGapsMenuItem.setState(true);
- renderGapsMenuItem.addItemListener(this);
- findMenuItem.setLabel("Find...");
- findMenuItem.addActionListener(this);
- searchMenu.setLabel("Search");
-
- abovePIDThreshold.setLabel("Above Identity Threshold");
- abovePIDThreshold.addItemListener(this);
- nucleotideColour.setLabel("Nucleotide");
- nucleotideColour.addActionListener(this);
- deleteGroups.setLabel("Undefine Groups");
- deleteGroups.addActionListener(this);
- copy.setLabel("Copy");
- copy.addActionListener(this);
- cut.setLabel("Cut");
- cut.addActionListener(this);
- delete.setLabel("Delete");
- delete.addActionListener(this);
- pasteMenu.setLabel("Paste");
- pasteNew.setLabel("To New Alignment");
- pasteNew.addActionListener(this);
- pasteThis.setLabel("Add To This Alignment");
- pasteThis.addActionListener(this);
- applyToAllGroups.setLabel("Apply Colour To All Groups");
- applyToAllGroups.setState(true);
- applyToAllGroups.addItemListener(this);
- font.setLabel("Font...");
- font.addActionListener(this);
- scaleAbove.setLabel("Scale Above");
- scaleAbove.setState(true);
- scaleAbove.setEnabled(false);
- scaleAbove.addItemListener(this);
- scaleLeft.setEnabled(false);
- scaleLeft.setState(true);
- scaleLeft.setLabel("Scale Left");
- scaleLeft.addItemListener(this);
- scaleRight.setEnabled(false);
- scaleRight.setState(true);
- scaleRight.setLabel("Scale Right");
- scaleRight.addItemListener(this);
- modifyPID.setLabel("Modify Identity Threshold...");
- modifyPID.addActionListener(this);
- modifyConservation.setLabel("Modify Conservation Threshold...");
- modifyConservation.addActionListener(this);
- sortByTreeMenu.setLabel("By Tree Order");
- sort.setLabel("Sort");
- calculate.setLabel("Calculate Tree");
- inputText.setLabel("Input from textbox");
- inputText.addActionListener(this);
-
- helpMenu.setLabel("Help");
- documentation.setLabel("Documentation");
- documentation.addActionListener(this);
-
- about.setLabel("About...");
- about.addActionListener(this);
- seqLimits.setState(true);
- seqLimits.setLabel("Show Sequence Limits");
- seqLimits.addItemListener(this);
- featureSettings.setLabel("Feature Settings...");
- featureSettings.addActionListener(this);
- sequenceFeatures.setLabel("Sequence Features");
- sequenceFeatures.addItemListener(this);
- sequenceFeatures.setState(false);
- annotationColour.setLabel("by Annotation...");
- annotationColour.addActionListener(this);
-
- alignFrameMenuBar.add(fileMenu);
- alignFrameMenuBar.add(editMenu);
- alignFrameMenuBar.add(searchMenu);
- alignFrameMenuBar.add(viewMenu);
- alignFrameMenuBar.add(colourMenu);
- alignFrameMenuBar.add(calculateMenu);
- alignFrameMenuBar.add(helpMenu);
- fileMenu.add(inputText);
- fileMenu.add(outputTextboxMenu);
- fileMenu.addSeparator();
- fileMenu.add(loadTree);
- fileMenu.add(closeMenuItem);
- editMenu.add(undoMenuItem);
- editMenu.add(redoMenuItem);
- editMenu.add(cut);
- editMenu.add(copy);
- editMenu.add(pasteMenu);
- editMenu.add(delete);
- editMenu.addSeparator();
- editMenu.add(selectAllSequenceMenuItem);
- editMenu.add(deselectAllSequenceMenuItem);
- editMenu.add(invertSequenceMenuItem);
- editMenu.add(deleteGroups);
- editMenu.addSeparator();
- editMenu.add(remove2LeftMenuItem);
- editMenu.add(remove2RightMenuItem);
- editMenu.add(removeGappedColumnMenuItem);
- editMenu.add(removeAllGapsMenuItem);
- editMenu.add(removeRedundancyMenuItem);
- searchMenu.add(findMenuItem);
- viewMenu.add(font);
- viewMenu.addSeparator();
- viewMenu.add(seqLimits);
- viewMenu.addSeparator();
- viewMenu.add(wrapMenuItem);
- viewMenu.add(scaleAbove);
- viewMenu.add(scaleLeft);
- viewMenu.add(scaleRight);
- viewMenu.addSeparator();
- viewMenu.add(viewBoxesMenuItem);
- viewMenu.add(viewTextMenuItem);
- viewMenu.add(colourTextMenuItem);
- viewMenu.add(renderGapsMenuItem);
- viewMenu.add(annotationPanelMenuItem);
- viewMenu.addSeparator();
- viewMenu.add(sequenceFeatures);
- viewMenu.add(featureSettings);
- viewMenu.addSeparator();
- viewMenu.add(overviewMenuItem);
- colourMenu.add(applyToAllGroups);
- colourMenu.addSeparator();
- colourMenu.add(noColourmenuItem);
- colourMenu.add(clustalColour);
- colourMenu.add(BLOSUM62Colour);
- colourMenu.add(PIDColour);
- colourMenu.add(zappoColour);
- colourMenu.add(taylorColour);
- colourMenu.add(hydrophobicityColour);
- colourMenu.add(helixColour);
- colourMenu.add(strandColour);
- colourMenu.add(turnColour);
- colourMenu.add(buriedColour);
- colourMenu.add(nucleotideColour);
- colourMenu.add(userDefinedColour);
- colourMenu.addSeparator();
- colourMenu.add(conservationMenuItem);
- colourMenu.add(modifyConservation);
- colourMenu.add(abovePIDThreshold);
- colourMenu.add(modifyPID);
- colourMenu.add(annotationColour);
- calculateMenu.add(sort);
- calculateMenu.add(calculate);
- calculateMenu.addSeparator();
- calculateMenu.add(pairwiseAlignmentMenuItem);
- calculateMenu.add(PCAMenuItem);
- this.add(statusBar, BorderLayout.SOUTH);
- pasteMenu.add(pasteNew);
- pasteMenu.add(pasteThis);
- sort.add(sortIDMenuItem);
- sort.add(sortByTreeMenu);
- sort.add(sortGroupMenuItem);
- sort.add(sortPairwiseMenuItem);
- calculate.add(averageDistanceTreeMenuItem);
- calculate.add(neighbourTreeMenuItem);
- calculate.add(avDistanceTreeBlosumMenuItem);
- calculate.add(njTreeBlosumMenuItem);
- helpMenu.add(documentation);
- helpMenu.add(about);
- }
-
- public void setEmbedded()
- {
-
- embeddedMenu = new Panel();
- embeddedEdit = new Label();
- embeddedSearch = new Label();
- embeddedView = new Label();
- embeddedColour = new Label();
- embeddedFile = new Label();
- embeddedHelp = new Label();
- embeddedCalculate = new Label();
- flowLayout1 = new FlowLayout();
- embeddedMenu.setBackground(Color.lightGray);
- embeddedMenu.setLayout(flowLayout1);
- embeddedEdit.setText("Edit");
- embeddedEdit.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
- embeddedSearch.setText("Search");
- embeddedSearch.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
- embeddedView.setText("View");
- embeddedView.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
- embeddedColour.setText("Colour");
- embeddedColour.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
- embeddedFile.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
- embeddedFile.setText("File");
- embeddedHelp.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
- embeddedHelp.setText("Help");
- embeddedCalculate.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
- embeddedCalculate.setText("Calculate");
- embeddedMenu.add(embeddedFile);
- embeddedMenu.add(embeddedEdit);
- embeddedMenu.add(embeddedSearch);
- embeddedMenu.add(embeddedView);
- embeddedMenu.add(embeddedColour);
- embeddedMenu.add(embeddedCalculate);
- embeddedMenu.add(embeddedHelp);
- flowLayout1.setAlignment(FlowLayout.LEFT);
- flowLayout1.setHgap(2);
- flowLayout1.setVgap(0);
- embeddedFile.addMouseListener(this);
- embeddedEdit.addMouseListener(this);
- embeddedSearch.addMouseListener(this);
- embeddedView.addMouseListener(this);
- embeddedColour.addMouseListener(this);
- embeddedCalculate.addMouseListener(this);
- embeddedHelp.addMouseListener(this);
-
- // setVisible(false);
- fileMenu.remove(closeMenuItem);
- fileMenu.remove(2); // Seperator
-
- applet.setLayout(new BorderLayout());
- applet.add(embeddedMenu, BorderLayout.NORTH);
- applet.add(statusBar, BorderLayout.SOUTH);
- // applet.validate();
-
- alignPanel.setSize(applet.size().width, applet.size().height
- - embeddedMenu.HEIGHT - statusBar.HEIGHT);
-
- applet.add(alignPanel, BorderLayout.CENTER);
- applet.validate();
-
- }
-
-
-
- PopupMenu filePopup, editPopup, searchPopup,
- viewPopup, colourPopup, calculatePopup, helpPopup;
- MenuItem featureSettings = new MenuItem();
- CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
- MenuItem annotationColour = new MenuItem();
-
- public void mousePressed(MouseEvent evt)
- {
- PopupMenu popup = null;
- Label source = (Label)evt.getSource();
- if(source==embeddedFile)
- {
- popup = filePopup = genPopupMenu(filePopup, fileMenu);
- }
- else if(source==embeddedEdit)
- {
- popup = editPopup = genPopupMenu(editPopup, editMenu);
- }
- else if(source==embeddedSearch)
- {
- popup = searchPopup = genPopupMenu(searchPopup, searchMenu);
- }
- else if(source==embeddedView)
- {
- popup = viewPopup = genPopupMenu(viewPopup, viewMenu);
- }
- else if(source==embeddedColour)
- {
- popup = colourPopup = genPopupMenu(colourPopup, colourMenu);
- }
- else if(source==embeddedCalculate)
- {
- popup = calculatePopup = genPopupMenu(calculatePopup, calculateMenu);
- }
- else if(source==embeddedHelp)
- {
- popup = helpPopup = genPopupMenu(helpPopup, helpMenu);
- }
-
- embeddedMenu.add(popup);
- popup.show(embeddedMenu,
- source.getBounds().x,
- source.getBounds().y + source.getBounds().getSize().height);
- }
-
- PopupMenu genPopupMenu(PopupMenu popup, Menu original)
- {
- if(popup!=null)
- {
- return popup;
- }
- popup = new PopupMenu();
- int m, mSize = original.getItemCount();
- for(m=0; m0)
+ alignPanel.seqPanel.seqCanvas
+ .getFeatureRenderer().featureLinks = featureLinks;
+ viewport.showSequenceFeatures = true;
+ sequenceFeatures.setState(true);
+ alignPanel.repaint();
+ }
+
+ }
+
+
+ public void keyPressed(KeyEvent evt)
+ {
+ if (viewport.cursorMode
+ && evt.getKeyCode() >= KeyEvent.VK_0
+ && evt.getKeyCode() <= KeyEvent.VK_9)
+ {
+ alignPanel.seqPanel.numberPressed(evt.getKeyChar());
+ }
+
+ switch (evt.getKeyCode())
+ {
+ case 27: // escape key
+ deselectAllSequenceMenuItem_actionPerformed();
+ break;
+ case KeyEvent.VK_X:
+ if (evt.isControlDown() || evt.isMetaDown())
+ {
+ cut_actionPerformed();
+ }
+ break;
+ case KeyEvent.VK_C:
+ if (viewport.cursorMode && !evt.isControlDown())
+ {
+ alignPanel.seqPanel.setCursorColumn();
+ }
+ if (evt.isControlDown() || evt.isMetaDown())
+ {
+ copy_actionPerformed();
+ }
+ break;
+ case KeyEvent.VK_V:
+ if (evt.isControlDown() || evt.isMetaDown())
+ {
+ paste(true);
+ }
+ break;
+ case KeyEvent.VK_A:
+ if (evt.isControlDown() || evt.isMetaDown())
+ {
+ selectAllSequenceMenuItem_actionPerformed();
+ }
+ break;
+ case KeyEvent.VK_DOWN:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.moveCursor(0,1);
+ }
+ else
+ moveSelectedSequences(false);
+ break;
+
+ case KeyEvent.VK_UP:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.moveCursor(0,-1);
+ }
+ else
+ moveSelectedSequences(true);
+ break;
+
+ case KeyEvent.VK_LEFT:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.moveCursor(-1,0);
+ }
+ break;
+
+ case KeyEvent.VK_RIGHT:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.moveCursor(1,0);
+ }
+ break;
+ case KeyEvent.VK_SPACE:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown());
+ }
+ break;
+
+ case KeyEvent.VK_DELETE:
+ case KeyEvent.VK_BACK_SPACE:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown());
+ }
+ else
+ {
+ cut_actionPerformed();
+ alignPanel.seqPanel.seqCanvas.repaint();
+ }
+ break;
+
+ case KeyEvent.VK_S:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setCursorRow();
+ }
+ break;
+ case KeyEvent.VK_P:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setCursorPosition();
+ }
+ break;
+
+ case KeyEvent.VK_ENTER:
+ case KeyEvent.VK_COMMA:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setCursorRowAndColumn();
+ }
+ break;
+
+ case KeyEvent.VK_Q:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setSelectionAreaAtCursor(true);
+ }
+ break;
+ case KeyEvent.VK_M:
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setSelectionAreaAtCursor(false);
+ }
+ break;
+
+ case KeyEvent.VK_F2:
+ viewport.cursorMode = ! viewport.cursorMode;
+ statusBar.setText("Keyboard editing mode is "+
+ (viewport.cursorMode ? "on" : "off"));
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
+ alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
+ }
+ alignPanel.seqPanel.seqCanvas.repaint();
+ break;
+
+ case KeyEvent.VK_F:
+ if (evt.isControlDown())
+ {
+ findMenuItem_actionPerformed();
+ }
+ break;
+ case KeyEvent.VK_H:
+ {
+ boolean toggleSeqs = !evt.isControlDown();
+ boolean toggleCols = !evt.isShiftDown();
+ boolean hide = false;
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ if(toggleSeqs)
+ {
+ if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
+ {
+ hide = true;
+ viewport.hideAllSelectedSeqs();
+ }
+ else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
+ viewport.showAllHiddenSeqs();
+ }
+
+ if(toggleCols)
+ {
+ if (viewport.colSel.getSelected().size() > 0)
+ {
+ viewport.hideSelectedColumns();
+ if(!toggleSeqs)
+ viewport.selectionGroup = sg;
+ }
+ else if (!hide)
+ viewport.showAllHiddenColumns();
+ }
+
+ alignPanel.repaint();
+ break;
+ }
+
+ }
+ }
+ public void keyReleased(KeyEvent evt)
+ {}
+ public void keyTyped(KeyEvent evt)
+ {}
+
+public void itemStateChanged(ItemEvent evt)
+ {
+ if(evt.getSource()==colourTextMenuItem)
+ colourTextMenuItem_actionPerformed();
+ else if(evt.getSource()==wrapMenuItem)
+ wrapMenuItem_actionPerformed();
+ else if(evt.getSource()==scaleAbove)
+ scaleAbove_actionPerformed();
+ else if(evt.getSource()==scaleLeft)
+ scaleLeft_actionPerformed();
+ else if(evt.getSource()==scaleRight)
+ scaleRight_actionPerformed();
+ else if(evt.getSource()==seqLimits)
+ seqLimits_itemStateChanged();
+ else if(evt.getSource()==viewBoxesMenuItem)
+ viewBoxesMenuItem_actionPerformed();
+ else if(evt.getSource()==viewTextMenuItem)
+ viewTextMenuItem_actionPerformed();
+ else if(evt.getSource()==renderGapsMenuItem)
+ renderGapsMenuItem_actionPerformed();
+ else if(evt.getSource()==annotationPanelMenuItem)
+ annotationPanelMenuItem_actionPerformed();
+ else if(evt.getSource()==sequenceFeatures)
+ {
+ viewport.showSequenceFeatures(sequenceFeatures.getState());
+ alignPanel.seqPanel.seqCanvas.repaint();
+ }
+ else if(evt.getSource()==conservationMenuItem)
+ conservationMenuItem_actionPerformed();
+ else if(evt.getSource()==abovePIDThreshold)
+ abovePIDThreshold_actionPerformed();
+ else if(evt.getSource()==applyToAllGroups)
+ applyToAllGroups_actionPerformed();
+ else if(evt.getSource()==autoCalculate)
+ viewport.autocalculateConsensus = autoCalculate.getState();
+ }
+ public void actionPerformed(ActionEvent evt)
+ {
+ Object source = evt.getSource();
+
+ if(source==inputText)
+ inputText_actionPerformed();
+ else if(source==loadTree)
+ loadTree_actionPerformed();
+ else if(source==loadApplication)
+ launchFullApplication();
+ else if(source==closeMenuItem)
+ closeMenuItem_actionPerformed();
+ else if(source==copy)
+ copy_actionPerformed();
+ else if(source==undoMenuItem)
+ undoMenuItem_actionPerformed();
+ else if(source==redoMenuItem)
+ redoMenuItem_actionPerformed();
+ else if(source==inputText)
+ inputText_actionPerformed();
+ else if(source==closeMenuItem)
+ closeMenuItem_actionPerformed();
+ else if(source==undoMenuItem)
+ undoMenuItem_actionPerformed();
+ else if(source==redoMenuItem)
+ redoMenuItem_actionPerformed();
+ else if(source==copy)
+ copy_actionPerformed();
+ else if(source==pasteNew)
+ pasteNew_actionPerformed();
+ else if(source==pasteThis)
+ pasteThis_actionPerformed();
+ else if(source==cut)
+ cut_actionPerformed();
+ else if(source==delete)
+ delete_actionPerformed();
+ else if(source==deleteGroups)
+ deleteGroups_actionPerformed();
+ else if(source==selectAllSequenceMenuItem)
+ selectAllSequenceMenuItem_actionPerformed();
+ else if(source==deselectAllSequenceMenuItem)
+ deselectAllSequenceMenuItem_actionPerformed();
+ else if(source==invertSequenceMenuItem)
+ invertSequenceMenuItem_actionPerformed();
+ else if(source==invertColSel)
+ { viewport.invertColumnSelection(); alignPanel.repaint(); }
+ else if(source==remove2LeftMenuItem)
+ remove2LeftMenuItem_actionPerformed();
+ else if(source==remove2RightMenuItem)
+ remove2RightMenuItem_actionPerformed();
+ else if(source==removeGappedColumnMenuItem)
+ removeGappedColumnMenuItem_actionPerformed();
+ else if(source==removeAllGapsMenuItem)
+ removeAllGapsMenuItem_actionPerformed();
+ else if(source==findMenuItem)
+ findMenuItem_actionPerformed();
+ else if(source==font)
+ font_actionPerformed();
+ else if(source==showColumns)
+ {
+ viewport.showAllHiddenColumns(); alignPanel.repaint();
+ }
+ else if(source==showSeqs)
+ {
+ viewport.showAllHiddenSeqs();
+ }
+ else if(source == hideColumns)
+ {
+ viewport.hideSelectedColumns(); alignPanel.repaint();
+ }
+ else if(source == hideSequences && viewport.getSelectionGroup()!=null)
+ {
+ viewport.hideAllSelectedSeqs();
+ }
+ else if(source==featureSettings)
+ featureSettings_actionPerformed();
+ else if(source==overviewMenuItem)
+ overviewMenuItem_actionPerformed();
+ else if(source==noColourmenuItem)
+ noColourmenuItem_actionPerformed();
+ else if(source==clustalColour)
+ clustalColour_actionPerformed();
+ else if(source==zappoColour)
+ zappoColour_actionPerformed();
+ else if(source==taylorColour)
+ taylorColour_actionPerformed();
+ else if(source==hydrophobicityColour)
+ hydrophobicityColour_actionPerformed();
+ else if(source==helixColour)
+ helixColour_actionPerformed();
+ else if(source==strandColour)
+ strandColour_actionPerformed();
+ else if(source==turnColour)
+ turnColour_actionPerformed();
+ else if(source==buriedColour)
+ buriedColour_actionPerformed();
+ else if(source==nucleotideColour)
+ nucleotideColour_actionPerformed();
+ else if(source==modifyPID)
+ modifyPID_actionPerformed();
+ else if(source==modifyConservation)
+ modifyConservation_actionPerformed();
+ else if(source==userDefinedColour)
+ userDefinedColour_actionPerformed();
+ else if(source==PIDColour)
+ PIDColour_actionPerformed();
+ else if(source==BLOSUM62Colour)
+ BLOSUM62Colour_actionPerformed();
+ else if(source==annotationColour)
+ new AnnotationColourChooser(viewport, alignPanel);
+ else if(source==sortPairwiseMenuItem)
+ sortPairwiseMenuItem_actionPerformed();
+ else if(source==sortIDMenuItem)
+ sortIDMenuItem_actionPerformed();
+ else if(source==sortGroupMenuItem)
+ sortGroupMenuItem_actionPerformed();
+ else if(source==removeRedundancyMenuItem)
+ removeRedundancyMenuItem_actionPerformed();
+ else if(source==pairwiseAlignmentMenuItem)
+ pairwiseAlignmentMenuItem_actionPerformed();
+ else if(source==PCAMenuItem)
+ PCAMenuItem_actionPerformed();
+ else if(source==averageDistanceTreeMenuItem)
+ averageDistanceTreeMenuItem_actionPerformed();
+ else if(source==neighbourTreeMenuItem)
+ neighbourTreeMenuItem_actionPerformed();
+ else if(source==njTreeBlosumMenuItem)
+ njTreeBlosumMenuItem_actionPerformed();
+ else if(source==avDistanceTreeBlosumMenuItem)
+ avTreeBlosumMenuItem_actionPerformed();
+ else if(source==documentation)
+ documentation_actionPerformed();
+ else if(source==about)
+ about_actionPerformed();
+
+ }
+
+ public void inputText_actionPerformed()
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame, "Cut & Paste Input", 500, 500);
+ }
+
+ protected void outputText_actionPerformed(ActionEvent e)
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame,
+ "Alignment output - " + e.getActionCommand(),
+ 600, 500);
+ cap.setText(new AppletFormatAdapter().formatSequences(e.getActionCommand(),
+ viewport.getAlignment().getSequences(),
+ viewport.showJVSuffix));
+ }
+
+ void launchFullApplication()
+ {
+ StringBuffer url = new StringBuffer(jalviewServletURL);
+
+ url.append("?open="+
+ appendProtocol( viewport.applet.getParameter("file") ) );
+
+ if(viewport.applet.getParameter("features")!=null)
+ {
+ url.append( "&features=" );
+ url.append( appendProtocol( viewport.applet.getParameter("features") ) );
+ }
+
+ if(viewport.applet.getParameter("annotations")!=null)
+ {
+ url.append( "&annotations=" );
+ url.append( appendProtocol( viewport.applet.getParameter("annotations") ) );
+ }
+
+ if(viewport.applet.getParameter("jnetfile")!=null)
+ {
+ url.append( "&annotations=" );
+ url.append( appendProtocol( viewport.applet.getParameter("jnetfile") ) );
+ }
+
+ if(viewport.applet.getParameter("defaultColour")!=null)
+ {
+ url.append("&colour=" +
+ removeWhiteSpace(viewport.applet.getParameter("defaultColour"))
+ );
+ }
+
+ if(viewport.applet.getParameter("userDefinedColour")!=null)
+ {
+ url.append( "&colour=" +
+ removeWhiteSpace( viewport.applet.getParameter("userDefinedColour") )
+ );
+ }
+
+ showURL(url.toString(), "FULL_APP");
+ }
+
+
+ String removeWhiteSpace(String colour)
+ {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < colour.length(); i++)
+ {
+ if (Character.isWhitespace(colour.charAt(i)))
+ sb.append("%20");
+ else
+ sb.append(colour.charAt(i));
+ }
+
+ return sb.toString();
+ }
+
+
+ String appendProtocol(String url)
+ {
+ try{
+ new URL(url);
+ }catch(java.net.MalformedURLException ex)
+ {
+ url = viewport.applet.getCodeBase()+url;
+ }
+ return url;
+ }
+
+ public void closeMenuItem_actionPerformed()
+ {
+ PaintRefresher.components.remove(viewport.alignment);
+ if(PaintRefresher.components.size()==0 && viewport.applet==null)
+ System.exit(0);
+
+ this.dispose();
+ }
+
+ Stack historyList = new Stack();
+ Stack redoList = new Stack();
+
+ void updateEditMenuBar()
+ {
+ if (historyList.size() > 0)
+ {
+ undoMenuItem.setEnabled(true);
+ HistoryItem hi = (HistoryItem) historyList.peek();
+ undoMenuItem.setLabel("Undo " + hi.getDescription());
+ }
+ else
+ {
+ undoMenuItem.setEnabled(false);
+ undoMenuItem.setLabel("Undo");
+ }
+
+ if (redoList.size() > 0)
+ {
+ redoMenuItem.setEnabled(true);
+ HistoryItem hi = (HistoryItem) redoList.peek();
+ redoMenuItem.setLabel("Redo " + hi.getDescription());
+ }
+ else
+ {
+ redoMenuItem.setEnabled(false);
+ redoMenuItem.setLabel("Redo");
+ }
+ }
+
+ public void addHistoryItem(HistoryItem hi)
+ {
+ historyList.push(hi);
+ redoList.removeAllElements();
+ updateEditMenuBar();
+ }
+
+ protected void undoMenuItem_actionPerformed()
+ {
+ HistoryItem nh,hi = (HistoryItem) historyList.pop();
+ redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
+ HistoryItem.HIDE));
+ if (hi.alColumnChanges!=null)
+ nh.alColumnChanges=hi.alColumnChanges.getInverse();
+ restoreHistoryItem(hi);
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ protected void redoMenuItem_actionPerformed()
+ {
+ HistoryItem nh,hi = (HistoryItem) redoList.pop();
+ historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
+ HistoryItem.HIDE));
+ if (hi.alColumnChanges!=null)
+ nh.alColumnChanges=hi.alColumnChanges.getInverse();
+ restoreHistoryItem(hi);
+ updateEditMenuBar();
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ // used by undo and redo
+ void restoreHistoryItem(HistoryItem hi)
+ {
+ hi.restore(viewport.getColumnSelection());
+ updateEditMenuBar();
+
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ public void moveSelectedSequences(boolean up)
+ {
+ SequenceGroup sg = viewport.getSelectionGroup();
+ if (sg == null)
+ {
+ return;
+ }
+
+ if (up)
+ {
+ for (int i = 1; i < viewport.alignment.getHeight(); i++)
+ {
+ SequenceI seq = viewport.alignment.getSequenceAt(i);
+ if (!sg.getSequences(false).contains(seq))
+ {
+ continue;
+ }
+
+ SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
+ if (sg.getSequences(false).contains(temp))
+ {
+ continue;
+ }
+
+ viewport.alignment.getSequences().setElementAt(temp, i);
+ viewport.alignment.getSequences().setElementAt(seq, i - 1);
+ }
+ }
+ else
+ {
+ for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
+ {
+ SequenceI seq = viewport.alignment.getSequenceAt(i);
+ if (!sg.getSequences(true).contains(seq))
+ {
+ continue;
+ }
+
+ SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
+ if (sg.getSequences(true).contains(temp))
+ {
+ continue;
+ }
+
+ viewport.alignment.getSequences().setElementAt(temp, i);
+ viewport.alignment.getSequences().setElementAt(seq, i + 1);
+ }
+ }
+
+ alignPanel.repaint();
+ }
+
+ static StringBuffer copiedSequences;
+ static Vector copiedHiddenColumns;
+ protected void copy_actionPerformed()
+ {
+ if (viewport.getSelectionGroup() == null)
+ {
+ return;
+ }
+
+ SequenceGroup sg = viewport.getSelectionGroup();
+ copiedSequences = new StringBuffer();
+ Hashtable orderedSeqs = new Hashtable();
+ for (int i = 0; i < sg.getSize(false); i++)
+ {
+ SequenceI seq = sg.getSequenceAt(i);
+ int index = viewport.alignment.findIndex(seq);
+ orderedSeqs.put(index + "", seq);
+ }
+
+ int index = 0, startRes, endRes;
+ char ch;
+
+ if (viewport.hasHiddenColumns && viewport.getSelectionGroup() != null)
+ {
+ copiedHiddenColumns = new Vector();
+ int hiddenOffset = viewport.getSelectionGroup().getStartRes();
+ for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
+ i++)
+ {
+ int[] region = (int[])
+ viewport.getColumnSelection().getHiddenColumns().elementAt(i);
+
+ copiedHiddenColumns.addElement(new int[]
+ {region[0] - hiddenOffset,
+ region[1] - hiddenOffset});
+ }
+ }
+ else
+ copiedHiddenColumns = null;
+
+
+ for (int i = 0; i < sg.getSize(false); i++)
+ {
+ SequenceI seq = null;
+
+ while (seq == null)
+ {
+ if (orderedSeqs.containsKey(index + ""))
+ {
+ seq = (SequenceI) orderedSeqs.get(index + "");
+ index++;
+
+ break;
+ }
+ else
+ {
+ index++;
+ }
+ }
+
+ //FIND START RES
+ //Returns residue following index if gap
+ startRes = seq.findPosition(sg.getStartRes());
+
+ //FIND END RES
+ //Need to find the residue preceeding index if gap
+ endRes = 0;
+
+ for (int j = 0; j < sg.getEndRes()+1 && j < seq.getLength(); j++)
+ {
+ ch = seq.getCharAt(j);
+ if (!jalview.util.Comparison.isGap( (ch)))
+ {
+ endRes++;
+ }
+ }
+
+ if(endRes>0)
+ {
+ endRes += seq.getStart() -1;
+ }
+
+ copiedSequences.append(seq.getName() + "\t" +
+ startRes + "\t" +
+ endRes + "\t" +
+ seq.getSequence(sg.getStartRes(),
+ sg.getEndRes() + 1) + "\n");
+ }
+
+ }
+
+ protected void pasteNew_actionPerformed()
+ {
+ paste(true);
+ }
+
+ protected void pasteThis_actionPerformed()
+ {
+ addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
+ HistoryItem.PASTE));
+ paste(false);
+ }
+
+ void paste(boolean newAlignment)
+ {
+ try
+ {
+ if (copiedSequences == null)
+ {
+ return;
+ }
+
+ StringTokenizer st = new StringTokenizer(copiedSequences.toString());
+ Vector seqs = new Vector();
+ while (st.hasMoreElements())
+ {
+ String name = st.nextToken();
+ int start = Integer.parseInt(st.nextToken());
+ int end = Integer.parseInt(st.nextToken());
+ Sequence sequence = new Sequence(name, st.nextToken(), start, end);
+
+ if (!newAlignment)
+ {
+ viewport.alignment.addSequence(sequence);
+ }
+ else
+ {
+ seqs.addElement(sequence);
+ }
+ }
+
+ if (newAlignment)
+ {
+ SequenceI[] newSeqs = new SequenceI[seqs.size()];
+ for (int i = 0; i < seqs.size(); i++)
+ {
+ newSeqs[i] = (SequenceI) seqs.elementAt(i);
+ }
+
+ String newtitle = new String("Copied sequences");
+ if (getTitle().startsWith("Copied sequences"))
+ {
+ newtitle = getTitle();
+ }
+ else
+ {
+ newtitle = newtitle.concat("- from " + getTitle());
+ }
+ AlignFrame af = new AlignFrame(new Alignment(newSeqs),
+ viewport.applet,
+ newtitle,
+ false);
+ if (copiedHiddenColumns != null)
+ {
+ for (int i = 0; i < copiedHiddenColumns.size(); i++)
+ {
+ int[] region = (int[]) copiedHiddenColumns.elementAt(i);
+ af.viewport.hideColumns(region[0], region[1]);
+ }
+ }
+
+
+ jalview.bin.JalviewLite.addFrame(af, newtitle, NEW_WINDOW_WIDTH,
+ NEW_WINDOW_HEIGHT);
+ }
+ else
+ {
+ viewport.setEndSeq(viewport.alignment.getHeight());
+ viewport.alignment.getWidth();
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ }
+ catch (Exception ex)
+ {} // could be anything being pasted in here
+
+ }
+
+ protected void cut_actionPerformed()
+ {
+ copy_actionPerformed();
+ delete_actionPerformed();
+ }
+
+ protected void delete_actionPerformed()
+ {
+ addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
+ HistoryItem.HIDE));
+ if (viewport.getSelectionGroup() == null)
+ {
+ return;
+ }
+
+
+ SequenceGroup sg = viewport.getSelectionGroup();
+ boolean allSequences = false;
+ if(sg.getSize(false)==viewport.alignment.getHeight())
+ allSequences = true;
+
+ for (int i = 0; i < sg.getSize(false); 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)
+ {
+ viewport.getColumnSelection().removeElements(sg.getStartRes(),
+ sg.getEndRes() + 1);
+ }
+
+
+ if (seq.getSequence().length() < 1)
+ {
+ viewport.getAlignment().deleteSequence(seq);
+ }
+ else
+ {
+ viewport.getAlignment().getSequences().setElementAt(seq, index);
+ }
+ }
+
+ viewport.setSelectionGroup(null);
+ viewport.alignment.deleteGroup(sg);
+ viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getSize().height);
+ if (viewport.getAlignment().getHeight() < 1)
+ {
+ try
+ {
+ this.setVisible(false);
+ }
+ catch (Exception ex)
+ {}
+ }
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+
+ }
+
+ protected void deleteGroups_actionPerformed()
+ {
+ viewport.alignment.deleteAllGroups();
+ viewport.setSelectionGroup(null);
+
+ alignPanel.repaint();
+ }
+
+ public void selectAllSequenceMenuItem_actionPerformed()
+ {
+ SequenceGroup sg = new SequenceGroup();
+ for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
+ {
+ sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
+ }
+ sg.setEndRes(viewport.alignment.getWidth()-1);
+ viewport.setSelectionGroup(sg);
+ alignPanel.repaint();
+ PaintRefresher.Refresh(null, viewport.alignment);
+ }
+
+ public void deselectAllSequenceMenuItem_actionPerformed()
+ {
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.keyboardNo1=null;
+ alignPanel.seqPanel.keyboardNo2=null;
+ }
+ viewport.setSelectionGroup(null);
+ viewport.getColumnSelection().clear();
+ viewport.setSelectionGroup(null);
+ alignPanel.idPanel.idCanvas.searchResults = null;
+ alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
+ alignPanel.repaint();
+ PaintRefresher.Refresh(null, viewport.alignment);
+ }
+
+ public void invertSequenceMenuItem_actionPerformed()
+ {
+ SequenceGroup sg = viewport.getSelectionGroup();
+ for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
+ {
+ sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
+ }
+
+ PaintRefresher.Refresh(null, viewport.alignment);
+ }
+
+ public void remove2LeftMenuItem_actionPerformed()
+ {
+ ColumnSelection colSel = viewport.getColumnSelection();
+ if (colSel.size() > 0)
+ {
+ HistoryItem edit;
+ addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,
+ HistoryItem.HIDE));
+ int min = colSel.getMin();
+ viewport.getAlignment().trimLeft(min);
+ colSel.compensateForEdit(0, min);
+ edit.addShift(0, min);
+ if (viewport.getSelectionGroup() != null)
+ {
+ viewport.getSelectionGroup().adjustForRemoveLeft(min);
+ }
+
+ Vector groups = viewport.alignment.getGroups();
+ for (int i = 0; i < groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
+ if (!sg.adjustForRemoveLeft(min))
+ {
+ viewport.alignment.deleteGroup(sg);
+ }
+ }
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+ }
+
+ public void remove2RightMenuItem_actionPerformed()
+ {
+ ColumnSelection colSel = viewport.getColumnSelection();
+ if (colSel.size() > 0)
+ {
+ addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
+ HistoryItem.HIDE));
+ int max = colSel.getMax();
+ viewport.getAlignment().trimRight(max);
+
+ if (viewport.getSelectionGroup() != null)
+ {
+ viewport.getSelectionGroup().adjustForRemoveRight(max);
+ }
+
+ Vector groups = viewport.alignment.getGroups();
+ for (int i = 0; i < groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
+ if (!sg.adjustForRemoveRight(max))
+ {
+ viewport.alignment.deleteGroup(sg);
+ }
+ }
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ }
+
+ public void removeGappedColumnMenuItem_actionPerformed()
+ {
+ HistoryItem edit;
+ addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",
+ viewport.alignment,
+ HistoryItem.HIDE));
+
+ //This is to maintain viewport position on first residue
+ //of first sequence
+ SequenceI seq = viewport.alignment.getSequenceAt(0);
+ int startRes = seq.findPosition(viewport.startRes);
+
+ viewport.getAlignment().removeGaps();
+
+ viewport.setStartRes(seq.findIndex(startRes)-1);
+
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ public void removeAllGapsMenuItem_actionPerformed()
+ {
+ // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences
+ // TODO: columnSelection.compensateforedits should be called (and passed to history item)
+ HistoryItem editgaps;
+ addHistoryItem(editgaps=new HistoryItem("Remove Gaps", viewport.alignment,
+ HistoryItem.HIDE));
+
+ //This is to maintain viewport position on first residue
+ //of first sequence
+ SequenceI seq = viewport.alignment.getSequenceAt(0);
+ int startRes = seq.findPosition(viewport.startRes);
+
+ SequenceI current;
+ Vector seqs=null;
+
+ int start=0, end = viewport.alignment.getWidth();
+
+ if (viewport.getSelectionGroup() != null
+ && viewport.getSelectionGroup().getSequences(false) != null
+ && viewport.getSelectionGroup().getSize(false)>0)
+ {
+ seqs = viewport.getSelectionGroup().getSequences(true);
+ start = viewport.getSelectionGroup().getStartRes();
+ end = viewport.getSelectionGroup().getEndRes()+1;
+ }
+ else
+ seqs = viewport.alignment.getSequences();
+
+ /* Commented out regions below are partial implementation of todo above.
+ * divide start,end into visible chunks, and for each:
+ int diff=end-start+1;
+ int diffmax=0;
+ int dr[] = new int[seqs.size()];
+ */
+ for (int i = 0; i < seqs.size(); i++)
+ {
+ current = (SequenceI) seqs.elementAt(i);
+ //dr[i]=
+ current.removeGaps(start, end);
+ /*if (d0) {
+ // record shift for history.
+ editgaps.addShift(start, diff);
+ if (viewport.hasHiddenColumns && diffmax>diff) {
+ // pad sequence
+ StringBuffer gaps=new StringBuffer(diffmax);
+ for (int i=0,j=diffmax-diff; i0) {
+ String sq = current.getSequence();
+ current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());
+ }
+ }
+ }
+ }*/
+
+ viewport.setStartRes(seq.findIndex(startRes)-1);
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ public void alignmentChanged()
+ {
+ viewport.alignment.padGaps();
+ if(viewport.autocalculateConsensus)
+ {
+ viewport.updateConsensus();
+ viewport.updateConservation();
+ }
+
+ resetAllColourSchemes();
+ if(alignPanel.overviewPanel!=null)
+ alignPanel.overviewPanel.updateOverviewImage();
+
+ viewport.alignment.adjustSequenceAnnotations();
+ alignPanel.repaint();
+ }
+
+ void resetAllColourSchemes()
+ {
+ ColourSchemeI cs = viewport.globalColourScheme;
+ if(cs!=null)
+ {
+ if (cs instanceof ClustalxColourScheme)
+ {
+ ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
+ resetClustalX(viewport.alignment.getSequences(),
+ viewport.alignment.getWidth());
+ }
+
+ cs.setConsensus(viewport.vconsensus);
+ if (cs.conservationApplied())
+ {
+ Alignment al = (Alignment) viewport.alignment;
+ Conservation c = new Conservation("All",
+ ResidueProperties.propHash, 3,
+ al.getSequences(), 0,
+ al.getWidth() - 1);
+ c.calculate();
+ c.verdict(false, viewport.ConsPercGaps);
+
+ cs.setConservation(c);
+ }
+ }
+
+ int s, sSize = viewport.alignment.getGroups().size();
+ for(s=0; s 1)
+ {
+ Frame frame = new Frame();
+ frame.add(new PairwiseAlignPanel(alignPanel));
+ jalview.bin.JalviewLite.addFrame(frame, "Pairwise Alignment", 600, 500);
+ }
+ }
+
+ public void PCAMenuItem_actionPerformed()
+ {
+ //are the sequences aligned?
+ if (!viewport.alignment.isAligned())
+ {
+ SequenceI current;
+ int Width = viewport.getAlignment().getWidth();
+
+ for (int i = 0; i < viewport.getAlignment().getSequences().size();
+ i++)
+ {
+ current = viewport.getAlignment().getSequenceAt(i);
+
+ if (current.getLength() < Width)
+ {
+ current.insertCharAt(Width - 1, viewport.getGapCharacter());
+ }
+ }
+ alignPanel.repaint();
+ }
+
+ if ( (viewport.getSelectionGroup() != null &&
+ viewport.getSelectionGroup().getSize(false) < 4 &&
+ viewport.getSelectionGroup().getSize(false) > 0)
+ || viewport.getAlignment().getHeight() < 4)
+ {
+ return;
+ }
+
+ try
+ {
+ new PCAPanel(viewport);
+ }
+ catch (java.lang.OutOfMemoryError ex)
+ {
+ }
+
+ }
+
+ public void averageDistanceTreeMenuItem_actionPerformed()
+ {
+ NewTreePanel("AV", "PID", "Average distance tree using PID");
+ }
+
+ public void neighbourTreeMenuItem_actionPerformed()
+ {
+ NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
+ }
+
+ protected void njTreeBlosumMenuItem_actionPerformed()
+ {
+ NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
+ }
+
+ protected void avTreeBlosumMenuItem_actionPerformed()
+ {
+ NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID");
+ }
+
+ void NewTreePanel(String type, String pwType, String title)
+ {
+ //are the sequences aligned?
+ if (!viewport.alignment.isAligned())
+ {
+ SequenceI current;
+ int Width = viewport.getAlignment().getWidth();
+
+ for (int i = 0; i < viewport.getAlignment().getSequences().size();
+ i++)
+ {
+ current = viewport.getAlignment().getSequenceAt(i);
+
+ if (current.getLength() < Width)
+ {
+ current.insertCharAt(Width - 1, viewport.getGapCharacter());
+ }
+ }
+ alignPanel.repaint();
+
+ }
+
+ if ( (viewport.getSelectionGroup() != null &&
+ viewport.getSelectionGroup().getSize(false) > 1)
+ || (viewport.getSelectionGroup() == null
+ && viewport.alignment.getHeight() > 1))
+ {
+ final TreePanel tp = new TreePanel(viewport,
+ type,
+ pwType);
+
+ addTreeMenuItem(tp, title);
+
+ jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
+ }
+ }
+
+ void loadTree_actionPerformed()
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
+ cap.setText("Paste your Newick tree file here.");
+ cap.treeImport = true;
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame, "Paste Newick file ", 400, 300);
+ }
+
+ public void loadTree(jalview.io.NewickFile tree, String treeFile)
+ {
+ TreePanel tp = new TreePanel(viewport,
+ treeFile,
+ "From File - ",
+ tree);
+ jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
+ addTreeMenuItem(tp, treeFile);
+ }
+
+ void addTreeMenuItem(final TreePanel treePanel, String title)
+ {
+ final MenuItem item = new MenuItem(title);
+ sortByTreeMenu.add(item);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ addHistoryItem(new HistoryItem("Sort", viewport.alignment,
+ HistoryItem.SORT));
+ AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());
+ alignPanel.repaint();
+ }
+ });
+
+ treePanel.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ sortByTreeMenu.remove(item);
+ };
+ });
+ }
+
+ protected void documentation_actionPerformed()
+ {
+ showURL("http://www.jalview.org/help.html", "HELP");
+ }
+
+ protected void about_actionPerformed()
+ {
+
+ class AboutPanel extends Canvas
+ {
+ String version;
+ public AboutPanel(String version)
+ { this.version = version; }
+
+ public void paint(Graphics g)
+ {
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+ g.setFont(new Font("Helvetica", Font.PLAIN, 12));
+ FontMetrics fm = g.getFontMetrics();
+ int fh = fm.getHeight();
+ int y = 5, x = 7;
+ g.setColor(Color.black);
+ g.setFont(new Font("Helvetica", Font.BOLD, 14));
+ g.drawString("Jalview - Release "+version, 200, y += fh);
+ g.setFont(new Font("Helvetica", Font.PLAIN, 12));
+ g.drawString("Authors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton.",
+ x, y += fh * 2);
+ g.drawString("Current development managed by Andrew Waterhouse; Barton Group, University of Dundee.",
+ x, y += fh);
+ g.drawString(
+ "For any issues relating to Jalview, email help@jalview.org", x,
+ y += fh);
+ g.drawString("If you use JalView, please cite:", x, y += fh + 8);
+ g.drawString("\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",
+ x, y += fh);
+ g.drawString("Bioinformatics, 2004 20;426-7.", x, y += fh);
+ }
+ }
+
+ String version = "test";
+ java.net.URL url = getClass().getResource("/.build_properties");
+ if (url != null)
+ {
+ try
+ {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ url.openStream()));
+ String line;
+ while ( (line = reader.readLine()) != null)
+ {
+ if (line.indexOf("VERSION") > -1)
+ {
+ version = line.substring(line.indexOf("=") + 1);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+
+ Frame frame = new Frame();
+ frame.add(new AboutPanel(version));
+ jalview.bin.JalviewLite.addFrame(frame, "Jalview", 580, 200);
+
+ }
+
+ public void showURL(String url, String target)
+ {
+ if (viewport.applet == null)
+ {
+ System.out.println("Not running as applet - no browser available.");
+ }
+ else
+ {
+ try
+ {
+ System.out.println("Show url: "+url);
+ viewport.applet.getAppletContext().showDocument(new java.net.URL(url),
+ target);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+
+ //////////////////////////////////////////////////////////////////////////////////
+ //JBuilder Graphics here
+
+ protected MenuBar alignFrameMenuBar = new MenuBar();
+ protected Menu fileMenu = new Menu("File");
+ protected MenuItem loadApplication = new MenuItem("View in Full Application");
+ protected MenuItem loadTree = new MenuItem("Load Associated Tree");
+ protected MenuItem closeMenuItem = new MenuItem("Close");
+ protected Menu editMenu = new Menu("Edit");
+ protected Menu viewMenu = new Menu("View");
+ protected Menu colourMenu = new Menu("Colour");
+ protected Menu calculateMenu = new Menu("Calculate");
+ protected MenuItem selectAllSequenceMenuItem = new MenuItem("Select all");
+ protected MenuItem deselectAllSequenceMenuItem = new MenuItem("Deselect All");
+ protected MenuItem invertSequenceMenuItem = new MenuItem("Invert Selection");
+ protected MenuItem remove2LeftMenuItem = new MenuItem();
+ protected MenuItem remove2RightMenuItem = new MenuItem();
+ protected MenuItem removeGappedColumnMenuItem = new MenuItem();
+ protected MenuItem removeAllGapsMenuItem = new MenuItem();
+ protected CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
+ protected CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
+ protected MenuItem sortPairwiseMenuItem = new MenuItem();
+ protected MenuItem sortIDMenuItem = new MenuItem();
+ protected MenuItem sortGroupMenuItem = new MenuItem();
+ protected MenuItem removeRedundancyMenuItem = new MenuItem();
+ protected MenuItem pairwiseAlignmentMenuItem = new MenuItem();
+ protected MenuItem PCAMenuItem = new MenuItem();
+ protected MenuItem averageDistanceTreeMenuItem = new MenuItem();
+ protected MenuItem neighbourTreeMenuItem = new MenuItem();
+ BorderLayout borderLayout1 = new BorderLayout();
+ public Label statusBar = new Label();
+ protected Menu outputTextboxMenu = new Menu();
+ protected MenuItem clustalColour = new MenuItem();
+ protected MenuItem zappoColour = new MenuItem();
+ protected MenuItem taylorColour = new MenuItem();
+ protected MenuItem hydrophobicityColour = new MenuItem();
+ protected MenuItem helixColour = new MenuItem();
+ protected MenuItem strandColour = new MenuItem();
+ protected MenuItem turnColour = new MenuItem();
+ protected MenuItem buriedColour = new MenuItem();
+ protected MenuItem userDefinedColour = new MenuItem();
+ protected MenuItem PIDColour = new MenuItem();
+ protected MenuItem BLOSUM62Colour = new MenuItem();
+ MenuItem njTreeBlosumMenuItem = new MenuItem();
+ MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
+ protected CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
+ protected CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
+ MenuItem overviewMenuItem = new MenuItem();
+ protected MenuItem undoMenuItem = new MenuItem();
+ protected MenuItem redoMenuItem = new MenuItem();
+ protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
+ MenuItem noColourmenuItem = new MenuItem();
+ protected CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
+ protected CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
+ MenuItem findMenuItem = new MenuItem();
+ Menu searchMenu = new Menu();
+ protected CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
+ protected MenuItem nucleotideColour = new MenuItem();
+ MenuItem deleteGroups = new MenuItem();
+ MenuItem delete = new MenuItem();
+ MenuItem copy = new MenuItem();
+ MenuItem cut = new MenuItem();
+ Menu pasteMenu = new Menu();
+ MenuItem pasteNew = new MenuItem();
+ MenuItem pasteThis = new MenuItem();
+ protected CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
+ protected MenuItem font = new MenuItem();
+ protected CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
+ protected CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
+ protected CheckboxMenuItem scaleRight = new CheckboxMenuItem();
+ MenuItem modifyPID = new MenuItem();
+ MenuItem modifyConservation = new MenuItem();
+ protected CheckboxMenuItem autoCalculate
+ = new CheckboxMenuItem("Autocalculate Consensus", true);
+ protected Menu sortByTreeMenu = new Menu();
+ Menu sort = new Menu();
+ Menu calculate = new Menu();
+ MenuItem inputText = new MenuItem();
+ Menu helpMenu = new Menu();
+ MenuItem documentation = new MenuItem();
+ MenuItem about = new MenuItem();
+ protected CheckboxMenuItem seqLimits = new CheckboxMenuItem();
+ Panel embeddedMenu;
+ Label embeddedEdit;
+ Label embeddedSearch;
+ Label embeddedView;
+ Label embeddedColour;
+ Label embeddedFile;
+ Label embeddedHelp;
+ Label embeddedCalculate;
+ FlowLayout flowLayout1;
+
+ private void jbInit() throws Exception {
+
+ setMenuBar(alignFrameMenuBar);
+
+ MenuItem item;
+
+ // dynamically fill save as menu with available formats
+ for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
+ {
+
+ item = new MenuItem( jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
+
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ outputText_actionPerformed(e);
+ }
+ });
+
+ outputTextboxMenu.add(item);
+ }
+ closeMenuItem.addActionListener(this);
+ loadApplication.addActionListener(this);
+
+ loadTree.addActionListener(this);
+ selectAllSequenceMenuItem.addActionListener(this);
+ deselectAllSequenceMenuItem.addActionListener(this);
+ invertSequenceMenuItem.addActionListener(this);
+ remove2LeftMenuItem.setLabel("Remove Left");
+ remove2LeftMenuItem.addActionListener(this);
+ remove2RightMenuItem.setLabel("Remove Right");
+ remove2RightMenuItem.addActionListener(this);
+ removeGappedColumnMenuItem.setLabel("Remove Empty Columns");
+ removeGappedColumnMenuItem.addActionListener(this);
+ removeAllGapsMenuItem.setLabel("Remove All Gaps");
+ removeAllGapsMenuItem.addActionListener(this);
+ viewBoxesMenuItem.setLabel("Boxes");
+ viewBoxesMenuItem.setState(true);
+ viewBoxesMenuItem.addItemListener(this);
+ viewTextMenuItem.setLabel("Text");
+ viewTextMenuItem.setState(true);
+ viewTextMenuItem.addItemListener(this);
+ sortPairwiseMenuItem.setLabel("by Pairwise Identity");
+ sortPairwiseMenuItem.addActionListener(this);
+ sortIDMenuItem.setLabel("by ID");
+ sortIDMenuItem.addActionListener(this);
+ sortGroupMenuItem.setLabel("by Group");
+ sortGroupMenuItem.addActionListener(this);
+ removeRedundancyMenuItem.setLabel("Remove Redundancy...");
+ removeRedundancyMenuItem.addActionListener(this);
+ pairwiseAlignmentMenuItem.setLabel("Pairwise Alignments...");
+ pairwiseAlignmentMenuItem.addActionListener(this);
+ PCAMenuItem.setLabel("Principal Component Analysis");
+ PCAMenuItem.addActionListener(this);
+ averageDistanceTreeMenuItem.setLabel(
+ "Average Distance Using % Identity");
+ averageDistanceTreeMenuItem.addActionListener(this);
+ neighbourTreeMenuItem.setLabel("Neighbour Joining Using % Identity");
+ neighbourTreeMenuItem.addActionListener(this);
+ alignFrameMenuBar.setFont(new java.awt.Font("Verdana", 0, 11));
+ statusBar.setBackground(Color.white);
+ statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
+ statusBar.setText("Status bar");
+ outputTextboxMenu.setLabel("Output to Textbox");
+ clustalColour.setLabel("Clustalx");
+
+ clustalColour.addActionListener(this);
+ zappoColour.setLabel("Zappo");
+ zappoColour.addActionListener(this);
+ taylorColour.setLabel("Taylor");
+ taylorColour.addActionListener(this);
+ hydrophobicityColour.setLabel("Hydrophobicity");
+ hydrophobicityColour.addActionListener(this);
+ helixColour.setLabel("Helix Propensity");
+ helixColour.addActionListener(this);
+ strandColour.setLabel("Strand Propensity");
+ strandColour.addActionListener(this);
+ turnColour.setLabel("Turn Propensity");
+ turnColour.addActionListener(this);
+ buriedColour.setLabel("Buried Index");
+ buriedColour.addActionListener(this);
+ userDefinedColour.setLabel("User Defined...");
+ userDefinedColour.addActionListener(this);
+ PIDColour.setLabel("Percentage Identity");
+ PIDColour.addActionListener(this);
+ BLOSUM62Colour.setLabel("BLOSUM62 Score");
+ BLOSUM62Colour.addActionListener(this);
+ avDistanceTreeBlosumMenuItem.setLabel(
+ "Average Distance Using BLOSUM62");
+ avDistanceTreeBlosumMenuItem.addActionListener(this);
+ njTreeBlosumMenuItem.setLabel("Neighbour Joining Using BLOSUM62");
+ njTreeBlosumMenuItem.addActionListener(this);
+ annotationPanelMenuItem.setLabel("Show Annotations");
+ annotationPanelMenuItem.addItemListener(this);
+ colourTextMenuItem.setLabel("Colour Text");
+ colourTextMenuItem.addItemListener(this);
+ overviewMenuItem.setLabel("Overview Window");
+ overviewMenuItem.addActionListener(this);
+ undoMenuItem.setEnabled(false);
+ undoMenuItem.setLabel("Undo");
+ undoMenuItem.addActionListener(this);
+ redoMenuItem.setEnabled(false);
+ redoMenuItem.setLabel("Redo");
+ redoMenuItem.addActionListener(this);
+ conservationMenuItem.setLabel("by Conservation");
+ conservationMenuItem.addItemListener(this);
+ noColourmenuItem.setLabel("None");
+ noColourmenuItem.addActionListener(this);
+ wrapMenuItem.setLabel("Wrap");
+ wrapMenuItem.addItemListener(this);
+ renderGapsMenuItem.setLabel("Show Gaps");
+ renderGapsMenuItem.setState(true);
+ renderGapsMenuItem.addItemListener(this);
+ findMenuItem.setLabel("Find...");
+ findMenuItem.addActionListener(this);
+ searchMenu.setLabel("Search");
+
+ abovePIDThreshold.setLabel("Above Identity Threshold");
+ abovePIDThreshold.addItemListener(this);
+ nucleotideColour.setLabel("Nucleotide");
+ nucleotideColour.addActionListener(this);
+ deleteGroups.setLabel("Undefine Groups");
+ deleteGroups.addActionListener(this);
+ copy.setLabel("Copy");
+ copy.addActionListener(this);
+ cut.setLabel("Cut");
+ cut.addActionListener(this);
+ delete.setLabel("Delete");
+ delete.addActionListener(this);
+ pasteMenu.setLabel("Paste");
+ pasteNew.setLabel("To New Alignment");
+ pasteNew.addActionListener(this);
+ pasteThis.setLabel("Add To This Alignment");
+ pasteThis.addActionListener(this);
+ applyToAllGroups.setLabel("Apply Colour To All Groups");
+ applyToAllGroups.setState(true);
+ applyToAllGroups.addItemListener(this);
+ font.setLabel("Font...");
+ font.addActionListener(this);
+ scaleAbove.setLabel("Scale Above");
+ scaleAbove.setState(true);
+ scaleAbove.setEnabled(false);
+ scaleAbove.addItemListener(this);
+ scaleLeft.setEnabled(false);
+ scaleLeft.setState(true);
+ scaleLeft.setLabel("Scale Left");
+ scaleLeft.addItemListener(this);
+ scaleRight.setEnabled(false);
+ scaleRight.setState(true);
+ scaleRight.setLabel("Scale Right");
+ scaleRight.addItemListener(this);
+ modifyPID.setLabel("Modify Identity Threshold...");
+ modifyPID.addActionListener(this);
+ modifyConservation.setLabel("Modify Conservation Threshold...");
+ modifyConservation.addActionListener(this);
+ sortByTreeMenu.setLabel("By Tree Order");
+ sort.setLabel("Sort");
+ calculate.setLabel("Calculate Tree");
+ autoCalculate.addItemListener(this);
+ inputText.setLabel("Input from textbox");
+ inputText.addActionListener(this);
+
+ helpMenu.setLabel("Help");
+ documentation.setLabel("Documentation");
+ documentation.addActionListener(this);
+
+ about.setLabel("About...");
+ about.addActionListener(this);
+ seqLimits.setState(true);
+ seqLimits.setLabel("Show Sequence Limits");
+ seqLimits.addItemListener(this);
+ featureSettings.setLabel("Feature Settings...");
+ featureSettings.addActionListener(this);
+ sequenceFeatures.setLabel("Sequence Features");
+ sequenceFeatures.addItemListener(this);
+ sequenceFeatures.setState(false);
+ annotationColour.setLabel("by Annotation...");
+ annotationColour.addActionListener(this);
+ invertSequenceMenuItem.setLabel("Invert Sequence Selection");
+ invertColSel.setLabel("Invert Column Selection");
+ menu1.setLabel("Show");
+ showColumns.setLabel("All Columns ");
+ showSeqs.setLabel("All Sequences");
+ menu2.setLabel("Hide");
+ hideColumns.setLabel("Selected Columns");
+ hideSequences.setLabel("Selected Sequences");
+ invertColSel.addActionListener(this);
+ showColumns.addActionListener(this);
+ showSeqs.addActionListener(this);
+ hideColumns.addActionListener(this);
+ hideSequences.addActionListener(this);
+
+
+ alignFrameMenuBar.add(fileMenu);
+ alignFrameMenuBar.add(editMenu);
+ alignFrameMenuBar.add(searchMenu);
+ alignFrameMenuBar.add(viewMenu);
+ alignFrameMenuBar.add(colourMenu);
+ alignFrameMenuBar.add(calculateMenu);
+ alignFrameMenuBar.add(helpMenu);
+ fileMenu.add(inputText);
+ fileMenu.add(outputTextboxMenu);
+ if(jalviewServletURL!=null)
+ fileMenu.add(loadApplication);
+ fileMenu.addSeparator();
+ fileMenu.add(loadTree);
+ fileMenu.add(closeMenuItem);
+ editMenu.add(undoMenuItem);
+ editMenu.add(redoMenuItem);
+ editMenu.add(cut);
+ editMenu.add(copy);
+ editMenu.add(pasteMenu);
+ editMenu.add(delete);
+ editMenu.addSeparator();
+ editMenu.add(selectAllSequenceMenuItem);
+ editMenu.add(deselectAllSequenceMenuItem);
+ editMenu.add(invertSequenceMenuItem);
+ editMenu.add(invertColSel);
+ editMenu.add(deleteGroups);
+ editMenu.addSeparator();
+ editMenu.add(remove2LeftMenuItem);
+ editMenu.add(remove2RightMenuItem);
+ editMenu.add(removeGappedColumnMenuItem);
+ editMenu.add(removeAllGapsMenuItem);
+ editMenu.add(removeRedundancyMenuItem);
+ searchMenu.add(findMenuItem);
+ viewMenu.add(font);
+ viewMenu.addSeparator();
+ viewMenu.add(menu1);
+ viewMenu.add(menu2);
+ viewMenu.addSeparator();
+ viewMenu.add(wrapMenuItem);
+ viewMenu.add(scaleAbove);
+ viewMenu.add(scaleLeft);
+ viewMenu.add(scaleRight);
+ viewMenu.addSeparator();
+ viewMenu.add(seqLimits);
+ viewMenu.add(viewBoxesMenuItem);
+ viewMenu.add(viewTextMenuItem);
+ viewMenu.add(colourTextMenuItem);
+ viewMenu.add(renderGapsMenuItem);
+ viewMenu.add(annotationPanelMenuItem);
+ viewMenu.addSeparator();
+ viewMenu.add(sequenceFeatures);
+ viewMenu.add(featureSettings);
+ viewMenu.addSeparator();
+ viewMenu.add(overviewMenuItem);
+ colourMenu.add(applyToAllGroups);
+ colourMenu.addSeparator();
+ colourMenu.add(noColourmenuItem);
+ colourMenu.add(clustalColour);
+ colourMenu.add(BLOSUM62Colour);
+ colourMenu.add(PIDColour);
+ colourMenu.add(zappoColour);
+ colourMenu.add(taylorColour);
+ colourMenu.add(hydrophobicityColour);
+ colourMenu.add(helixColour);
+ colourMenu.add(strandColour);
+ colourMenu.add(turnColour);
+ colourMenu.add(buriedColour);
+ colourMenu.add(nucleotideColour);
+ colourMenu.add(userDefinedColour);
+ colourMenu.addSeparator();
+ colourMenu.add(conservationMenuItem);
+ colourMenu.add(modifyConservation);
+ colourMenu.add(abovePIDThreshold);
+ colourMenu.add(modifyPID);
+ colourMenu.add(annotationColour);
+ calculateMenu.add(sort);
+ calculateMenu.add(calculate);
+ calculateMenu.addSeparator();
+ calculateMenu.add(pairwiseAlignmentMenuItem);
+ calculateMenu.add(PCAMenuItem);
+ calculateMenu.add(autoCalculate);
+ this.add(statusBar, BorderLayout.SOUTH);
+ pasteMenu.add(pasteNew);
+ pasteMenu.add(pasteThis);
+ sort.add(sortIDMenuItem);
+ sort.add(sortByTreeMenu);
+ sort.add(sortGroupMenuItem);
+ sort.add(sortPairwiseMenuItem);
+ calculate.add(averageDistanceTreeMenuItem);
+ calculate.add(neighbourTreeMenuItem);
+ calculate.add(avDistanceTreeBlosumMenuItem);
+ calculate.add(njTreeBlosumMenuItem);
+ helpMenu.add(documentation);
+ helpMenu.add(about);
+ menu1.add(showColumns);
+ menu1.add(showSeqs);
+ menu2.add(hideColumns);
+ menu2.add(hideSequences);
+ }
+
+ public void setEmbedded()
+ {
+
+ embeddedMenu = new Panel();
+ embeddedEdit = new Label();
+ embeddedSearch = new Label();
+ embeddedView = new Label();
+ embeddedColour = new Label();
+ embeddedFile = new Label();
+ embeddedHelp = new Label();
+ embeddedCalculate = new Label();
+ flowLayout1 = new FlowLayout();
+ embeddedMenu.setBackground(Color.lightGray);
+ embeddedMenu.setLayout(flowLayout1);
+ embeddedEdit.setText("Edit");
+ embeddedEdit.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
+ embeddedSearch.setText("Search");
+ embeddedSearch.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
+ embeddedView.setText("View");
+ embeddedView.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
+ embeddedColour.setText("Colour");
+ embeddedColour.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
+ embeddedFile.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
+ embeddedFile.setText("File");
+ embeddedHelp.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
+ embeddedHelp.setText("Help");
+ embeddedCalculate.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));
+ embeddedCalculate.setText("Calculate");
+ embeddedMenu.add(embeddedFile);
+ embeddedMenu.add(embeddedEdit);
+ embeddedMenu.add(embeddedSearch);
+ embeddedMenu.add(embeddedView);
+ embeddedMenu.add(embeddedColour);
+ embeddedMenu.add(embeddedCalculate);
+ embeddedMenu.add(embeddedHelp);
+ flowLayout1.setAlignment(FlowLayout.LEFT);
+ flowLayout1.setHgap(2);
+ flowLayout1.setVgap(0);
+ embeddedFile.addMouseListener(this);
+ embeddedEdit.addMouseListener(this);
+ embeddedSearch.addMouseListener(this);
+ embeddedView.addMouseListener(this);
+ embeddedColour.addMouseListener(this);
+ embeddedCalculate.addMouseListener(this);
+ embeddedHelp.addMouseListener(this);
+
+ // setVisible(false);
+ fileMenu.remove(closeMenuItem);
+ fileMenu.remove(3); // Seperator
+
+ viewport.applet.setLayout(new BorderLayout());
+ viewport.applet.add(embeddedMenu, BorderLayout.NORTH);
+ viewport.applet.add(statusBar, BorderLayout.SOUTH);
+ // viewport.applet.validate();
+
+ alignPanel.setSize(viewport.applet.size().width, viewport.applet.size().height
+ - embeddedMenu.HEIGHT - statusBar.HEIGHT);
+
+ viewport.applet.add(alignPanel, BorderLayout.CENTER);
+ viewport.applet.validate();
+
+ }
+
+
+
+ PopupMenu filePopup, editPopup, searchPopup,
+ viewPopup, colourPopup, calculatePopup, helpPopup;
+ MenuItem featureSettings = new MenuItem();
+ CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
+ MenuItem annotationColour = new MenuItem();
+ MenuItem invertColSel = new MenuItem();
+ Menu menu1 = new Menu();
+ MenuItem showColumns = new MenuItem();
+ MenuItem showSeqs = new MenuItem();
+ Menu menu2 = new Menu();
+ MenuItem hideColumns = new MenuItem();
+ MenuItem hideSequences = new MenuItem();
+
+ public void mousePressed(MouseEvent evt)
+ {
+ PopupMenu popup = null;
+ Label source = (Label)evt.getSource();
+ if(source==embeddedFile)
+ {
+ popup = filePopup = genPopupMenu(filePopup, fileMenu);
+ }
+ else if(source==embeddedEdit)
+ {
+ popup = editPopup = genPopupMenu(editPopup, editMenu);
+ }
+ else if(source==embeddedSearch)
+ {
+ popup = searchPopup = genPopupMenu(searchPopup, searchMenu);
+ }
+ else if(source==embeddedView)
+ {
+ popup = viewPopup = genPopupMenu(viewPopup, viewMenu);
+ }
+ else if(source==embeddedColour)
+ {
+ popup = colourPopup = genPopupMenu(colourPopup, colourMenu);
+ }
+ else if(source==embeddedCalculate)
+ {
+ popup = calculatePopup = genPopupMenu(calculatePopup, calculateMenu);
+ }
+ else if(source==embeddedHelp)
+ {
+ popup = helpPopup = genPopupMenu(helpPopup, helpMenu);
+ }
+
+ embeddedMenu.add(popup);
+ popup.show(embeddedMenu,
+ source.getBounds().x,
+ source.getBounds().y + source.getBounds().getSize().height);
+ }
+
+ PopupMenu genPopupMenu(PopupMenu popup, Menu original)
+ {
+ if(popup!=null)
+ {
+ return popup;
+ }
+ popup = new PopupMenu();
+ int m, mSize = original.getItemCount();
+ for(m=0; m 1)
- {
- mouseOver = "[" + maxRes + "] ";
- maxRes = "+";
- }
-
-
- mouseOver += (int) value + "%";
- annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
-
- }
-
- if (consensus == null)
- {
- consensus = new AlignmentAnnotation("Consensus",
- "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
- if (showConsensus)
- {
- alignment.addAnnotation(consensus);
- }
- }
- else
- {
- consensus.annotations = annotations;
- }
-
- if(globalColourScheme!=null)
- globalColourScheme.setConsensus(vconsensus);
-
- }
-
- public SequenceGroup getSelectionGroup()
- {
- return selectionGroup;
- }
-
- public void setSelectionGroup(SequenceGroup sg)
- {
- selectionGroup = sg;
- }
-
- public boolean getConservationSelected()
- {
- return conservationColourSelected;
- }
-
- public void setConservationSelected(boolean b)
- {
- conservationColourSelected = b;
- }
-
- public boolean getAbovePIDThreshold()
- {
- return abovePIDThreshold;
- }
-
- public void setAbovePIDThreshold(boolean b)
- {
- abovePIDThreshold = b;
- }
-
- public int getStartRes()
- {
- return startRes;
- }
-
- public int getEndRes()
- {
- return endRes;
- }
-
- public int getStartSeq()
- {
- return startSeq;
- }
-
- public void setGlobalColourScheme(ColourSchemeI cs)
- {
- globalColourScheme = cs;
- }
-
- public ColourSchemeI getGlobalColourScheme()
- {
- return globalColourScheme;
- }
-
- public void setStartRes(int res)
- {
- this.startRes = res;
- }
-
- public void setStartSeq(int seq)
- {
- this.startSeq = seq;
- }
-
- public void setEndRes(int res)
- {
- if (res > alignment.getWidth() - 1)
- {
- // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
- res = alignment.getWidth() - 1;
- }
- if (res < 0)
- {
- res = 0;
- }
- this.endRes = res;
- }
-
- public void setEndSeq(int seq)
- {
- if (seq > alignment.getHeight())
- {
- seq = alignment.getHeight();
- }
- if (seq < 0)
- {
- seq = 0;
- }
- this.endSeq = seq;
- }
-
- public int getEndSeq()
- {
- return endSeq;
- }
-
- public void setFont(Font f)
- {
- font = f;
- java.awt.Frame temp = new java.awt.Frame();
- temp.addNotify();
- java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
- setCharHeight(fm.getHeight());
- setCharWidth(fm.charWidth('M'));
- }
-
- public Font getFont()
- {
- return font;
- }
-
- public void setCharWidth(int w)
- {
- this.charWidth = w;
- }
-
- public int getCharWidth()
- {
- return charWidth;
- }
-
- public void setCharHeight(int h)
- {
- this.charHeight = h;
- }
-
- public int getCharHeight()
- {
- return charHeight;
- }
-
- public void setWrappedWidth(int w)
- {
- this.wrappedWidth = w;
- }
-
- public int getwrappedWidth()
- {
- return wrappedWidth;
- }
-
- public AlignmentI getAlignment()
- {
- return alignment;
- }
-
- public void setAlignment(AlignmentI align)
- {
- this.alignment = align;
- }
-
- public void setWrapAlignment(boolean state)
- {
- wrapAlignment = state;
- }
-
- public void setShowText(boolean state)
- {
- showText = state;
- }
-
- public void setRenderGaps(boolean state)
- {
- renderGaps = state;
- }
-
- public boolean getColourText()
- {
- return showColourText;
- }
-
- public void setColourText(boolean state)
- {
- showColourText = state;
- }
-
- public void setShowBoxes(boolean state)
- {
- showBoxes = state;
- }
-
- public boolean getWrapAlignment()
- {
- return wrapAlignment;
- }
-
- public boolean getShowText()
- {
- return showText;
- }
-
- public boolean getShowBoxes()
- {
- return showBoxes;
- }
-
- public char getGapCharacter()
- {
- return getAlignment().getGapCharacter();
- }
-
- public void setGapCharacter(char gap)
- {
- if (getAlignment() != null)
- {
- getAlignment().setGapCharacter(gap);
- }
- }
-
- public void setThreshold(int thresh)
- {
- threshold = thresh;
- }
-
- public int getThreshold()
- {
- return threshold;
- }
-
- public void setIncrement(int inc)
- {
- increment = inc;
- }
-
- public int getIncrement()
- {
- return increment;
- }
-
- public int getIndex(int y)
- {
- int y1 = 0;
- int starty = getStartSeq();
- int endy = getEndSeq();
-
- for (int i = starty; i <= endy; i++)
- {
- if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
- {
- int y2 = y1 + getCharHeight();
-
- if (y >= y1 && y <= y2)
- {
- return i;
- }
- y1 = y2;
- }
- else
- {
- return -1;
- }
- }
- return -1;
- }
-
- public ColumnSelection getColumnSelection()
- {
- return colSel;
- }
-
- public void resetSeqLimits(int height)
- {
- setEndSeq(height / getCharHeight());
- }
-
- public void setCurrentTree(NJTree tree)
- {
- currentTree = tree;
- }
-
- public NJTree getCurrentTree()
- {
- return currentTree;
- }
-
- public void setColourAppliesToAllGroups(boolean b)
- {
- colourAppliesToAllGroups = b;
- }
-
- public boolean getColourAppliesToAllGroups()
- {
- return colourAppliesToAllGroups;
- }
-
- public boolean getShowJVSuffix()
- {
- return showJVSuffix;
- }
-
- public void setShowJVSuffix(boolean b)
- {
- showJVSuffix = b;
- }
-
- public boolean getShowAnnotation()
- {
- return showAnnotation;
- }
-
- public void setShowAnnotation(boolean b)
- {
- showAnnotation = b;
- }
-
- public boolean getScaleAboveWrapped()
- {
- return scaleAboveWrapped;
- }
-
- public boolean getScaleLeftWrapped()
- {
- return scaleLeftWrapped;
- }
-
- public boolean getScaleRightWrapped()
- {
- return scaleRightWrapped;
- }
-
- public void setScaleAboveWrapped(boolean b)
- {
- scaleAboveWrapped = b;
- }
-
- public void setScaleLeftWrapped(boolean b)
- {
- scaleLeftWrapped = b;
- }
-
- public void setScaleRightWrapped(boolean b)
- {
- scaleRightWrapped = b;
- }
-
- public void setIgnoreGapsConsensus(boolean b)
- {
- ignoreGapsInConsensusCalculation = b;
- updateConsensus();
- if (globalColourScheme!=null)
- {
- globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
- ignoreGapsInConsensusCalculation);
-
- }
- }
-
- /**
- * Property change listener for changes in alignment
- *
- * @param listener DOCUMENT ME!
- */
- public void addPropertyChangeListener(
- java.beans.PropertyChangeListener listener)
- {
- changeSupport.addPropertyChangeListener(listener);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param listener DOCUMENT ME!
- */
- public void removePropertyChangeListener(
- java.beans.PropertyChangeListener listener)
- {
- changeSupport.removePropertyChangeListener(listener);
- }
-
- /**
- * Property change listener for changes in alignment
- *
- * @param prop DOCUMENT ME!
- * @param oldvalue DOCUMENT ME!
- * @param newvalue DOCUMENT ME!
- */
- public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
- {
- changeSupport.firePropertyChange(prop, oldvalue, newvalue);
- }
-
-
-
- public boolean getIgnoreGapsConsensus()
- {
- return ignoreGapsInConsensusCalculation;
- }
-
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+
+import jalview.analysis.*;
+import jalview.bin.*;
+import jalview.datamodel.*;
+import jalview.schemes.*;
+
+public class AlignViewport
+{
+ int startRes;
+ int endRes;
+
+ int startSeq;
+ int endSeq;
+
+
+ boolean cursorMode = false;
+
+ boolean showJVSuffix = true;
+ boolean showText = true;
+ boolean showColourText = false;
+ boolean showBoxes = true;
+ boolean wrapAlignment = false;
+ boolean renderGaps = true;
+ boolean showSequenceFeatures = false;
+ boolean showAnnotation = true;
+ boolean showConservation = true;
+ boolean showQuality = true;
+ boolean showConsensus = true;
+
+ boolean colourAppliesToAllGroups = true;
+ ColourSchemeI globalColourScheme = null;
+ boolean conservationColourSelected = false;
+ boolean abovePIDThreshold = false;
+
+ SequenceGroup selectionGroup;
+
+ int charHeight;
+ int charWidth;
+ int wrappedWidth;
+
+ Font font = new Font("SansSerif", Font.PLAIN, 10);
+ boolean validCharWidth = true;
+ AlignmentI alignment;
+
+ ColumnSelection colSel = new ColumnSelection();
+
+ int threshold;
+ int increment;
+
+ NJTree currentTree = null;
+
+ boolean scaleAboveWrapped = true;
+ boolean scaleLeftWrapped = true;
+ boolean scaleRightWrapped = true;
+
+ // The following vector holds the features which are
+ // currently visible, in the correct order or rendering
+ Hashtable featuresDisplayed;
+
+ boolean hasHiddenColumns = false;
+ boolean hasHiddenRows = false;
+ boolean showHiddenMarkers = true;
+
+
+ public Vector vconsensus;
+ AlignmentAnnotation consensus;
+ AlignmentAnnotation conservation;
+ AlignmentAnnotation quality;
+
+ boolean autocalculateConsensus = true;
+
+ public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
+
+ private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
+
+ boolean ignoreGapsInConsensusCalculation = false;
+
+ jalview.bin.JalviewLite applet;
+
+ boolean MAC = false;
+
+ public AlignViewport(AlignmentI al, JalviewLite applet)
+ {
+ this.applet = applet;
+ setAlignment(al);
+ this.startRes = 0;
+ this.endRes = al.getWidth() - 1;
+ this.startSeq = 0;
+ this.endSeq = al.getHeight() - 1;
+ setFont(font);
+
+ if(System.getProperty("os.name").startsWith("Mac"))
+ MAC = true;
+
+ if (applet != null)
+ {
+ String param = applet.getParameter("showFullId");
+ if (param != null)
+ {
+ showJVSuffix = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showAnnotation");
+ if (param != null)
+ {
+ showAnnotation = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showConservation");
+ if (param != null)
+ {
+ showConservation = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showQuality");
+ if (param != null)
+ {
+ showQuality = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showConsensus");
+ if (param != null)
+ {
+ showConsensus = Boolean.valueOf(param).booleanValue();
+ }
+ }
+ // We must set conservation and consensus before setting colour,
+ // as Blosum and Clustal require this to be done
+ updateConservation();
+ updateConsensus();
+
+
+ if (applet != null)
+ {
+ String colour = applet.getParameter("defaultColour");
+
+ if(colour == null)
+ {
+ colour = applet.getParameter("userDefinedColour");
+ if(colour !=null)
+ colour = "User Defined";
+ }
+
+ if(colour != null)
+ {
+ globalColourScheme = ColourSchemeProperty.getColour(alignment, colour);
+ if (globalColourScheme != null)
+ {
+ globalColourScheme.setConsensus(vconsensus);
+ }
+ }
+
+ if(applet.getParameter("userDefinedColour")!=null)
+ {
+ ((UserColourScheme)globalColourScheme).parseAppletParameter(
+ applet.getParameter("userDefinedColour"));
+ }
+
+
+ }
+ }
+
+ public void showSequenceFeatures(boolean b)
+ {
+ showSequenceFeatures = b;
+ }
+
+ public boolean getShowSequenceFeatures()
+ {
+ return showSequenceFeatures;
+ }
+
+
+ public void updateConservation()
+ {
+ if(alignment.isNucleotide())
+ return;
+
+ Conservation cons = new jalview.analysis.Conservation("All",
+ jalview.schemes.ResidueProperties.propHash, 3,
+ alignment.getSequences(), 0,
+ alignment.getWidth() - 1);
+ cons.calculate();
+ cons.verdict(false, ConsPercGaps);
+ cons.findQuality();
+ int alWidth = alignment.getWidth();
+ Annotation[] annotations = new Annotation[alWidth];
+ Annotation[] qannotations = new Annotation[alWidth];
+ String sequence = cons.getConsSequence().getSequence();
+ float minR, minG, minB, maxR, maxG, maxB;
+ minR = 0.3f;
+ minG = 0.0f;
+ minB = 0f;
+ maxR = 1.0f - minR;
+ maxG = 0.9f - minG;
+ maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
+ float min = 0f;
+ float max = 11f;
+ float qmin = cons.qualityRange[0].floatValue();
+ float qmax = cons.qualityRange[1].floatValue();
+
+ for (int i = 0; i < alWidth; i++)
+ {
+ float value = 0;
+ try
+ {
+ value = Integer.parseInt(sequence.charAt(i) + "");
+ }
+ catch (Exception ex)
+ {
+ if (sequence.charAt(i) == '*')
+ {
+ value = 11;
+ }
+ if (sequence.charAt(i) == '+')
+ {
+ value = 10;
+ }
+ }
+ float vprop = value - min;
+ vprop /= max;
+
+ annotations[i] = new Annotation(sequence.charAt(i) + "",
+ "", ' ', value,
+ new Color(minR + maxR * vprop,
+ minG + maxG * vprop,
+ minB + maxB * vprop));
+ // Quality calc
+ value = ( (Double) cons.quality.elementAt(i)).floatValue();
+ vprop = value - qmin;
+ vprop /= qmax;
+ qannotations[i] = new Annotation(" ",
+ String.valueOf(value), ' ', value,
+ new
+ Color(minR + maxR * vprop,
+ minG + maxG * vprop,
+ minB + maxB * vprop));
+ }
+
+ if (conservation == null)
+ {
+ conservation = new AlignmentAnnotation("Conservation",
+ "Conservation of total alignment less than " +
+ ConsPercGaps + "% gaps",
+ annotations,
+ 0f, // cons.qualityRange[0].floatValue(),
+ 11f, // cons.qualityRange[1].floatValue()
+ AlignmentAnnotation.BAR_GRAPH);
+ if (showConservation)
+ {
+ alignment.addAnnotation(conservation);
+ }
+ quality = new AlignmentAnnotation("Quality",
+ "Alignment Quality based on Blosum62 scores",
+ qannotations,
+ cons.qualityRange[0].floatValue(),
+ cons.qualityRange[1].floatValue(),
+ AlignmentAnnotation.BAR_GRAPH);
+ if (showQuality)
+ {
+ alignment.addAnnotation(quality);
+ }
+ }
+ else
+ {
+ conservation.annotations = annotations;
+ quality.annotations = qannotations;
+ quality.graphMax = cons.qualityRange[1].floatValue();
+ }
+
+ }
+
+ public void updateConsensus()
+ {
+ Annotation[] annotations = new Annotation[alignment.getWidth()];
+
+ // this routine prevents vconsensus becoming a new object each time
+ // consenus is calculated. Important for speed of Blosum62
+ // and PID colouring of alignment
+ if (vconsensus == null)
+ {
+ vconsensus = alignment.getAAFrequency();
+ }
+ else
+ {
+ Vector temp = alignment.getAAFrequency();
+ vconsensus.removeAllElements();
+ Enumeration e = temp.elements();
+ while (e.hasMoreElements())
+ {
+ vconsensus.addElement(e.nextElement());
+ }
+ }
+ Hashtable hash = null;
+ for (int i = 0; i < alignment.getWidth(); i++)
+ {
+ hash = (Hashtable) vconsensus.elementAt(i);
+ float value = 0;
+ if(ignoreGapsInConsensusCalculation)
+ value = ((Float)hash.get("pid_nogaps")).floatValue();
+ else
+ value = ((Float)hash.get("pid_gaps")).floatValue();
+
+ String maxRes = hash.get("maxResidue").toString();
+ String mouseOver = hash.get("maxResidue") + " ";
+ if (maxRes.length() > 1)
+ {
+ mouseOver = "[" + maxRes + "] ";
+ maxRes = "+";
+ }
+
+
+ mouseOver += (int) value + "%";
+ annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
+
+ }
+
+ if (consensus == null)
+ {
+ consensus = new AlignmentAnnotation("Consensus",
+ "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+ if (showConsensus)
+ {
+ alignment.addAnnotation(consensus);
+ }
+ }
+ else
+ {
+ consensus.annotations = annotations;
+ }
+
+ if(globalColourScheme!=null)
+ globalColourScheme.setConsensus(vconsensus);
+
+ }
+ /**
+ * get the consensus sequence as displayed under the PID consensus annotation row.
+ * @return consensus sequence as a new sequence object
+ */
+ /**
+ * get the consensus sequence as displayed under the PID consensus annotation row.
+ * @return consensus sequence as a new sequence object
+ */
+ public SequenceI getConsensusSeq() {
+ if (consensus==null)
+ updateConsensus();
+ if (consensus==null)
+ return null;
+ StringBuffer seqs=new StringBuffer();
+ for (int i=0; i alignment.getWidth() - 1)
+ {
+ // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
+ res = alignment.getWidth() - 1;
+ }
+ if (res < 0)
+ {
+ res = 0;
+ }
+ this.endRes = res;
+ }
+
+ public void setEndSeq(int seq)
+ {
+ if (seq > alignment.getHeight())
+ {
+ seq = alignment.getHeight();
+ }
+ if (seq < 0)
+ {
+ seq = 0;
+ }
+ this.endSeq = seq;
+ }
+
+ public int getEndSeq()
+ {
+ return endSeq;
+ }
+
+ java.awt.Frame nullFrame;
+ public void setFont(Font f)
+ {
+ font = f;
+ if(nullFrame == null)
+ {
+ nullFrame = new java.awt.Frame();
+ nullFrame.addNotify();
+ }
+
+ java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
+ setCharHeight(fm.getHeight());
+ charWidth = fm.charWidth('M');
+ }
+
+ public Font getFont()
+ {
+ return font;
+ }
+
+ public int getCharWidth()
+ {
+ return charWidth;
+ }
+
+ public void setCharHeight(int h)
+ {
+ this.charHeight = h;
+ }
+
+ public int getCharHeight()
+ {
+ return charHeight;
+ }
+
+ public void setWrappedWidth(int w)
+ {
+ this.wrappedWidth = w;
+ }
+
+ public int getwrappedWidth()
+ {
+ return wrappedWidth;
+ }
+
+ public AlignmentI getAlignment()
+ {
+ return alignment;
+ }
+
+ public void setAlignment(AlignmentI align)
+ {
+ this.alignment = align;
+ }
+
+ public void setWrapAlignment(boolean state)
+ {
+ wrapAlignment = state;
+ }
+
+ public void setShowText(boolean state)
+ {
+ showText = state;
+ }
+
+ public void setRenderGaps(boolean state)
+ {
+ renderGaps = state;
+ }
+
+ public boolean getColourText()
+ {
+ return showColourText;
+ }
+
+ public void setColourText(boolean state)
+ {
+ showColourText = state;
+ }
+
+ public void setShowBoxes(boolean state)
+ {
+ showBoxes = state;
+ }
+
+ public boolean getWrapAlignment()
+ {
+ return wrapAlignment;
+ }
+
+ public boolean getShowText()
+ {
+ return showText;
+ }
+
+ public boolean getShowBoxes()
+ {
+ return showBoxes;
+ }
+
+ public char getGapCharacter()
+ {
+ return getAlignment().getGapCharacter();
+ }
+
+ public void setGapCharacter(char gap)
+ {
+ if (getAlignment() != null)
+ {
+ getAlignment().setGapCharacter(gap);
+ }
+ }
+
+ public void setThreshold(int thresh)
+ {
+ threshold = thresh;
+ }
+
+ public int getThreshold()
+ {
+ return threshold;
+ }
+
+ public void setIncrement(int inc)
+ {
+ increment = inc;
+ }
+
+ public int getIncrement()
+ {
+ return increment;
+ }
+
+ public void setHiddenColumns(ColumnSelection colsel)
+ {
+ this.colSel = colsel;
+ if(colSel.getHiddenColumns()!=null)
+ hasHiddenColumns = true;
+ }
+
+ public ColumnSelection getColumnSelection()
+ {
+ return colSel;
+ }
+
+ public void resetSeqLimits(int height)
+ {
+ setEndSeq(height / getCharHeight());
+ }
+
+ public void setCurrentTree(NJTree tree)
+ {
+ currentTree = tree;
+ }
+
+ public NJTree getCurrentTree()
+ {
+ return currentTree;
+ }
+
+ public void setColourAppliesToAllGroups(boolean b)
+ {
+ colourAppliesToAllGroups = b;
+ }
+
+ public boolean getColourAppliesToAllGroups()
+ {
+ return colourAppliesToAllGroups;
+ }
+
+ public boolean getShowJVSuffix()
+ {
+ return showJVSuffix;
+ }
+
+ public void setShowJVSuffix(boolean b)
+ {
+ showJVSuffix = b;
+ }
+
+ public boolean getShowAnnotation()
+ {
+ return showAnnotation;
+ }
+
+ public void setShowAnnotation(boolean b)
+ {
+ showAnnotation = b;
+ }
+
+ public boolean getScaleAboveWrapped()
+ {
+ return scaleAboveWrapped;
+ }
+
+ public boolean getScaleLeftWrapped()
+ {
+ return scaleLeftWrapped;
+ }
+
+ public boolean getScaleRightWrapped()
+ {
+ return scaleRightWrapped;
+ }
+
+ public void setScaleAboveWrapped(boolean b)
+ {
+ scaleAboveWrapped = b;
+ }
+
+ public void setScaleLeftWrapped(boolean b)
+ {
+ scaleLeftWrapped = b;
+ }
+
+ public void setScaleRightWrapped(boolean b)
+ {
+ scaleRightWrapped = b;
+ }
+
+ public void setIgnoreGapsConsensus(boolean b)
+ {
+ ignoreGapsInConsensusCalculation = b;
+ updateConsensus();
+ if (globalColourScheme!=null)
+ {
+ globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
+ ignoreGapsInConsensusCalculation);
+
+ }
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void addPropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void removePropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param prop DOCUMENT ME!
+ * @param oldvalue DOCUMENT ME!
+ * @param newvalue DOCUMENT ME!
+ */
+ public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
+ {
+ changeSupport.firePropertyChange(prop, oldvalue, newvalue);
+ }
+
+
+
+ public boolean getIgnoreGapsConsensus()
+ {
+ return ignoreGapsInConsensusCalculation;
+ }
+ public void hideSelectedColumns()
+ {
+ if (colSel.size() < 1)
+ return;
+
+ colSel.hideSelectedColumns();
+ setSelectionGroup(null);
+
+ hasHiddenColumns = true;
+ }
+
+ public void invertColumnSelection()
+ {
+ int column;
+ for (int i = 0; i < alignment.getWidth(); i++)
+ {
+ column = i;
+
+ if (colSel.contains(column))
+ colSel.removeElement(column);
+ else
+ colSel.addElement(column);
+
+ }
+ }
+
+
+ public void hideColumns(int start, int end)
+ {
+ if(start==end)
+ colSel.hideColumns(start);
+ else
+ colSel.hideColumns(start, end);
+
+ hasHiddenColumns = true;
+ }
+
+ public void hideSequence(SequenceI seq)
+ {
+ if(seq!=null)
+ {
+ alignment.getHiddenSequences().hideSequence(seq);
+ hasHiddenRows = true;
+ firePropertyChange("alignment", null, alignment.getSequences());
+ }
+ }
+
+ public void hideAllSelectedSeqs()
+ {
+ if (selectionGroup == null)
+ return;
+
+ SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
+
+ for (int i = 0; i < seqs.length; i++)
+ {
+ alignment.getHiddenSequences().hideSequence(seqs[i]);
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ hasHiddenRows = true;
+ setSelectionGroup(null);
+ }
+
+ public void showColumn(int col)
+ {
+ colSel.revealHiddenColumns(col);
+ if(colSel.getHiddenColumns()==null)
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenColumns()
+ {
+ colSel.revealAllHiddenColumns();
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenSeqs()
+ {
+ if(alignment.getHiddenSequences().getSize()>0)
+ {
+ if(selectionGroup==null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth()-1);
+ }
+ Vector tmp = alignment.getHiddenSequences().showAll();
+ for(int t=0; t last)
+ {
+ hideStart = last;
+ } else
+ continue;
+ }
+
+ if (hideStart>end)
+ break;
+
+ if (hideEnd>end)
+ hideEnd=end;
+
+ if (hideStart>hideEnd)
+ break;
+ /**
+ * form operations...
+ */
+ if (lastblockEnd)
+ {
+ break;
+ }
+
+
+ visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
+
+ blockStart = hideEnd+1;
+ blockEnd = end;
+ }
+
+ if(end>blockStart)
+ visibleSeq.append(seqs[i].getSequence(blockStart, end));
+
+ selection[i] = visibleSeq.toString();
+ }
+ else
+ {
+ selection[i] = seqs[i].getSequence(start, end);
+ }
+ }
+
+ return selection;
+ }
+
+ public boolean getShowHiddenMarkers()
+ {
+ return showHiddenMarkers;
+ }
+
+ public void setShowHiddenMarkers(boolean show)
+ {
+ showHiddenMarkers = show;
+ }
+
+
+}
diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java
index e0c327f..ae97aaa 100755
--- a/src/jalview/appletgui/AlignmentPanel.java
+++ b/src/jalview/appletgui/AlignmentPanel.java
@@ -1,567 +1,585 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-
-public class AlignmentPanel extends Panel implements AdjustmentListener
-{
-
- AlignViewport av;
- OverviewPanel overviewPanel;
- SeqPanel seqPanel;
- IdPanel idPanel;
- IdwidthAdjuster idwidthAdjuster;
- public AlignFrame alignFrame;
- ScalePanel scalePanel;
- AnnotationPanel annotationPanel;
- AnnotationLabels alabels;
-
- // this value is set false when selection area being dragged
- boolean fastPaint = true;
-
- boolean MAC = false;
-
- public AlignmentPanel(AlignFrame af, final AlignViewport av)
- {
- try
- {
- jbInit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- if(System.getProperty("os.name").startsWith("Mac"))
- MAC = true;
-
- alignFrame = af;
- this.av = av;
- seqPanel = new SeqPanel(av, this);
- idPanel = new IdPanel(av, this);
- scalePanel = new ScalePanel(av, this);
- idwidthAdjuster = new IdwidthAdjuster(this);
- annotationPanel = new AnnotationPanel(this);
- alabels = new AnnotationLabels(this);
-
- setAnnotationVisible(av.showAnnotation);
-
- idPanelHolder.add(idPanel, BorderLayout.CENTER);
- idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
- annotationScroller.add(annotationPanel);
- annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
- scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
- seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
-
- fontChanged();
- setScrollValues(0, 0);
-
- hscroll.addAdjustmentListener(this);
- vscroll.addAdjustmentListener(this);
-
- addComponentListener(new ComponentAdapter()
- {
- public void componentResized(ComponentEvent evt)
- {
- setScrollValues(av.getStartRes(), av.getStartSeq());
- repaint();
- }
- });
-
- Dimension d = calculateIdWidth();
- idPanel.idCanvas.setSize(d);
-
- hscrollFillerPanel.setSize(d.width, annotationPanel.getSize().height);
- annotationScroller.setSize(annotationPanel.getSize());
-
- idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
- annotationSpaceFillerHolder.setSize(d.width,
- annotationPanel.getSize().height);
- alabels.setSize(d.width, annotationPanel.getSize().height);
-
- }
-
-
- public void fontChanged()
- {
- // set idCanvas bufferedImage to null
- // to prevent drawing old image
- idPanel.idCanvas.image =null;
- FontMetrics fm = getFontMetrics(av.getFont());
-
- scalePanel.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
- idwidthAdjuster.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
-
- int ap = annotationPanel.adjustPanelHeight();
- annotationPanel.repaint();
- Dimension d = calculateIdWidth();
- d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height);
- alabels.setSize(d.width+4, ap );
- idPanel.idCanvas.setSize(d);
- hscrollFillerPanel.setSize(d);
-
- validate();
- repaint();
-
- if(overviewPanel!=null)
- overviewPanel.updateOverviewImage();
- }
-
- public void setIdWidth(int w, int h)
- {
- idPanel.idCanvas.setSize(w, h);
- idPanelHolder.setSize(w, idPanelHolder.getSize().height);
- alabels.setSize(w, alabels.getSize().height);
- validate();
- }
-
- Dimension calculateIdWidth()
- {
- Frame frame = new Frame();
- frame.addNotify();
- Graphics g = frame.getGraphics();
- if (g == null)
- {
- Frame f = new Frame();
- f.addNotify();
- g = f.getGraphics();
- }
-
- FontMetrics fm = g.getFontMetrics(av.font);
- AlignmentI al = av.getAlignment();
-
- int i = 0;
- int idWidth = 0;
- String id;
- while (i < al.getHeight() && al.getSequenceAt(i) != null)
- {
- SequenceI s = al.getSequenceAt(i);
- id = s.getDisplayId(av.getShowJVSuffix());
-
- if (fm.stringWidth(id) > idWidth)
- {
- idWidth = fm.stringWidth(id);
- }
- i++;
- }
-
- // Also check annotation label widths
- i = 0;
- if (al.getAlignmentAnnotation() != null)
- {
- fm = g.getFontMetrics(frame.getFont());
- while (i < al.getAlignmentAnnotation().length)
- {
- String label = al.getAlignmentAnnotation()[i].label;
- if (fm.stringWidth(label) > idWidth)
- {
- idWidth = fm.stringWidth(label);
- }
- i++;
- }
- }
-
- return new Dimension(idWidth, idPanel.idCanvas.getSize().height);
- }
-
- public void highlightSearchResults(SearchResults results)
- {
- seqPanel.seqCanvas.highlightSearchResults(results);
-
- // do we need to scroll the panel?
- if (results != null)
- {
- SequenceI seq = results.getResultSequence(0);
- int seqIndex = av.alignment.findIndex(seq);
- int start = seq.findIndex(results.getResultStart(0)) - 1;
- int end = seq.findIndex(results.getResultEnd(0)) - 1;
-
- if(!av.wrapAlignment)
- {
- if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
- ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
- {
- if (start > av.alignment.getWidth() - hextent)
- {
- start = av.alignment.getWidth() - hextent;
- if (start < 0)
- start = 0;
- }
- if (seqIndex > av.alignment.getHeight() - vextent)
- {
- seqIndex = av.alignment.getHeight() - vextent;
- if (seqIndex < 0)
- seqIndex = 0;
- }
- setScrollValues(start, seqIndex);
- }
- }
- else
- {
- int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
- seqCanvas.getSize().width);
- if (start < av.getStartRes() || start > (av.getStartRes() + cwidth))
- {
- vscroll.setValue(start / cwidth);
- av.startRes = vscroll.getValue() * cwidth;
- }
- }
- }
-
- repaint();
- }
-
- public OverviewPanel getOverviewPanel()
- {
- return overviewPanel;
- }
-
- public void setOverviewPanel(OverviewPanel op)
- {
- overviewPanel = op;
- }
-
- public void setAnnotationVisible(boolean b)
- {
- if (!av.wrapAlignment)
- {
- annotationSpaceFillerHolder.setVisible(b);
- annotationScroller.setVisible(b);
- }
- validate();
- repaint();
- }
-
- public void setWrapAlignment(boolean wrap)
- {
- av.startSeq = 0;
- scalePanelHolder.setVisible(!wrap);
-
-
- hscroll.setVisible(!wrap);
- idwidthAdjuster.setVisible(!wrap);
-
- if (wrap)
- {
- annotationScroller.setVisible(false);
- annotationSpaceFillerHolder.setVisible(false);
- }
- else if (av.showAnnotation)
- {
- annotationScroller.setVisible(true);
- annotationSpaceFillerHolder.setVisible(true);
- }
-
-
- idSpaceFillerPanel1.setVisible(!wrap);
-
- fontChanged();//This is so that the scalePanel is resized correctly
-
- validate();
- repaint();
-
- }
-
-
- int hextent = 0;
- int vextent = 0;
-
- // return value is true if the scroll is valid
- public boolean scrollUp(boolean up)
- {
- if (up)
- {
- if (vscroll.getValue() < 1)
- {
- return false;
- }
- setScrollValues(hscroll.getValue(), vscroll.getValue()-1);
- }
- else
- {
- if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
- {
- return false;
- }
- setScrollValues(hscroll.getValue(), vscroll.getValue()+1);
- }
- repaint();
- return true;
- }
-
- public boolean scrollRight(boolean right)
- {
-
- if (right)
- {
- if (hscroll.getValue() < 1)
- {
- return false;
- }
- setScrollValues(hscroll.getValue()-1, vscroll.getValue());
- }
- else
- {
- if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
- {
- return false;
- }
- setScrollValues(hscroll.getValue()+1, vscroll.getValue());
- }
-
- repaint();
- return true;
- }
-
- public void setScrollValues(int x, int y)
- {
- av.setStartRes(x);
- av.setStartSeq(y);
- av.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() - 1);
-
- hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;
- vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;
-
- if (hextent > av.alignment.getWidth())
- {
- hextent = av.alignment.getWidth();
- }
- if (vextent > av.alignment.getHeight())
- {
- vextent = av.alignment.getHeight();
- }
-
- if (hextent + x > av.getAlignment().getWidth())
- {
- x = av.getAlignment().getWidth() - hextent;
- }
-
- if (vextent + y > av.getAlignment().getHeight())
- {
- y = av.getAlignment().getHeight() - vextent;
- }
-
- if (y < 0)
- {
- y = 0;
- }
-
- if (x < 0)
- {
- x = 0;
- }
-
- int endSeq = y + vextent;
- if (endSeq > av.alignment.getHeight())
- {
- endSeq = av.alignment.getHeight();
- }
-
- av.setEndSeq(endSeq);
- hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth());
- vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight());
- }
-
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- int oldX = av.getStartRes();
- int oldY = av.getStartSeq();
-
-
- if (evt==null || evt.getSource() == hscroll)
- {
- int x = hscroll.getValue();
- av.setStartRes(x);
- av.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() -
- 1);
- }
-
-
- if (evt==null || evt.getSource() == vscroll)
- {
- int offy = vscroll.getValue();
- if (av.getWrapAlignment())
- {
- int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
- seqCanvas.getSize().width);
- av.setStartRes(vscroll.getValue() * rowSize);
- av.setEndRes( (vscroll.getValue() + 1) * rowSize);
- }
- else
- {
- av.setStartSeq(offy);
- av.setEndSeq(offy +
- seqPanel.seqCanvas.getSize().height / av.getCharHeight());
- }
- }
-
- if (overviewPanel != null)
- {
- overviewPanel.setBoxPosition();
- }
-
- int scrollX = av.startRes - oldX;
- int scrollY = av.startSeq - oldY;
-
- if (av.getWrapAlignment() || !fastPaint || MAC)
- {
- repaint();
- }
- else
- {
- // Make sure we're not trying to draw a panel
- // larger than the visible window
- if(scrollX>av.endRes-av.startRes)
- {
- scrollX = av.endRes - av.startRes;
- }
- else if(scrollX idWidth)
+ {
+ idWidth = fm.stringWidth(id);
+ }
+ i++;
+ }
+
+ // Also check annotation label widths
+ i = 0;
+ if (al.getAlignmentAnnotation() != null)
+ {
+ fm = g.getFontMetrics(av.nullFrame.getFont());
+ while (i < al.getAlignmentAnnotation().length)
+ {
+ String label = al.getAlignmentAnnotation()[i].label;
+ if (fm.stringWidth(label) > idWidth)
+ {
+ idWidth = fm.stringWidth(label);
+ }
+ i++;
+ }
+ }
+
+ return new Dimension(idWidth, idPanel.idCanvas.getSize().height);
+ }
+
+ public void highlightSearchResults(SearchResults results)
+ {
+ seqPanel.seqCanvas.highlightSearchResults(results);
+
+ // do we need to scroll the panel?
+ if (results != null)
+ {
+ SequenceI seq = results.getResultSequence(0);
+ int seqIndex = av.alignment.findIndex(seq);
+ int start = seq.findIndex(results.getResultStart(0)) - 1;
+ int end = seq.findIndex(results.getResultEnd(0)) - 1;
+
+ if(!av.wrapAlignment)
+ {
+ if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
+ ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
+ {
+ if (start > av.alignment.getWidth() - hextent)
+ {
+ start = av.alignment.getWidth() - hextent;
+ if (start < 0)
+ start = 0;
+ }
+ if (seqIndex > av.alignment.getHeight() - vextent)
+ {
+ seqIndex = av.alignment.getHeight() - vextent;
+ if (seqIndex < 0)
+ seqIndex = 0;
+ }
+ setScrollValues(start, seqIndex);
+ }
+ }
+ else
+ {
+ scrollToWrappedVisible(start);
+ }
+ }
+
+ repaint();
+ }
+
+ void scrollToWrappedVisible(int res)
+ {
+ int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
+ if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
+ {
+ vscroll.setValue(res / cwidth);
+ av.startRes = vscroll.getValue() * cwidth;
+ }
+ }
+
+
+ public OverviewPanel getOverviewPanel()
+ {
+ return overviewPanel;
+ }
+
+ public void setOverviewPanel(OverviewPanel op)
+ {
+ overviewPanel = op;
+ }
+
+ public void setAnnotationVisible(boolean b)
+ {
+ if (!av.wrapAlignment)
+ {
+ annotationSpaceFillerHolder.setVisible(b);
+ annotationPanel.setVisible(b);
+ }
+ validate();
+ repaint();
+ }
+
+ public void setWrapAlignment(boolean wrap)
+ {
+ av.startSeq = 0;
+ scalePanelHolder.setVisible(!wrap);
+
+
+ hscroll.setVisible(!wrap);
+ idwidthAdjuster.setVisible(!wrap);
+
+ if (wrap)
+ {
+ annotationPanel.setVisible(false);
+ annotationSpaceFillerHolder.setVisible(false);
+ }
+ else if (av.showAnnotation)
+ {
+ annotationPanel.setVisible(true);
+ annotationSpaceFillerHolder.setVisible(true);
+ }
+
+
+ idSpaceFillerPanel1.setVisible(!wrap);
+
+ fontChanged();//This is so that the scalePanel is resized correctly
+
+ validate();
+ repaint();
+
+ }
+
+
+ int hextent = 0;
+ int vextent = 0;
+
+ // return value is true if the scroll is valid
+ public boolean scrollUp(boolean up)
+ {
+ if (up)
+ {
+ if (vscroll.getValue() < 1)
+ {
+ return false;
+ }
+ setScrollValues(hscroll.getValue(), vscroll.getValue()-1);
+ }
+ else
+ {
+ if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
+ {
+ return false;
+ }
+ setScrollValues(hscroll.getValue(), vscroll.getValue()+1);
+ }
+
+ repaint();
+ return true;
+ }
+
+ public boolean scrollRight(boolean right)
+ {
+ if (!right)
+ {
+ if (hscroll.getValue() < 1)
+ {
+ return false;
+ }
+ setScrollValues(hscroll.getValue()-1, vscroll.getValue());
+ }
+ else
+ {
+ if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
+ {
+ return false;
+ }
+ setScrollValues(hscroll.getValue()+1, vscroll.getValue());
+ }
+
+ repaint();
+ return true;
+ }
+
+ public void setScrollValues(int x, int y)
+ {
+ int width = av.alignment.getWidth();
+ int height = av.alignment.getHeight();
+
+ if(av.hasHiddenColumns)
+ width = av.getColumnSelection().findColumnPosition(width);
+
+ av.setStartRes(x);
+ av.setStartSeq(y);
+
+ av.setEndRes( (x + (seqPanel.seqCanvas.getSize().width / av.charWidth)) -1);
+
+ hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;
+ vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;
+
+ if (hextent > width)
+ {
+ hextent = width;
+ }
+
+ if (vextent > height)
+ {
+ vextent = height;
+ }
+
+ if ( (hextent + x) > width)
+ {
+ x = width - hextent;
+ }
+
+ if ( (vextent + y) > height)
+ {
+ y = height - vextent;
+ }
+
+ if (y < 0)
+ {
+ y = 0;
+ }
+
+ if (x < 0)
+ {
+ x = 0;
+ }
+
+ int endSeq = y + vextent;
+ if (endSeq > av.alignment.getHeight())
+ {
+ endSeq = av.alignment.getHeight();
+ }
+
+ av.setEndSeq(endSeq);
+ hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth());
+ vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight());
+
+ if(overviewPanel!=null)
+ overviewPanel.setBoxPosition();
+
+ }
+
+ public void adjustmentValueChanged(AdjustmentEvent evt)
+ {
+ int oldX = av.getStartRes();
+ int oldY = av.getStartSeq();
+
+
+ if (evt==null || evt.getSource() == hscroll)
+ {
+ int x = hscroll.getValue();
+ av.setStartRes(x);
+ av.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() -
+ 1);
+ }
+
+
+ if (evt==null || evt.getSource() == vscroll)
+ {
+ int offy = vscroll.getValue();
+ if (av.getWrapAlignment())
+ {
+ int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
+ seqCanvas.getSize().width);
+ av.setStartRes(vscroll.getValue() * rowSize);
+ av.setEndRes( (vscroll.getValue() + 1) * rowSize);
+ }
+ else
+ {
+ av.setStartSeq(offy);
+ av.setEndSeq(offy +
+ seqPanel.seqCanvas.getSize().height / av.getCharHeight());
+ }
+ }
+
+ if (overviewPanel != null)
+ {
+ overviewPanel.setBoxPosition();
+ }
+
+ int scrollX = av.startRes - oldX;
+ int scrollY = av.startSeq - oldY;
+
+ if (av.getWrapAlignment() || !fastPaint || av.MAC)
+ {
+ repaint();
+ }
+ else
+ {
+ // Make sure we're not trying to draw a panel
+ // larger than the visible window
+ if(scrollX>av.endRes-av.startRes)
+ {
+ scrollX = av.endRes - av.startRes;
+ }
+ else if(scrollX 0)
- annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
- }
-
- threshold.addItem("No Threshold");
- threshold.addItem("Above Threshold");
- threshold.addItem("Below Threshold");
-
- adjusting = false;
-
- changeColour();
-
- frame = new Frame();
- frame.add(this);
- jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480, 145);
- validate();
- }
-
- public AnnotationColourChooser()
- {
- try
- {
- jbInit();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- private void jbInit()
- throws Exception
- {
- minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- minColour.setLabel("Min Colour");
- minColour.addActionListener(this);
-
- maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- maxColour.setLabel("Max Colour");
- maxColour.addActionListener(this);
-
- ok.setLabel("OK");
- ok.addActionListener(this);
-
- cancel.setLabel("Cancel");
- cancel.addActionListener(this);
-
- this.setLayout(borderLayout1);
- jPanel2.setLayout(flowLayout1);
- annotations.addItemListener(this);
-
- jPanel1.setBackground(Color.white);
- jPanel2.setBackground(Color.white);
- threshold.addItemListener(this);
- jPanel3.setLayout(null);
- thresholdValue.addActionListener(this);
-
- slider.setBackground(Color.white);
- slider.setEnabled(false);
- slider.setBounds(new Rectangle(172, 7, 120, 16));
- thresholdValue.setEnabled(false);
- thresholdValue.setBounds(new Rectangle(295, 4, 83, 22));
- thresholdValue.setColumns(10);
- jPanel3.setBackground(Color.white);
- currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- currentColours.setLabel("Use Original Colours");
- currentColours.addItemListener(this);
-
- threshold.setBounds(new Rectangle(19, 4, 141, 22));
- jPanel1.add(ok);
- jPanel1.add(cancel);
- jPanel2.add(annotations);
- jPanel2.add(currentColours);
- jPanel2.add(minColour);
- jPanel2.add(maxColour);
- jPanel3.add(threshold);
- jPanel3.add(slider);
- jPanel3.add(thresholdValue);
- this.add(jPanel2, java.awt.BorderLayout.NORTH);
- this.add(jPanel3, java.awt.BorderLayout.CENTER);
- this.add(jPanel1, java.awt.BorderLayout.SOUTH);
- }
-
- Choice annotations = new Choice();
- Button minColour = new Button();
- Button maxColour = new Button();
- Button ok = new Button();
- Button cancel = new Button();
- Panel jPanel1 = new Panel();
- Panel jPanel2 = new Panel();
- Choice threshold = new Choice();
- FlowLayout flowLayout1 = new FlowLayout();
- Panel jPanel3 = new Panel();
- Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
- TextField thresholdValue = new TextField(20);
- Checkbox currentColours = new Checkbox();
- BorderLayout borderLayout1 = new BorderLayout();
-
-
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource() == thresholdValue)
- {
- try
- {
- float f = new Float(thresholdValue.getText()).floatValue();
- slider.setValue( (int) (f * 1000));
- adjustmentValueChanged(null);
- }
- catch (NumberFormatException ex)
- {}
- }
- else if (evt.getSource() == minColour)
- minColour_actionPerformed(null);
- else if (evt.getSource() == maxColour)
- maxColour_actionPerformed(null);
-
- else if (evt.getSource() == ok)
- {
- changeColour();
- frame.setVisible(false);
- }
- else if (evt.getSource() == cancel)
- {
- reset();
- ap.repaint();
- frame.setVisible(false);
- }
-
- else
- changeColour();
- }
-
-
- public void itemStateChanged(ItemEvent evt)
- {
- if (evt.getSource() == currentColours)
- {
- if (currentColours.getState())
- {
- reset();
- }
-
- maxColour.setEnabled(!currentColours.getState());
- minColour.setEnabled(!currentColours.getState());
-
- }
-
- changeColour();
- }
-
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- if (!adjusting)
- {
- thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
- if (currentColours.getState()
- && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
- {
- changeColour();
- }
-
- currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
- ap.repaint();
- }
- }
-
- public void minColour_actionPerformed(Color newCol)
- {
- if (newCol != null)
- {
- minColour.setBackground(newCol);
- minColour.repaint();
- changeColour();
- }
- else
- new UserDefinedColours(this, "Min Colour",
- minColour.getBackground());
-
- }
-
- public void maxColour_actionPerformed(Color newCol)
- {
- if (newCol != null)
- {
- maxColour.setBackground(newCol);
- maxColour.repaint();
- changeColour();
- }
- else
- new UserDefinedColours(this, "Max Colour",
- maxColour.getBackground());
- }
-
-
- void changeColour()
- {
- // Check if combobox is still adjusting
- if (adjusting)
- return;
-
- // We removed the non-graph annotations when filling the combobox
- // so allow for them again here
- int nograph = 0, graph = -1;
- for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
- {
- if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
- nograph++;
- else
- graph++;
-
- if (graph == annotations.getSelectedIndex())
- break;
- }
-
- currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
-
- int aboveThreshold = -1;
- if (threshold.getSelectedItem().equals("Above Threshold"))
- aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
- else if (threshold.getSelectedItem().equals("Below Threshold"))
- aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
-
- slider.setEnabled(true);
- thresholdValue.setEnabled(true);
-
- if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
- {
- slider.setEnabled(false);
- thresholdValue.setEnabled(false);
- thresholdValue.setText("");
- }
- else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
- currentAnnotation.threshold == null)
- {
- currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
- ( (currentAnnotation.graphMax -
- currentAnnotation.graphMin) / 2f,
- "Threshold",
- Color.black));
- }
-
- if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
- {
- adjusting = true;
-
- slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
- slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
- slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
- thresholdValue.setText(currentAnnotation.threshold.value + "");
- slider.setEnabled(true);
- thresholdValue.setEnabled(true);
- adjusting = false;
- }
-
- AnnotationColourGradient acg = null;
- if (currentColours.getState())
- acg = new AnnotationColourGradient(
- currentAnnotation,
- av.getGlobalColourScheme(), aboveThreshold);
- else
- acg =
- new AnnotationColourGradient(
- currentAnnotation,
- minColour.getBackground(),
- maxColour.getBackground(),
- aboveThreshold);
-
- av.setGlobalColourScheme(acg);
-
- if (av.alignment.getGroups() != null)
- {
- Vector allGroups = ap.av.alignment.getGroups();
- SequenceGroup sg;
- for (int g = 0; g < allGroups.size(); g++)
- {
- sg = (SequenceGroup) allGroups.elementAt(g);
-
- if (sg.cs == null)
- {
- continue;
- }
-
- if (currentColours.getState())
- sg.cs = new AnnotationColourGradient(
- currentAnnotation,
- sg.cs, aboveThreshold);
- else
- sg.cs = new AnnotationColourGradient(
- currentAnnotation,
- minColour.getBackground(),
- maxColour.getBackground(),
- aboveThreshold);
-
- }
- }
-
- ap.repaint();
- }
-
-
- void reset()
- {
- av.setGlobalColourScheme(oldcs);
- if (av.alignment.getGroups() != null)
- {
- Vector allGroups = ap.av.alignment.getGroups();
- SequenceGroup sg;
- for (int g = 0; g < allGroups.size(); g++)
- {
- sg = (SequenceGroup) allGroups.elementAt(g);
- sg.cs = (ColourSchemeI)oldgroupColours.get(sg);
- }
- }
- ap.repaint();
-
- }
-
-
-
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.appletgui;
+
+import java.awt.event.*;
+import java.awt.*;
+
+import jalview.schemes.*;
+import java.util.*;
+import jalview.datamodel.SequenceGroup;
+
+public class AnnotationColourChooser extends Panel implements ActionListener,
+ AdjustmentListener, ItemListener
+{
+ Frame frame;
+ AlignViewport av;
+ AlignmentPanel ap;
+ ColourSchemeI oldcs;
+ Hashtable oldgroupColours;
+ jalview.datamodel.AlignmentAnnotation currentAnnotation;
+ boolean adjusting = false;
+
+ public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception ex)
+ {}
+
+ oldcs = av.getGlobalColourScheme();
+ if (av.alignment.getGroups() != null)
+ {
+ oldgroupColours = new Hashtable();
+ Vector allGroups = ap.av.alignment.getGroups();
+ SequenceGroup sg;
+ for (int g = 0; g < allGroups.size(); g++)
+ {
+ sg = (SequenceGroup) allGroups.elementAt(g);
+ oldgroupColours.put(sg, sg.cs);
+ }
+ }
+ this.av = av;
+ this.ap = ap;
+
+ slider.addAdjustmentListener(this);
+
+ if (av.alignment.getAlignmentAnnotation() == null)
+ return;
+
+ if (oldcs instanceof AnnotationColourGradient)
+ {
+ AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
+ minColour.setBackground(acg.getMinColour());
+ maxColour.setBackground(acg.getMaxColour());
+ }
+ else
+ {
+ minColour.setBackground(Color.orange);
+ maxColour.setBackground(Color.red);
+ }
+
+ adjusting = true;
+ for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
+ {
+ if (av.alignment.getAlignmentAnnotation()[i].graph > 0)
+ annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
+ }
+
+ threshold.addItem("No Threshold");
+ threshold.addItem("Above Threshold");
+ threshold.addItem("Below Threshold");
+
+ adjusting = false;
+
+ changeColour();
+
+ frame = new Frame();
+ frame.add(this);
+ jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480, 145);
+ validate();
+ }
+
+ public AnnotationColourChooser()
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ private void jbInit()
+ throws Exception
+ {
+ minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
+ minColour.setLabel("Min Colour");
+ minColour.addActionListener(this);
+
+ maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
+ maxColour.setLabel("Max Colour");
+ maxColour.addActionListener(this);
+
+ ok.setLabel("OK");
+ ok.addActionListener(this);
+
+ cancel.setLabel("Cancel");
+ cancel.addActionListener(this);
+
+ this.setLayout(borderLayout1);
+ jPanel2.setLayout(flowLayout1);
+ annotations.addItemListener(this);
+
+ jPanel1.setBackground(Color.white);
+ jPanel2.setBackground(Color.white);
+ threshold.addItemListener(this);
+ jPanel3.setLayout(null);
+ thresholdValue.addActionListener(this);
+
+ slider.setBackground(Color.white);
+ slider.setEnabled(false);
+ slider.setBounds(new Rectangle(172, 7, 120, 16));
+ thresholdValue.setEnabled(false);
+ thresholdValue.setBounds(new Rectangle(295, 4, 83, 22));
+ thresholdValue.setColumns(10);
+ jPanel3.setBackground(Color.white);
+ currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
+ currentColours.setLabel("Use Original Colours");
+ currentColours.addItemListener(this);
+
+ threshold.setBounds(new Rectangle(19, 4, 141, 22));
+ jPanel1.add(ok);
+ jPanel1.add(cancel);
+ jPanel2.add(annotations);
+ jPanel2.add(currentColours);
+ jPanel2.add(minColour);
+ jPanel2.add(maxColour);
+ jPanel3.add(threshold);
+ jPanel3.add(slider);
+ jPanel3.add(thresholdValue);
+ this.add(jPanel2, java.awt.BorderLayout.NORTH);
+ this.add(jPanel3, java.awt.BorderLayout.CENTER);
+ this.add(jPanel1, java.awt.BorderLayout.SOUTH);
+ }
+
+ Choice annotations = new Choice();
+ Button minColour = new Button();
+ Button maxColour = new Button();
+ Button ok = new Button();
+ Button cancel = new Button();
+ Panel jPanel1 = new Panel();
+ Panel jPanel2 = new Panel();
+ Choice threshold = new Choice();
+ FlowLayout flowLayout1 = new FlowLayout();
+ Panel jPanel3 = new Panel();
+ Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
+ TextField thresholdValue = new TextField(20);
+ Checkbox currentColours = new Checkbox();
+ BorderLayout borderLayout1 = new BorderLayout();
+
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource() == thresholdValue)
+ {
+ try
+ {
+ float f = new Float(thresholdValue.getText()).floatValue();
+ slider.setValue( (int) (f * 1000));
+ adjustmentValueChanged(null);
+ }
+ catch (NumberFormatException ex)
+ {}
+ }
+ else if (evt.getSource() == minColour)
+ minColour_actionPerformed(null);
+ else if (evt.getSource() == maxColour)
+ maxColour_actionPerformed(null);
+
+ else if (evt.getSource() == ok)
+ {
+ changeColour();
+ frame.setVisible(false);
+ }
+ else if (evt.getSource() == cancel)
+ {
+ reset();
+ ap.repaint();
+ frame.setVisible(false);
+ }
+
+ else
+ changeColour();
+ }
+
+
+ public void itemStateChanged(ItemEvent evt)
+ {
+ if (evt.getSource() == currentColours)
+ {
+ if (currentColours.getState())
+ {
+ reset();
+ }
+
+ maxColour.setEnabled(!currentColours.getState());
+ minColour.setEnabled(!currentColours.getState());
+
+ }
+
+ changeColour();
+ }
+
+ public void adjustmentValueChanged(AdjustmentEvent evt)
+ {
+ if (!adjusting)
+ {
+ thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
+ if (currentColours.getState()
+ && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
+ {
+ changeColour();
+ }
+
+ currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
+ ap.repaint();
+ }
+ }
+
+ public void minColour_actionPerformed(Color newCol)
+ {
+ if (newCol != null)
+ {
+ minColour.setBackground(newCol);
+ minColour.repaint();
+ changeColour();
+ }
+ else
+ new UserDefinedColours(this, "Min Colour",
+ minColour.getBackground());
+
+ }
+
+ public void maxColour_actionPerformed(Color newCol)
+ {
+ if (newCol != null)
+ {
+ maxColour.setBackground(newCol);
+ maxColour.repaint();
+ changeColour();
+ }
+ else
+ new UserDefinedColours(this, "Max Colour",
+ maxColour.getBackground());
+ }
+
+
+ void changeColour()
+ {
+ // Check if combobox is still adjusting
+ if (adjusting)
+ return;
+
+ // We removed the non-graph annotations when filling the combobox
+ // so allow for them again here
+ int nograph = 0, graph = -1;
+ for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
+ {
+ if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
+ nograph++;
+ else
+ graph++;
+
+ if (graph == annotations.getSelectedIndex())
+ break;
+ }
+
+ currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
+
+ int aboveThreshold = -1;
+ if (threshold.getSelectedItem().equals("Above Threshold"))
+ aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
+ else if (threshold.getSelectedItem().equals("Below Threshold"))
+ aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
+
+ slider.setEnabled(true);
+ thresholdValue.setEnabled(true);
+
+ if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
+ {
+ slider.setEnabled(false);
+ thresholdValue.setEnabled(false);
+ thresholdValue.setText("");
+ }
+ else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
+ currentAnnotation.threshold == null)
+ {
+ currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
+ ( (currentAnnotation.graphMax -
+ currentAnnotation.graphMin) / 2f,
+ "Threshold",
+ Color.black));
+ }
+
+ if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
+ {
+ adjusting = true;
+
+ slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
+ slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
+ slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
+ thresholdValue.setText(currentAnnotation.threshold.value + "");
+ slider.setEnabled(true);
+ thresholdValue.setEnabled(true);
+ adjusting = false;
+ }
+
+ AnnotationColourGradient acg = null;
+ if (currentColours.getState())
+ acg = new AnnotationColourGradient(
+ currentAnnotation,
+ av.getGlobalColourScheme(), aboveThreshold);
+ else
+ acg =
+ new AnnotationColourGradient(
+ currentAnnotation,
+ minColour.getBackground(),
+ maxColour.getBackground(),
+ aboveThreshold);
+
+ av.setGlobalColourScheme(acg);
+
+ if (av.alignment.getGroups() != null)
+ {
+ Vector allGroups = ap.av.alignment.getGroups();
+ SequenceGroup sg;
+ for (int g = 0; g < allGroups.size(); g++)
+ {
+ sg = (SequenceGroup) allGroups.elementAt(g);
+
+ if (sg.cs == null)
+ {
+ continue;
+ }
+
+ if (currentColours.getState())
+ sg.cs = new AnnotationColourGradient(
+ currentAnnotation,
+ sg.cs, aboveThreshold);
+ else
+ sg.cs = new AnnotationColourGradient(
+ currentAnnotation,
+ minColour.getBackground(),
+ maxColour.getBackground(),
+ aboveThreshold);
+
+ }
+ }
+
+ ap.repaint();
+ }
+
+
+ void reset()
+ {
+ av.setGlobalColourScheme(oldcs);
+ if (av.alignment.getGroups() != null)
+ {
+ Vector allGroups = ap.av.alignment.getGroups();
+ SequenceGroup sg;
+ for (int g = 0; g < allGroups.size(); g++)
+ {
+ sg = (SequenceGroup) allGroups.elementAt(g);
+ sg.cs = (ColourSchemeI)oldgroupColours.get(sg);
+ }
+ }
+ ap.repaint();
+
+ }
+
+
+
+}
diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java
index ae47b72..ae6ef37 100755
--- a/src/jalview/appletgui/AnnotationLabels.java
+++ b/src/jalview/appletgui/AnnotationLabels.java
@@ -1,203 +1,243 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-
-public class AnnotationLabels
- extends Panel implements ActionListener
-{
- boolean active = false;
- AlignmentPanel ap;
- AlignViewport av;
- boolean resizing = false;
- int oldY, mouseX;
- static String ADDNEW = "Add new row";
- static String HIDE = "Hide this row";
- static String DELETE = "Delete this row";
- static String SHOWALL = "Show all hidden rows";
- static String OUTPUT_TEXT = "Show Values In Textbox";
- int selectedRow = 0;
- int scrollOffset = 0;
-
- public AnnotationLabels(AlignmentPanel ap)
- {
- this.ap = ap;
- this.av = ap.av;
- setLayout(null);
- addMouseListener(new MouseAdapter()
- {
- public void mousePressed(MouseEvent evt)
- {
- doMousePressed(evt);
- }
- });
- }
-
- public AnnotationLabels(AlignViewport av)
-{
- this.av = av;
-}
-
-
- public void setScrollOffset(int y)
- {
- scrollOffset = y;
- repaint();
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
-
- if (evt.getActionCommand().equals(HIDE))
- {
- aa[selectedRow].visible = false;
- }
- else if (evt.getActionCommand().equals(SHOWALL))
- {
- for (int i = 0; i < aa.length; i++)
- {
- aa[i].visible = true;
- }
- }
- else if (evt.getActionCommand().equals(OUTPUT_TEXT))
- {
- CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
- Frame frame = new Frame();
- frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame,
- ap.alignFrame.getTitle() + " - " +
- aa[selectedRow].label, 500, 100);
- cap.setText(aa[selectedRow].toString());
- }
-
- ap.annotationPanel.adjustPanelHeight();
- setSize(getSize().width, ap.annotationPanel.getSize().height);
- ap.validate();
- ap.repaint();
- }
-
- public void doMousePressed(MouseEvent evt)
- {
- int y = evt.getY() - scrollOffset;
- AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
- int height = 0;
- for (int i = 0; i < aa.length; i++)
- {
- if (!aa[i].visible)
- {
- continue;
- }
-
- height += aa[i].height;
- if (y < height)
- {
- selectedRow = i;
- break;
- }
- }
-
- PopupMenu pop = new PopupMenu("Annotations");
- MenuItem item = new MenuItem(HIDE);
- item.addActionListener(this);
- pop.add(item);
- item = new MenuItem(SHOWALL);
- item.addActionListener(this);
- pop.add(item);
- this.add(pop);
- item = new MenuItem(OUTPUT_TEXT);
- item.addActionListener(this);
- pop.add(item);
-
- if (aa[selectedRow].label.equals("Consensus"))
- {
- pop.addSeparator();
- final CheckboxMenuItem cbmi = new CheckboxMenuItem(
- "Ignore Gaps In Consensus",
- ap.av.getIgnoreGapsConsensus());
-
- cbmi.addItemListener(new ItemListener()
- {
- public void itemStateChanged(ItemEvent e)
- {
- ap.av.setIgnoreGapsConsensus(cbmi.getState());
- ap.repaint();
- }
- });
- pop.add(cbmi);
- }
-
- pop.show(this, evt.getX(), evt.getY());
-
- }
-
- public void paint(Graphics g)
- {
- drawComponent(g, getSize().width);
- }
-
- public void drawComponent(Graphics g, int width)
- {
- FontMetrics fm = g.getFontMetrics(g.getFont());
- g.setColor(Color.white);
- g.fillRect(0, 0, getSize().width, getSize().height);
-
- g.translate(0, scrollOffset);
- g.setColor(Color.black);
-
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
- int y = g.getFont().getSize();
- int x = 0;
-
- if (aa != null)
- {
- for (int i = 0; i < aa.length; i++)
- {
- if (!aa[i].visible)
- {
- continue;
- }
-
- x = width - fm.stringWidth(aa[i].label) - 3;
-
- if (aa[i].graph>0)
- {
- y += (aa[i].height / 3);
- }
-
- g.drawString(aa[i].label, x, y);
-
- if (aa[i].graph>0)
- {
- y += (2 * aa[i].height / 3);
- }
- else
- {
- y += aa[i].height;
- }
- }
- }
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.Vector;
+
+import jalview.datamodel.*;
+
+public class AnnotationLabels
+ extends Panel implements ActionListener
+{
+ boolean active = false;
+ AlignmentPanel ap;
+ AlignViewport av;
+ boolean resizing = false;
+ int oldY, mouseX;
+ static String ADDNEW = "Add new row";
+ static String HIDE = "Hide this row";
+ static String DELETE = "Delete this row";
+ static String SHOWALL = "Show all hidden rows";
+ static String OUTPUT_TEXT = "Show Values In Textbox";
+ static String COPYCONS_SEQ = "Copy Consensus Sequence";
+
+ int selectedRow = 0;
+ int scrollOffset = 0;
+
+ public AnnotationLabels(AlignmentPanel ap)
+ {
+ this.ap = ap;
+ this.av = ap.av;
+ setLayout(null);
+ addMouseListener(new MouseAdapter()
+ {
+ public void mousePressed(MouseEvent evt)
+ {
+ doMousePressed(evt);
+ }
+ });
+ }
+
+ public AnnotationLabels(AlignViewport av)
+{
+ this.av = av;
+}
+
+
+ public void setScrollOffset(int y)
+ {
+ scrollOffset = y;
+ repaint();
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+
+ if (evt.getActionCommand().equals(HIDE))
+ {
+ aa[selectedRow].visible = false;
+ }
+ else if (evt.getActionCommand().equals(SHOWALL))
+ {
+ for (int i = 0; i < aa.length; i++)
+ {
+ aa[i].visible = true;
+ }
+ }
+ else if (evt.getActionCommand().equals(OUTPUT_TEXT))
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame,
+ ap.alignFrame.getTitle() + " - " +
+ aa[selectedRow].label, 500, 100);
+ cap.setText(aa[selectedRow].toString());
+ }
+ else if (evt.getActionCommand().equals(COPYCONS_SEQ))
+ {
+ SequenceI cons=av.getConsensusSeq();
+ if (cons!=null)
+ copy_annotseqtoclipboard(cons);
+
+ }
+ ap.annotationPanel.adjustPanelHeight();
+ setSize(getSize().width, ap.annotationPanel.getSize().height);
+ ap.validate();
+ ap.repaint();
+ }
+
+ public void doMousePressed(MouseEvent evt)
+ {
+ int y = evt.getY() - scrollOffset;
+ AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
+ int height = 0;
+ for (int i = 0; i < aa.length; i++)
+ {
+ if (!aa[i].visible)
+ {
+ continue;
+ }
+
+ height += aa[i].height;
+ if (y < height)
+ {
+ selectedRow = i;
+ break;
+ }
+ }
+
+ PopupMenu pop = new PopupMenu("Annotations");
+ MenuItem item = new MenuItem(HIDE);
+ item.addActionListener(this);
+ pop.add(item);
+ item = new MenuItem(SHOWALL);
+ item.addActionListener(this);
+ pop.add(item);
+ this.add(pop);
+ item = new MenuItem(OUTPUT_TEXT);
+ item.addActionListener(this);
+ pop.add(item);
+
+ if (aa[selectedRow].label.equals("Consensus"))
+ {
+ pop.addSeparator();
+ final CheckboxMenuItem cbmi = new CheckboxMenuItem(
+ "Ignore Gaps In Consensus",
+ ap.av.getIgnoreGapsConsensus());
+
+ cbmi.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent e)
+ {
+ ap.av.setIgnoreGapsConsensus(cbmi.getState());
+ ap.repaint();
+ }
+ });
+ pop.add(cbmi);
+ final MenuItem cpcons=new MenuItem(COPYCONS_SEQ);
+ cpcons.addActionListener(this);
+ pop.add(cpcons);
+ }
+
+ pop.show(this, evt.getX(), evt.getY());
+
+ }
+/**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void copy_annotseqtoclipboard(SequenceI sq)
+ {
+ if (sq==null || sq.getLength()<1)
+ return;
+ jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
+ jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
+ sq.getStart() + "\t" +
+ sq.getEnd() + "\t" +
+ sq.getSequence() + "\n");
+ if (av.hasHiddenColumns)
+ {
+ jalview.appletgui.AlignFrame.copiedHiddenColumns=new Vector();
+ for(int i=0; i0)
+ {
+ y += (aa[i].height / 3);
+ }
+
+ g.drawString(aa[i].label, x, y);
+
+ if (aa[i].graph>0)
+ {
+ y += (2 * aa[i].height / 3);
+ }
+ else
+ {
+ y += aa[i].height;
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java
index cb638dd..9a029a7 100755
--- a/src/jalview/appletgui/AnnotationPanel.java
+++ b/src/jalview/appletgui/AnnotationPanel.java
@@ -1,682 +1,782 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-
-public class AnnotationPanel
- extends Panel implements AdjustmentListener
-{
- AlignViewport av;
- AlignmentPanel ap;
- int activeRow = -1;
-
- Vector activeRes;
- static String HELIX = "Helix";
- static String SHEET = "Sheet";
- static String LABEL = "Label";
- static String REMOVE = "Remove Annotation";
- static String COLOUR = "Colour";
- static Color HELIX_COLOUR = Color.red.darker();
- static Color SHEET_COLOUR = Color.green.darker().darker();
-
- Image image;
- Graphics gg;
- FontMetrics fm;
- int imgWidth = 0;
-
- boolean fastPaint = false;
-
- public static int GRAPH_HEIGHT = 40;
-
- public AnnotationPanel(AlignmentPanel ap)
- {
- this.ap = ap;
- av = ap.av;
- this.setLayout(null);
- adjustPanelHeight();
-
- addMouseMotionListener(new MouseMotionAdapter()
- {
- public void mouseMoved(MouseEvent evt)
- {
- doMouseMoved(evt);
- }
- });
-
- // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );
- }
-
-
- public AnnotationPanel(AlignViewport av)
- {
- this.av = av;
- }
-
-
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- ap.alabels.setScrollOffset( -evt.getValue());
- }
-
- public int adjustPanelHeight()
- {
- // setHeight of panels
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
-
-
- int height = 0;
- if (aa != null)
- {
- for (int i = 0; i < aa.length; i++)
- {
- if (!aa[i].visible)
- {
- continue;
- }
-
- aa[i].height = 0;
-
- if (aa[i].hasText)
- {
- aa[i].height += av.charHeight;
- }
- if (aa[i].hasIcons)
- {
- aa[i].height += 16;
- }
-
- if (aa[i].graph>0)
- {
- aa[i].height += GRAPH_HEIGHT;
- }
-
- if (aa[i].height == 0)
- {
- aa[i].height = 20;
- }
- height += aa[i].height;
- }
- }
- else
- {
- height = 20;
- }
-
- this.setSize(getSize().width, height);
- if(ap!=null)
- ap.annotationScroller.setSize(getSize().width, height);
-
-
- repaint();
-
- return height;
-
- }
-
- public void addEditableColumn(int i)
- {
- if (activeRow == -1)
- {
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
- if(aa ==null)
- return;
-
- for (int j = 0; j < aa.length; j++)
- {
- if (aa[j].editable)
- {
- activeRow = j;
- break;
- }
- }
- }
-
- if (activeRes == null)
- {
- activeRes = new Vector();
- activeRes.addElement(String.valueOf(i));
- return;
- }
-
- activeRes.addElement(String.valueOf(i));
- }
-
- public void doMouseMoved(MouseEvent evt)
- {
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
- if (aa == null)
- {
- return;
- }
-
- int row = -1;
- int height = 0;
- for (int i = 0; i < aa.length; i++)
- {
-
- if (aa[i].visible)
- {
- height += aa[i].height;
- }
-
- if (evt.getY() < height)
- {
- row = i;
- break;
- }
- }
-
- int res = evt.getX() / av.getCharWidth() + av.getStartRes();
- if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)
- {
- StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
- " " +
- aa[row].annotations[res].description);
- ap.alignFrame.statusBar.setText(text.toString());
- }
- }
-
- public void update(Graphics g)
- {
- paint(g);
- }
-
- public void paint(Graphics g)
- {
- imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
-
- if (image == null || imgWidth != image.getWidth(this))
- {
- image = createImage(imgWidth, ap.annotationPanel.getSize().height);
- gg = image.getGraphics();
- gg.setFont(av.getFont());
- fm = gg.getFontMetrics();
- fastPaint = false;
- }
-
- if (fastPaint)
- {
- g.drawImage(image, 0, 0, this);
- fastPaint = false;
- return;
- }
-
- drawComponent(gg, av.startRes, av.endRes + 1);
- g.drawImage(image, 0, 0, this);
- }
-
- public void fastPaint(int horizontal)
- {
- if (horizontal == 0
- || av.alignment.getAlignmentAnnotation() == null
- || av.alignment.getAlignmentAnnotation().length < 1
- )
- {
- repaint();
- return;
- }
-
- gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
- int sr = av.startRes, er = av.endRes + 1, transX = 0;
-
- if (horizontal > 0) // scrollbar pulled right, image to the left
- {
- transX = (er - sr - horizontal) * av.charWidth;
- sr = er - horizontal;
- }
- else if (horizontal < 0)
- {
- er = sr - horizontal;
- }
-
- gg.translate(transX, 0);
-
- drawComponent(gg, sr, er);
-
- gg.translate( -transX, 0);
-
- fastPaint = true;
- repaint();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param g DOCUMENT ME!
- * @param startRes DOCUMENT ME!
- * @param endRes DOCUMENT ME!
- */
- public void drawComponent(Graphics g, int startRes, int endRes)
- {
- g.setFont(av.getFont());
-
- if (fm == null)
- fm = g.getFontMetrics();
-
-
- g.setColor(Color.white);
- g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
-
- if ((av.alignment.getAlignmentAnnotation() == null) ||
- (av.alignment.getAlignmentAnnotation().length < 1))
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, getSize().width, getSize().height);
- g.setColor(Color.black);
- g.drawString("Alignment has no annotations", 20, 15);
-
- return;
- }
-
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
-
- int j;
- int x = 0;
- int y = 0;
- char[] lastSS = new char[aa.length];
- int[] lastSSX = new int[aa.length];
- int iconOffset = av.charHeight / 2;
- boolean validRes = false;
-
- boolean [] graphGroupDrawn = new boolean[aa.length];
-
-
- //\u03B2 \u03B1
- for (int i = 0; i < aa.length; i++)
- {
- AlignmentAnnotation row = aa[i];
-
- if (!row.visible)
- {
- continue;
- }
-
-
-
- if (row.graph>0)
- {
- if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )
- continue;
-
- // this is so that we draw the characters below the graph
- y += row.height;
-
- if (row.hasText)
- {
- y -= av.charHeight;
- }
- }
-
- if (row.hasText)
- {
- iconOffset = av.charHeight / 2;
- }
- else
- {
- iconOffset = 0;
- }
-
- for (j = startRes; j < endRes; j++)
- {
- if ((row.annotations.length <= j) ||
- (row.annotations[j] == null))
- {
- validRes = false;
- }
- else
- {
- validRes = true;
- }
-
- x = (j - startRes) * av.charWidth;
-
- if (activeRow == i)
- {
- g.setColor(Color.red);
-
- if (activeRes != null)
- {
- for (int n = 0; n < activeRes.size(); n++)
- {
- int v = Integer.parseInt(activeRes.elementAt(n).toString());
-
- if (v == j)
- {
- g.fillRect((j - startRes) * av.charWidth, y,
- av.charWidth, row.height);
- }
- }
- }
- }
-
- if (validRes &&
- (row.annotations[j].displayCharacter.length() > 0))
- {
-
- int charOffset = (av.charWidth -
- fm.charWidth(row.annotations[j].displayCharacter.charAt(
- 0))) / 2;
- g.setColor(row.annotations[j].colour);
-
- if (j == 0 || row.graph>0)
- {
- g.drawString(row.annotations[j].displayCharacter, x+charOffset,
- y + iconOffset + 3);
- }
- else if (((row.annotations[j - 1] == null) ||
- (!row.annotations[j].displayCharacter.equals(
- row.annotations[j - 1].displayCharacter))))
- {
- g.drawString(row.annotations[j].displayCharacter, x+charOffset,
- y + iconOffset + 3);
- }
- }
-
- if (row.hasIcons)
- {
- if (!validRes ||
- (row.annotations[j].secondaryStructure != lastSS[i]))
- {
- switch (lastSS[i])
- {
- case 'H':
- g.setColor(HELIX_COLOUR);
- g.fillRoundRect(lastSSX[i], y + 4 + iconOffset,
- x - lastSSX[i], 7, 8, 8);
-
- break;
-
- case 'E':
- g.setColor(SHEET_COLOUR);
- g.fillRect(lastSSX[i], y + 4 + iconOffset,
- x - lastSSX[i] - 4, 7);
- g.fillPolygon(new int[] { x - 4, x - 4, x },
- new int[]
- {
- y + iconOffset, y + 14 + iconOffset,
- y + 8 + iconOffset
- }, 3);
-
- break;
-
-
- default:
- g.setColor(Color.gray);
- g.fillRect(lastSSX[i], y + 6 + iconOffset,
- x - lastSSX[i], 2);
-
- break;
- }
-
- if (validRes)
- {
- lastSS[i] = row.annotations[j].secondaryStructure;
- }
- else
- {
- lastSS[i] = ' ';
- }
-
- lastSSX[i] = x;
- }
- }
- }
-
- x += av.charWidth;
-
- if (row.hasIcons)
- {
- switch (lastSS[i])
- {
- case 'H':
- g.setColor(HELIX_COLOUR);
- g.fillRoundRect(lastSSX[i], y + 4 + iconOffset,
- x - lastSSX[i], 7, 8, 8);
-
- break;
-
- case 'E':
- g.setColor(SHEET_COLOUR);
-
- if (row.annotations.length > endRes
- && row.annotations[endRes].secondaryStructure != 'E')
- {
- g.fillRect(lastSSX[i], y + 4 + iconOffset,
- x - lastSSX[i] - 4, 7);
- g.fillPolygon(new int[]
- {x - 4, x - 4, x},
- new int[]
- {
- y + iconOffset, y + 14 + iconOffset,
- y + 7 + iconOffset
- }, 3);
- }
- else
- g.fillRect(lastSSX[i], y + 4 + iconOffset,
- x - lastSSX[i], 7);
-
- break;
-
- case 'C':
- break;
-
- default:
- g.setColor(Color.gray);
- g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
-
- break;
- }
- }
-
- if (row.graph>0)
- {
- if(row.graph == AlignmentAnnotation.LINE_GRAPH )
- {
- if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])
- {
- float groupmax=-999999, groupmin=9999999;
- for(int gg=0; gggroupmax)
- groupmax = aa[gg].graphMax;
- if(aa[gg].graphMin0 && row.hasText)
- {
- y += av.charHeight;
- }
-
- if (row.graph==0)
- {
- y += aa[i].height;
- }
- }
- }
-
- public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
- int sRes, int eRes,
- int y,
- float min, float max,
- int graphHeight)
- {
- if(sRes>aa.annotations.length)
- return;
-
-
- eRes = Math.min(eRes, aa.annotations.length);
-
- int x = 0;
-
- //Adjustment for fastpaint to left
- if(eResaa.annotations.length)
- return;
-
-
- eRes = Math.min(eRes, aa.annotations.length);
-
- int x=0, y1, y2;
-
- float range = max - min;
-
- y1 = y2 = y;
-
- if(min<0)
- y2 = (int)(y - (0-min / (range))*aa.graphHeight);
-
- g.setColor(Color.gray);
-
- g.drawLine(x,y2,(eRes-sRes)*av.charWidth,y2);
-
- for (int j = sRes; j < eRes; j++)
- {
-
- if (aa.annotations[j] == null)
- {
- x += av.charWidth;
- continue;
- }
-
- g.setColor(aa.annotations[j].colour);
- y1 = y - (int) (((aa.annotations[j].value-min) / (range)) * aa.graphHeight);
-
- if(y1-y2>0)
- g.fillRect(x, y2, av.charWidth, y1-y2 );
- else
- g.fillRect(x, y1, av.charWidth, y2-y1 );
-
- x += av.charWidth;
- }
-
-
- if(aa.threshold!=null)
- {
- g.setColor(aa.threshold.colour);
- y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);
- g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
- }
-
-
- }
-
- // used by overview window
- public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, width, y);
- g.setColor(new Color(0, 0, 180));
-
- int x = 0, height;
-
- for (int j = sRes; j < eRes; j++)
- {
- g.setColor(aa.annotations[j].colour);
-
- height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
- if(height>y)
- height = y;
- g.fillRect(x, y - height, av.charWidth, height);
- x += av.charWidth;
- }
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+
+public class AnnotationPanel
+ extends Panel implements AdjustmentListener
+{
+ AlignViewport av;
+ AlignmentPanel ap;
+ int activeRow = -1;
+
+ Vector activeRes;
+ static String HELIX = "Helix";
+ static String SHEET = "Sheet";
+ static String LABEL = "Label";
+ static String REMOVE = "Remove Annotation";
+ static String COLOUR = "Colour";
+ static Color HELIX_COLOUR = Color.red.darker();
+ static Color SHEET_COLOUR = Color.green.darker().darker();
+
+ Image image;
+ Graphics gg;
+ FontMetrics fm;
+ int imgWidth = 0;
+
+ boolean fastPaint = false;
+
+ public static int GRAPH_HEIGHT = 40;
+
+ boolean MAC = false;
+
+ public AnnotationPanel(AlignmentPanel ap)
+ {
+ if (System.getProperty("os.name").startsWith("Mac"))
+ MAC = true;
+
+ this.ap = ap;
+ av = ap.av;
+ setLayout(null);
+ adjustPanelHeight();
+
+ addMouseMotionListener(new MouseMotionAdapter()
+ {
+ public void mouseMoved(MouseEvent evt)
+ {
+ doMouseMoved(evt);
+ }
+ });
+
+ // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );
+ }
+
+
+ public AnnotationPanel(AlignViewport av)
+ {
+ this.av = av;
+ }
+
+
+ public void adjustmentValueChanged(AdjustmentEvent evt)
+ {
+ ap.alabels.setScrollOffset( -evt.getValue());
+ }
+
+ public int adjustPanelHeight()
+ {
+ // setHeight of panels
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+
+
+ int height = 0;
+ if (aa != null)
+ {
+ for (int i = 0; i < aa.length; i++)
+ {
+ if (!aa[i].visible)
+ {
+ continue;
+ }
+
+ aa[i].height = 0;
+
+ if (aa[i].hasText)
+ {
+ aa[i].height += av.charHeight;
+ }
+ if (aa[i].hasIcons)
+ {
+ aa[i].height += 16;
+ }
+
+ if (aa[i].graph>0)
+ {
+ aa[i].height += GRAPH_HEIGHT;
+ }
+
+ if (aa[i].height == 0)
+ {
+ aa[i].height = 20;
+ }
+ height += aa[i].height;
+ }
+ }
+ else
+ {
+ height = 20;
+ }
+
+ this.setSize(getSize().width, height);
+
+ repaint();
+
+ return height;
+
+ }
+
+ public void addEditableColumn(int i)
+ {
+ if (activeRow == -1)
+ {
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+ if(aa ==null)
+ return;
+
+ for (int j = 0; j < aa.length; j++)
+ {
+ if (aa[j].editable)
+ {
+ activeRow = j;
+ break;
+ }
+ }
+ }
+
+ if (activeRes == null)
+ {
+ activeRes = new Vector();
+ activeRes.addElement(String.valueOf(i));
+ return;
+ }
+
+ activeRes.addElement(String.valueOf(i));
+ }
+
+ public void doMouseMoved(MouseEvent evt)
+ {
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+ if (aa == null)
+ {
+ return;
+ }
+
+ int row = -1;
+ int height = 0;
+ for (int i = 0; i < aa.length; i++)
+ {
+
+ if (aa[i].visible)
+ {
+ height += aa[i].height;
+ }
+
+ if (evt.getY() < height)
+ {
+ row = i;
+ break;
+ }
+ }
+
+ int res = evt.getX() / av.getCharWidth() + av.getStartRes();
+
+ if(av.hasHiddenColumns)
+ res = av.getColumnSelection().adjustForHiddenColumns(res);
+
+ if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)
+ {
+ StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
+ " " +
+ aa[row].annotations[res].description);
+ ap.alignFrame.statusBar.setText(text.toString());
+ }
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void paint(Graphics g)
+ {
+
+ imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
+
+ if (image == null || imgWidth != image.getWidth(this))
+ {
+ image = createImage(imgWidth, ap.annotationPanel.getSize().height);
+ gg = image.getGraphics();
+ gg.setFont(av.getFont());
+ fm = gg.getFontMetrics();
+ fastPaint = false;
+ }
+
+ if (fastPaint)
+ {
+ g.drawImage(image, 0, 0, this);
+ fastPaint = false;
+ return;
+ }
+
+ drawComponent(gg, av.startRes, av.endRes + 1);
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+ g.drawImage(image, 0, 0, this);
+ }
+
+ public void fastPaint(int horizontal)
+ {
+ if (horizontal == 0
+ || av.alignment.getAlignmentAnnotation() == null
+ || av.alignment.getAlignmentAnnotation().length < 1
+ )
+ {
+ repaint();
+ return;
+ }
+
+ gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
+ int sr = av.startRes, er = av.endRes + 1, transX = 0;
+
+ if (horizontal > 0) // scrollbar pulled right, image to the left
+ {
+ transX = (er - sr - horizontal) * av.charWidth;
+ sr = er - horizontal;
+ }
+ else if (horizontal < 0)
+ {
+ er = sr - horizontal;
+ }
+
+ gg.translate(transX, 0);
+
+ drawComponent(gg, sr, er);
+
+ gg.translate( -transX, 0);
+
+ fastPaint = true;
+ repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param g DOCUMENT ME!
+ * @param startRes DOCUMENT ME!
+ * @param endRes DOCUMENT ME!
+ */
+ public void drawComponent(Graphics g, int startRes, int endRes)
+ {
+ g.setFont(av.getFont());
+
+ if (fm == null)
+ fm = g.getFontMetrics();
+
+
+ g.setColor(Color.white);
+ g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
+
+ if ((av.alignment.getAlignmentAnnotation() == null) ||
+ (av.alignment.getAlignmentAnnotation().length < 1))
+ {
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+ g.setColor(Color.black);
+ if(av.validCharWidth)
+ g.drawString("Alignment has no annotations", 20, 15);
+
+ return;
+ }
+
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+
+ int x = 0;
+ int y = 0;
+ int column=0;
+ char lastSS;
+ int lastSSX;
+ int iconOffset = av.charHeight / 2;
+ boolean validRes = false;
+
+ boolean [] graphGroupDrawn = new boolean[aa.length];
+
+
+ //\u03B2 \u03B1
+ for (int i = 0; i < aa.length; i++)
+ {
+ AlignmentAnnotation row = aa[i];
+
+ if (!row.visible)
+ {
+ continue;
+ }
+
+ lastSS = ' ';
+ lastSSX = 0;
+
+ if (row.graph>0)
+ {
+ if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )
+ continue;
+
+ // this is so that we draw the characters below the graph
+ y += row.height;
+
+ if (row.hasText)
+ {
+ y -= av.charHeight;
+ }
+ }
+
+ if (row.hasText)
+ {
+ iconOffset = av.charHeight / 2;
+ }
+ else
+ {
+ iconOffset = 0;
+ }
+
+ x = 0;
+ while(x < endRes-startRes)
+ {
+ if (av.hasHiddenColumns)
+ {
+ column = av.getColumnSelection().adjustForHiddenColumns(startRes+x);
+ if (column > row.annotations.length-1)
+ {
+ break;
+ }
+ }
+ else
+ column = startRes+x;
+
+ if ( (row.annotations.length <= column) ||
+ (row.annotations[column] == null))
+ {
+ validRes = false;
+ }
+ else
+ {
+ validRes = true;
+ }
+
+
+ if (av.validCharWidth && validRes &&
+ (row.annotations[column].displayCharacter.length() > 0))
+ {
+ int charOffset = (av.charWidth -
+ fm.charWidth(row.annotations[column].displayCharacter.charAt(
+ 0))) / 2;
+ g.setColor(row.annotations[column].colour);
+
+ if (column == 0 || row.graph>0)
+ {
+ g.drawString(row.annotations[column].displayCharacter,
+ (x*av.charWidth)+charOffset,
+ y + iconOffset + 3);
+ }
+ else if (
+ row.annotations[column - 1] == null
+ ||(!row.annotations[column].displayCharacter.equals(
+ row.annotations[column - 1].displayCharacter)
+ ||
+ (row.annotations[column].displayCharacter.length() <2 &&
+ row.annotations[column].secondaryStructure==' ')))
+ {
+ g.drawString(row.annotations[column].displayCharacter,
+ (x*av.charWidth)+charOffset,
+ y + iconOffset + 3);
+ }
+ }
+
+ if (row.hasIcons)
+ {
+ if (!validRes ||
+ (row.annotations[column].secondaryStructure != lastSS))
+ {
+ switch (lastSS)
+ {
+ case 'H':
+ g.setColor(HELIX_COLOUR);
+ if (MAC)
+ {
+ //Off by 1 offset when drawing rects and ovals
+ //to offscreen image on the MAC
+ g.fillRoundRect(lastSSX, y + 4 + iconOffset,
+ (x*av.charWidth) - lastSSX, 7, 8, 8);
+ break;
+ }
+
+ int sCol = (lastSSX / av.charWidth) + startRes;
+ int x1 = lastSSX;
+ int x2 = (x*av.charWidth);
+
+ if(sCol==0 ||
+ row.annotations[sCol-1]==null ||
+ row.annotations[sCol-1].secondaryStructure!='H')
+ {
+ g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ;
+ x1 += av.charWidth/2;
+ }
+
+ if(row.annotations[column]==null ||
+ row.annotations[column].secondaryStructure!='H')
+ {
+ g.fillArc((x*av.charWidth)-av.charWidth,
+ y+4+iconOffset, av.charWidth, 8, 270,180);
+ x2 -= av.charWidth/2;
+ }
+
+ g.fillRect(x1, y+4+iconOffset, x2-x1, 8);
+ break;
+
+ case 'E':
+ g.setColor(SHEET_COLOUR);
+ g.fillRect(lastSSX, y + 4 + iconOffset,
+ (x*av.charWidth) - lastSSX - 4, 7);
+ g.fillPolygon(new int[] { (x*av.charWidth) - 4,
+ (x*av.charWidth) - 4,
+ (x*av.charWidth) },
+ new int[]
+ {
+ y + iconOffset, y + 14 + iconOffset,
+ y + 8 + iconOffset
+ }, 3);
+
+ break;
+
+
+ default:
+ g.setColor(Color.gray);
+ g.fillRect(lastSSX, y + 6 + iconOffset,
+ (x*av.charWidth) - lastSSX, 2);
+
+ break;
+ }
+
+ if (validRes)
+ {
+ lastSS = row.annotations[column].secondaryStructure;
+ }
+ else
+ {
+ lastSS = ' ';
+ }
+
+ lastSSX = (x*av.charWidth);
+ }
+ }
+
+
+ column++;
+ x++;
+ }
+
+ if(column>=row.annotations.length)
+ column = row.annotations.length-1;
+
+ // x ++;
+
+ if (row.hasIcons)
+ {
+ switch (lastSS)
+ {
+ case 'H':
+ g.setColor(HELIX_COLOUR);
+ if (MAC)
+ {
+ //Off by 1 offset when drawing rects and ovals
+ //to offscreen image on the MAC
+ g.fillRoundRect(lastSSX, y + 4 + iconOffset,
+ (x*av.charWidth) - lastSSX, 7, 8, 8);
+ break;
+ }
+
+ int sCol = (lastSSX / av.charWidth) + startRes;
+ int x1 = lastSSX;
+ int x2 = (x*av.charWidth);
+
+ if (sCol == 0 ||
+ row.annotations[sCol - 1] == null ||
+ row.annotations[sCol - 1].secondaryStructure != 'H')
+ {
+ g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
+ x1 += av.charWidth / 2;
+ }
+
+ if (row.annotations[column] == null ||
+ row.annotations[column].secondaryStructure != 'H')
+ {
+ g.fillArc((x*av.charWidth) - av.charWidth,
+ y + 4 + iconOffset, av.charWidth, 8, 270,
+ 180);
+ x2 -= av.charWidth / 2;
+ }
+
+ g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
+
+ break;
+
+ case 'E':
+ g.setColor(SHEET_COLOUR);
+
+ if (row.annotations[endRes] == null
+ || row.annotations[endRes].secondaryStructure != 'E')
+ {
+ g.fillRect(lastSSX, y + 4 + iconOffset,
+ (x*av.charWidth) - lastSSX - 4, 7);
+ g.fillPolygon(new int[]
+ {(x*av.charWidth) - 4,
+ (x*av.charWidth) - 4,
+ (x*av.charWidth)},
+ new int[]
+ {
+ y + iconOffset, y + 14 + iconOffset,
+ y + 7 + iconOffset
+ }, 3);
+ }
+ else
+ {
+ g.fillRect(lastSSX, y + 4 + iconOffset,
+ (x+1) * av.charWidth - lastSSX, 7);
+ }
+ break;
+
+ default:
+ g.setColor(Color.gray);
+ if(!av.wrapAlignment || endRes==av.endRes)
+ g.fillRect(lastSSX, y + 6 + iconOffset,
+ (x*av.charWidth) - lastSSX, 2);
+
+ break;
+ }
+ }
+
+ if (row.graph>0)
+ {
+ if(row.graph == AlignmentAnnotation.LINE_GRAPH )
+ {
+ if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])
+ {
+ float groupmax=-999999, groupmin=9999999;
+ for(int gg=0; gggroupmax)
+ groupmax = aa[gg].graphMax;
+ if(aa[gg].graphMin0 && row.hasText)
+ {
+ y += av.charHeight;
+ }
+
+ if (row.graph==0)
+ {
+ y += aa[i].height;
+ }
+ }
+ }
+
+ public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
+ int sRes, int eRes,
+ int y,
+ float min, float max,
+ int graphHeight)
+ {
+ if(sRes>aa.annotations.length)
+ return;
+
+
+
+ int x = 0;
+
+ //Adjustment for fastpaint to left
+ if(eRes aaMax)
+ {
+ break;
+ }
+
+ if(aa.annotations[column]==null || aa.annotations[column-1]==null)
+ {
+ x++;
+ continue;
+ }
+
+ g.setColor(aa.annotations[column].colour);
+ y1 = y - (int) (((aa.annotations[column-1].value-min) / range) * graphHeight);
+ y2 = y - (int) (((aa.annotations[column].value-min) / range) * graphHeight);
+
+ g.drawLine(x*av.charWidth-av.charWidth/2, y1, x*av.charWidth+av.charWidth/2, y2);
+ x ++;
+ }
+
+ if(aa.threshold!=null)
+ {
+ g.setColor(aa.threshold.colour);
+
+ y2 = (int)(y - ((aa.threshold.value-min) / range)*graphHeight);
+ g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
+ }
+ }
+
+ public void drawBarGraph(Graphics g, AlignmentAnnotation aa,
+ int sRes, int eRes,
+ float min, float max,
+ int y)
+ {
+ if(sRes>aa.annotations.length)
+ return;
+
+ eRes = Math.min(eRes, aa.annotations.length);
+
+ int x=0, y1=y, y2=y;
+
+ float range = max - min;
+
+ if(min<0)
+ y2 = y - (int)((0-min / (range))*aa.graphHeight);
+
+ g.setColor(Color.gray);
+
+ g.drawLine(x,y2,(eRes-sRes)*av.charWidth,y2);
+
+ int column;
+ int aaMax = aa.annotations.length-1;
+
+ while( x < eRes-sRes )
+ {
+ column = sRes + x;
+ if(av.hasHiddenColumns)
+ {
+ column = av.getColumnSelection().adjustForHiddenColumns(column);
+ }
+
+ if(column > aaMax)
+ {
+ break;
+ }
+
+ if (aa.annotations[column] == null)
+ {
+ x ++;
+ continue;
+ }
+
+ g.setColor(aa.annotations[column].colour);
+ y1 = y - (int) (((aa.annotations[column].value-min) / (range)) * aa.graphHeight);
+
+ if(y1-y2>0)
+ g.fillRect(x*av.charWidth, y2, av.charWidth, y1-y2 );
+ else
+ g.fillRect(x*av.charWidth, y1, av.charWidth, y2-y1 );
+
+ x ++ ;
+
+ }
+ if(aa.threshold!=null)
+ {
+ g.setColor(aa.threshold.colour);
+ y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);
+ g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
+ }
+ }
+
+ // used by overview window
+ public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
+ {
+ g.setColor(Color.white);
+ g.fillRect(0, 0, width, y);
+ g.setColor(new Color(0, 0, 180));
+
+ int x = 0, height;
+
+ for (int j = sRes; j < eRes; j++)
+ {
+ g.setColor(aa.annotations[j].colour);
+
+ height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
+ if(height>y)
+ height = y;
+ g.fillRect(x, y - height, av.charWidth, height);
+ x += av.charWidth;
+ }
+ }
+}
diff --git a/src/jalview/appletgui/ColumnSelection.java b/src/jalview/appletgui/ColumnSelection.java
deleted file mode 100755
index 33c4604..0000000
--- a/src/jalview/appletgui/ColumnSelection.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-/**
- * NOTE: Columns are zero based.
- */
-public class ColumnSelection
-{
- Vector selected = new Vector();
-
- public void addElement(int col)
- {
- if(!selected.contains(new Integer(col)))
- selected.addElement(new Integer(col));
- }
-
- public void clear()
- {
- selected.removeAllElements();
- }
-
- public void removeElement(int col)
- {
- Integer colInt = new Integer(col);
- if (selected.contains(colInt))
- {
- selected.removeElement(colInt);
- }
- }
-
- public void removeElements(int start, int end)
- {
- Integer colInt;
- for(int i=start; i max)
- {
- max = columnAt(i);
- }
- }
- return max;
- }
-
- public int getMin()
- {
- int min = 1000000000;
-
- for (int i = 0; i < selected.size(); i++)
- {
- if (columnAt(i) < min)
- {
- min = columnAt(i);
- }
- }
- return min;
- }
-
- public Vector asVector()
- {
- return selected;
- }
-
- public void compensateForEdit(int start, int change)
- {
- for (int i = 0; i < size(); i++)
- {
- int temp = columnAt(i);
-
- if (temp >= start)
- {
- selected.setElementAt(new Integer(temp - change), i);
- }
- }
- }
-}
diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java
index 4b890bb..1b73d92 100755
--- a/src/jalview/appletgui/CutAndPasteTransfer.java
+++ b/src/jalview/appletgui/CutAndPasteTransfer.java
@@ -1,184 +1,184 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-import jalview.io.*;
-
-public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener
-{
- boolean pdbImport = false;
- boolean treeImport = false;
- Sequence seq;
- AlignFrame alignFrame;
-
- public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
- {
- try {
- jbInit();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- this.alignFrame = alignFrame;
-
- if (!forImport)
- {
- buttonPanel.setVisible(false);
- }
- }
-
- public String getText()
- {
- return textarea.getText();
- }
-
- public void setText(String text)
- {
- textarea.setText(text);
- }
-
- public void setPDBImport(Sequence seq)
- {
- this.seq = seq;
- pdbImport = true;
- }
-
-
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource()==ok)
- ok_actionPerformed();
- else if(evt.getSource()==cancel)
- cancel_actionPerformed();
- }
-
- protected void ok_actionPerformed()
- {
- String text = getText();
- int length = text.length();
- textarea.append("\n");
- if(textarea.getText().length()==length)
- {
- String warning = "\n\n#################################################\n"
- +"WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
- +"\nCAN'T INPUT FULL ALIGNMENT"
- +"\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
- +"\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
- +"\n#################################################\n";
- textarea.setText(text.substring(0, text.length()-warning.length())
- +warning);
-
- textarea.setCaretPosition(text.length());
- }
-
- if(pdbImport)
- {
- new MCview.AppletPDBViewer(text, AppletFormatAdapter.PASTE,
- seq,
- alignFrame.getSeqcanvas());
- }
- else if(treeImport)
- {
- try{
- jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(),
- "Paste");
-
- fin.parse();
- if(fin.getTree()!=null)
- alignFrame.loadTree(fin, "Pasted tree file");
-
- }
- catch (Exception ex)
- {
- textarea.setText("Could not parse Newick file!\n" + ex);
- return;
- }
- }
- else if(alignFrame!=null)
- {
- SequenceI[] sequences = null;
-
- String format = new IdentifyFile().Identify(text, AppletFormatAdapter.PASTE);
- try{
- sequences = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format);
- }catch(java.io.IOException ex)
- {
- ex.printStackTrace();
- }
- if (sequences != null)
- {
- AlignFrame af = new AlignFrame(new Alignment(sequences), alignFrame.applet,
- "Cut & Paste input - " + format,
- false);
- af.statusBar.setText("Successfully pasted alignment file");
- }
- }
-
- if(this.getParent() instanceof Frame)
- ((Frame)this.getParent()).setVisible(false);
- else
- ((Dialog)this.getParent()).setVisible(false);
- }
-
- protected void cancel_actionPerformed()
- {
- textarea.setText("");
- if(this.getParent() instanceof Frame)
- ((Frame)this.getParent()).setVisible(false);
- else
- ((Dialog)this.getParent()).setVisible(false);
- }
-
- protected TextArea textarea = new TextArea();
- Button ok = new Button();
- Button cancel = new Button();
- protected Panel buttonPanel = new Panel();
- BorderLayout borderLayout1 = new BorderLayout();
-
-
- private void jbInit() throws Exception {
- textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
- textarea.setText("Paste your alignment file here");
- textarea.addMouseListener(this);
- this.setLayout(borderLayout1);
- ok.setLabel("OK");
- ok.addActionListener(this);
- cancel.setLabel("Cancel");
- cancel.addActionListener(this);
- this.add(buttonPanel, BorderLayout.SOUTH);
- buttonPanel.add(ok, null);
- buttonPanel.add(cancel, null);
- this.add(textarea, java.awt.BorderLayout.CENTER);
- }
-
- public void mousePressed(MouseEvent evt) {
- if (textarea.getText().startsWith("Paste your")) {
- textarea.setText("");
- }
- }
- public void mouseReleased(MouseEvent evt){}
- public void mouseClicked(MouseEvent evt){}
- public void mouseEntered(MouseEvent evt){}
- public void mouseExited(MouseEvent evt){}
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+import jalview.io.*;
+
+public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener
+{
+ boolean pdbImport = false;
+ boolean treeImport = false;
+ Sequence seq;
+ AlignFrame alignFrame;
+
+ public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
+ {
+ try {
+ jbInit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ this.alignFrame = alignFrame;
+
+ if (!forImport)
+ {
+ buttonPanel.setVisible(false);
+ }
+ }
+
+ public String getText()
+ {
+ return textarea.getText();
+ }
+
+ public void setText(String text)
+ {
+ textarea.setText(text);
+ }
+
+ public void setPDBImport(Sequence seq)
+ {
+ this.seq = seq;
+ pdbImport = true;
+ }
+
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource()==ok)
+ ok_actionPerformed();
+ else if(evt.getSource()==cancel)
+ cancel_actionPerformed();
+ }
+
+ protected void ok_actionPerformed()
+ {
+ String text = getText();
+ int length = text.length();
+ textarea.append("\n");
+ if(textarea.getText().length()==length)
+ {
+ String warning = "\n\n#################################################\n"
+ +"WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
+ +"\nCAN'T INPUT FULL ALIGNMENT"
+ +"\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
+ +"\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
+ +"\n#################################################\n";
+ textarea.setText(text.substring(0, text.length()-warning.length())
+ +warning);
+
+ textarea.setCaretPosition(text.length());
+ }
+
+ if(pdbImport)
+ {
+ new MCview.AppletPDBViewer(text, AppletFormatAdapter.PASTE,
+ seq,
+ alignFrame.getSeqcanvas());
+ }
+ else if(treeImport)
+ {
+ try{
+ jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(),
+ "Paste");
+
+ fin.parse();
+ if(fin.getTree()!=null)
+ alignFrame.loadTree(fin, "Pasted tree file");
+
+ }
+ catch (Exception ex)
+ {
+ textarea.setText("Could not parse Newick file!\n" + ex);
+ return;
+ }
+ }
+ else if(alignFrame!=null)
+ {
+ SequenceI[] sequences = null;
+
+ String format = new IdentifyFile().Identify(text, AppletFormatAdapter.PASTE);
+ try{
+ sequences = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format);
+ }catch(java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ if (sequences != null)
+ {
+ AlignFrame af = new AlignFrame(new Alignment(sequences), alignFrame.viewport.applet,
+ "Cut & Paste input - " + format,
+ false);
+ af.statusBar.setText("Successfully pasted alignment file");
+ }
+ }
+
+ if(this.getParent() instanceof Frame)
+ ((Frame)this.getParent()).setVisible(false);
+ else
+ ((Dialog)this.getParent()).setVisible(false);
+ }
+
+ protected void cancel_actionPerformed()
+ {
+ textarea.setText("");
+ if(this.getParent() instanceof Frame)
+ ((Frame)this.getParent()).setVisible(false);
+ else
+ ((Dialog)this.getParent()).setVisible(false);
+ }
+
+ protected TextArea textarea = new TextArea();
+ Button ok = new Button();
+ Button cancel = new Button();
+ protected Panel buttonPanel = new Panel();
+ BorderLayout borderLayout1 = new BorderLayout();
+
+
+ private void jbInit() throws Exception {
+ textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
+ textarea.setText("Paste your alignment file here");
+ textarea.addMouseListener(this);
+ this.setLayout(borderLayout1);
+ ok.setLabel("OK");
+ ok.addActionListener(this);
+ cancel.setLabel("Cancel");
+ cancel.addActionListener(this);
+ this.add(buttonPanel, BorderLayout.SOUTH);
+ buttonPanel.add(ok, null);
+ buttonPanel.add(cancel, null);
+ this.add(textarea, java.awt.BorderLayout.CENTER);
+ }
+
+ public void mousePressed(MouseEvent evt) {
+ if (textarea.getText().startsWith("Paste your")) {
+ textarea.setText("");
+ }
+ }
+ public void mouseReleased(MouseEvent evt){}
+ public void mouseClicked(MouseEvent evt){}
+ public void mouseEntered(MouseEvent evt){}
+ public void mouseExited(MouseEvent evt){}
+}
diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java
index 83a8340..727694d 100755
--- a/src/jalview/appletgui/FeatureRenderer.java
+++ b/src/jalview/appletgui/FeatureRenderer.java
@@ -1,420 +1,424 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.appletgui;
-
-import jalview.datamodel.*;
-
-import java.awt.*;
-
-import java.util.*;
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class FeatureRenderer
-{
- AlignViewport av;
-
-
- // A higher level for grouping features of a
- // particular type
- Hashtable featureGroups = null;
-
- // This is actually an Integer held in the hashtable,
- // Retrieved using the key feature type
- Object currentColour;
-
- String [] renderOrder;
-
- FontMetrics fm;
- int charOffset;
-
- /**
- * Creates a new FeatureRenderer object.
- *
- * @param av DOCUMENT ME!
- */
- public FeatureRenderer(AlignViewport av)
- {
- this.av = av;
- initColours();
- }
-
-
- public void transferSettings(FeatureRenderer fr)
- {
- renderOrder = fr.renderOrder;
- featureGroups = fr.featureGroups;
- featureColours = fr.featureColours;
- }
-
-
- public Color findFeatureColour(Color initialCol, SequenceI seq, int i)
- {
- overview = true;
- if(!av.showSequenceFeatures)
- return initialCol;
-
- lastSequence = seq;
- sequenceFeatures = lastSequence.getSequenceFeatures();
- if(sequenceFeatures==null)
- return initialCol;
-
- sfSize = sequenceFeatures.length;
-
- if(jalview.util.Comparison.isGap(lastSequence.getCharAt(i)))
- return Color.white;
-
- currentColour = null;
-
- drawSequence(null, lastSequence, lastSequence.findPosition(i), -1,-1, -1, -1);
-
- if(currentColour==null)
- return initialCol;
-
- return new Color( ((Integer)currentColour).intValue() );
- }
-
- /**
- * This is used by the Molecule Viewer to get the accurate colour
- * of the rendered sequence
- */
- boolean overview = false;
-
- int white = Color.white.getRGB();
- public int findFeatureColour(int initialCol, int seqIndex, int column)
- {
- if(!av.showSequenceFeatures)
- return initialCol;
-
- if(seqIndex!=lastSequenceIndex)
- {
- lastSequence = av.alignment.getSequenceAt(seqIndex);
- lastSequenceIndex = seqIndex;
- sequenceFeatures = lastSequence.getSequenceFeatures();
- if(sequenceFeatures==null)
- return initialCol;
-
- sfSize = sequenceFeatures.length;
- }
-
-
- if(jalview.util.Comparison.isGap(lastSequence.getCharAt(column)))
- return Color.white.getRGB();
-
- currentColour = null;
-
- drawSequence(null, lastSequence, lastSequence.findPosition(column), -1,-1, -1, -1);
-
- if(currentColour==null)
- return initialCol;
-
- return ((Integer)currentColour).intValue();
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param g DOCUMENT ME!
- * @param seq DOCUMENT ME!
- * @param sg DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- * @param x1 DOCUMENT ME!
- * @param y1 DOCUMENT ME!
- * @param width DOCUMENT ME!
- * @param height DOCUMENT ME!
- */
- // String type;
- // SequenceFeature sf;
- int lastSequenceIndex=-1;
- SequenceI lastSequence;
- SequenceFeature [] sequenceFeatures;
- int sfSize, sfindex, spos, epos;
-
- public void drawSequence(Graphics g, SequenceI seq,
- int start, int end, int y1, int width, int height)
- {
- if ( seq.getSequenceFeatures() == null
- || seq.getSequenceFeatures().length==0)
- return;
-
-
- if (av.featuresDisplayed == null || renderOrder==null)
- {
- findAllFeatures();
- if(av.featuresDisplayed.size()<1)
- return;
-
- sequenceFeatures = seq.getSequenceFeatures();
- sfSize = sequenceFeatures.length;
- }
- if(lastSequence==null || seq!=lastSequence)
- {
- lastSequence = seq;
- sequenceFeatures = seq.getSequenceFeatures();
- sfSize = sequenceFeatures.length;
- }
- if(!overview)
- {
- spos = lastSequence.findPosition(start);
- epos = lastSequence.findPosition(end);
- if(g!=null)
- fm = g.getFontMetrics();
- }
- String type;
- for(int renderIndex=0; renderIndex epos
- || sequenceFeatures[sfindex].getEnd() < spos))
- continue;
-
- if (overview)
- {
- if (sequenceFeatures[sfindex].begin <= start &&
- sequenceFeatures[sfindex].end >= start)
- {
- currentColour = av.featuresDisplayed.get(sequenceFeatures[sfindex].
- type);
- }
-
- }
- else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
- {
-
- renderFeature(g, seq,
- seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
- seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
- new Color( ( (Integer) av.featuresDisplayed.get(
- sequenceFeatures[sfindex].type)).intValue()),
- start, end, y1, width, height);
- renderFeature(g, seq,
- seq.findIndex(sequenceFeatures[sfindex].end) - 1,
- seq.findIndex(sequenceFeatures[sfindex].end) - 1,
- new Color( ( (Integer) av.featuresDisplayed.get(
- sequenceFeatures[sfindex].type)).intValue()),
- start, end, y1, width, height);
-
- }
- else
- renderFeature(g, seq,
- seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
- seq.findIndex(sequenceFeatures[sfindex].end) - 1,
- getColour(sequenceFeatures[sfindex].type),
- start, end, y1, width, height);
-
- }
- }
- }
-
-
- char s;
- int i;
- void renderFeature(Graphics g, SequenceI seq,
- int fstart, int fend, Color featureColour, int start, int end, int y1, int width, int height)
- {
-
- if (((fstart <= end) && (fend >= start)))
- {
- if (fstart < start)
- { // fix for if the feature we have starts before the sequence start,
- fstart = start; // but the feature end is still valid!!
- }
-
- if (fend >= end)
- {
- fend = end;
- }
-
- for (i = fstart; i <= fend; i++)
- {
- s = seq.getSequence().charAt(i);
-
- if (jalview.util.Comparison.isGap(s))
- {
- continue;
- }
-
- g.setColor(featureColour);
-
- g.fillRect( (i - start) * width, y1, width, height);
-
- g.setColor(Color.white);
- charOffset = (width - fm.charWidth(s)) / 2;
- g.drawString(String.valueOf(s),
- charOffset + (width * (i - start)),
- (y1 + height) - height / 5); //pady = height / 5;
-
- }
- }
- }
-
- void findAllFeatures()
- {
- av.featuresDisplayed = new Hashtable();
- Vector allfeatures = new Vector();
- for (int i = 0; i < av.alignment.getHeight(); i++)
- {
- SequenceFeature [] features = av.alignment.getSequenceAt(i).getSequenceFeatures();
-
- if (features == null)
- continue;
-
- int index = 0;
- while (index < features.length)
- {
- if (!av.featuresDisplayed.containsKey(features[index].getType()))
- {
- av.featuresDisplayed.put(features[index].getType(),
- new Integer( getColour(features[index].getType()).getRGB()) );
- allfeatures.addElement(features[index].getType());
- }
- index++;
- }
- }
-
- renderOrder = new String[allfeatures.size()];
- Enumeration en = allfeatures.elements();
- int i = allfeatures.size()-1;
- while(en.hasMoreElements())
- {
- renderOrder[i] = en.nextElement().toString();
- i--;
- }
- }
-
- public Color getColour(String featureType)
- {
- return (Color)featureColours.get(featureType);
- }
-
- public void addNewFeature(String name, Color col)
- {
-
- setColour(name, col);
- if(av.featuresDisplayed==null)
- av.featuresDisplayed = new Hashtable();
-
-
- av.featuresDisplayed.put(name, "NOGROUP");
- }
-
- public void setColour(String featureType, Color col)
- {
- featureColours.put(featureType, col);
- }
-
- public void setFeaturePriority(Object [][] data)
- {
- // The feature table will display high priority
- // features at the top, but theses are the ones
- // we need to render last, so invert the data
- if(av.featuresDisplayed!=null)
- av.featuresDisplayed.clear();
-
- renderOrder = new String[data.length];
-
- if (data.length > 0)
- for (int i = 0; i < data.length; i++)
- {
- String type = data[i][0].toString();
- setColour(type, (Color) data[i][1]);
- if ( ( (Boolean) data[i][2]).booleanValue())
- {
- av.featuresDisplayed.put(type, new Integer(getColour(type).getRGB()));
- }
-
- renderOrder[data.length - i - 1] = type;
- }
- }
-
- Hashtable featureColours = new Hashtable();
- void initColours()
- {
- featureColours.put("active site", new Color(255, 75, 0));
- featureColours.put("binding site", new Color(245, 85, 0));
- featureColours.put("calcium-binding region", new Color(235, 95, 0));
- featureColours.put("chain", new Color(225, 105, 0));
- featureColours.put("coiled-coil region", new Color(215, 115, 0));
- featureColours.put("compositionally biased region", new Color(205, 125, 0));
- featureColours.put("cross-link", new Color(195, 135, 0));
- featureColours.put("disulfide bond", new Color(185, 145, 0));
- featureColours.put("DNA-binding region", new Color(175, 155, 0));
- featureColours.put("domain", new Color(165, 165, 0));
- featureColours.put("glycosylation site", new Color(155, 175, 0));
- featureColours.put("helix", new Color(145, 185, 0));
- featureColours.put("initiator methionine", new Color(135, 195, 5));
- featureColours.put("lipid moiety-binding region", new Color(125, 205, 15));
- featureColours.put("metal ion-binding site", new Color(115, 215, 25));
- featureColours.put("modified residue", new Color(105, 225, 35));
- featureColours.put("mutagenesis site", new Color(95, 235, 45));
- featureColours.put("non-consecutive residues", new Color(85, 245, 55));
- featureColours.put("non-terminal residue", new Color(75, 255, 65));
- featureColours.put("nucleotide phosphate-binding region",
- new Color(65, 245, 75));
- featureColours.put("peptide", new Color(55, 235, 85));
- featureColours.put("propeptide", new Color(45, 225, 95));
- featureColours.put("region of interest", new Color(35, 215, 105));
- featureColours.put("repeat", new Color(25, 205, 115));
- featureColours.put("selenocysteine", new Color(15, 195, 125));
- featureColours.put("sequence conflict", new Color(5, 185, 135));
- featureColours.put("sequence variant", new Color(0, 175, 145));
- featureColours.put("short sequence motif", new Color(0, 165, 155));
- featureColours.put("signal peptide", new Color(0, 155, 165));
- featureColours.put("site", new Color(0, 145, 175));
- featureColours.put("splice variant", new Color(0, 135, 185));
- featureColours.put("strand", new Color(0, 125, 195));
- featureColours.put("topological domain", new Color(0, 115, 205));
- featureColours.put("transit peptide", new Color(0, 105, 215));
- featureColours.put("transmembrane region", new Color(0, 95, 225));
- featureColours.put("turn", new Color(0, 85, 235));
- featureColours.put("unsure residue", new Color(0, 75, 245));
- featureColours.put("zinc finger region", new Color(0, 65, 255));
- }
-
-}
-
-
-
+
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.appletgui;
+
+import jalview.datamodel.*;
+
+import java.awt.*;
+
+import java.util.*;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class FeatureRenderer
+{
+ AlignViewport av;
+
+ Hashtable featureColours = new Hashtable();
+
+ // A higher level for grouping features of a
+ // particular type
+ Hashtable featureGroups = null;
+
+ // Holds web links for feature groups and feature types
+ // in the form label|link
+ Hashtable featureLinks = null;
+
+
+ // This is actually an Integer held in the hashtable,
+ // Retrieved using the key feature type
+ Object currentColour;
+
+ String [] renderOrder;
+
+ FontMetrics fm;
+ int charOffset;
+
+ float transparency = 1f;
+
+ TransparencySetter transparencySetter = null;
+
+ /**
+ * Creates a new FeatureRenderer object.
+ *
+ * @param av DOCUMENT ME!
+ */
+ public FeatureRenderer(AlignViewport av)
+ {
+ this.av = av;
+
+ if(!System.getProperty("java.version").startsWith("1.1"))
+ transparencySetter = new TransparencySetter();
+ }
+
+
+ public void transferSettings(FeatureRenderer fr)
+ {
+ renderOrder = fr.renderOrder;
+ featureGroups = fr.featureGroups;
+ featureColours = fr.featureColours;
+ transparency = fr.transparency;
+ }
+
+
+ public Color findFeatureColour(Color initialCol, SequenceI seq, int i)
+ {
+ overview = true;
+ if(!av.showSequenceFeatures)
+ return initialCol;
+
+ lastSequence = seq;
+ sequenceFeatures = lastSequence.getSequenceFeatures();
+ if(sequenceFeatures==null)
+ return initialCol;
+
+ sfSize = sequenceFeatures.length;
+
+ if(jalview.util.Comparison.isGap(lastSequence.getCharAt(i)))
+ return Color.white;
+
+ currentColour = null;
+
+ drawSequence(null, lastSequence, lastSequence.findPosition(i), -1,-1);
+
+ if(currentColour==null)
+ return initialCol;
+
+ return new Color( ((Integer)currentColour).intValue() );
+ }
+
+ /**
+ * This is used by the Molecule Viewer to get the accurate colour
+ * of the rendered sequence
+ */
+ boolean overview = false;
+
+ int white = Color.white.getRGB();
+ public int findFeatureColour(int initialCol, int seqIndex, int column)
+ {
+ if(!av.showSequenceFeatures)
+ return initialCol;
+
+ if(seqIndex!=lastSequenceIndex)
+ {
+ lastSequence = av.alignment.getSequenceAt(seqIndex);
+ lastSequenceIndex = seqIndex;
+ sequenceFeatures = lastSequence.getSequenceFeatures();
+ if(sequenceFeatures==null)
+ return initialCol;
+
+ sfSize = sequenceFeatures.length;
+ }
+
+
+ if(jalview.util.Comparison.isGap(lastSequence.getCharAt(column)))
+ return Color.white.getRGB();
+
+ currentColour = null;
+
+ drawSequence(null, lastSequence, lastSequence.findPosition(column), -1,-1);
+
+ if(currentColour==null)
+ return initialCol;
+
+ return ((Integer)currentColour).intValue();
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param g DOCUMENT ME!
+ * @param seq DOCUMENT ME!
+ * @param sg DOCUMENT ME!
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ * @param x1 DOCUMENT ME!
+ * @param y1 DOCUMENT ME!
+ * @param width DOCUMENT ME!
+ * @param height DOCUMENT ME!
+ */
+ // String type;
+ // SequenceFeature sf;
+ int lastSequenceIndex=-1;
+ SequenceI lastSequence;
+ SequenceFeature [] sequenceFeatures;
+ int sfSize, sfindex, spos, epos;
+
+ public void drawSequence(Graphics g, SequenceI seq,
+ int start, int end, int y1)
+ {
+ if ( seq.getSequenceFeatures() == null
+ || seq.getSequenceFeatures().length==0)
+ return;
+
+ if(transparencySetter!=null && g!=null)
+ {
+ transparencySetter.setTransparency(g, transparency);
+ }
+
+ if (av.featuresDisplayed == null || renderOrder==null)
+ {
+ findAllFeatures();
+ if(av.featuresDisplayed.size()<1)
+ return;
+
+ sequenceFeatures = seq.getSequenceFeatures();
+ sfSize = sequenceFeatures.length;
+ }
+ if(lastSequence==null || seq!=lastSequence)
+ {
+ lastSequence = seq;
+ sequenceFeatures = seq.getSequenceFeatures();
+ sfSize = sequenceFeatures.length;
+ }
+ if(!overview)
+ {
+ spos = lastSequence.findPosition(start);
+ epos = lastSequence.findPosition(end);
+ if(g!=null)
+ fm = g.getFontMetrics();
+ }
+ String type;
+ for(int renderIndex=0; renderIndex epos
+ || sequenceFeatures[sfindex].getEnd() < spos))
+ continue;
+
+ if (overview)
+ {
+ if (sequenceFeatures[sfindex].begin <= start &&
+ sequenceFeatures[sfindex].end >= start)
+ {
+ currentColour = av.featuresDisplayed.get(sequenceFeatures[sfindex].
+ type);
+ }
+
+ }
+ else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
+ {
+
+ renderFeature(g, seq,
+ seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
+ seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
+ new Color( ( (Integer) av.featuresDisplayed.get(
+ sequenceFeatures[sfindex].type)).intValue()),
+ start, end, y1);
+ renderFeature(g, seq,
+ seq.findIndex(sequenceFeatures[sfindex].end) - 1,
+ seq.findIndex(sequenceFeatures[sfindex].end) - 1,
+ new Color( ( (Integer) av.featuresDisplayed.get(
+ sequenceFeatures[sfindex].type)).intValue()),
+ start, end, y1);
+
+ }
+ else
+ renderFeature(g, seq,
+ seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
+ seq.findIndex(sequenceFeatures[sfindex].end) - 1,
+ getColour(sequenceFeatures[sfindex].type),
+ start, end, y1);
+
+ }
+ }
+
+ if(transparencySetter!=null && g!=null)
+ {
+ transparencySetter.setTransparency(g, 1.0f);
+ }
+ }
+
+
+ char s;
+ int i;
+ void renderFeature(Graphics g, SequenceI seq,
+ int fstart, int fend, Color featureColour, int start, int end, int y1)
+ {
+
+ if (((fstart <= end) && (fend >= start)))
+ {
+ if (fstart < start)
+ { // fix for if the feature we have starts before the sequence start,
+ fstart = start; // but the feature end is still valid!!
+ }
+
+ if (fend >= end)
+ {
+ fend = end;
+ }
+
+ for (i = fstart; i <= fend; i++)
+ {
+ s = seq.getSequence().charAt(i);
+
+ if (jalview.util.Comparison.isGap(s))
+ {
+ continue;
+ }
+
+ g.setColor(featureColour);
+
+ g.fillRect( (i - start) * av.charWidth, y1, av.charWidth, av.charHeight);
+
+ if(!av.validCharWidth)
+ continue;
+
+ g.setColor(Color.white);
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;
+ g.drawString(String.valueOf(s),
+ charOffset + (av.charWidth * (i - start)),
+ (y1 + av.charHeight) - av.charHeight / 5); //pady = height / 5;
+
+ }
+ }
+ }
+
+ void findAllFeatures()
+ {
+ jalview.schemes.UserColourScheme ucs = new
+ jalview.schemes.UserColourScheme();
+
+ av.featuresDisplayed = new Hashtable();
+ Vector allfeatures = new Vector();
+ for (int i = 0; i < av.alignment.getHeight(); i++)
+ {
+ SequenceFeature [] features = av.alignment.getSequenceAt(i).getSequenceFeatures();
+
+ if (features == null)
+ continue;
+
+ int index = 0;
+ while (index < features.length)
+ {
+ if (!av.featuresDisplayed.containsKey(features[index].getType()))
+ {
+ if (getColour(features[index].getType()) == null)
+ {
+ featureColours.put(features[index].getType(),
+ ucs.createColourFromName(features[index].
+ getType()));
+ }
+
+
+ av.featuresDisplayed.put(features[index].getType(),
+ new Integer( getColour(features[index].getType()).getRGB()) );
+ allfeatures.addElement(features[index].getType());
+ }
+ index++;
+ }
+ }
+
+ renderOrder = new String[allfeatures.size()];
+ Enumeration en = allfeatures.elements();
+ int i = allfeatures.size()-1;
+ while(en.hasMoreElements())
+ {
+ renderOrder[i] = en.nextElement().toString();
+ i--;
+ }
+ }
+
+ public Color getColour(String featureType)
+ {
+ return (Color)featureColours.get(featureType);
+ }
+
+ public void addNewFeature(String name, Color col)
+ {
+
+ setColour(name, col);
+ if(av.featuresDisplayed==null)
+ av.featuresDisplayed = new Hashtable();
+
+
+ av.featuresDisplayed.put(name, "NOGROUP");
+ }
+
+ public void setColour(String featureType, Color col)
+ {
+ featureColours.put(featureType, col);
+ }
+
+ public void setFeaturePriority(Object [][] data)
+ {
+ // The feature table will display high priority
+ // features at the top, but theses are the ones
+ // we need to render last, so invert the data
+ if(av.featuresDisplayed!=null)
+ av.featuresDisplayed.clear();
+
+ renderOrder = new String[data.length];
+
+ if (data.length > 0)
+ for (int i = 0; i < data.length; i++)
+ {
+ String type = data[i][0].toString();
+ setColour(type, (Color) data[i][1]);
+ if ( ( (Boolean) data[i][2]).booleanValue())
+ {
+ av.featuresDisplayed.put(type, new Integer(getColour(type).getRGB()));
+ }
+
+ renderOrder[data.length - i - 1] = type;
+ }
+ }
+}
+
+ class TransparencySetter
+ {
+ void setTransparency(Graphics g, float value)
+ {
+ Graphics2D g2 = (Graphics2D) g;
+ g2.setComposite(
+ AlphaComposite.getInstance(
+ AlphaComposite.SRC_OVER, value));
+ }
+ }
+
+
+
+
diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java
index 6710ed4..77d221e 100755
--- a/src/jalview/appletgui/FeatureSettings.java
+++ b/src/jalview/appletgui/FeatureSettings.java
@@ -1,375 +1,513 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.appletgui;
-
-import jalview.datamodel.*;
-import java.awt.*;
-import java.util.*;
-import java.awt.event.*;
-
-
-public class FeatureSettings extends Panel implements ItemListener,
- MouseListener, MouseMotionListener
-{
- FeatureRenderer fr;
- AlignmentPanel ap;
- AlignViewport av;
- Frame frame;
- Panel groupPanel;
- Panel featurePanel = new Panel();
- ScrollPane scrollPane;
- boolean alignmentHasFeatures = false;
-
- public FeatureSettings(AlignViewport av, final AlignmentPanel ap)
- {
- this.ap = ap;
- this.av = av;
- fr = ap.seqPanel.seqCanvas.getFeatureRenderer();
-
- setTableData();
-
- this.setLayout(new BorderLayout());
- scrollPane = new ScrollPane();
- scrollPane.add(featurePanel);
- if (alignmentHasFeatures)
- add(scrollPane, BorderLayout.CENTER);
-
- if(groupPanel!=null)
- {
- groupPanel.setLayout(
- new GridLayout( fr.featureGroups.size() / 4 + 1, 4));
- groupPanel.validate();
-
- add(groupPanel, BorderLayout.NORTH);
- }
- frame = new Frame();
- frame.add(this);
- int height = featurePanel.getComponentCount()*50 +30;
-
- height = Math.max(100, height);
- height = Math.min(400, height);
-
- jalview.bin.JalviewLite.addFrame(frame, "Feature Settings", 280,
- height);
- }
-
- public void paint(Graphics g)
- {
- g.setColor(Color.black);
- g.drawString("No Features added to this alignment!!", 10, 20);
- }
-
- void setTableData()
- {
- alignmentHasFeatures = false;
-
- if(fr.featureGroups==null)
- fr.featureGroups = new Hashtable();
-
- Vector allFeatures = new Vector();
- Vector allGroups = new Vector();
- SequenceFeature[] tmpfeatures;
- String group;
-
-
- for (int i = 0; i < av.alignment.getHeight(); i++)
- {
- if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
- continue;
-
- alignmentHasFeatures = true;
-
- tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
- int index = 0;
- while (index < tmpfeatures.length)
- {
- if(tmpfeatures[index].getFeatureGroup()!=null)
- {
- group = tmpfeatures[index].featureGroup;
- if(!allGroups.contains(group))
- {
- allGroups.addElement(group);
-
- boolean visible = true;
- if (fr.featureGroups.containsKey(group))
- {
- visible = ( (Boolean) fr.featureGroups.get(group)).booleanValue();
- }
-
- fr.featureGroups.put(group, new Boolean(visible));
-
- if (groupPanel == null)
- {
- groupPanel = new Panel();
- }
-
- Checkbox check = new Checkbox(group, visible);
- check.setFont(new Font("Serif", Font.BOLD, 12));
- check.addItemListener(this);
- groupPanel.add(check);
- }
- }
-
- if (!allFeatures.contains(tmpfeatures[index].getType()))
- {
- allFeatures.addElement(tmpfeatures[index].getType());
- }
- index ++;
- }
- }
-
- resetTable(false);
- }
-
- //This routine adds and removes checkboxes depending on
- //Group selection states
- void resetTable(boolean groupsChanged)
- {
- SequenceFeature [] tmpfeatures;
- String group=null, type;
- Vector visibleChecks = new Vector();
-
- for (int i = 0; i < av.alignment.getHeight(); i++)
- {
- if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
- continue;
-
- tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
- int index = 0;
- while (index < tmpfeatures.length)
- {
- group = tmpfeatures[index].featureGroup;
-
- if (group==null || fr.featureGroups.get(group)==null ||
- ((Boolean) fr.featureGroups.get(group)).booleanValue())
- {
- type = tmpfeatures[index].getType();
- if(!visibleChecks.contains(type) )
- {
- visibleChecks.addElement(type);
- }
- }
- index++;
- }
- }
-
- Component[] comps;
- int cSize = featurePanel.getComponentCount();
- Checkbox check;
- //This will remove any checkboxes which shouldn't be
- //visible
- for (int i = 0; i < cSize; i++)
- {
- comps = featurePanel.getComponents();
- check = (Checkbox) comps[i];
- if (!visibleChecks.contains(check.getLabel()))
- {
- featurePanel.remove(i);
- cSize --;
- i--;
- }
- }
-
- if(fr.renderOrder!=null)
- {
- //First add the checks in the previous render order,
- //in case the window has been closed and reopened
- for(int ro=fr.renderOrder.length-1; ro>-1; ro--)
- {
- String item = fr.renderOrder[ro];
-
- if(!visibleChecks.contains(item))
- continue;
-
- visibleChecks.removeElement(item);
-
- addCheck(false, item);
- }
- }
-
- // now add checkboxes which should be visible,
- // if they have not already been added
- Enumeration en = visibleChecks.elements();
- while(en.hasMoreElements())
- {
- addCheck(groupsChanged, en.nextElement().toString());
- }
-
-
- featurePanel.setLayout(new GridLayout(featurePanel.getComponentCount(), 1, 10,5));
- featurePanel.validate();
-
-
- if(scrollPane!=null)
- scrollPane.validate();
-
- itemStateChanged(null);
- }
-
- void addCheck(boolean groupsChanged, String type)
- {
- boolean addCheck;
- Component [] comps = featurePanel.getComponents();
- Checkbox check;
- addCheck = true;
- for (int i = 0; i < featurePanel.getComponentCount(); i++)
- {
- check = (Checkbox) comps[i];
- if (check.getLabel().equals(type))
- {
- addCheck = false;
- break;
- }
- }
-
- if (addCheck)
- {
- boolean selected = false;
- if (groupsChanged || av.featuresDisplayed.containsKey(type))
- {
- selected = true;
- }
-
- check = new Checkbox(type, selected);
- check.addMouseListener(this);
- check.addMouseMotionListener(this);
- check.setBackground(fr.getColour(type));
- check.addItemListener(this);
- featurePanel.add(check);
- }
- }
-
- public void itemStateChanged(ItemEvent evt)
- {
- if (evt != null)
- {
- //Is the source a top level featureGroup?
- Checkbox source = (Checkbox) evt.getSource();
- if (fr.featureGroups.containsKey(source.getLabel()))
- {
- fr.featureGroups.put(source.getLabel(), new Boolean(source.getState()));
- ap.seqPanel.seqCanvas.repaint();
- if (ap.overviewPanel != null)
- ap.overviewPanel.updateOverviewImage();
-
- resetTable(true);
- return;
- }
- }
-
- Component[] comps = featurePanel.getComponents();
- int cSize = comps.length;
-
- Object[][] tmp = new Object[cSize][3];
- int tmpSize = 0;
- for (int i = 0; i < cSize; i++)
- {
- Checkbox check = (Checkbox) comps[i];
- tmp[tmpSize][0] = check.getLabel();
- tmp[tmpSize][1] = fr.getColour(check.getLabel());
- tmp[tmpSize][2] = new Boolean(check.getState());
- tmpSize++;
- }
-
- Object[][]data = new Object[tmpSize][3];
- System.arraycopy(tmp, 0, data,0, tmpSize);
-
- fr.setFeaturePriority(data);
- ap.seqPanel.seqCanvas.repaint();
- if (ap.overviewPanel != null)
- ap.overviewPanel.updateOverviewImage();
- }
-
- Checkbox selectedCheck;
- boolean dragging = false;
-
- public void mousePressed(MouseEvent evt)
- {
- selectedCheck = (Checkbox)evt.getSource();
- }
-
- public void mouseDragged(MouseEvent evt)
- {
- dragging = true;
- }
-
- public void mouseReleased(MouseEvent evt)
- {
- Component comp = null;
- Checkbox target = null;
-
- int height = evt.getY()+evt.getComponent().getLocation().y;
-
- if(height > this.getSize().height)
- {
- comp = featurePanel.getComponent(featurePanel.getComponentCount()-1);
- }
- else if(height < 0)
- {
- comp = featurePanel.getComponent(0);
- }
- else
- {
- comp = featurePanel.getComponentAt(evt.getX(),
- evt.getY() +
- evt.getComponent().getLocation().y);
- }
-
- if(comp!=null && comp instanceof Checkbox)
- target = (Checkbox)comp;
-
- if ( selectedCheck != null
- && target != null
- && selectedCheck != target)
- {
- int targetIndex = -1;
- for(int i=0; i1)
- {
- new UserDefinedColours(this, check.getLabel(),
- fr.getColour(check.getLabel()));
- }
- }
- public void mouseMoved(MouseEvent evt){}
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.appletgui;
+
+import jalview.datamodel.*;
+import java.awt.*;
+import java.util.*;
+import java.awt.event.*;
+
+
+public class FeatureSettings extends Panel implements ItemListener,
+ MouseListener, MouseMotionListener, ActionListener, AdjustmentListener
+{
+ FeatureRenderer fr;
+ AlignmentPanel ap;
+ AlignViewport av;
+ Frame frame;
+ Panel groupPanel;
+ Panel featurePanel = new Panel();
+ ScrollPane scrollPane;
+ boolean alignmentHasFeatures = false;
+ Image linkImage;
+ Scrollbar transparency ;
+
+ public FeatureSettings(AlignViewport av, final AlignmentPanel ap)
+ {
+ this.ap = ap;
+ this.av = av;
+ fr = ap.seqPanel.seqCanvas.getFeatureRenderer();
+
+ transparency = new Scrollbar(Scrollbar.HORIZONTAL,
+ 100 - (int)(fr.transparency*100), 1, 1, 100);
+
+ if(fr.transparencySetter!=null)
+ {
+ transparency.addAdjustmentListener(this);
+ }
+ else
+ transparency.setEnabled(false);
+
+ java.net.URL url = getClass().getResource("/images/link.gif");
+ if (url != null)
+ {
+ linkImage = java.awt.Toolkit.getDefaultToolkit().getImage(url);
+ }
+
+
+ if(av.featuresDisplayed==null)
+ fr.findAllFeatures();
+
+ setTableData();
+
+ this.setLayout(new BorderLayout());
+ scrollPane = new ScrollPane();
+ scrollPane.add(featurePanel);
+ if (alignmentHasFeatures)
+ add(scrollPane, BorderLayout.CENTER);
+
+ Button invert = new Button("Invert Selection");
+ invert.addActionListener(this);
+
+ Panel lowerPanel = new Panel(new GridLayout(2,1,5,10));
+ lowerPanel.add(invert);
+
+ Panel tPanel = new Panel(new BorderLayout());
+
+ if(fr.transparencySetter!=null)
+ {
+ tPanel.add(transparency, BorderLayout.CENTER);
+ tPanel.add(new Label("Transparency"), BorderLayout.EAST);
+ }
+ else
+ tPanel.add(new Label("Transparency not available in this web browser"), BorderLayout.CENTER);
+
+ lowerPanel.add(tPanel, BorderLayout.SOUTH);
+
+ add(lowerPanel, BorderLayout.SOUTH);
+
+
+
+ if(groupPanel!=null)
+ {
+ groupPanel.setLayout(
+ new GridLayout( fr.featureGroups.size() / 4 + 1, 4));
+ groupPanel.validate();
+
+ add(groupPanel, BorderLayout.NORTH);
+ }
+ frame = new Frame();
+ frame.add(this);
+ int height = featurePanel.getComponentCount()*50 +60;
+
+
+ height = Math.max(200, height);
+ height = Math.min(400, height);
+
+ jalview.bin.JalviewLite.addFrame(frame, "Feature Settings", 280,
+ height);
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setColor(Color.black);
+ g.drawString("No Features added to this alignment!!", 10, 20);
+ g.drawString("(Features can be added from searches or", 10, 40);
+ g.drawString("from Jalview / GFF features files)", 10, 60);
+ }
+
+ void setTableData()
+ {
+ alignmentHasFeatures = false;
+
+ if(fr.featureGroups==null)
+ fr.featureGroups = new Hashtable();
+
+ Vector allFeatures = new Vector();
+ Vector allGroups = new Vector();
+ SequenceFeature[] tmpfeatures;
+ String group;
+
+
+ for (int i = 0; i < av.alignment.getHeight(); i++)
+ {
+ if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
+ continue;
+
+ alignmentHasFeatures = true;
+
+ tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
+ int index = 0;
+ while (index < tmpfeatures.length)
+ {
+ if(tmpfeatures[index].getFeatureGroup()!=null)
+ {
+ group = tmpfeatures[index].featureGroup;
+ if(!allGroups.contains(group))
+ {
+ allGroups.addElement(group);
+
+ boolean visible = true;
+ if (fr.featureGroups.containsKey(group))
+ {
+ visible = ( (Boolean) fr.featureGroups.get(group)).booleanValue();
+ }
+
+ fr.featureGroups.put(group, new Boolean(visible));
+
+ if (groupPanel == null)
+ {
+ groupPanel = new Panel();
+ }
+
+ Checkbox check = new MyCheckbox(
+ group,
+ visible,
+ (fr.featureLinks!=null && fr.featureLinks.containsKey(group))
+ );
+
+
+ check.addMouseListener(this);
+ check.setFont(new Font("Serif", Font.BOLD, 12));
+ check.addItemListener(this);
+ groupPanel.add(check);
+ }
+ }
+
+ if (!allFeatures.contains(tmpfeatures[index].getType()))
+ {
+ allFeatures.addElement(tmpfeatures[index].getType());
+ }
+ index ++;
+ }
+ }
+
+ resetTable(false);
+ }
+
+ //This routine adds and removes checkboxes depending on
+ //Group selection states
+ void resetTable(boolean groupsChanged)
+ {
+ SequenceFeature [] tmpfeatures;
+ String group=null, type;
+ Vector visibleChecks = new Vector();
+
+ for (int i = 0; i < av.alignment.getHeight(); i++)
+ {
+ if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
+ continue;
+
+ tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
+ int index = 0;
+ while (index < tmpfeatures.length)
+ {
+ group = tmpfeatures[index].featureGroup;
+
+ if (group==null || fr.featureGroups.get(group)==null ||
+ ((Boolean) fr.featureGroups.get(group)).booleanValue())
+ {
+ type = tmpfeatures[index].getType();
+ if(!visibleChecks.contains(type) )
+ {
+ visibleChecks.addElement(type);
+ }
+ }
+ index++;
+ }
+ }
+
+ Component[] comps;
+ int cSize = featurePanel.getComponentCount();
+ Checkbox check;
+ //This will remove any checkboxes which shouldn't be
+ //visible
+ for (int i = 0; i < cSize; i++)
+ {
+ comps = featurePanel.getComponents();
+ check = (Checkbox) comps[i];
+ if (!visibleChecks.contains(check.getLabel()))
+ {
+ featurePanel.remove(i);
+ cSize --;
+ i--;
+ }
+ }
+
+ if(fr.renderOrder!=null)
+ {
+ //First add the checks in the previous render order,
+ //in case the window has been closed and reopened
+ for(int ro=fr.renderOrder.length-1; ro>-1; ro--)
+ {
+ String item = fr.renderOrder[ro];
+
+ if(!visibleChecks.contains(item))
+ continue;
+
+ visibleChecks.removeElement(item);
+
+ addCheck(false, item);
+ }
+ }
+
+ // now add checkboxes which should be visible,
+ // if they have not already been added
+ Enumeration en = visibleChecks.elements();
+
+ while(en.hasMoreElements())
+ {
+ addCheck(groupsChanged, en.nextElement().toString());
+ }
+
+
+ featurePanel.setLayout(new GridLayout(featurePanel.getComponentCount(), 1, 10,5));
+ featurePanel.validate();
+
+
+ if(scrollPane!=null)
+ scrollPane.validate();
+
+ itemStateChanged(null);
+ }
+
+ void addCheck(boolean groupsChanged, String type)
+ {
+ boolean addCheck;
+ Component [] comps = featurePanel.getComponents();
+ Checkbox check;
+ addCheck = true;
+ for (int i = 0; i < featurePanel.getComponentCount(); i++)
+ {
+ check = (Checkbox) comps[i];
+ if (check.getLabel().equals(type))
+ {
+ addCheck = false;
+ break;
+ }
+ }
+
+ if (addCheck)
+ {
+ boolean selected = false;
+ if (groupsChanged || av.featuresDisplayed.containsKey(type))
+ {
+ selected = true;
+ }
+
+ check = new MyCheckbox(type,
+ selected,
+ (fr.featureLinks!=null && fr.featureLinks.containsKey(type))
+ );
+
+ check.addMouseListener(this);
+ check.addMouseMotionListener(this);
+ check.setBackground(fr.getColour(type));
+ check.addItemListener(this);
+ featurePanel.add(check);
+ }
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ for(int i=0; iselectedCheck.stringWidth+20)
+ {
+ evt.consume();
+ }
+ }
+
+ }
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ if(((Component)evt.getSource()).getParent()!=featurePanel)
+ return;
+ dragging = true;
+ }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ if(((Component)evt.getSource()).getParent()!=featurePanel)
+ return;
+
+ Component comp = null;
+ Checkbox target = null;
+
+ int height = evt.getY()+evt.getComponent().getLocation().y;
+
+ if(height > featurePanel.getSize().height)
+ {
+
+ comp = featurePanel.getComponent(featurePanel.getComponentCount()-1);
+ }
+ else if(height < 0)
+ {
+ comp = featurePanel.getComponent(0);
+ }
+ else
+ {
+ comp = featurePanel.getComponentAt(evt.getX(),
+ evt.getY() +
+ evt.getComponent().getLocation().y);
+ }
+
+ if(comp!=null && comp instanceof Checkbox)
+ target = (Checkbox)comp;
+
+ if ( selectedCheck != null
+ && target != null
+ && selectedCheck != target)
+ {
+ int targetIndex = -1;
+ for(int i=0; i check.stringWidth + 20)
+ {
+ evt.consume();
+ String link = fr.featureLinks.get(check.getLabel()).toString();
+ ap.alignFrame.showURL(link.substring(link.indexOf("|") + 1),
+ link.substring(0, link.indexOf("|")));
+ }
+ }
+
+ if(check.getParent()!=featurePanel)
+ return;
+
+ if(evt.getClickCount()>1)
+ {
+ new UserDefinedColours(this, check.getLabel(),
+ fr.getColour(check.getLabel()));
+ }
+ }
+ public void mouseMoved(MouseEvent evt){}
+
+ public void adjustmentValueChanged(AdjustmentEvent evt)
+ {
+ fr.transparency = ( (float) (100 - transparency.getValue()) / 100f);
+ ap.seqPanel.seqCanvas.repaint();
+
+ }
+
+ class MyCheckbox extends Checkbox
+ {
+ public int stringWidth;
+ boolean hasLink;
+ public MyCheckbox(String label, boolean checked, boolean haslink)
+ {
+ super(label, checked);
+
+ FontMetrics fm = av.nullFrame.getFontMetrics(av.nullFrame.getFont());
+ stringWidth = fm.stringWidth(label);
+ this.hasLink = haslink;
+ }
+
+ public void paint(Graphics g)
+ {
+ if (hasLink)
+ g.drawImage(linkImage, stringWidth + 25,(
+ getSize().height-linkImage.getHeight(this))/2,
+ this);
+ }
+ }
+}
+
+
diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java
index 1201278..1fe05ac 100755
--- a/src/jalview/appletgui/Finder.java
+++ b/src/jalview/appletgui/Finder.java
@@ -1,344 +1,352 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-
-public class Finder extends Panel implements ActionListener
-{
- AlignViewport av;
- AlignmentPanel ap;
- Frame frame;
-
- SearchResults searchResults;
-
- int seqIndex = 0;
- int resIndex = 0;
- public Finder(final AlignmentPanel ap)
- {
- try
- {
- jbInit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- this.av = ap.av;
- this.ap = ap;
- frame = new Frame();
- frame.add(this);
- jalview.bin.JalviewLite.addFrame(frame, "Find", 340, 120);
- frame.repaint();
- frame.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent evt)
- {
- ap.highlightSearchResults(null);
- }
- });
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- if (evt.getSource() == textfield)
- doSearch(false);
-
- else if (evt.getSource() == findNext)
- doSearch(false);
-
- else if (evt.getSource() == findAll)
- {
- resIndex = 0;
- seqIndex = 0;
- doSearch(true);
- }
- else if(evt.getSource() == createNewGroup)
- createNewGroup_actionPerformed();
- }
-
-
- public void createNewGroup_actionPerformed()
- {
-
- CutAndPasteTransfer cap = new CutAndPasteTransfer(true, null);
- Dialog dialog = new Dialog(ap.alignFrame, "Enter New Feature Name", true);
- dialog.add(cap);
-
- cap.setText(textfield.getText());
-
- dialog.setBounds( frame.getLocation().x+frame.getSize().width+5,
- frame.getLocation().y+20,300,100);
- dialog.show();
-
-
- String featureName = cap.getText().trim();
- if(featureName.length()<1)
- return;
-
-
- for (int i = 0; i < searchResults.getSize(); i ++ )
- {
- SequenceI seq = searchResults.getResultSequence(i);
-
- SequenceFeature sf = new SequenceFeature(featureName,
- null, null,
- searchResults.getResultStart(i),
- searchResults.getResultEnd(i), "Search Results");
-
- ap.seqPanel.seqCanvas.getFeatureRenderer().addNewFeature(
- featureName, new Color(60,160,115));
- seq.addSequenceFeature(sf);
- }
-
- ap.seqPanel.seqCanvas.getFeatureRenderer().findAllFeatures();
- ap.alignFrame.sequenceFeatures.setState(true);
- av.showSequenceFeatures(true);
- ap.highlightSearchResults(null);
- }
-
- void doSearch(boolean findAll)
- {
- createNewGroup.setEnabled(false);
-
- String searchString = textfield.getText().toUpperCase();
-
- com.stevesoft.pat.Regex regex = new com.stevesoft.pat.Regex(searchString);
-
- searchResults = new SearchResults();
-
- Sequence seq;
- String item = null;
- boolean found = false;
-
- ////// is the searchString a residue number?
- try
- {
- int res = Integer.parseInt(searchString);
- found = true;
-
- if (av.getSelectionGroup() == null || av.getSelectionGroup().getSize() < 1)
- {
- seq = (Sequence) av.getAlignment().getSequenceAt(0);
- }
- else
- {
- seq = (Sequence) (av.getSelectionGroup().getSequenceAt(0));
- }
-
-
- searchResults.addResult(seq, res, res);
-
- }
- catch (NumberFormatException ex)
- {}
- ///////////////////////////////////////////////
-
-
- int end = av.alignment.getHeight();
-
- SequenceGroup selection = av.getSelectionGroup();
- if (selection != null)
- {
- if (selection.getSize() < 1 ||
- (selection.getEndRes() - selection.getStartRes() < 2))
- {
- selection = null;
- }
- }
-
- while (!found && seqIndex < end)
- {
-
- seq = (Sequence) av.alignment.getSequenceAt(seqIndex);
-
- if (selection != null && !selection.sequences.contains(seq))
- {
- seqIndex++;
- resIndex = 0;
- continue;
- }
-
- item = seq.getSequence().toUpperCase();
-
- if (selection != null && selection.getEndRes() < av.alignment.getWidth())
- {
- item = item.substring(0, selection.getEndRes() + 1);
- }
-
- ///Shall we ignore gaps????
- StringBuffer noGapsSB = new StringBuffer();
- int insertCount = 0;
- Vector spaces = new Vector();
-
- for (int j = 0; j < item.length(); j++)
- {
-
- if (!jalview.util.Comparison.isGap(item.charAt(j)))
- {
- noGapsSB.append(item.charAt(j));
- spaces.addElement(new Integer(insertCount));
- }
- else
- {
- insertCount++;
- }
- }
-
- String noGaps = noGapsSB.toString();
-
- for (int r = resIndex; r < noGaps.length(); r++)
- {
-
- if (regex.searchFrom(noGaps, r))
- {
- resIndex = regex.matchedFrom();
- if (selection != null &&
- (resIndex + Integer.parseInt(spaces.elementAt(resIndex).toString())) <
- selection.getStartRes())
- {
- continue;
- }
-
-
- int sres = seq.findPosition(resIndex +
- Integer.parseInt(spaces.
- elementAt(resIndex).toString()));
- int eres = seq.findPosition(regex.matchedTo() - 1 +
- Integer.parseInt(
- spaces.elementAt(regex.matchedTo() - 1).
- toString()));
-
- searchResults.addResult(seq, sres, eres);
-
- if (!findAll)
- {
- // thats enough, break and display the result
- found = true;
- resIndex++;
- break;
- }
-
- r = resIndex;
- }
- else
- break;
- }
- if (!found)
- {
- seqIndex++;
- resIndex = 0;
- }
- }
-
- Vector idMatch = new Vector();
- for (int id = 0; id < av.alignment.getHeight(); id++)
- {
- if (regex.search(av.alignment.getSequenceAt(id).getName()))
- {
- idMatch.addElement(av.alignment.getSequenceAt(id));
- }
- }
-
- if (searchResults.getSize() == 0 && idMatch.size() > 0)
- {
- ap.idPanel.highlightSearchResults(idMatch);
- }
-
- if (searchResults.getSize() > 0)
- {
- createNewGroup.setEnabled(true);
- }
- else
- {
- searchResults = null;
- resIndex = 0;
- seqIndex = 0;
- }
-
- // if allResults is null, this effectively switches displaySearch flag in seqCanvas
- ap.highlightSearchResults(searchResults);
-
- if (findAll)
- {
- String message = (searchResults==null?0 : searchResults.getSize()) + " matches found.";
- ap.alignFrame.statusBar.setText("Search results: "+searchString+" : "+message);
- }
-
- }
-
- Label jLabel1 = new Label();
- protected TextField textfield = new TextField();
- protected Button findAll = new Button();
- protected Button findNext = new Button();
- Panel jPanel1 = new Panel();
- GridLayout gridLayout1 = new GridLayout();
- protected Button createNewGroup = new Button();
-
-
- private void jbInit() throws Exception {
- jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
- jLabel1.setText("Find");
- jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
- this.setLayout(null);
- textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- textfield.setText("");
- textfield.setBounds(new Rectangle(40, 27, 133, 21));
- textfield.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyTyped(KeyEvent e) {
- textfield_keyTyped(e);
- }
- });
- textfield.addActionListener(this);
- findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- findAll.setLabel("Find all");
- findAll.addActionListener(this);
- findNext.setEnabled(false);
- findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- findNext.setLabel("Find Next");
- findNext.addActionListener(this);
- jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
- jPanel1.setLayout(gridLayout1);
- gridLayout1.setHgap(0);
- gridLayout1.setRows(3);
- gridLayout1.setVgap(2);
- createNewGroup.setEnabled(false);
- createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- createNewGroup.setLabel("New Feature");
- createNewGroup.addActionListener(this);
- jPanel1.add(findNext, null);
- jPanel1.add(findAll, null);
- jPanel1.add(createNewGroup, null);
- this.add(textfield, null);
- this.add(jLabel1, null);
- this.add(jPanel1, null);
- }
-
- void textfield_keyTyped(KeyEvent e) {
- findNext.setEnabled(true);
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+import java.awt.Rectangle;
+
+public class Finder extends Panel implements ActionListener
+{
+ AlignViewport av;
+ AlignmentPanel ap;
+ Frame frame;
+
+ SearchResults searchResults;
+
+ int seqIndex = 0;
+ int resIndex = 0;
+ public Finder(final AlignmentPanel ap)
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ this.av = ap.av;
+ this.ap = ap;
+ frame = new Frame();
+ frame.add(this);
+ jalview.bin.JalviewLite.addFrame(frame, "Find", 340, 120);
+ frame.repaint();
+ frame.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent evt)
+ {
+ ap.highlightSearchResults(null);
+ }
+ });
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ if (evt.getSource() == textfield)
+ doSearch(false);
+
+ else if (evt.getSource() == findNext)
+ doSearch(false);
+
+ else if (evt.getSource() == findAll)
+ {
+ resIndex = 0;
+ seqIndex = 0;
+ doSearch(true);
+ }
+ else if(evt.getSource() == createNewGroup)
+ createNewGroup_actionPerformed();
+ }
+
+
+ public void createNewGroup_actionPerformed()
+ {
+
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(true, null);
+ Dialog dialog = new Dialog(ap.alignFrame, "Enter New Feature Name", true);
+ dialog.add(cap);
+
+ cap.setText(textfield.getText());
+
+ dialog.setBounds( frame.getLocation().x+frame.getSize().width+5,
+ frame.getLocation().y+20,300,100);
+ dialog.show();
+
+
+ String featureName = cap.getText().trim();
+ if(featureName.length()<1)
+ return;
+
+
+ for (int i = 0; i < searchResults.getSize(); i ++ )
+ {
+ SequenceI seq = searchResults.getResultSequence(i);
+
+ SequenceFeature sf = new SequenceFeature(featureName,
+ null, null,
+ searchResults.getResultStart(i),
+ searchResults.getResultEnd(i), "Search Results");
+
+ ap.seqPanel.seqCanvas.getFeatureRenderer().addNewFeature(
+ featureName, new Color(60,160,115));
+ seq.addSequenceFeature(sf);
+ }
+
+ ap.seqPanel.seqCanvas.getFeatureRenderer().findAllFeatures();
+ ap.alignFrame.sequenceFeatures.setState(true);
+ av.showSequenceFeatures(true);
+ ap.highlightSearchResults(null);
+ }
+
+ void doSearch(boolean findAll)
+ {
+ createNewGroup.setEnabled(false);
+
+ String searchString = textfield.getText();
+ if(!caseSensitive.getState())
+ searchString = searchString.toUpperCase();
+
+ com.stevesoft.pat.Regex regex = new com.stevesoft.pat.Regex(searchString);
+
+ searchResults = new SearchResults();
+
+ Sequence seq;
+ String item = null;
+ boolean found = false;
+
+ ////// is the searchString a residue number?
+ try
+ {
+ int res = Integer.parseInt(searchString);
+ found = true;
+
+ if (av.getSelectionGroup() == null || av.getSelectionGroup().getSize(false) < 1)
+ {
+ seq = (Sequence) av.getAlignment().getSequenceAt(0);
+ }
+ else
+ {
+ seq = (Sequence) (av.getSelectionGroup().getSequenceAt(0));
+ }
+
+
+ searchResults.addResult(seq, res, res);
+
+ }
+ catch (NumberFormatException ex)
+ {}
+ ///////////////////////////////////////////////
+
+
+ int end = av.alignment.getHeight();
+
+ SequenceGroup selection = av.getSelectionGroup();
+ if (selection != null)
+ {
+ if (selection.getSize(false) < 1 ||
+ (selection.getEndRes() - selection.getStartRes() < 2))
+ {
+ selection = null;
+ }
+ }
+
+ while (!found && seqIndex < end)
+ {
+
+ seq = (Sequence) av.alignment.getSequenceAt(seqIndex);
+
+ if (selection != null && !selection.getSequences(false).contains(seq))
+ {
+ seqIndex++;
+ resIndex = 0;
+ continue;
+ }
+
+ item = seq.getSequence();
+ if(!caseSensitive.getState())
+ item = item.toUpperCase();
+
+ if (selection != null && selection.getEndRes() < av.alignment.getWidth())
+ {
+ item = item.substring(0, selection.getEndRes() + 1);
+ }
+
+ ///Shall we ignore gaps????
+ StringBuffer noGapsSB = new StringBuffer();
+ int insertCount = 0;
+ Vector spaces = new Vector();
+
+ for (int j = 0; j < item.length(); j++)
+ {
+
+ if (!jalview.util.Comparison.isGap(item.charAt(j)))
+ {
+ noGapsSB.append(item.charAt(j));
+ spaces.addElement(new Integer(insertCount));
+ }
+ else
+ {
+ insertCount++;
+ }
+ }
+
+ String noGaps = noGapsSB.toString();
+
+ for (int r = resIndex; r < noGaps.length(); r++)
+ {
+
+ if (regex.searchFrom(noGaps, r))
+ {
+ resIndex = regex.matchedFrom();
+ if (selection != null &&
+ (resIndex + Integer.parseInt(spaces.elementAt(resIndex).toString())) <
+ selection.getStartRes())
+ {
+ continue;
+ }
+
+
+ int sres = seq.findPosition(resIndex +
+ Integer.parseInt(spaces.
+ elementAt(resIndex).toString()));
+ int eres = seq.findPosition(regex.matchedTo() - 1 +
+ Integer.parseInt(
+ spaces.elementAt(regex.matchedTo() - 1).
+ toString()));
+
+ searchResults.addResult(seq, sres, eres);
+
+ if (!findAll)
+ {
+ // thats enough, break and display the result
+ found = true;
+ resIndex++;
+ break;
+ }
+
+ r = resIndex;
+ }
+ else
+ break;
+ }
+ if (!found)
+ {
+ seqIndex++;
+ resIndex = 0;
+ }
+ }
+
+ Vector idMatch = new Vector();
+ for (int id = 0; id < av.alignment.getHeight(); id++)
+ {
+ if (regex.search(av.alignment.getSequenceAt(id).getName()))
+ {
+ idMatch.addElement(av.alignment.getSequenceAt(id));
+ }
+ }
+
+ if (searchResults.getSize() == 0 && idMatch.size() > 0)
+ {
+ ap.idPanel.highlightSearchResults(idMatch);
+ }
+
+ if (searchResults.getSize() > 0)
+ {
+ createNewGroup.setEnabled(true);
+ }
+ else
+ {
+ searchResults = null;
+ resIndex = 0;
+ seqIndex = 0;
+ }
+
+ // if allResults is null, this effectively switches displaySearch flag in seqCanvas
+ ap.highlightSearchResults(searchResults);
+
+ if (findAll)
+ {
+ String message = (searchResults==null?0 : searchResults.getSize()) + " matches found.";
+ ap.alignFrame.statusBar.setText("Search results: "+searchString+" : "+message);
+ }
+
+ }
+
+ Label jLabel1 = new Label();
+ protected TextField textfield = new TextField();
+ protected Button findAll = new Button();
+ protected Button findNext = new Button();
+ Panel jPanel1 = new Panel();
+ GridLayout gridLayout1 = new GridLayout();
+ protected Button createNewGroup = new Button();
+ Checkbox caseSensitive = new Checkbox();
+
+ private void jbInit() throws Exception {
+ jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
+ jLabel1.setText("Find");
+ jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
+ this.setLayout(null);
+ textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+ textfield.setText("");
+ textfield.setBounds(new Rectangle(40, 27, 133, 21));
+ textfield.addKeyListener(new java.awt.event.KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ textfield_keyTyped(e);
+ }
+ });
+ textfield.addActionListener(this);
+ findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+ findAll.setLabel("Find all");
+ findAll.addActionListener(this);
+ findNext.setEnabled(false);
+ findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+ findNext.setLabel("Find Next");
+ findNext.addActionListener(this);
+ jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
+ jPanel1.setLayout(gridLayout1);
+ gridLayout1.setHgap(0);
+ gridLayout1.setRows(3);
+ gridLayout1.setVgap(2);
+ createNewGroup.setEnabled(false);
+ createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+ createNewGroup.setLabel("New Feature");
+ createNewGroup.addActionListener(this);
+ caseSensitive.setLabel("Match Case");
+ caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
+ jPanel1.add(findNext, null);
+ jPanel1.add(findAll, null);
+ jPanel1.add(createNewGroup, null);
+ this.add(caseSensitive);
+ this.add(textfield, null);
+ this.add(jLabel1, null);
+ this.add(jPanel1, null);
+ }
+
+ void textfield_keyTyped(KeyEvent e) {
+ findNext.setEnabled(true);
+ }
+
+}
diff --git a/src/jalview/appletgui/FontChooser.java b/src/jalview/appletgui/FontChooser.java
index 843ffe7..e73355f 100755
--- a/src/jalview/appletgui/FontChooser.java
+++ b/src/jalview/appletgui/FontChooser.java
@@ -1,258 +1,258 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-
-import java.awt.event.*;
-
-public class FontChooser
- extends Panel implements ActionListener, ItemListener
-{
- AlignmentPanel ap;
- TreePanel tp;
- Font oldFont;
- boolean init = true;
- Frame frame;
-
- public FontChooser(TreePanel tp)
- {
- try
- {
- jbInit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- this.tp = tp;
- oldFont = tp.getTreeFont();
- init();
- }
-
- public FontChooser(AlignmentPanel ap)
- {
- try
- {
- jbInit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- this.ap = ap;
- oldFont = ap.av.getFont();
- init();
- }
-
- void init()
- {
- String fonts[] = Toolkit.getDefaultToolkit().getFontList();
- for (int i = 0; i < fonts.length; i++)
- {
- fontName.addItem(fonts[i]);
- }
-
- for (int i = 1; i < 31; i++)
- {
- fontSize.addItem(i + "");
- }
-
- fontStyle.addItem("plain");
- fontStyle.addItem("bold");
- fontStyle.addItem("italic");
-
- fontName.select(oldFont.getName());
- fontSize.select(oldFont.getSize() + "");
- fontStyle.select(oldFont.getStyle());
-
- Frame frame = new Frame();
- this.frame = frame;
- frame.add(this);
- jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 115);
-
- init = false;
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource()==ok)
- ok_actionPerformed();
- else if(evt.getSource()==cancel)
- cancel_actionPerformed();
- }
-
- public void itemStateChanged(ItemEvent evt)
- {
- if(evt.getSource()==fontName)
- fontName_actionPerformed();
- else if(evt.getSource()==fontSize)
- fontSize_actionPerformed();
- else if(evt.getSource()==fontStyle)
- fontStyle_actionPerformed();
- }
-
-
- protected void ok_actionPerformed()
- {
- frame.setVisible(false);
- if (ap != null)
- {
- if (ap.getOverviewPanel() != null)
- {
- ap.getOverviewPanel().updateOverviewImage();
- }
- }
-
- }
-
- protected void cancel_actionPerformed()
- {
- if(ap!=null)
- {
- ap.av.setFont(oldFont);
- ap.repaint();
- }
- else if(tp!=null)
- {
- tp.setTreeFont(oldFont);
- tp.treeCanvas.repaint();
- }
-
- fontName.select(oldFont.getName());
- fontSize.select(oldFont.getSize() + "");
- fontStyle.select(oldFont.getStyle());
-
- frame.setVisible(false);
- }
-
- void changeFont()
- {
- Font newFont = new Font(fontName.getSelectedItem().toString(),
- fontStyle.getSelectedIndex(),
- Integer.parseInt(fontSize.getSelectedItem().
- toString())
- );
- if (ap != null)
- {
- ap.av.setFont(newFont);
- ap.fontChanged();
- }
- else if(tp != null)
- {
- tp.setTreeFont(newFont);
- }
- }
-
- protected void fontName_actionPerformed()
- {
- if (init)
- {
- return;
- }
- changeFont();
- }
-
- protected void fontSize_actionPerformed()
- {
- if (init)
- {
- return;
- }
- changeFont();
- }
-
- protected void fontStyle_actionPerformed()
- {
- if (init)
- {
- return;
- }
- changeFont();
- }
- Label label1 = new Label();
- protected Choice fontSize = new Choice();
- protected Choice fontStyle = new Choice();
- Label label2 = new Label();
- Label label3 = new Label();
- protected Choice fontName = new Choice();
- Button ok = new Button();
- Button cancel = new Button();
- Panel panel1 = new Panel();
- Panel panel2 = new Panel();
- Panel panel3 = new Panel();
- BorderLayout borderLayout1 = new BorderLayout();
- BorderLayout borderLayout2 = new BorderLayout();
- BorderLayout borderLayout3 = new BorderLayout();
- Panel panel4 = new Panel();
- Panel panel5 = new Panel();
- BorderLayout borderLayout4 = new BorderLayout();
-
-
- private void jbInit() throws Exception {
- label1.setFont(new java.awt.Font("Verdana", 0, 11));
- label1.setAlignment(Label.RIGHT);
- label1.setText("Font: ");
- this.setLayout(borderLayout4);
- fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
- fontSize.addItemListener(this);
- fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
- fontStyle.addItemListener(this);
- label2.setAlignment(Label.RIGHT);
- label2.setFont(new java.awt.Font("Verdana", 0, 11));
- label2.setText("Size: ");
- label3.setAlignment(Label.RIGHT);
- label3.setFont(new java.awt.Font("Verdana", 0, 11));
- label3.setText("Style: ");
- fontName.setFont(new java.awt.Font("Verdana", 0, 11));
- fontName.addItemListener(this);
- ok.setFont(new java.awt.Font("Verdana", 0, 11));
- ok.setLabel("OK");
- ok.addActionListener(this);
- cancel.setFont(new java.awt.Font("Verdana", 0, 11));
- cancel.setLabel("Cancel");
- cancel.addActionListener(this);
- this.setBackground(Color.white);
- panel1.setLayout(borderLayout1);
- panel2.setLayout(borderLayout3);
- panel3.setLayout(borderLayout2);
- panel5.setBackground(Color.white);
- panel4.setBackground(Color.white);
- panel1.setBackground(Color.white);
- panel2.setBackground(Color.white);
- panel3.setBackground(Color.white);
- panel1.add(label1, BorderLayout.WEST);
- panel1.add(fontName, BorderLayout.CENTER);
- panel5.add(panel1, null);
- panel5.add(panel3, null);
- panel5.add(panel2, null);
- panel2.add(label3, BorderLayout.WEST);
- panel2.add(fontStyle, BorderLayout.CENTER);
- panel3.add(label2, BorderLayout.WEST);
- panel3.add(fontSize, BorderLayout.CENTER);
- this.add(panel4, BorderLayout.SOUTH);
- panel4.add(ok, null);
- panel4.add(cancel, null);
- this.add(panel5, BorderLayout.CENTER);
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+
+import java.awt.event.*;
+
+public class FontChooser
+ extends Panel implements ActionListener, ItemListener
+{
+ AlignmentPanel ap;
+ TreePanel tp;
+ Font oldFont;
+ boolean init = true;
+ Frame frame;
+
+ public FontChooser(TreePanel tp)
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ this.tp = tp;
+ oldFont = tp.getTreeFont();
+ init();
+ }
+
+ public FontChooser(AlignmentPanel ap)
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ this.ap = ap;
+ oldFont = ap.av.getFont();
+ init();
+ }
+
+ void init()
+ {
+ String fonts[] = Toolkit.getDefaultToolkit().getFontList();
+ for (int i = 0; i < fonts.length; i++)
+ {
+ fontName.addItem(fonts[i]);
+ }
+
+ for (int i = 1; i < 31; i++)
+ {
+ fontSize.addItem(i + "");
+ }
+
+ fontStyle.addItem("plain");
+ fontStyle.addItem("bold");
+ fontStyle.addItem("italic");
+
+ fontName.select(oldFont.getName());
+ fontSize.select(oldFont.getSize() + "");
+ fontStyle.select(oldFont.getStyle());
+
+ Frame frame = new Frame();
+ this.frame = frame;
+ frame.add(this);
+ jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 115);
+
+ init = false;
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource()==ok)
+ ok_actionPerformed();
+ else if(evt.getSource()==cancel)
+ cancel_actionPerformed();
+ }
+
+ public void itemStateChanged(ItemEvent evt)
+ {
+ if(evt.getSource()==fontName)
+ fontName_actionPerformed();
+ else if(evt.getSource()==fontSize)
+ fontSize_actionPerformed();
+ else if(evt.getSource()==fontStyle)
+ fontStyle_actionPerformed();
+ }
+
+
+ protected void ok_actionPerformed()
+ {
+ frame.setVisible(false);
+ if (ap != null)
+ {
+ if (ap.getOverviewPanel() != null)
+ {
+ ap.getOverviewPanel().updateOverviewImage();
+ }
+ }
+
+ }
+
+ protected void cancel_actionPerformed()
+ {
+ if(ap!=null)
+ {
+ ap.av.setFont(oldFont);
+ ap.repaint();
+ }
+ else if(tp!=null)
+ {
+ tp.setTreeFont(oldFont);
+ tp.treeCanvas.repaint();
+ }
+
+ fontName.select(oldFont.getName());
+ fontSize.select(oldFont.getSize() + "");
+ fontStyle.select(oldFont.getStyle());
+
+ frame.setVisible(false);
+ }
+
+ void changeFont()
+ {
+ Font newFont = new Font(fontName.getSelectedItem().toString(),
+ fontStyle.getSelectedIndex(),
+ Integer.parseInt(fontSize.getSelectedItem().
+ toString())
+ );
+ if (ap != null)
+ {
+ ap.av.setFont(newFont);
+ ap.fontChanged();
+ }
+ else if(tp != null)
+ {
+ tp.setTreeFont(newFont);
+ }
+ }
+
+ protected void fontName_actionPerformed()
+ {
+ if (init)
+ {
+ return;
+ }
+ changeFont();
+ }
+
+ protected void fontSize_actionPerformed()
+ {
+ if (init)
+ {
+ return;
+ }
+ changeFont();
+ }
+
+ protected void fontStyle_actionPerformed()
+ {
+ if (init)
+ {
+ return;
+ }
+ changeFont();
+ }
+ Label label1 = new Label();
+ protected Choice fontSize = new Choice();
+ protected Choice fontStyle = new Choice();
+ Label label2 = new Label();
+ Label label3 = new Label();
+ protected Choice fontName = new Choice();
+ Button ok = new Button();
+ Button cancel = new Button();
+ Panel panel1 = new Panel();
+ Panel panel2 = new Panel();
+ Panel panel3 = new Panel();
+ BorderLayout borderLayout1 = new BorderLayout();
+ BorderLayout borderLayout2 = new BorderLayout();
+ BorderLayout borderLayout3 = new BorderLayout();
+ Panel panel4 = new Panel();
+ Panel panel5 = new Panel();
+ BorderLayout borderLayout4 = new BorderLayout();
+
+
+ private void jbInit() throws Exception {
+ label1.setFont(new java.awt.Font("Verdana", 0, 11));
+ label1.setAlignment(Label.RIGHT);
+ label1.setText("Font: ");
+ this.setLayout(borderLayout4);
+ fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
+ fontSize.addItemListener(this);
+ fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
+ fontStyle.addItemListener(this);
+ label2.setAlignment(Label.RIGHT);
+ label2.setFont(new java.awt.Font("Verdana", 0, 11));
+ label2.setText("Size: ");
+ label3.setAlignment(Label.RIGHT);
+ label3.setFont(new java.awt.Font("Verdana", 0, 11));
+ label3.setText("Style: ");
+ fontName.setFont(new java.awt.Font("Verdana", 0, 11));
+ fontName.addItemListener(this);
+ ok.setFont(new java.awt.Font("Verdana", 0, 11));
+ ok.setLabel("OK");
+ ok.addActionListener(this);
+ cancel.setFont(new java.awt.Font("Verdana", 0, 11));
+ cancel.setLabel("Cancel");
+ cancel.addActionListener(this);
+ this.setBackground(Color.white);
+ panel1.setLayout(borderLayout1);
+ panel2.setLayout(borderLayout3);
+ panel3.setLayout(borderLayout2);
+ panel5.setBackground(Color.white);
+ panel4.setBackground(Color.white);
+ panel1.setBackground(Color.white);
+ panel2.setBackground(Color.white);
+ panel3.setBackground(Color.white);
+ panel1.add(label1, BorderLayout.WEST);
+ panel1.add(fontName, BorderLayout.CENTER);
+ panel5.add(panel1, null);
+ panel5.add(panel3, null);
+ panel5.add(panel2, null);
+ panel2.add(label3, BorderLayout.WEST);
+ panel2.add(fontStyle, BorderLayout.CENTER);
+ panel3.add(label2, BorderLayout.WEST);
+ panel3.add(fontSize, BorderLayout.CENTER);
+ this.add(panel4, BorderLayout.SOUTH);
+ panel4.add(ok, null);
+ panel4.add(cancel, null);
+ this.add(panel5, BorderLayout.CENTER);
+ }
+
+}
diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java
index 44ba2e0..b8255ca 100755
--- a/src/jalview/appletgui/IdCanvas.java
+++ b/src/jalview/appletgui/IdCanvas.java
@@ -1,276 +1,345 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-
-import jalview.datamodel.*;
-
-public class IdCanvas
- extends Panel
-{
- protected AlignViewport av;
-
- protected boolean showScores = true;
-
- protected int maxIdLength = -1;
- protected String maxIdStr = null;
- Image image;
- Graphics gg;
- int imgHeight = 0;
- boolean fastPaint = false;
-
- java.util.Vector searchResults;
-
- public IdCanvas(AlignViewport av)
- {
- setLayout(null);
- this.av = av;
- PaintRefresher.Register(this, av.alignment);
- }
-
- public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
- int ypos)
- {
- int charHeight = av.getCharHeight();
-
- if (searchResults != null && searchResults.contains(s))
- {
- gg.setColor(Color.black);
- gg.fillRect(0, ((i - starty) * charHeight) + ypos,
- getSize().width, charHeight);
- gg.setColor(Color.white);
- }
- else if (av.getSelectionGroup() != null &&
- av.getSelectionGroup().sequences.contains(s))
- {
- gg.setColor(Color.lightGray);
- gg.fillRect(0, ((i - starty) * charHeight) + ypos,
- getSize().width, charHeight);
- gg.setColor(Color.white);
- }
- else
- {
- gg.setColor(s.getColor());
- gg.fillRect(0, ((i - starty) * charHeight) + ypos,
- getSize().width, charHeight);
- gg.setColor(Color.black);
- }
-
-
- gg.drawString( s.getDisplayId(av.getShowJVSuffix()), 0,
- ((i - starty) * charHeight) + ypos +
- charHeight - (charHeight / 5));
-
- }
-
- public void fastPaint(int vertical)
- {
- if (gg == null)
- {
- repaint();
- return;
- }
-
- gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.charHeight);
-
- int ss = av.startSeq, es = av.endSeq, transY = 0;
- if (vertical > 0) // scroll down
- {
- ss = es - vertical;
- if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
- {
- ss = av.startSeq;
- }
- else
- {
- transY = imgHeight - vertical * av.charHeight;
- }
- }
- else if (vertical < 0)
- {
- es = ss - vertical;
- if (es > av.endSeq)
- {
- es = av.endSeq;
- }
- }
-
- gg.translate(0, transY);
-
- drawIds(ss, es);
-
- gg.translate(0, -transY);
-
- fastPaint = true;
- repaint();
- }
-
- public void update(Graphics g)
- {
- paint(g);
- }
-
- public void paint(Graphics g)
- {
- if (getSize().height < 0 || getSize().width < 0)
- {
- return;
- }
- if (fastPaint)
- {
- fastPaint = false;
- g.drawImage(image, 0, 0, this);
- return;
- }
-
- imgHeight = getSize().height;
- imgHeight -= imgHeight % av.charHeight;
-
- if (imgHeight < 1)
- {
- return;
- }
-
- if (image == null || imgHeight != image.getHeight(this))
- {
- image = createImage(getSize().width, imgHeight);
- gg = image.getGraphics();
- gg.setFont(av.getFont());
- }
-
- //Fill in the background
- gg.setColor(Color.white);
- Font italic = new Font(av.getFont().getName(), Font.ITALIC,
- av.getFont().getSize());
- gg.setFont(italic);
-
- gg.fillRect(0, 0, getSize().width, getSize().height);
- drawIds(av.getStartSeq(), av.endSeq);
- g.drawImage(image, 0, 0, this);
- }
-
- void drawIds(int starty, int endy)
- {
- Color currentColor = Color.white;
- Color currentTextColor = Color.black;
- Font italic = new Font(av.getFont().getName(), Font.ITALIC,
- av.getFont().getSize());
-
- if (av.getWrapAlignment())
- {
- int annotationHeight = 0;
- AnnotationLabels labels = null;
-
- if(av.showAnnotation)
- {
- AnnotationPanel ap = new AnnotationPanel(av);
- annotationHeight = ap.adjustPanelHeight();
- labels = new AnnotationLabels(av);
- }
-
- int hgap = av.charHeight;
- if (av.scaleAboveWrapped)
- hgap += av.charHeight;
-
- int cHeight = av.getAlignment().getHeight() * av.charHeight
- + hgap
- + annotationHeight;
-
- int rowSize = av.getEndRes() - av.getStartRes();
-
- // Draw the rest of the panels
- for (int ypos = hgap, row = av.startRes;
- (ypos <= getSize().height) && (row < av.alignment.getWidth());
- ypos += cHeight, row += rowSize)
- {
- for (int i = starty; i < av.alignment.getHeight(); i++)
- {
- SequenceI s = av.alignment.getSequenceAt(i);
- gg.setFont(italic);
- drawIdString(gg, s, i, 0, ypos);
- }
-
- if(labels!=null)
- {
- gg.translate(0, ypos+(av.getAlignment().getHeight() * av.charHeight));
- labels.drawComponent(gg, getSize().width);
- gg.translate(0, -ypos-(av.getAlignment().getHeight() * av.charHeight));
- }
- }
-
- }
- else
- {
-
- //Now draw the id strings
- for (int i = starty; i < endy; i++)
- {
- // Selected sequence colours
-
- if (searchResults != null &&
- searchResults.contains(av.alignment.getSequenceAt(i)))
- {
- gg.setColor(Color.black);
- currentColor = Color.black;
- currentTextColor = Color.white;
- }
- else if (av.getSelectionGroup() != null
- &&
- av.getSelectionGroup().sequences.contains(av.alignment.
- getSequenceAt(i)))
- {
- currentColor = Color.lightGray;
- currentTextColor = Color.black;
- }
- else
- {
- currentColor = av.alignment.getSequenceAt(i).getColor();
- currentTextColor = Color.black;
- }
-
- gg.setColor(currentColor);
-
- gg.fillRect(0,
- ((i - starty) * av.charHeight),
- getSize().width,
- av.charHeight);
-
- gg.setColor(currentTextColor);
-
- gg.drawString(av.alignment.getSequenceAt(i)
- .getDisplayId(av.getShowJVSuffix()), 0,
- ((i - starty) * av.charHeight) +
- av.charHeight - (av.charHeight / 5));
- }
-
- // add a border
- gg.setColor(Color.white);
- gg.fillRect(getSize().width - 4, 0, 4, getSize().height);
- }
-
- }
-
- public void setHighlighted(java.util.Vector found)
- {
- searchResults = found;
- repaint();
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+
+import jalview.datamodel.*;
+
+public class IdCanvas
+ extends Panel
+{
+ protected AlignViewport av;
+
+ protected boolean showScores = true;
+
+ protected int maxIdLength = -1;
+ protected String maxIdStr = null;
+ Image image;
+ Graphics gg;
+ int imgHeight = 0;
+ boolean fastPaint = false;
+
+ java.util.Vector searchResults;
+
+ public IdCanvas(AlignViewport av)
+ {
+ setLayout(null);
+ this.av = av;
+ PaintRefresher.Register(this, av.alignment);
+ }
+
+ public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
+ int ypos)
+ {
+ int charHeight = av.getCharHeight();
+
+ if (searchResults != null && searchResults.contains(s))
+ {
+ gg.setColor(Color.black);
+ gg.fillRect(0, ((i - starty) * charHeight) + ypos,
+ getSize().width, charHeight);
+ gg.setColor(Color.white);
+ }
+ else if (av.getSelectionGroup() != null &&
+ av.getSelectionGroup().getSequences(false).contains(s))
+ {
+ gg.setColor(Color.lightGray);
+ gg.fillRect(0, ((i - starty) * charHeight) + ypos,
+ getSize().width, charHeight);
+ gg.setColor(Color.white);
+ }
+ else
+ {
+ gg.setColor(s.getColor());
+ gg.fillRect(0, ((i - starty) * charHeight) + ypos,
+ getSize().width, charHeight);
+ gg.setColor(Color.black);
+ }
+
+
+ gg.drawString( s.getDisplayId(av.getShowJVSuffix()), 0,
+ ((i - starty) * charHeight) + ypos +
+ charHeight - (charHeight / 5));
+
+ if (av.hasHiddenRows && av.showHiddenMarkers)
+ drawMarker(i, starty, ypos);
+
+ }
+
+ public void fastPaint(int vertical)
+ {
+ if (gg == null)
+ {
+ repaint();
+ return;
+ }
+
+ gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.charHeight);
+
+ int ss = av.startSeq, es = av.endSeq, transY = 0;
+ if (vertical > 0) // scroll down
+ {
+ ss = es - vertical;
+ if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
+ {
+ ss = av.startSeq;
+ }
+ else
+ {
+ transY = imgHeight - vertical * av.charHeight;
+ }
+ }
+ else if (vertical < 0)
+ {
+ es = ss - vertical;
+ if (es > av.endSeq)
+ {
+ es = av.endSeq;
+ }
+ }
+
+ gg.translate(0, transY);
+
+ drawIds(ss, es);
+
+ gg.translate(0, -transY);
+
+ fastPaint = true;
+ repaint();
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void paint(Graphics g)
+ {
+ if (getSize().height < 0 || getSize().width < 0)
+ {
+ return;
+ }
+ if (fastPaint)
+ {
+ fastPaint = false;
+ g.drawImage(image, 0, 0, this);
+ return;
+ }
+
+ imgHeight = getSize().height;
+ imgHeight -= imgHeight % av.charHeight;
+
+ if (imgHeight < 1)
+ {
+ return;
+ }
+
+ if (image == null || imgHeight != image.getHeight(this))
+ {
+ image = createImage(getSize().width, imgHeight);
+ gg = image.getGraphics();
+ gg.setFont(av.getFont());
+ }
+
+ //Fill in the background
+ gg.setColor(Color.white);
+ Font italic = new Font(av.getFont().getName(), Font.ITALIC,
+ av.getFont().getSize());
+ gg.setFont(italic);
+
+ gg.fillRect(0, 0, getSize().width, getSize().height);
+ drawIds(av.startSeq, av.endSeq);
+ g.drawImage(image, 0, 0, this);
+ }
+
+ void drawIds(int starty, int endy)
+ {
+ Font italic = new Font(av.getFont().getName(), Font.ITALIC,
+ av.getFont().getSize());
+
+ gg.setFont(italic);
+
+ Color currentColor = Color.white;
+ Color currentTextColor = Color.black;
+
+ if (av.getWrapAlignment())
+ {
+ int maxwidth = av.alignment.getWidth();
+ int alheight = av.alignment.getHeight();
+
+ if (av.hasHiddenColumns)
+ maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+
+ int annotationHeight = 0;
+ AnnotationLabels labels = null;
+
+ if (av.showAnnotation)
+ {
+ AnnotationPanel ap = new AnnotationPanel(av);
+ annotationHeight = ap.adjustPanelHeight();
+ labels = new AnnotationLabels(av);
+ }
+
+ int hgap = av.charHeight;
+ if (av.scaleAboveWrapped)
+ hgap += av.charHeight;
+
+ int cHeight = alheight * av.charHeight
+ + hgap
+ + annotationHeight;
+
+ int rowSize = av.getEndRes() - av.getStartRes();
+
+ // Draw the rest of the panels
+ for (int ypos = hgap, row = av.startRes;
+ (ypos <= getSize().height) && (row < maxwidth);
+ ypos += cHeight, row += rowSize)
+ {
+ for (int i = starty; i < alheight; i++)
+ {
+ if (av.hasHiddenRows)
+ {
+ setHiddenFont(i);
+ }
+ else
+ gg.setFont(italic);
+
+ SequenceI s = av.alignment.getSequenceAt(i);
+ drawIdString(gg, s, i, 0, ypos);
+ }
+
+ if (labels != null)
+ {
+ gg.translate(0, ypos + (alheight * av.charHeight));
+ labels.drawComponent(gg, getSize().width);
+ gg.translate(0, -ypos - (alheight * av.charHeight));
+ }
+
+ }
+ }
+ else
+ {
+ //Now draw the id strings
+
+ //Now draw the id strings
+ for (int i = starty; i < endy; i++)
+ {
+ if (av.hasHiddenRows)
+ {
+ setHiddenFont(i);
+ }
+
+ // Selected sequence colours
+ if ( (searchResults != null) &&
+ searchResults.contains(av.alignment.getSequenceAt(i)))
+ {
+ currentColor = Color.black;
+ currentTextColor = Color.white;
+ }
+ else if ( (av.getSelectionGroup() != null) &&
+ av.getSelectionGroup().getSequences(false).contains(
+ av.alignment.getSequenceAt(i)))
+ {
+ currentColor = Color.lightGray;
+ currentTextColor = Color.black;
+ }
+ else
+ {
+ currentColor = av.alignment.getSequenceAt(i).getColor();
+ currentTextColor = Color.black;
+ }
+
+ gg.setColor(currentColor);
+
+ gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
+ av.charHeight);
+
+ gg.setColor(currentTextColor);
+
+ String string = av.alignment.getSequenceAt(i).getDisplayId(av.
+ getShowJVSuffix());
+
+ gg.drawString(string, 0,
+ ( ( (i - starty) * av.charHeight) + av.charHeight) -
+ (av.charHeight / 5));
+
+ if (av.hasHiddenRows && av.showHiddenMarkers)
+ drawMarker(i, starty, 0);
+ }
+ }
+ }
+
+ public void setHighlighted(java.util.Vector found)
+ {
+ searchResults = found;
+ repaint();
+ }
+
+ void drawMarker(int i, int starty, int yoffset)
+ {
+ int hiddenIndex = av.adjustForHiddenSeqs(i);
+ int lastIndex = av.adjustForHiddenSeqs(i - 1);
+ int nextIndex = av.adjustForHiddenSeqs(i + 1);
+
+ boolean below = (hiddenIndex > lastIndex + 1);
+ boolean above = (nextIndex>hiddenIndex+1);
+
+ gg.setColor(Color.blue);
+ if(below)
+ {
+ gg.fillPolygon(new int[]
+ {getSize().width- av.charHeight,
+ getSize().width- av.charHeight,
+ getSize().width},
+ new int[]
+ {
+ (i - starty) * av.charHeight +yoffset,
+ (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,
+ (i - starty) * av.charHeight+yoffset
+ }, 3);
+ }
+ if(above)
+ {
+ gg.fillPolygon(new int[]
+ {getSize().width- av.charHeight,
+ getSize().width - av.charHeight,
+ getSize().width },
+ new int[]
+ {
+ (i - starty+1) * av.charHeight +yoffset,
+ (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,
+ (i - starty+1) * av.charHeight +yoffset
+ }, 3);
+
+ }
+ }
+
+ void setHiddenFont(int i)
+ {
+ /* System.out.println(i+" "+av.alignment.getHeight());
+ if (av.alignment.getSequenceAt(i).getHiddenSequences() != null)
+ gg.setFont(new Font(av.getFont().getName(), Font.BOLD,
+ av.getFont().getSize()));
+ else
+ gg.setFont(new Font(av.getFont().getName(), Font.ITALIC,
+ av.getFont().getSize()));*/
+ }
+}
diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java
index d159a4c..a04d7bf 100755
--- a/src/jalview/appletgui/IdPanel.java
+++ b/src/jalview/appletgui/IdPanel.java
@@ -1,350 +1,339 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-
-public class IdPanel
- extends Panel implements MouseListener, MouseMotionListener
-{
-
- protected IdCanvas idCanvas;
- protected AlignViewport av;
- protected AlignmentPanel alignPanel;
- ScrollThread scrollThread = null;
-
- int offy;
- int width;
- int lastid = -1;
- boolean mouseDragging = false;
- java.util.Vector links = new java.util.Vector();
-
- public IdPanel(AlignViewport av, AlignmentPanel parent)
- {
- this.av = av;
- alignPanel = parent;
- idCanvas = new IdCanvas(av);
- setLayout(new BorderLayout());
- add(idCanvas, BorderLayout.CENTER);
- idCanvas.addMouseListener(this);
- idCanvas.addMouseMotionListener(this);
-
- String label, url;
- if(parent.alignFrame.applet!=null)
- {
- for (int i = 1; i < 10; i++)
- {
- label = parent.alignFrame.applet.getParameter("linkLabel_" + i);
- url = parent.alignFrame.applet.getParameter("linkURL_" + i);
-
- if (label != null && url != null)
- links.addElement(label + "|" + url);
-
- }
- }
- if (links.size() < 1)
- {
- links = new java.util.Vector();
- links.addElement("SRS|http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[uniprot-all:$SEQUENCE_ID$]+-vn+2");
- }
- }
-
- public void mouseMoved(MouseEvent e)
- {}
-
- public void mouseDragged(MouseEvent e)
- {
- mouseDragging = true;
-
- int y = e.getY();
- if (av.getWrapAlignment())
- {
- y -= 2 * av.charHeight;
- }
- int seq = av.getIndex(y);
-
- if (seq < 0)
- {
- return;
- }
-
- if (seq < lastid)
- {
- selectSeqs(lastid - 1, seq);
- }
- else if (seq > lastid)
- {
- selectSeqs(lastid + 1, seq);
- }
-
- lastid = seq;
- alignPanel.repaint();
- }
-
- public void mouseClicked(MouseEvent e)
- {
- if (e.getClickCount() < 2)
- return;
-
- int y = e.getY();
-
- if (av.getWrapAlignment())
- {
- y -= (2 * av.charHeight);
- }
-
- //DEFAULT LINK IS FIRST IN THE LINK LIST
- int seq = av.getIndex(y);
- String id = av.getAlignment().getSequenceAt(seq).getName();
- if (id.indexOf("|") > -1)
- id = id.substring(id.lastIndexOf("|") + 1);
-
- String target = links.elementAt(0).toString();
- target = target.substring(0, target.indexOf("|"));
- String url = links.elementAt(0).toString();
- url = url.substring(url.indexOf("|")+1);
-
- int index = url.indexOf("$SEQUENCE_ID$");
- url = url.substring(0, index)+ id + url.substring(index+13);
-
- try
- {
-
- alignPanel.alignFrame.showURL(url, target);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- public void mouseEntered(MouseEvent e)
- {
- if (scrollThread != null)
- {
- scrollThread.running = false;
- }
- }
-
- public void mouseExited(MouseEvent e)
- {
- if (av.getWrapAlignment())
- {
- return;
- }
-
- if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
- {
- scrollThread = new ScrollThread(true);
- }
-
- if (mouseDragging && e.getY() >= getSize().height &&
- av.alignment.getHeight() > av.getEndSeq())
- {
- scrollThread = new ScrollThread(false);
- }
- }
-
- public void mousePressed(MouseEvent e)
- {
- if (e.getClickCount() >1 )
- {
- return;
- }
-
- int y = e.getY();
- if (av.getWrapAlignment())
- {
- y -= 2 * av.charHeight;
- }
-
- int seq = av.getIndex(y);
- if (seq == -1)
- {
- return;
- }
-
- if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) ==
- InputEvent.BUTTON3_MASK)
- {
- APopupMenu popup = new APopupMenu(alignPanel, (Sequence) av.getAlignment().getSequenceAt(seq), links);
- this.add(popup);
- popup.show(this, e.getX(), e.getY());
- return;
- }
-
- if (!e.isControlDown() && !e.isShiftDown() &&
- av.alignment.findGroup(av.alignment.getSequenceAt(seq)) != null)
- {
-
- SequenceGroup selection = new SequenceGroup();
- SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(seq));
- selection.setStartRes(0);
- selection.setEndRes(av.alignment.getWidth() - 1);
- for (int i = 0; i < sg.getSize(); i++)
- {
- selection.addSequence(sg.getSequenceAt(i), true);
- }
-
- av.setSelectionGroup(selection);
- return;
- }
-
- if (av.getSelectionGroup() == null ||
- (!e.isControlDown() && av.getSelectionGroup() != null))
- {
- av.setSelectionGroup(new SequenceGroup());
- }
-
- av.getSelectionGroup().setStartRes(0);
- av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
-
- if (e.isShiftDown() && lastid != -1)
- {
- selectSeqs(lastid, seq);
- }
- else
- {
- selectSeq(seq);
- }
-
- alignPanel.repaint();
- }
-
- void selectSeq(int seq)
- {
- lastid = seq;
- SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
- av.getSelectionGroup().addOrRemove(pickedSeq, false);
- }
-
- void selectSeqs(int start, int end)
- {
-
- lastid = start;
- if (end < start)
- {
- int tmp = start;
- start = end;
- end = tmp;
- lastid = end;
- }
-
- for (int i = start; i <= end; i++)
- {
- av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), false);
- }
-
- }
-
- public void mouseReleased(MouseEvent e)
- {
- if (scrollThread != null)
- {
- scrollThread.running = false;
- }
-
- if(av.getSelectionGroup()!=null)
- av.getSelectionGroup().recalcConservation();
-
- mouseDragging = false;
- PaintRefresher.Refresh(this, av.alignment);
- }
-
- public void highlightSearchResults(java.util.Vector found)
- {
- idCanvas.setHighlighted(found);
-
- if (found == null)
- {
- return;
- }
-
- int index = av.alignment.findIndex( (SequenceI) found.elementAt(0));
-
- // do we need to scroll the panel?
- if (av.getStartSeq() > index || av.getEndSeq() < index)
- {
- alignPanel.setScrollValues(av.getStartRes(), index);
- }
- }
-
- // this class allows scrolling off the bottom of the visible alignment
- class ScrollThread
- extends Thread
- {
- boolean running = false;
- boolean up = true;
- public ScrollThread(boolean up)
- {
- this.up = up;
- start();
- }
-
- public void stopScrolling()
- {
- running = false;
- }
-
- public void run()
- {
- running = true;
- while (running)
- {
- if (alignPanel.scrollUp(up))
- {
- // scroll was ok, so add new sequence to selection
- int seq = av.getStartSeq();
- if (!up)
- {
- seq = av.getEndSeq();
- }
-
- if (seq < lastid)
- {
- selectSeqs(lastid - 1, seq);
- }
- else if (seq > lastid)
- {
- selectSeqs(lastid + 1, seq);
- }
-
- lastid = seq;
- }
- else
- {
- running = false;
- }
-
- alignPanel.repaint();
- try
- {
- Thread.sleep(100);
- }
- catch (Exception ex)
- {}
- }
- }
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+
+public class IdPanel
+ extends Panel implements MouseListener, MouseMotionListener
+{
+
+ protected IdCanvas idCanvas;
+ protected AlignViewport av;
+ protected AlignmentPanel alignPanel;
+ ScrollThread scrollThread = null;
+
+ int offy;
+ int width;
+ int lastid = -1;
+ boolean mouseDragging = false;
+ java.util.Vector links = new java.util.Vector();
+
+ public IdPanel(AlignViewport av, AlignmentPanel parent)
+ {
+ this.av = av;
+ alignPanel = parent;
+ idCanvas = new IdCanvas(av);
+ setLayout(new BorderLayout());
+ add(idCanvas, BorderLayout.CENTER);
+ idCanvas.addMouseListener(this);
+ idCanvas.addMouseMotionListener(this);
+
+ String label, url;
+ if(av.applet!=null)
+ {
+ for (int i = 1; i < 10; i++)
+ {
+ label = av.applet.getParameter("linkLabel_" + i);
+ url = av.applet.getParameter("linkURL_" + i);
+
+ if (label != null && url != null)
+ links.addElement(label + "|" + url);
+
+ }
+ }
+ if (links.size() < 1)
+ {
+ links = new java.util.Vector();
+ links.addElement("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
+ }
+ }
+
+ Tooltip tooltip;
+ public void mouseMoved(MouseEvent e)
+ {
+ int seq = alignPanel.seqPanel.findSeq(e);
+
+ SequenceI sequence = av.getAlignment().getSequenceAt(seq);
+
+ if(sequence.getDescription()==null)
+ {
+ if(tooltip!=null)
+ tooltip.setVisible(false);
+ tooltip = null;
+ return;
+ }
+
+ if (tooltip == null)
+ tooltip = new Tooltip(
+ sequence.getDisplayId(true)
+ + "\n" + sequence.getDescription(), idCanvas);
+ else
+ tooltip.setTip(sequence.getDisplayId(true)
+ + "\n" + sequence.getDescription());
+
+ tooltip.repaint();
+
+ }
+
+ public void mouseDragged(MouseEvent e)
+ {
+ mouseDragging = true;
+
+ int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
+
+ if (seq < lastid)
+ {
+ selectSeqs(lastid - 1, seq);
+ }
+ else if (seq > lastid)
+ {
+ selectSeqs(lastid + 1, seq);
+ }
+
+ lastid = seq;
+ alignPanel.repaint();
+ }
+
+ public void mouseClicked(MouseEvent e)
+ {
+ if (e.getClickCount() < 2)
+ return;
+
+
+ //DEFAULT LINK IS FIRST IN THE LINK LIST
+ int seq = alignPanel.seqPanel.findSeq(e);
+ String id = av.getAlignment().getSequenceAt(seq).getName();
+ if (id.indexOf("|") > -1)
+ id = id.substring(id.lastIndexOf("|") + 1);
+
+ String target = links.elementAt(0).toString();
+ target = target.substring(0, target.indexOf("|"));
+ String url = links.elementAt(0).toString();
+ url = url.substring(url.indexOf("|")+1);
+
+ int index = url.indexOf("$SEQUENCE_ID$");
+ url = url.substring(0, index)+ id + url.substring(index+13);
+
+ try
+ {
+
+ alignPanel.alignFrame.showURL(url, target);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void mouseEntered(MouseEvent e)
+ {
+ if (scrollThread != null)
+ {
+ scrollThread.running = false;
+ }
+ }
+
+ public void mouseExited(MouseEvent e)
+ {
+ if (av.getWrapAlignment())
+ {
+ return;
+ }
+
+ if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
+ {
+ scrollThread = new ScrollThread(true);
+ }
+
+ if (mouseDragging && e.getY() >= getSize().height &&
+ av.alignment.getHeight() > av.getEndSeq())
+ {
+ scrollThread = new ScrollThread(false);
+ }
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ if (e.getClickCount() >1 )
+ {
+ return;
+ }
+
+ int y = e.getY();
+ if (av.getWrapAlignment())
+ {
+ y -= 2 * av.charHeight;
+ }
+
+ int seq = alignPanel.seqPanel.findSeq(e);
+
+ if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) ==
+ InputEvent.BUTTON3_MASK)
+ {
+ APopupMenu popup = new APopupMenu(alignPanel, (Sequence) av.getAlignment().getSequenceAt(seq), links);
+ this.add(popup);
+ popup.show(this, e.getX(), e.getY());
+ return;
+ }
+
+
+ if ((av.getSelectionGroup() == null) ||
+ ((!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
+ {
+ av.setSelectionGroup(new SequenceGroup());
+ av.getSelectionGroup().setStartRes(0);
+ av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
+ }
+
+
+ if (e.isShiftDown() && lastid != -1)
+ {
+ selectSeqs(lastid, seq);
+ }
+ else
+ {
+ selectSeq(seq);
+ }
+
+ alignPanel.repaint();
+ }
+
+ void selectSeq(int seq)
+ {
+ lastid = seq;
+ SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
+ av.getSelectionGroup().addOrRemove(pickedSeq, false);
+ }
+
+ void selectSeqs(int start, int end)
+ {
+
+ lastid = start;
+ if (end < start)
+ {
+ int tmp = start;
+ start = end;
+ end = tmp;
+ lastid = end;
+ }
+
+ for (int i = start; i <= end; i++)
+ {
+ av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), false);
+ }
+
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ if (scrollThread != null)
+ {
+ scrollThread.running = false;
+ }
+
+ if(av.getSelectionGroup()!=null)
+ av.getSelectionGroup().recalcConservation();
+
+ mouseDragging = false;
+ PaintRefresher.Refresh(this, av.alignment);
+ }
+
+ public void highlightSearchResults(java.util.Vector found)
+ {
+ idCanvas.setHighlighted(found);
+
+ if (found == null)
+ {
+ return;
+ }
+
+ int index = av.alignment.findIndex( (SequenceI) found.elementAt(0));
+
+ // do we need to scroll the panel?
+ if (av.getStartSeq() > index || av.getEndSeq() < index)
+ {
+ alignPanel.setScrollValues(av.getStartRes(), index);
+ }
+ }
+
+ // this class allows scrolling off the bottom of the visible alignment
+ class ScrollThread
+ extends Thread
+ {
+ boolean running = false;
+ boolean up = true;
+ public ScrollThread(boolean up)
+ {
+ this.up = up;
+ start();
+ }
+
+ public void stopScrolling()
+ {
+ running = false;
+ }
+
+ public void run()
+ {
+ running = true;
+ while (running)
+ {
+ if (alignPanel.scrollUp(up))
+ {
+ // scroll was ok, so add new sequence to selection
+ int seq = av.getStartSeq();
+ if (!up)
+ {
+ seq = av.getEndSeq();
+ }
+
+ if (seq < lastid)
+ {
+ selectSeqs(lastid - 1, seq);
+ }
+ else if (seq > lastid && seq 20 || dif > 0)
- {
- ap.setIdWidth(d.width + dif, d.height);
- this.setSize(d.width + dif, getSize().height);
- }
-
- oldX = evt.getX();
- }
-
- public void mouseMoved(MouseEvent evt)
- {}
-
- public void mouseClicked(MouseEvent evt)
- {}
-
- public void paint(Graphics g)
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, getSize().width, getSize().height);
- if (active)
- {
- if (image != null)
- {
- g.drawImage(image, getSize().width - 20, 2, this);
- }
- }
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class IdwidthAdjuster
+ extends Panel implements MouseListener, MouseMotionListener
+{
+ boolean active = false;
+ int oldX = 0;
+ Image image;
+ AlignmentPanel ap;
+
+ public IdwidthAdjuster(AlignmentPanel ap)
+ {
+ setLayout(null);
+ this.ap = ap;
+ java.net.URL url = getClass().getResource("/images/idwidth.gif");
+ if (url != null)
+ {
+ image = java.awt.Toolkit.getDefaultToolkit().getImage(url);
+ }
+
+ addMouseListener(this);
+ addMouseMotionListener(this);
+ }
+
+ public void mousePressed(MouseEvent evt)
+ {
+ oldX = evt.getX();
+ }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ active = false;
+ repaint();
+ }
+
+ public void mouseEntered(MouseEvent evt)
+ {
+ active = true;
+ repaint();
+ }
+
+ public void mouseExited(MouseEvent evt)
+ {
+ active = false;
+ repaint();
+ }
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ active = true;
+ Dimension d = ap.idPanel.idCanvas.getSize();
+ int dif = evt.getX() - oldX;
+
+ if (d.width + dif > 20 || dif > 0)
+ {
+ ap.setIdWidth(d.width + dif, d.height);
+ this.setSize(d.width + dif, getSize().height);
+ }
+
+ oldX = evt.getX();
+ }
+
+ public void mouseMoved(MouseEvent evt)
+ {}
+
+ public void mouseClicked(MouseEvent evt)
+ {}
+
+ public void paint(Graphics g)
+ {
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+ if (active)
+ {
+ if (image != null)
+ {
+ g.drawImage(image, getSize().width - 20, 2, this);
+ }
+ }
+ }
+
+}
diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java
index a4b7f06..2c7a2f2 100755
--- a/src/jalview/appletgui/OverviewPanel.java
+++ b/src/jalview/appletgui/OverviewPanel.java
@@ -1,374 +1,439 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.awt.event.*;
-
-public class OverviewPanel
- extends Panel implements Runnable, MouseMotionListener, MouseListener
-{
- Image miniMe;
- AlignViewport av;
- AlignmentPanel ap;
- float scalew = 1f;
- float scaleh = 1f;
-
- public int width, sequencesHeight;
- int graphHeight = 20;
- int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
-
- boolean resizing = false;
-
- // Can set different properties in this seqCanvas than
- // main visible SeqCanvas
- SequenceRenderer sr;
- FeatureRenderer fr;
-
-
- Frame nullFrame;
-
- public OverviewPanel(AlignmentPanel ap)
- {
- this.av = ap.av;
- this.ap = ap;
- setLayout(null);
- nullFrame = new Frame();
- nullFrame.addNotify();
-
-
- sr = new SequenceRenderer(av);
- sr.graphics = nullFrame.getGraphics();
- sr.renderGaps( false );
- sr.forOverview = true;
- fr = new FeatureRenderer(av);
- fr.overview = true;
-
-
-
- // scale the initial size of overviewpanel to shape of alignment
- float initialScale = (float) av.alignment.getWidth() /
- (float) av.alignment.getHeight();
-
- if(av.vconsensus==null)
- graphHeight = 0;
-
- if (av.alignment.getWidth() > av.alignment.getHeight())
- {
- // wider
- width = 400;
- sequencesHeight = (int) (400f / initialScale);
- if(sequencesHeight<40)
- sequencesHeight = 40;
- }
- else
- {
- // taller
- width = (int) (400f * initialScale);
- sequencesHeight = 300;
- if (width < 120)
- {
- width = 120;
- }
- }
-
- setSize(new Dimension(width, sequencesHeight + graphHeight));
- addComponentListener(new ComponentAdapter()
- {
-
- public void componentResized(ComponentEvent evt)
- {
- if (getSize().width != width ||
- getSize().height != sequencesHeight + graphHeight)
- {
- updateOverviewImage();
- }
- }
- });
-
- addMouseMotionListener(this);
-
- addMouseListener(this);
-
- updateOverviewImage();
-
- }
-
-
- public void mouseEntered(MouseEvent evt)
- {}
- public void mouseExited(MouseEvent evt)
- {}
- public void mouseClicked(MouseEvent evt)
- {}
- public void mouseMoved(MouseEvent evt)
- {}
- public void mousePressed(MouseEvent evt)
- {
- boxX = evt.getX();
- boxY = evt.getY();
-
- checkValid();
- repaint();
- }
-
- public void mouseReleased(MouseEvent evt)
- {
- boxX = evt.getX();
- boxY = evt.getY();
- checkValid();
- ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
- (int) (boxY / scaleh / av.getCharHeight()));
- }
-
- public void mouseDragged(MouseEvent evt)
- {
- boxX = evt.getX();
- boxY = evt.getY();
- checkValid();
- ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
- (int) (boxY / scaleh / av.getCharHeight()));
-
- repaint();
- ap.repaint();
- }
-
- void checkValid()
- {
- if (boxY < 0)
- {
- boxY = 0;
- }
-
- if (boxY > sequencesHeight - boxHeight)
- {
- boxY = sequencesHeight - boxHeight + 1;
- }
-
- if (boxX < 0)
- {
- boxX = 0;
- }
-
- if (boxX > width - boxWidth)
- {
- boxX = width - boxWidth;
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- public void updateOverviewImage()
- {
- if (resizing)
- {
- resizeAgain = true;
- return;
- }
-
- if (av.showSequenceFeatures)
- {
- fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
- fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
- }
-
- resizing = true;
-
- if ( (getSize().width > 0) && (getSize().height > 0))
- {
- width = getSize().width;
- sequencesHeight = getSize().height - graphHeight;
- }
- setSize(new Dimension(width, sequencesHeight + graphHeight));
- setBoxPosition();
-
- Thread thread = new Thread(this);
- thread.start();
- repaint();
- }
-
- // This is set true if the user resizes whilst
- // the overview is being calculated
- boolean resizeAgain = false;
-
- public void run()
- {
- miniMe = null;
- int alwidth = av.alignment.getWidth();
- int alheight = av.alignment.getHeight();
-
- if (av.showSequenceFeatures)
- {
- fr.renderOrder = ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;
- fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
- fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
- fr.sequenceFeatures = ap.seqPanel.seqCanvas.getFeatureRenderer().sequenceFeatures;
- }
-
- if (getSize().width > 0 && getSize().height > 0)
- {
- width = getSize().width;
- sequencesHeight = getSize().height - graphHeight;
- }
-
- setSize(new Dimension(width, sequencesHeight + graphHeight));
-
- int fullsizeWidth = alwidth * av.getCharWidth();
- int fullsizeHeight = alheight * av.getCharHeight();
-
- scalew = (float) width / (float) fullsizeWidth;
- scaleh = (float) sequencesHeight / (float) fullsizeHeight;
-
- miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
-
- Graphics mg = miniMe.getGraphics();
- float sampleCol = (float) alwidth / (float) width;
- float sampleRow = (float) alheight / (float) sequencesHeight;
-
- int lastcol=0, lastseq=0;
- int xstart=0, ystart=0;
- Color color = Color.yellow;
- int col, sameRow = 0, sameCol = 0;
- jalview.datamodel.SequenceI sequence;
-
- for (int row = 0; row <= sequencesHeight; row++)
- {
- if((int)(row*sampleRow)==lastseq)
- {
- sameRow ++;
- continue;
- }
-
- sequence = av.getAlignment().getSequenceAt(lastseq);
-
- for (col = 0; col < width; col++)
- {
- if((int)(col*sampleCol) == lastcol)
- {
- sameCol ++;
- continue;
- }
-
- lastcol = (int)(col*sampleCol);
-
- if(sequence.getLength()>lastcol)
- {
- color = sr.findSequenceColour(sequence, lastcol);
-
- if (av.showSequenceFeatures)
- color = fr.findFeatureColour(color,
- sequence,
- lastcol);
- }
- else
- color = color.white;
-
- mg.setColor(color);
- if (sameCol == 1 && sameRow == 1)
- mg.drawLine(xstart, ystart, xstart, ystart);
- else
- mg.fillRect(xstart, ystart, sameCol, sameRow);
-
- xstart = col;
- sameCol = 1;
- }
-
-
- lastseq = (int)(row*sampleRow);
- ystart = row;
- sameRow = 1;
- }
-
- if (av.conservation != null)
- {
- for (col = 0; col < width; col++)
- {
- lastcol = (int) (col * sampleCol);
- {
- mg.translate(col, sequencesHeight);
- ap.annotationPanel.drawGraph(mg, av.conservation,
- (int) (sampleCol) + 1,
- graphHeight,
- (int) (col * sampleCol),
- (int) (col * sampleCol) + 1);
- mg.translate( -col, -sequencesHeight);
- }
- }
- }
-
-
-
- System.gc();
-
- resizing = false;
-
- setBoxPosition();
-
- if(resizeAgain)
- {
- resizeAgain = false;
- updateOverviewImage();
- }
- }
-
- public void setBoxPosition()
- {
- int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
- int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();
-
- scalew = (float) width / (float) fullsizeWidth;
- scaleh = (float) sequencesHeight / (float) fullsizeHeight;
-
- boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
- boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
- boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *
- av.getCharWidth() * scalew);
- boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
- repaint();
- }
-
- public void update(Graphics g)
- {
- paint(g);
- }
-
- public void paint(Graphics g)
- {
- if (miniMe != null)
- {
- g.drawImage(miniMe, 0, 0, this);
- }
- else
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, getSize().width, getSize().height);
- g.setColor(Color.black);
- g.setFont(new Font("Verdana", Font.BOLD, 15));
- g.drawString("Recalculating", 5, sequencesHeight / 2);
- g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
- }
-
- g.setColor(Color.red);
- g.drawRect(boxX, boxY, boxWidth, boxHeight);
- g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class OverviewPanel
+ extends Panel implements Runnable, MouseMotionListener, MouseListener
+{
+ Image miniMe;
+ Image offscreen;
+ AlignViewport av;
+ AlignmentPanel ap;
+ float scalew = 1f;
+ float scaleh = 1f;
+
+ public int width, sequencesHeight;
+ int graphHeight = 20;
+ int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
+
+ boolean resizing = false;
+
+ // Can set different properties in this seqCanvas than
+ // main visible SeqCanvas
+ SequenceRenderer sr;
+ FeatureRenderer fr;
+
+
+ Frame nullFrame;
+
+ public OverviewPanel(AlignmentPanel ap)
+ {
+ this.av = ap.av;
+ this.ap = ap;
+ setLayout(null);
+ nullFrame = new Frame();
+ nullFrame.addNotify();
+
+
+ sr = new SequenceRenderer(av);
+ sr.graphics = nullFrame.getGraphics();
+ sr.renderGaps = false;
+ sr.forOverview = true;
+ fr = new FeatureRenderer(av);
+ fr.overview = true;
+
+
+
+ // scale the initial size of overviewpanel to shape of alignment
+ float initialScale = (float) av.alignment.getWidth() /
+ (float) av.alignment.getHeight();
+
+ if(av.vconsensus==null)
+ graphHeight = 0;
+
+ if (av.alignment.getWidth() > av.alignment.getHeight())
+ {
+ // wider
+ width = 400;
+ sequencesHeight = (int) (400f / initialScale);
+ if(sequencesHeight<40)
+ sequencesHeight = 40;
+ }
+ else
+ {
+ // taller
+ width = (int) (400f * initialScale);
+ sequencesHeight = 300;
+ if (width < 120)
+ {
+ width = 120;
+ }
+ }
+
+ setSize(new Dimension(width, sequencesHeight + graphHeight));
+ addComponentListener(new ComponentAdapter()
+ {
+
+ public void componentResized(ComponentEvent evt)
+ {
+ if (getSize().width != width ||
+ getSize().height != sequencesHeight + graphHeight)
+ {
+ updateOverviewImage();
+ }
+ }
+ });
+
+ addMouseMotionListener(this);
+
+ addMouseListener(this);
+
+ updateOverviewImage();
+
+ }
+
+
+ public void mouseEntered(MouseEvent evt)
+ {}
+ public void mouseExited(MouseEvent evt)
+ {}
+ public void mouseClicked(MouseEvent evt)
+ {}
+ public void mouseMoved(MouseEvent evt)
+ {}
+ public void mousePressed(MouseEvent evt)
+ {
+ boxX = evt.getX();
+ boxY = evt.getY();
+ checkValid();
+ }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ boxX = evt.getX();
+ boxY = evt.getY();
+ checkValid();
+ }
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ boxX = evt.getX();
+ boxY = evt.getY();
+ checkValid();
+ }
+
+ void checkValid()
+ {
+ if (boxY < 0)
+ {
+ boxY = 0;
+ }
+
+ if (boxY > (sequencesHeight - boxHeight))
+ {
+ boxY = sequencesHeight - boxHeight + 1;
+ }
+
+ if (boxX < 0)
+ {
+ boxX = 0;
+ }
+
+ if (boxX > (width - boxWidth))
+ {
+ if(av.hasHiddenColumns)
+ {
+ //Try smallest possible box
+ boxWidth = (int) ( (av.endRes - av.startRes + 1) *
+ av.getCharWidth() * scalew);
+ }
+ boxX = width - boxWidth;
+ }
+
+ int col = (int) (boxX / scalew / av.getCharWidth());
+ int row = (int) (boxY / scaleh / av.getCharHeight());
+
+ if (av.hasHiddenColumns)
+ {
+ if (!av.getColumnSelection().isVisible(col))
+ {
+ return;
+ }
+
+ col = av.getColumnSelection().findColumnPosition(col);
+ }
+
+ if( av.hasHiddenRows )
+ {
+ row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);
+ }
+
+ ap.setScrollValues( col, row );
+ ap.repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void updateOverviewImage()
+ {
+ if (resizing)
+ {
+ resizeAgain = true;
+ return;
+ }
+
+ if (av.showSequenceFeatures)
+ {
+ fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
+ fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
+ }
+
+ resizing = true;
+
+ if ( (getSize().width > 0) && (getSize().height > 0))
+ {
+ width = getSize().width;
+ sequencesHeight = getSize().height - graphHeight;
+ }
+ setSize(new Dimension(width, sequencesHeight + graphHeight));
+
+ Thread thread = new Thread(this);
+ thread.start();
+ repaint();
+ }
+
+ // This is set true if the user resizes whilst
+ // the overview is being calculated
+ boolean resizeAgain = false;
+
+ public void run()
+ {
+ miniMe = null;
+ int alwidth = av.alignment.getWidth();
+ int alheight = av.alignment.getHeight();
+
+ if (av.showSequenceFeatures)
+ {
+ fr.transferSettings( ap.seqPanel.seqCanvas.getFeatureRenderer() );
+ }
+
+ if (getSize().width > 0 && getSize().height > 0)
+ {
+ width = getSize().width;
+ sequencesHeight = getSize().height - graphHeight;
+ }
+
+ setSize(new Dimension(width, sequencesHeight + graphHeight));
+
+ int fullsizeWidth = alwidth * av.getCharWidth();
+ int fullsizeHeight = alheight * av.getCharHeight();
+
+ scalew = (float) width / (float) fullsizeWidth;
+ scaleh = (float) sequencesHeight / (float) fullsizeHeight;
+
+ miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
+ offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);
+
+ Graphics mg = miniMe.getGraphics();
+ float sampleCol = (float) alwidth / (float) width;
+ float sampleRow = (float) alheight / (float) sequencesHeight;
+
+ int lastcol=0, lastrow=0;
+ int xstart=0, ystart=0;
+ Color color = Color.yellow;
+ int row, col, sameRow = 0, sameCol = 0;
+ jalview.datamodel.SequenceI seq;
+ boolean hiddenRow = false;
+ for (row = 0; row <= sequencesHeight; row++)
+ {
+ if((int)(row*sampleRow)==lastrow)
+ {
+ sameRow ++;
+ continue;
+ }
+
+ hiddenRow = false;
+ if (av.hasHiddenRows)
+ {
+ seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
+ if (seq == null)
+ {
+ int index =
+ av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(lastrow);
+
+ seq = av.alignment.getSequenceAt(index);
+ }
+ else
+ {
+ hiddenRow = true;
+ }
+ }
+ else
+ seq = av.alignment.getSequenceAt(lastrow);
+
+ for (col = 0; col < width; col++)
+ {
+ if ( (int) (col * sampleCol) == lastcol && (int) (row * sampleRow) == lastrow)
+ {
+ sameCol ++;
+ continue;
+ }
+
+ lastcol = (int) (col * sampleCol);
+
+ if (seq.getLength() > lastcol)
+ {
+ color = sr.getResidueBoxColour(
+ seq, lastcol);
+
+ if (av.showSequenceFeatures)
+ color = fr.findFeatureColour(color, seq, lastcol);
+ }
+ else
+ {
+ color = Color.white; //White
+ }
+
+ if (hiddenRow ||
+ (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
+ {
+ color = color.darker().darker();
+ }
+
+ mg.setColor(color);
+ if (sameCol == 1 && sameRow == 1)
+ mg.drawLine(xstart, ystart, xstart, ystart);
+ else
+ mg.fillRect(xstart, ystart, sameCol, sameRow);
+
+ xstart = col;
+ sameCol = 1;
+ }
+ lastrow = (int)(row*sampleRow);
+ ystart = row;
+ sameRow = 1;
+ }
+
+ if (av.conservation != null)
+ {
+ for (col = 0; col < width; col++)
+ {
+ lastcol = (int) (col * sampleCol);
+ {
+ mg.translate(col, sequencesHeight);
+ ap.annotationPanel.drawGraph(mg, av.conservation,
+ (int) (sampleCol) + 1,
+ graphHeight,
+ (int) (col * sampleCol),
+ (int) (col * sampleCol) + 1);
+ mg.translate( -col, -sequencesHeight);
+ }
+ }
+ }
+ System.gc();
+
+ resizing = false;
+
+ setBoxPosition();
+
+ if(resizeAgain)
+ {
+ resizeAgain = false;
+ updateOverviewImage();
+ }
+}
+
+ public void setBoxPosition()
+ {
+ int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
+ int fullsizeHeight = (av.alignment.getHeight()
+ + av.alignment.getHiddenSequences().getSize()) *
+ av.getCharHeight();
+
+ int startRes = av.getStartRes();
+ int endRes = av.getEndRes();
+
+ if (av.hasHiddenColumns)
+ {
+ startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
+ endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
+ }
+
+ int startSeq = av.startSeq;
+ int endSeq = av.endSeq;
+
+ if (av.hasHiddenRows)
+ {
+ startSeq =
+ av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
+
+ endSeq =
+ av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
+
+ }
+
+ scalew = (float) width / (float) fullsizeWidth;
+ scaleh = (float) sequencesHeight / (float) fullsizeHeight;
+
+ boxX = (int) (startRes * av.getCharWidth() * scalew);
+ boxY = (int) (startSeq * av.getCharHeight() * scaleh);
+
+ if (av.hasHiddenColumns)
+ boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
+ else
+ boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
+
+ boxHeight = (int) ( (endSeq - startSeq) * av.getCharHeight() * scaleh);
+
+ repaint();
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void paint(Graphics g)
+ {
+ Graphics og = offscreen.getGraphics();
+ if (miniMe != null)
+ {
+ og.drawImage(miniMe, 0, 0, this);
+ og.setColor(Color.red);
+ og.drawRect(boxX, boxY, boxWidth, boxHeight);
+ og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
+ g.drawImage(offscreen, 0,0, this);
+ }
+ else
+ {
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 15));
+ g.drawString("Recalculating", 5, sequencesHeight / 2);
+ g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
+ }
+ }
+
+}
diff --git a/src/jalview/appletgui/PCAPanel.java b/src/jalview/appletgui/PCAPanel.java
index a75de06..de3fd32 100755
--- a/src/jalview/appletgui/PCAPanel.java
+++ b/src/jalview/appletgui/PCAPanel.java
@@ -1,258 +1,293 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.analysis.*;
-import jalview.datamodel.*;
-
-
-public class PCAPanel
- extends Frame implements Runnable, ActionListener, ItemListener
-{
- PCA pca;
- int top;
- RotatableCanvas rc;
- AlignViewport av;
- SequenceI [] seqs;
-
-
- public PCAPanel(AlignViewport av)
- {
- try
- {
- jbInit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- for (int i = 1; i < 8; i++)
- {
- xCombobox.addItem("dim " + i);
- yCombobox.addItem("dim " + i);
- zCombobox.addItem("dim " + i);
- }
-
- this.av = av;
- if (av.getSelectionGroup()!=null && av.getSelectionGroup().getSize() > 3)
- {
- seqs = new Sequence[av.getSelectionGroup().getSize()];
- for (int i = 0; i < av.getSelectionGroup().getSize(); i++)
- {
- seqs[i] = av.getSelectionGroup().getSequenceAt(i);
- }
- }
- else
- {
- seqs = new Sequence[av.getAlignment().getHeight()];
- for (int i = 0; i < av.getAlignment().getHeight(); i++)
- {
- seqs[i] = av.getAlignment().getSequenceAt(i);
- }
- }
-
- rc = new RotatableCanvas(av);
- add(rc, BorderLayout.CENTER);
-
- jalview.bin.JalviewLite.addFrame(this, "Principal component analysis",
- 400, 400);
-
-
- Thread worker = new Thread(this);
- worker.start();
- }
-
- /**
- * DOCUMENT ME!
- */
- public void run()
- {
- pca = new PCA(seqs);
- pca.run();
-
- // Now find the component coordinates
- int ii = 0;
-
- while ((ii < seqs.length) && (seqs[ii] != null))
- {
- ii++;
- }
-
- double[][] comps = new double[ii][ii];
-
- for (int i = 0; i < ii; i++)
- {
- if (pca.getEigenvalue(i) > 1e-4)
- {
- comps[i] = pca.component(i);
- }
- }
-
- //////////////////
- xCombobox.select(0);
- yCombobox.select(1);
- zCombobox.select(2);
-
- top = pca.getM().rows - 1;
-
- Vector points = new Vector();
- float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
-
- for (int i = 0; i < pca.getM().rows; i++)
- {
- SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
- points.addElement(sp);
- }
-
- rc.setPoints(points, pca.getM().rows);
- rc.repaint();
- seqs = null;
- this.repaint();
- }
-
- void doDimensionChange()
- {
- if (top == 0)
- {
- return;
- }
-
- int dim1 = top - xCombobox.getSelectedIndex();
- int dim2 = top - yCombobox.getSelectedIndex();
- int dim3 = top - zCombobox.getSelectedIndex();
-
- float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
- for (int i = 0; i < pca.getM().rows; i++)
- {
- ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];
- }
-
- rc.img = null;
- rc.rotmat.setIdentity();
- rc.initAxes();
- rc.paint(rc.getGraphics());
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- values_actionPerformed();
- }
-
- public void itemStateChanged(ItemEvent evt)
- {
- if(evt.getSource()==xCombobox)
- xCombobox_actionPerformed();
- else if(evt.getSource()==yCombobox)
- yCombobox_actionPerformed();
- else if(evt.getSource()==zCombobox)
- zCombobox_actionPerformed();
- }
-
-
- protected void xCombobox_actionPerformed()
- {
- doDimensionChange();
- }
-
- protected void yCombobox_actionPerformed()
- {
- doDimensionChange();
- }
-
- protected void zCombobox_actionPerformed()
- {
- doDimensionChange();
- }
-
- public void values_actionPerformed()
- {
-
- CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
- Frame frame = new Frame();
- frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame, "PCA details", 500, 500);
-
- cap.setText(pca.getDetails());
- }
-
- public void labels_itemStateChanged(ItemEvent itemEvent)
- {
- rc.showLabels( labels.getState() );
- }
- Panel jPanel2 = new Panel();
- Label jLabel1 = new Label();
- Label jLabel2 = new Label();
- Label jLabel3 = new Label();
- protected Choice xCombobox = new Choice();
- protected Choice yCombobox = new Choice();
- protected Choice zCombobox = new Choice();
- FlowLayout flowLayout1 = new FlowLayout();
- BorderLayout borderLayout1 = new BorderLayout();
- MenuBar menuBar1 = new MenuBar();
- Menu menu1 = new Menu();
- Menu menu2 = new Menu();
- protected CheckboxMenuItem labels = new CheckboxMenuItem();
- MenuItem values = new MenuItem();
-
- private void jbInit()
- throws Exception
- {
- this.setLayout(borderLayout1);
- jPanel2.setLayout(flowLayout1);
- jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
- jLabel1.setText("x=");
- jLabel2.setFont(new java.awt.Font("Verdana", 0, 12));
- jLabel2.setText("y=");
- jLabel3.setFont(new java.awt.Font("Verdana", 0, 12));
- jLabel3.setText("z=");
- jPanel2.setBackground(Color.white);
- zCombobox.setFont(new java.awt.Font("Verdana", 0, 12));
- zCombobox.addItemListener(this);
- yCombobox.setFont(new java.awt.Font("Verdana", 0, 12));
- yCombobox.addItemListener(this);
- xCombobox.setFont(new java.awt.Font("Verdana", 0, 12));
- xCombobox.addItemListener(this);
- this.setMenuBar(menuBar1);
- menu1.setLabel("File");
- menu2.setLabel("View");
- labels.setLabel("Labels");
- labels.addItemListener(this);
- values.setLabel("Output Values...");
- values.addActionListener(this);
- this.add(jPanel2, BorderLayout.SOUTH);
- jPanel2.add(jLabel1, null);
- jPanel2.add(xCombobox, null);
- jPanel2.add(jLabel2, null);
- jPanel2.add(yCombobox, null);
- jPanel2.add(jLabel3, null);
- jPanel2.add(zCombobox, null);
- menuBar1.add(menu1);
- menuBar1.add(menu2);
- menu2.add(labels);
- menu1.add(values);
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.analysis.*;
+import jalview.datamodel.*;
+
+
+public class PCAPanel
+ extends Frame implements Runnable, ActionListener, ItemListener
+{
+ PCA pca;
+ int top;
+ RotatableCanvas rc;
+ AlignViewport av;
+ SequenceI [] seqs;
+ AlignmentView seqstrings;
+
+
+ public PCAPanel(AlignViewport av)
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ for (int i = 1; i < 8; i++)
+ {
+ xCombobox.addItem("dim " + i);
+ yCombobox.addItem("dim " + i);
+ zCombobox.addItem("dim " + i);
+ }
+
+ this.av = av;
+ seqstrings = av.getAlignmentView(av.getSelectionGroup()!=null);
+ if(av.getSelectionGroup()==null)
+ {
+ seqs = av.alignment.getSequencesArray();
+ }
+ else
+ {
+ seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
+ }
+ SeqCigar sq[]=seqstrings.getSequences();
+ int length = sq[0].getWidth();
+
+ for (int i = 0; i < seqs.length; i++)
+ {
+ if (sq[i].getWidth() != length)
+ {
+ System.out.println("Sequences must be equal length for PCA analysis");
+ return;
+ }
+ }
+
+
+ rc = new RotatableCanvas(av);
+ add(rc, BorderLayout.CENTER);
+
+ jalview.bin.JalviewLite.addFrame(this, "Principal component analysis",
+ 400, 400);
+
+
+ Thread worker = new Thread(this);
+ worker.start();
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void run()
+ {
+ pca = new PCA(seqstrings.getSequenceStrings(' '));
+ pca.run();
+
+ // Now find the component coordinates
+ int ii = 0;
+
+ while ((ii < seqs.length) && (seqs[ii] != null))
+ {
+ ii++;
+ }
+
+ double[][] comps = new double[ii][ii];
+
+ for (int i = 0; i < ii; i++)
+ {
+ if (pca.getEigenvalue(i) > 1e-4)
+ {
+ comps[i] = pca.component(i);
+ }
+ }
+
+ //////////////////
+ xCombobox.select(0);
+ yCombobox.select(1);
+ zCombobox.select(2);
+
+ top = pca.getM().rows - 1;
+
+ Vector points = new Vector();
+ float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
+
+ for (int i = 0; i < pca.getM().rows; i++)
+ {
+ SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
+ points.addElement(sp);
+ }
+
+ rc.setPoints(points, pca.getM().rows);
+ rc.repaint();
+ seqs = null;
+ this.repaint();
+ }
+
+ void doDimensionChange()
+ {
+ if (top == 0)
+ {
+ return;
+ }
+
+ int dim1 = top - xCombobox.getSelectedIndex();
+ int dim2 = top - yCombobox.getSelectedIndex();
+ int dim3 = top - zCombobox.getSelectedIndex();
+
+ float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
+ for (int i = 0; i < pca.getM().rows; i++)
+ {
+ ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];
+ }
+
+ rc.img = null;
+ rc.rotmat.setIdentity();
+ rc.initAxes();
+ rc.paint(rc.getGraphics());
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource()==inputData)
+ showOriginalData();
+ else
+ values_actionPerformed();
+ }
+
+ public void itemStateChanged(ItemEvent evt)
+ {
+ if(evt.getSource()==xCombobox)
+ xCombobox_actionPerformed();
+ else if(evt.getSource()==yCombobox)
+ yCombobox_actionPerformed();
+ else if(evt.getSource()==zCombobox)
+ zCombobox_actionPerformed();
+ }
+
+
+ protected void xCombobox_actionPerformed()
+ {
+ doDimensionChange();
+ }
+
+ protected void yCombobox_actionPerformed()
+ {
+ doDimensionChange();
+ }
+
+ protected void zCombobox_actionPerformed()
+ {
+ doDimensionChange();
+ }
+
+ public void values_actionPerformed()
+ {
+
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame, "PCA details", 500, 500);
+
+ cap.setText(pca.getDetails());
+ }
+
+ void showOriginalData()
+ {
+ // decide if av alignment is sufficiently different to original data to warrant a new window to be created
+ // create new alignmnt window with hidden regions (unhiding hidden regions yields unaligned seqs)
+ // or create a selection box around columns in alignment view
+ // test Alignment(SeqCigar[])
+ Object[] alAndColsel = seqstrings.getAlignmentAndColumnSelection(av.
+ getGapCharacter());
+
+
+ if (alAndColsel != null && alAndColsel[0]!=null)
+ {
+ Alignment al = new Alignment( (SequenceI[]) alAndColsel[0]);
+ AlignFrame af = new AlignFrame(al,
+ av.applet,
+ "Original Data for PCA",
+ false);
+
+ af.viewport.setHiddenColumns( (ColumnSelection) alAndColsel[1] );
+ }
+ }
+
+ public void labels_itemStateChanged(ItemEvent itemEvent)
+ {
+ rc.showLabels( labels.getState() );
+ }
+ Panel jPanel2 = new Panel();
+ Label jLabel1 = new Label();
+ Label jLabel2 = new Label();
+ Label jLabel3 = new Label();
+ protected Choice xCombobox = new Choice();
+ protected Choice yCombobox = new Choice();
+ protected Choice zCombobox = new Choice();
+ FlowLayout flowLayout1 = new FlowLayout();
+ BorderLayout borderLayout1 = new BorderLayout();
+ MenuBar menuBar1 = new MenuBar();
+ Menu menu1 = new Menu();
+ Menu menu2 = new Menu();
+ protected CheckboxMenuItem labels = new CheckboxMenuItem();
+ MenuItem values = new MenuItem();
+ MenuItem inputData = new MenuItem();
+
+ private void jbInit()
+ throws Exception
+ {
+ this.setLayout(borderLayout1);
+ jPanel2.setLayout(flowLayout1);
+ jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
+ jLabel1.setText("x=");
+ jLabel2.setFont(new java.awt.Font("Verdana", 0, 12));
+ jLabel2.setText("y=");
+ jLabel3.setFont(new java.awt.Font("Verdana", 0, 12));
+ jLabel3.setText("z=");
+ jPanel2.setBackground(Color.white);
+ zCombobox.setFont(new java.awt.Font("Verdana", 0, 12));
+ zCombobox.addItemListener(this);
+ yCombobox.setFont(new java.awt.Font("Verdana", 0, 12));
+ yCombobox.addItemListener(this);
+ xCombobox.setFont(new java.awt.Font("Verdana", 0, 12));
+ xCombobox.addItemListener(this);
+ this.setMenuBar(menuBar1);
+ menu1.setLabel("File");
+ menu2.setLabel("View");
+ labels.setLabel("Labels");
+ labels.addItemListener(this);
+ values.setLabel("Output Values...");
+ values.addActionListener(this);
+ inputData.setLabel("Input Data...");
+ this.add(jPanel2, BorderLayout.SOUTH);
+ jPanel2.add(jLabel1, null);
+ jPanel2.add(xCombobox, null);
+ jPanel2.add(jLabel2, null);
+ jPanel2.add(yCombobox, null);
+ jPanel2.add(jLabel3, null);
+ jPanel2.add(zCombobox, null);
+ menuBar1.add(menu1);
+ menuBar1.add(menu2);
+ menu2.add(labels);
+ menu1.add(values);
+ menu1.add(inputData);
+ inputData.addActionListener(this);
+ }
+
+}
diff --git a/src/jalview/appletgui/PaintRefresher.java b/src/jalview/appletgui/PaintRefresher.java
index 9a220a4..4a10099 100755
--- a/src/jalview/appletgui/PaintRefresher.java
+++ b/src/jalview/appletgui/PaintRefresher.java
@@ -1,72 +1,72 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.util.*;
-import jalview.datamodel.*;
-
-public class PaintRefresher
-{
- static Hashtable components = new Hashtable();
-
- public static void Register(Component comp, AlignmentI al)
- {
- if(components.containsKey(al))
- {
- Vector comps = (Vector)components.get(al);
- comps.addElement(comp);
- }
- else
- {
- Vector vcoms = new Vector();
- vcoms.addElement(comp);
- components.put(al, vcoms);
- }
- }
-
- public static void Refresh(AlignmentI al)
- {
- Refresh(null, al);
- }
-
- public static void Refresh(Component c, AlignmentI al)
- {
- Component temp;
- Vector coms = (Vector)components.get(al);
- Enumeration e = coms.elements();
- while( e.hasMoreElements() )
- {
- temp = (Component)e.nextElement();
-
- if(!temp.isValid())
- coms.removeElement( temp );
- else if( temp == c )
- continue;
- else
- temp.repaint();
- }
-
- }
-
-}
-
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.util.*;
+import jalview.datamodel.*;
+
+public class PaintRefresher
+{
+ static Hashtable components = new Hashtable();
+
+ public static void Register(Component comp, AlignmentI al)
+ {
+ if(components.containsKey(al))
+ {
+ Vector comps = (Vector)components.get(al);
+ comps.addElement(comp);
+ }
+ else
+ {
+ Vector vcoms = new Vector();
+ vcoms.addElement(comp);
+ components.put(al, vcoms);
+ }
+ }
+
+ public static void Refresh(AlignmentI al)
+ {
+ Refresh(null, al);
+ }
+
+ public static void Refresh(Component c, AlignmentI al)
+ {
+ Component temp;
+ Vector coms = (Vector)components.get(al);
+ Enumeration e = coms.elements();
+ while( e.hasMoreElements() )
+ {
+ temp = (Component)e.nextElement();
+
+ if(!temp.isValid())
+ coms.removeElement( temp );
+ else if( temp == c )
+ continue;
+ else
+ temp.repaint();
+ }
+
+ }
+
+}
+
diff --git a/src/jalview/appletgui/PairwiseAlignPanel.java b/src/jalview/appletgui/PairwiseAlignPanel.java
index fc2bfb7..f3fc433 100755
--- a/src/jalview/appletgui/PairwiseAlignPanel.java
+++ b/src/jalview/appletgui/PairwiseAlignPanel.java
@@ -1,129 +1,170 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.event.*;
-
-import jalview.analysis.*;
-import jalview.datamodel.*;
-import java.awt.*;
-
-public class PairwiseAlignPanel
- extends Panel implements ActionListener
-{
- Vector sequences = new Vector();
- AlignmentPanel ap;
-
- public PairwiseAlignPanel(AlignmentPanel ap)
- {
- try
- {
- jbInit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- this.ap = ap;
- float scores[][] = new float[ap.av.alignment.getHeight()][ap.av.alignment.
- getHeight()];
- double totscore = 0;
- int count = ap.av.getSelectionGroup().getSize();
-
- int acount = 0;
- for (int i = 1; i < count; i++)
- {
- for (int j = 0; j < i; j++)
- {
- acount++;
- AlignSeq as = new AlignSeq(ap.av.getSelectionGroup().getSequenceAt(i),
- ap.av.getSelectionGroup().getSequenceAt(j),
- "pep");
-
- as.calcScoreMatrix();
- as.traceAlignment();
- as.printAlignment(System.out);
- scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;
- totscore = totscore + scores[i][j];
-
- textarea.append(as.getOutput());
- sequences.addElement(new Sequence(as.getS1().getName(), as.getAStr1()));
- sequences.addElement(new Sequence(as.getS2().getName(), as.getAStr2()));
-
- }
- }
-
- if (count > 2)
- {
- for (int i = 0; i < count; i++)
- {
- for (int j = 0; j < i; j++)
- {
- jalview.util.Format.print(System.out, "%7.3f",
- scores[i][j] / totscore);
- }
- }
- }
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource()==viewInEditorButton)
- viewInEditorButton_actionPerformed();
- }
-
- protected void viewInEditorButton_actionPerformed()
- {
-
- Sequence[] seq = new Sequence[sequences.size()];
-
- for (int i = 0; i < sequences.size(); i++)
- {
- seq[i] = (Sequence) sequences.elementAt(i);
- }
-
- new AlignFrame(new Alignment(seq),
- ap.alignFrame.applet,
- "Pairwise Aligned Sequences",
- false);
-
- }
- protected ScrollPane scrollPane = new ScrollPane();
- protected TextArea textarea = new TextArea();
- protected Button viewInEditorButton = new Button();
- Panel jPanel1 = new Panel();
- BorderLayout borderLayout1 = new BorderLayout();
-
- private void jbInit() throws Exception {
- this.setLayout(borderLayout1);
- textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
- textarea.setText("");
- viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
- viewInEditorButton.setLabel("View in alignment editor");
- viewInEditorButton.addActionListener(this);
- this.add(scrollPane, BorderLayout.CENTER);
- scrollPane.add(textarea);
- this.add(jPanel1, BorderLayout.SOUTH);
- jPanel1.add(viewInEditorButton, null);
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.event.*;
+
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import java.awt.*;
+
+public class PairwiseAlignPanel
+ extends Panel implements ActionListener
+{
+ Vector sequences = new Vector();
+ AlignmentPanel ap;
+
+ public PairwiseAlignPanel(AlignmentPanel ap)
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ this.ap = ap;
+ sequences = new Vector();
+
+ SequenceI[] seqs;
+ String[] seqStrings = ap.av.getViewAsString(true);
+
+ if (ap.av.getSelectionGroup() == null)
+ {
+ seqs = ap.av.alignment.getSequencesArray();
+ }
+ else
+ {
+ seqs = ap.av.getSelectionGroup().getSequencesInOrder(ap.av.alignment);
+ }
+
+ float scores[][] = new float[seqs.length][seqs.length];
+ double totscore = 0;
+ int count = ap.av.getSelectionGroup().getSize(false);
+
+ Sequence seq;
+
+ for (int i = 1; i < count; i++)
+ {
+ for (int j = 0; j < i; j++)
+ {
+
+ AlignSeq as = new AlignSeq(seqs[i], seqStrings[i],
+ seqs[j], seqStrings[j], "pep");
+
+ if (as.s1str.length() == 0 || as.s2str.length() == 0)
+ {
+ continue;
+ }
+
+ as.calcScoreMatrix();
+ as.traceAlignment();
+
+ as.printAlignment(System.out);
+ scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;
+ totscore = totscore + scores[i][j];
+
+ textarea.append(as.getOutput());
+ seq = new Sequence(as.getS1().getName(),
+ as.getAStr1(),
+ as.getS1().getStart(),
+ as.getS1().getEnd()
+ );
+ sequences.addElement(seq);
+
+ seq = new Sequence(as.getS2().getName(),
+ as.getAStr2(),
+ as.getS2().getStart(),
+ as.getS2().getEnd());
+ sequences.addElement(seq);
+ }
+ }
+
+ if (count > 2)
+ {
+ System.out.println(
+ "Pairwise alignment scaled similarity score matrix\n");
+
+ for (int i = 0; i < count; i++)
+ {
+ jalview.util.Format.print(System.out, "%s \n",
+ ("" + i) + " " +
+ seqs[i].getName());
+ }
+
+ System.out.println("\n");
+
+ for (int i = 0; i < count; i++)
+ {
+ for (int j = 0; j < i; j++)
+ {
+ jalview.util.Format.print(System.out, "%7.3f",
+ scores[i][j] / totscore);
+ }
+ }
+
+ System.out.println("\n");
+ }
+ }
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource()==viewInEditorButton)
+ viewInEditorButton_actionPerformed();
+ }
+
+ protected void viewInEditorButton_actionPerformed()
+ {
+
+ Sequence[] seq = new Sequence[sequences.size()];
+
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ seq[i] = (Sequence) sequences.elementAt(i);
+ }
+
+ new AlignFrame(new Alignment(seq),
+ ap.av.applet,
+ "Pairwise Aligned Sequences",
+ false);
+
+ }
+ protected ScrollPane scrollPane = new ScrollPane();
+ protected TextArea textarea = new TextArea();
+ protected Button viewInEditorButton = new Button();
+ Panel jPanel1 = new Panel();
+ BorderLayout borderLayout1 = new BorderLayout();
+
+ private void jbInit() throws Exception {
+ this.setLayout(borderLayout1);
+ textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
+ textarea.setText("");
+ viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
+ viewInEditorButton.setLabel("View in alignment editor");
+ viewInEditorButton.addActionListener(this);
+ this.add(scrollPane, BorderLayout.CENTER);
+ scrollPane.add(textarea);
+ this.add(jPanel1, BorderLayout.SOUTH);
+ jPanel1.add(viewInEditorButton, null);
+ }
+
+}
diff --git a/src/jalview/appletgui/RedundancyPanel.java b/src/jalview/appletgui/RedundancyPanel.java
index 504338a..2fe3576 100755
--- a/src/jalview/appletgui/RedundancyPanel.java
+++ b/src/jalview/appletgui/RedundancyPanel.java
@@ -1,129 +1,289 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-
-public class RedundancyPanel extends SliderPanel
-{
- AlignmentPanel ap;
-
- SequenceI[] oldAlignment;
-
- public RedundancyPanel(AlignmentPanel ap)
- {
- super(ap, 0, false, null);
-
- this.ap = ap;
-
- label.setText("Enter the redundancy threshold");
-
- slider.addAdjustmentListener(new AdjustmentListener()
- {
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- valueField.setText(slider.getValue() + "");
- }
- });
-
- slider.setMinimum(0);
- slider.setMaximum(100);
- slider.setValue(100);
-
- }
-
- public void applyButton_actionPerformed()
- {
- float threshold = slider.getValue();
- Vector del;
-
- oldAlignment = new SequenceI[ap.av.alignment.getHeight()];
- for (int i = 0; i < ap.av.alignment.getHeight(); i++)
- {
- oldAlignment[i] = new Sequence(ap.av.alignment.getSequenceAt(i).getName(),
- ap.av.alignment.getSequenceAt(i).
- getSequence());
- }
-
- undoButton.setEnabled(true);
-
- SequenceGroup sg = ap.av.getSelectionGroup();
- if (sg != null && sg.getSize() > 1)
- {
-
- del = ap.av.alignment.removeRedundancy(threshold, sg.sequences);
- for (int i = 0; i < del.size(); i++)
- {
- if (sg.sequences.contains( (SequenceI) del.elementAt(i)))
- {
- sg.deleteSequence( (SequenceI) del.elementAt(i), true);
- }
- }
-
- }
- else
- {
- Vector s = new Vector();
- int i = 0;
- while (i < ap.av.alignment.getHeight())
- {
- s.addElement(ap.av.alignment.getSequenceAt(i));
- i++;
- }
- del = ap.av.alignment.removeRedundancy(threshold, s);
- for (int j = 0; j < del.size(); j++)
- {
- if (sg.sequences.contains( (SequenceI) del.elementAt(j)))
- {
- sg.deleteSequence( (SequenceI) del.elementAt(j), true);
- }
-
- }
- }
-
- ap.repaint();
-
- }
-
- public void undoButton_actionPerformed()
- {
- undoButton.setEnabled(false);
- ap.av.setAlignment(new Alignment(oldAlignment));
- oldAlignment = null;
- ap.repaint();
- }
-
- public void valueField_actionPerformed(ActionEvent e)
- {
- try
- {
- int i = Integer.parseInt(valueField.getText());
- slider.setValue(i);
- }
- catch (Exception ex)
- {
- valueField.setText(slider.getValue() + "");
- }
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.event.*;
+
+import java.awt.*;
+
+import jalview.datamodel.*;
+import jalview.appletgui.PaintRefresher;
+
+public class RedundancyPanel extends SliderPanel implements Runnable, WindowListener
+{
+ AlignmentPanel ap;
+
+ Stack historyList = new Stack(); // simpler than synching with alignFrame.
+ float [] redundancy;
+ SequenceI [] originalSequences;
+ Frame frame;
+ Vector redundantSeqs;
+
+ public RedundancyPanel(AlignmentPanel ap)
+ {
+ super(ap, 0, false, null);
+
+ redundantSeqs = new Vector();
+ this.ap = ap;
+ undoButton.setVisible(true);
+ applyButton.setVisible(true);
+ allGroupsCheck.setVisible(false);
+
+ label.setText("Enter the redundancy threshold");
+ valueField.setText("100");
+
+ slider.setVisibleAmount(1);
+ slider.setMinimum(0);
+ slider.setMaximum(100+slider.getVisibleAmount());
+ slider.setValue(100);
+
+ slider.addAdjustmentListener(new AdjustmentListener()
+ {
+ public void adjustmentValueChanged(AdjustmentEvent evt)
+ {
+ valueField.setText(slider.getValue() + "");
+ sliderValueChanged();
+ }
+ });
+
+ frame = new Frame();
+ frame.add(this);
+ jalview.bin.JalviewLite.addFrame(frame, "Redundancy threshold selection",
+ 400, 100);
+
+ frame.addWindowListener(this);
+
+ Thread worker = new Thread(this);
+ worker.start();
+ }
+ /**
+ * This is a copy of remove redundancy in jalivew.datamodel.Alignment
+ * except we dont want to remove redundancy, just calculate once
+ * so we can use the slider to dynamically hide redundant sequences
+ *
+ * @param threshold DOCUMENT ME!
+ * @param sel DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public void run()
+ {
+ label.setText("Calculating....");
+
+ slider.setVisible(false);
+ applyButton.setEnabled(false);
+ valueField.setVisible(false);
+
+ validate();
+
+ String[] omitHidden = null;
+
+ SequenceGroup sg = ap.av.getSelectionGroup();
+ int height;
+
+ int start, end;
+
+ if ( (sg != null) && (sg.getSize(false) >= 1))
+ {
+ originalSequences = sg.getSequencesInOrder(ap.av.alignment);
+ start = sg.getStartRes();
+ end = sg.getEndRes();
+ }
+ else
+ {
+ originalSequences = ap.av.alignment.getSequencesArray();
+ start = 0;
+ end = ap.av.alignment.getWidth();
+ }
+
+ height = originalSequences.length;
+
+ redundancy = new float[height];
+ for (int i = 0; i < height; i++)
+ {
+ redundancy[i] = 0f;
+ }
+
+ // if (ap.av.hasHiddenColumns)
+ {
+ // omitHidden = ap.av.getSelectionAsString();
+ }
+
+
+ // long start = System.currentTimeMillis();
+
+ float pid;
+ String seqi, seqj;
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < i; j++)
+ {
+ if(i==j)
+ continue;
+
+ if(omitHidden==null)
+ {
+ seqi = originalSequences[i].getSequence(start, end);
+ seqj = originalSequences[j].getSequence(start, end);
+ }
+ else
+ {
+ seqi = omitHidden[i];
+ seqj = omitHidden[j];
+ }
+
+ pid = jalview.util.Comparison.PID( seqi, seqj );
+
+ if(seqj.length() < seqi.length())
+ redundancy[j] = Math.max(pid, redundancy[j]);
+ else
+ redundancy[i] = Math.max(pid, redundancy[i]);
+
+ }
+ }
+
+
+ label.setText("Enter the redundancy threshold");
+ slider.setVisible(true);
+ applyButton.setEnabled(true);
+ valueField.setVisible(true);
+
+ validate();
+ // System.out.println("blob done "+ (System.currentTimeMillis()-start));
+ }
+
+ void sliderValueChanged()
+ {
+ if(redundancy==null)
+ return;
+
+ float value = slider.getValue();
+
+ for(int i=0; i redundancy[i])
+ redundantSeqs.removeElement(originalSequences[i]);
+ else if(!redundantSeqs.contains(originalSequences[i]))
+ redundantSeqs.addElement(originalSequences[i]);
+ }
+
+ ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
+
+ PaintRefresher.Refresh(null,ap.av.alignment);
+
+ }
+ public void applyButton_actionPerformed()
+ {
+ historyList.push(new HistoryItem("Remove redundancy",
+ ap.av.alignment, HistoryItem.HIDE));
+
+ if ((historyList.size() == 1) ||
+ !ap.alignFrame.historyList.contains(historyList.firstElement()))
+ {
+ ap.alignFrame.addHistoryItem((HistoryItem) historyList.firstElement());
+ ap.alignFrame.updateEditMenuBar();
+ }
+
+ Vector del = new Vector();
+
+ undoButton.setEnabled(true);
+
+ float value = slider.getValue();
+ SequenceGroup sg = ap.av.getSelectionGroup();
+
+ for (int i = 0; i < redundancy.length; i++)
+ {
+ if (value <= redundancy[i])
+ {
+ SequenceI seq = originalSequences[i];
+ ap.av.alignment.deleteSequence(seq);
+ del.addElement(seq);
+ if (sg != null)
+ {
+ sg.deleteSequence(seq, false);
+ }
+ }
+ }
+
+
+ // This has to be done before the restoreHistoryItem method of alignFrame will
+ // actually restore these sequences.
+ if (del.size() > 0)
+ {
+ for (int i = 0, j = del.size(); i < j; i++)
+ {
+ SequenceI sq = (SequenceI) del.elementAt(i);
+ sq.deleteChars(0, sq.getLength());
+ }
+ }
+
+ ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
+ ap.alignFrame.updateEditMenuBar();
+
+ }
+
+ public void undoButton_actionPerformed()
+ {
+ HistoryItem hi = (HistoryItem) historyList.pop();
+ ap.alignFrame.restoreHistoryItem(hi);
+
+ if (historyList.size() == 0)
+ {
+ undoButton.setEnabled(false);
+ }
+ ap.alignFrame.updateEditMenuBar();
+ }
+
+ public void valueField_actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ int i = Integer.parseInt(valueField.getText());
+ slider.setValue(i);
+ }
+ catch (Exception ex)
+ {
+ valueField.setText(slider.getValue() + "");
+ }
+ }
+
+
+ public void windowOpened(WindowEvent evt)
+ {}
+
+ public void windowClosing(WindowEvent evt)
+ {
+ ap.idPanel.idCanvas.setHighlighted(null);
+ }
+
+ public void windowClosed(WindowEvent evt)
+ {}
+
+ public void windowActivated(WindowEvent evt)
+ {}
+ public void windowDeactivated(WindowEvent evt)
+ {}
+ public void windowIconified(WindowEvent evt)
+ {}
+ public void windowDeiconified(WindowEvent evt)
+ {}
+}
diff --git a/src/jalview/appletgui/RotatableCanvas.java b/src/jalview/appletgui/RotatableCanvas.java
index 370de5f..3edf819 100755
--- a/src/jalview/appletgui/RotatableCanvas.java
+++ b/src/jalview/appletgui/RotatableCanvas.java
@@ -1,619 +1,619 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-import jalview.math.*;
-import jalview.util.*;
-
-public class RotatableCanvas
- extends Panel implements MouseListener,
- MouseMotionListener,
- KeyListener
-{
- RotatableMatrix idmat = new RotatableMatrix(3, 3);
- RotatableMatrix objmat = new RotatableMatrix(3, 3);
- RotatableMatrix rotmat = new RotatableMatrix(3, 3);
- String tooltip;
- int toolx, tooly;
-
- //RubberbandRectangle rubberband;
-
- boolean drawAxes = true;
-
- int omx = 0;
- int mx = 0;
- int omy = 0;
- int my = 0;
-
- Image img;
- Graphics ig;
-
- Dimension prefsize;
-
- float centre[] = new float[3];
- float width[] = new float[3];
-
- float max[] = new float[3];
- float min[] = new float[3];
-
- float maxwidth;
- float scale;
-
- int npoint;
-
- Vector points;
- float[][] orig;
- float[][] axes;
-
- int startx;
- int starty;
-
- int lastx;
- int lasty;
-
- int rectx1;
- int recty1;
- int rectx2;
- int recty2;
-
- float scalefactor = 1;
-
- AlignViewport av;
- boolean showLabels = false;
-
- public RotatableCanvas(AlignViewport av)
- {
- this.av = av;
- }
-
- public void showLabels(boolean b)
- {
- showLabels = b;
- repaint();
- }
-
- public void setPoints(Vector points, int npoint)
- {
- this.points = points;
- this.npoint = npoint;
- PaintRefresher.Register(this, av.alignment);
-
- prefsize = getPreferredSize();
- orig = new float[npoint][3];
-
- for (int i = 0; i < npoint; i++)
- {
- SequencePoint sp = (SequencePoint) points.elementAt(i);
- for (int j = 0; j < 3; j++)
- {
- orig[i][j] = sp.coord[j];
- }
- }
- //Initialize the matrices to identity
-
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- if (i != j)
- {
- idmat.addElement(i, j, 0);
- objmat.addElement(i, j, 0);
- rotmat.addElement(i, j, 0);
- }
- else
- {
- idmat.addElement(i, j, 0);
- objmat.addElement(i, j, 0);
- rotmat.addElement(i, j, 0);
- }
- }
- }
-
- axes = new float[3][3];
- initAxes();
-
- findCentre();
- findWidth();
-
- scale = findScale();
-
- // System.out.println("Scale factor = " + scale);
-
- addMouseListener(this);
- addKeyListener(this);
- // if (getParent() != null) {
- // getParent().addKeyListener(this);
- //}
- addMouseMotionListener(this);
-
- // Add rubberband
- // rubberband = new RubberbandRectangle(this);
- // rubberband.setActive(true);
- // rubberband.addListener(this);
- }
-
- /* public boolean handleSequenceSelectionEvent(SequenceSelectionEvent evt) {
- redrawneeded = true;
- repaint();
- return true;
- }
-
- public void removeNotify() {
- controller.removeListener(this);
- super.removeNotify();
- }*/
-
- public void initAxes()
- {
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- if (i != j)
- {
- axes[i][j] = 0;
- }
- else
- {
- axes[i][j] = 1;
- }
- }
- }
- }
-
- public void findWidth()
- {
- max = new float[3];
- min = new float[3];
-
- max[0] = (float) - 1e30;
- max[1] = (float) - 1e30;
- max[2] = (float) - 1e30;
-
- min[0] = (float) 1e30;
- min[1] = (float) 1e30;
- min[2] = (float) 1e30;
-
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < npoint; j++)
- {
- SequencePoint sp = (SequencePoint) points.elementAt(j);
- if (sp.coord[i] >= max[i])
- {
- max[i] = sp.coord[i];
- }
- if (sp.coord[i] <= min[i])
- {
- min[i] = sp.coord[i];
- }
- }
- }
-
- // System.out.println("xmax " + max[0] + " min " + min[0]);
- //System.out.println("ymax " + max[1] + " min " + min[1]);
- //System.out.println("zmax " + max[2] + " min " + min[2]);
-
- width[0] = Math.abs(max[0] - min[0]);
- width[1] = Math.abs(max[1] - min[1]);
- width[2] = Math.abs(max[2] - min[2]);
-
- maxwidth = width[0];
-
- if (width[1] > width[0])
- {
- maxwidth = width[1];
- }
- if (width[2] > width[1])
- {
- maxwidth = width[2];
- }
-
- //System.out.println("Maxwidth = " + maxwidth);
- }
-
- public float findScale()
- {
- int dim, width, height;
- if (getSize().width != 0)
- {
- width = getSize().width;
- height = getSize().height;
- }
- else
- {
- width = prefsize.width;
- height = prefsize.height;
- }
-
- if (width < height)
- {
- dim = width;
- }
- else
- {
- dim = height;
- }
-
- return (float) (dim * scalefactor / (2 * maxwidth));
- }
-
- public void findCentre()
- {
- //Find centre coordinate
- findWidth();
-
- centre[0] = (max[0] + min[0]) / 2;
- centre[1] = (max[1] + min[1]) / 2;
- centre[2] = (max[2] + min[2]) / 2;
-
- // System.out.println("Centre x " + centre[0]);
- //System.out.println("Centre y " + centre[1]);
- //System.out.println("Centre z " + centre[2]);
- }
-
- public Dimension getPreferredSize()
- {
- if (prefsize != null)
- {
- return prefsize;
- }
- else
- {
- return new Dimension(400, 400);
- }
- }
-
- public Dimension getMinimumSize()
- {
- return getPreferredSize();
- }
-
- public void update(Graphics g)
- {
- paint(g);
- }
- public void paint(Graphics g)
- {
- if (points == null)
- {
- g.setFont(new Font("Verdana", Font.PLAIN, 18));
- g.drawString("Calculating PCA....", 20, getSize().height / 2);
- }
- else
- {
-
- //Only create the image at the beginning -
- if ( (img == null) || (prefsize.width != getSize().width) ||
- (prefsize.height != getSize().height))
- {
- prefsize.width = getSize().width;
- prefsize.height = getSize().height;
-
- scale = findScale();
-
- // System.out.println("New scale = " + scale);
- img = createImage(getSize().width, getSize().height);
- ig = img.getGraphics();
-
- }
-
- drawBackground(ig, Color.black);
- drawScene(ig);
- if (drawAxes == true)
- {
- drawAxes(ig);
- }
-
- if(tooltip!=null)
- {
- ig.setColor(Color.red);
- ig.drawString(tooltip, toolx, tooly);
- }
-
- g.drawImage(img, 0, 0, this);
- }
- }
-
- public void drawAxes(Graphics g)
- {
-
- g.setColor(Color.yellow);
- for (int i = 0; i < 3; i++)
- {
- g.drawLine(getSize().width / 2, getSize().height / 2,
- (int) (axes[i][0] * scale * max[0] + getSize().width / 2),
- (int) (axes[i][1] * scale * max[1] + getSize().height / 2));
- }
- }
-
- public void drawBackground(Graphics g, Color col)
- {
- g.setColor(col);
- g.fillRect(0, 0, prefsize.width, prefsize.height);
- }
-
- public void drawScene(Graphics g)
- {
- //boolean darker = false;
-
- int halfwidth = getSize().width / 2;
- int halfheight = getSize().height / 2;
-
- for (int i = 0; i < npoint; i++)
- {
- SequencePoint sp = (SequencePoint) points.elementAt(i);
- int x = (int) ( (float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
- int y = (int) ( (float) (sp.coord[1] - centre[1]) * scale) + halfheight;
- float z = sp.coord[1] - centre[2];
-
- if (sp.sequence.getColor() == Color.black)
- {
- g.setColor(Color.white);
- }
- else
- {
- g.setColor(sp.sequence.getColor());
- }
-
- if (av.getSelectionGroup() != null)
- {
- if (av.getSelectionGroup().sequences.contains( ( (SequencePoint) points.
- elementAt(i)).sequence))
- {
- g.setColor(Color.gray);
- }
- }
- if (z < 0)
- {
- g.setColor(g.getColor().darker());
- }
-
- g.fillRect(x - 3, y - 3, 6, 6);
- if (showLabels)
- {
- g.setColor(Color.red);
- g.drawString( ( (SequencePoint) points.elementAt(i)).sequence.
- getName(),
- x - 3, y - 4);
- }
- }
- }
-
- public Dimension minimumsize()
- {
- return prefsize;
- }
-
- public Dimension preferredsize()
- {
- return prefsize;
- }
-
- public void keyTyped(KeyEvent evt)
- {}
-
- public void keyReleased(KeyEvent evt)
- {}
-
- public void keyPressed(KeyEvent evt)
- {
- if (evt.getKeyCode() == KeyEvent.VK_UP)
- {
- scalefactor = (float) (scalefactor * 1.1);
- scale = findScale();
- }
- else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
- {
- scalefactor = (float) (scalefactor * 0.9);
- scale = findScale();
- }
- else if (evt.getKeyChar() == 's')
- {
- System.err.println("DEBUG: Rectangle selection"); // log.debug
- if (rectx2 != -1 && recty2 != -1)
- {
- rectSelect(rectx1, recty1, rectx2, recty2);
-
- }
- }
- repaint();
- }
-
- public void printPoints()
- {
- for (int i = 0; i < npoint; i++)
- {
- SequencePoint sp = (SequencePoint) points.elementAt(i);
- Format.print(System.out, "%5d ", i);
- for (int j = 0; j < 3; j++)
- {
- Format.print(System.out, "%13.3f ", sp.coord[j]);
- }
- System.out.println();
- }
- }
-
- public void mouseClicked(MouseEvent evt)
- {}
-
- public void mouseEntered(MouseEvent evt)
- {}
-
- public void mouseExited(MouseEvent evt)
- {}
-
- public void mouseReleased(MouseEvent evt)
- {}
-
- public void mousePressed(MouseEvent evt)
- {
- int x = evt.getX();
- int y = evt.getY();
-
- mx = x;
- my = y;
-
- omx = mx;
- omy = my;
-
- startx = x;
- starty = y;
-
- rectx1 = x;
- recty1 = y;
-
- rectx2 = -1;
- recty2 = -1;
-
- SequenceI found = findPoint(x, y);
-
- if (found != null)
- {
- if (av.getSelectionGroup() != null)
- {
- av.getSelectionGroup().addOrRemove(found, true);
- av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1);
- PaintRefresher.Refresh(this, av.alignment);
- }
- else
- {
- av.setSelectionGroup(new SequenceGroup());
- av.getSelectionGroup().addOrRemove(found, true);
- av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1);
-
- }
- }
- repaint();
- }
-
-
- public void mouseMoved(MouseEvent evt)
- {
- SequenceI found = findPoint(evt.getX(), evt.getY());
- if(found==null)
- tooltip = null;
- else
- {
- tooltip = found.getName();
- toolx = evt.getX();
- tooly = evt.getY();
- }
- repaint();
- }
-
- public void mouseDragged(MouseEvent evt)
- {
- mx = evt.getX();
- my = evt.getY();
-
- rotmat.setIdentity();
-
- rotmat.rotate( (float) (my - omy), 'x');
- rotmat.rotate( (float) (mx - omx), 'y');
-
- for (int i = 0; i < npoint; i++)
- {
- SequencePoint sp = (SequencePoint) points.elementAt(i);
- sp.coord[0] -= centre[0];
- sp.coord[1] -= centre[1];
- sp.coord[2] -= centre[2];
-
- //Now apply the rotation matrix
- sp.coord = rotmat.vectorMultiply(sp.coord);
-
- //Now translate back again
- sp.coord[0] += centre[0];
- sp.coord[1] += centre[1];
- sp.coord[2] += centre[2];
- }
-
- for (int i = 0; i < 3; i++)
- {
- axes[i] = rotmat.vectorMultiply(axes[i]);
- }
- omx = mx;
- omy = my;
-
- paint(this.getGraphics());
- }
-
- public void rectSelect(int x1, int y1, int x2, int y2)
- {
- //boolean changedSel = false;
- for (int i = 0; i < npoint; i++)
- {
- SequencePoint sp = (SequencePoint) points.elementAt(i);
- int tmp1 = (int) ( (sp.coord[0] - centre[0]) * scale +
- (float) getSize().width / 2.0);
- int tmp2 = (int) ( (sp.coord[1] - centre[1]) * scale +
- (float) getSize().height / 2.0);
-
- if (tmp1 > x1 && tmp1 < x2 && tmp2 > y1 && tmp2 < y2)
- {
- if (av != null)
- {
- if (!av.getSelectionGroup().sequences.contains(sp.sequence))
- {
- av.getSelectionGroup().addSequence(sp.sequence, true);
- }
- }
- }
- }
- }
-
- public SequenceI findPoint(int x, int y)
- {
-
- int halfwidth = getSize().width / 2;
- int halfheight = getSize().height / 2;
-
- int found = -1;
-
- for (int i = 0; i < npoint; i++)
- {
-
- SequencePoint sp = (SequencePoint) points.elementAt(i);
- int px = (int) ( (float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
- int py = (int) ( (float) (sp.coord[1] - centre[1]) * scale) + halfheight;
-
- if (Math.abs(px - x) < 3 && Math.abs(py - y) < 3)
- {
- found = i;
- }
- }
- if (found != -1)
- {
- return ( (SequencePoint) points.elementAt(found)).sequence;
- }
- else
- {
- return null;
- }
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+import jalview.math.*;
+import jalview.util.*;
+
+public class RotatableCanvas
+ extends Panel implements MouseListener,
+ MouseMotionListener,
+ KeyListener
+{
+ RotatableMatrix idmat = new RotatableMatrix(3, 3);
+ RotatableMatrix objmat = new RotatableMatrix(3, 3);
+ RotatableMatrix rotmat = new RotatableMatrix(3, 3);
+ String tooltip;
+ int toolx, tooly;
+
+ //RubberbandRectangle rubberband;
+
+ boolean drawAxes = true;
+
+ int omx = 0;
+ int mx = 0;
+ int omy = 0;
+ int my = 0;
+
+ Image img;
+ Graphics ig;
+
+ Dimension prefsize;
+
+ float centre[] = new float[3];
+ float width[] = new float[3];
+
+ float max[] = new float[3];
+ float min[] = new float[3];
+
+ float maxwidth;
+ float scale;
+
+ int npoint;
+
+ Vector points;
+ float[][] orig;
+ float[][] axes;
+
+ int startx;
+ int starty;
+
+ int lastx;
+ int lasty;
+
+ int rectx1;
+ int recty1;
+ int rectx2;
+ int recty2;
+
+ float scalefactor = 1;
+
+ AlignViewport av;
+ boolean showLabels = false;
+
+ public RotatableCanvas(AlignViewport av)
+ {
+ this.av = av;
+ }
+
+ public void showLabels(boolean b)
+ {
+ showLabels = b;
+ repaint();
+ }
+
+ public void setPoints(Vector points, int npoint)
+ {
+ this.points = points;
+ this.npoint = npoint;
+ PaintRefresher.Register(this, av.alignment);
+
+ prefsize = getPreferredSize();
+ orig = new float[npoint][3];
+
+ for (int i = 0; i < npoint; i++)
+ {
+ SequencePoint sp = (SequencePoint) points.elementAt(i);
+ for (int j = 0; j < 3; j++)
+ {
+ orig[i][j] = sp.coord[j];
+ }
+ }
+ //Initialize the matrices to identity
+
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ if (i != j)
+ {
+ idmat.addElement(i, j, 0);
+ objmat.addElement(i, j, 0);
+ rotmat.addElement(i, j, 0);
+ }
+ else
+ {
+ idmat.addElement(i, j, 0);
+ objmat.addElement(i, j, 0);
+ rotmat.addElement(i, j, 0);
+ }
+ }
+ }
+
+ axes = new float[3][3];
+ initAxes();
+
+ findCentre();
+ findWidth();
+
+ scale = findScale();
+
+ // System.out.println("Scale factor = " + scale);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ // if (getParent() != null) {
+ // getParent().addKeyListener(this);
+ //}
+ addMouseMotionListener(this);
+
+ // Add rubberband
+ // rubberband = new RubberbandRectangle(this);
+ // rubberband.setActive(true);
+ // rubberband.addListener(this);
+ }
+
+ /* public boolean handleSequenceSelectionEvent(SequenceSelectionEvent evt) {
+ redrawneeded = true;
+ repaint();
+ return true;
+ }
+
+ public void removeNotify() {
+ controller.removeListener(this);
+ super.removeNotify();
+ }*/
+
+ public void initAxes()
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ if (i != j)
+ {
+ axes[i][j] = 0;
+ }
+ else
+ {
+ axes[i][j] = 1;
+ }
+ }
+ }
+ }
+
+ public void findWidth()
+ {
+ max = new float[3];
+ min = new float[3];
+
+ max[0] = (float) - 1e30;
+ max[1] = (float) - 1e30;
+ max[2] = (float) - 1e30;
+
+ min[0] = (float) 1e30;
+ min[1] = (float) 1e30;
+ min[2] = (float) 1e30;
+
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < npoint; j++)
+ {
+ SequencePoint sp = (SequencePoint) points.elementAt(j);
+ if (sp.coord[i] >= max[i])
+ {
+ max[i] = sp.coord[i];
+ }
+ if (sp.coord[i] <= min[i])
+ {
+ min[i] = sp.coord[i];
+ }
+ }
+ }
+
+ // System.out.println("xmax " + max[0] + " min " + min[0]);
+ //System.out.println("ymax " + max[1] + " min " + min[1]);
+ //System.out.println("zmax " + max[2] + " min " + min[2]);
+
+ width[0] = Math.abs(max[0] - min[0]);
+ width[1] = Math.abs(max[1] - min[1]);
+ width[2] = Math.abs(max[2] - min[2]);
+
+ maxwidth = width[0];
+
+ if (width[1] > width[0])
+ {
+ maxwidth = width[1];
+ }
+ if (width[2] > width[1])
+ {
+ maxwidth = width[2];
+ }
+
+ //System.out.println("Maxwidth = " + maxwidth);
+ }
+
+ public float findScale()
+ {
+ int dim, width, height;
+ if (getSize().width != 0)
+ {
+ width = getSize().width;
+ height = getSize().height;
+ }
+ else
+ {
+ width = prefsize.width;
+ height = prefsize.height;
+ }
+
+ if (width < height)
+ {
+ dim = width;
+ }
+ else
+ {
+ dim = height;
+ }
+
+ return (float) (dim * scalefactor / (2 * maxwidth));
+ }
+
+ public void findCentre()
+ {
+ //Find centre coordinate
+ findWidth();
+
+ centre[0] = (max[0] + min[0]) / 2;
+ centre[1] = (max[1] + min[1]) / 2;
+ centre[2] = (max[2] + min[2]) / 2;
+
+ // System.out.println("Centre x " + centre[0]);
+ //System.out.println("Centre y " + centre[1]);
+ //System.out.println("Centre z " + centre[2]);
+ }
+
+ public Dimension getPreferredSize()
+ {
+ if (prefsize != null)
+ {
+ return prefsize;
+ }
+ else
+ {
+ return new Dimension(400, 400);
+ }
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return getPreferredSize();
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+ public void paint(Graphics g)
+ {
+ if (points == null)
+ {
+ g.setFont(new Font("Verdana", Font.PLAIN, 18));
+ g.drawString("Calculating PCA....", 20, getSize().height / 2);
+ }
+ else
+ {
+
+ //Only create the image at the beginning -
+ if ( (img == null) || (prefsize.width != getSize().width) ||
+ (prefsize.height != getSize().height))
+ {
+ prefsize.width = getSize().width;
+ prefsize.height = getSize().height;
+
+ scale = findScale();
+
+ // System.out.println("New scale = " + scale);
+ img = createImage(getSize().width, getSize().height);
+ ig = img.getGraphics();
+
+ }
+
+ drawBackground(ig, Color.black);
+ drawScene(ig);
+ if (drawAxes == true)
+ {
+ drawAxes(ig);
+ }
+
+ if(tooltip!=null)
+ {
+ ig.setColor(Color.red);
+ ig.drawString(tooltip, toolx, tooly);
+ }
+
+ g.drawImage(img, 0, 0, this);
+ }
+ }
+
+ public void drawAxes(Graphics g)
+ {
+
+ g.setColor(Color.yellow);
+ for (int i = 0; i < 3; i++)
+ {
+ g.drawLine(getSize().width / 2, getSize().height / 2,
+ (int) (axes[i][0] * scale * max[0] + getSize().width / 2),
+ (int) (axes[i][1] * scale * max[1] + getSize().height / 2));
+ }
+ }
+
+ public void drawBackground(Graphics g, Color col)
+ {
+ g.setColor(col);
+ g.fillRect(0, 0, prefsize.width, prefsize.height);
+ }
+
+ public void drawScene(Graphics g)
+ {
+ //boolean darker = false;
+
+ int halfwidth = getSize().width / 2;
+ int halfheight = getSize().height / 2;
+
+ for (int i = 0; i < npoint; i++)
+ {
+ SequencePoint sp = (SequencePoint) points.elementAt(i);
+ int x = (int) ( (float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
+ int y = (int) ( (float) (sp.coord[1] - centre[1]) * scale) + halfheight;
+ float z = sp.coord[1] - centre[2];
+
+ if (sp.sequence.getColor() == Color.black)
+ {
+ g.setColor(Color.white);
+ }
+ else
+ {
+ g.setColor(sp.sequence.getColor());
+ }
+
+ if (av.getSelectionGroup() != null)
+ {
+ if (av.getSelectionGroup().getSequences(false).contains( ( (SequencePoint) points.
+ elementAt(i)).sequence))
+ {
+ g.setColor(Color.gray);
+ }
+ }
+ if (z < 0)
+ {
+ g.setColor(g.getColor().darker());
+ }
+
+ g.fillRect(x - 3, y - 3, 6, 6);
+ if (showLabels)
+ {
+ g.setColor(Color.red);
+ g.drawString( ( (SequencePoint) points.elementAt(i)).sequence.
+ getName(),
+ x - 3, y - 4);
+ }
+ }
+ }
+
+ public Dimension minimumsize()
+ {
+ return prefsize;
+ }
+
+ public Dimension preferredsize()
+ {
+ return prefsize;
+ }
+
+ public void keyTyped(KeyEvent evt)
+ {}
+
+ public void keyReleased(KeyEvent evt)
+ {}
+
+ public void keyPressed(KeyEvent evt)
+ {
+ if (evt.getKeyCode() == KeyEvent.VK_UP)
+ {
+ scalefactor = (float) (scalefactor * 1.1);
+ scale = findScale();
+ }
+ else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+ {
+ scalefactor = (float) (scalefactor * 0.9);
+ scale = findScale();
+ }
+ else if (evt.getKeyChar() == 's')
+ {
+ System.err.println("DEBUG: Rectangle selection"); // log.debug
+ if (rectx2 != -1 && recty2 != -1)
+ {
+ rectSelect(rectx1, recty1, rectx2, recty2);
+
+ }
+ }
+ repaint();
+ }
+
+ public void printPoints()
+ {
+ for (int i = 0; i < npoint; i++)
+ {
+ SequencePoint sp = (SequencePoint) points.elementAt(i);
+ Format.print(System.out, "%5d ", i);
+ for (int j = 0; j < 3; j++)
+ {
+ Format.print(System.out, "%13.3f ", sp.coord[j]);
+ }
+ System.out.println();
+ }
+ }
+
+ public void mouseClicked(MouseEvent evt)
+ {}
+
+ public void mouseEntered(MouseEvent evt)
+ {}
+
+ public void mouseExited(MouseEvent evt)
+ {}
+
+ public void mouseReleased(MouseEvent evt)
+ {}
+
+ public void mousePressed(MouseEvent evt)
+ {
+ int x = evt.getX();
+ int y = evt.getY();
+
+ mx = x;
+ my = y;
+
+ omx = mx;
+ omy = my;
+
+ startx = x;
+ starty = y;
+
+ rectx1 = x;
+ recty1 = y;
+
+ rectx2 = -1;
+ recty2 = -1;
+
+ SequenceI found = findPoint(x, y);
+
+ if (found != null)
+ {
+ if (av.getSelectionGroup() != null)
+ {
+ av.getSelectionGroup().addOrRemove(found, true);
+ av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1);
+ PaintRefresher.Refresh(this, av.alignment);
+ }
+ else
+ {
+ av.setSelectionGroup(new SequenceGroup());
+ av.getSelectionGroup().addOrRemove(found, true);
+ av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1);
+
+ }
+ }
+ repaint();
+ }
+
+
+ public void mouseMoved(MouseEvent evt)
+ {
+ SequenceI found = findPoint(evt.getX(), evt.getY());
+ if(found==null)
+ tooltip = null;
+ else
+ {
+ tooltip = found.getName();
+ toolx = evt.getX();
+ tooly = evt.getY();
+ }
+ repaint();
+ }
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ mx = evt.getX();
+ my = evt.getY();
+
+ rotmat.setIdentity();
+
+ rotmat.rotate( (float) (my - omy), 'x');
+ rotmat.rotate( (float) (mx - omx), 'y');
+
+ for (int i = 0; i < npoint; i++)
+ {
+ SequencePoint sp = (SequencePoint) points.elementAt(i);
+ sp.coord[0] -= centre[0];
+ sp.coord[1] -= centre[1];
+ sp.coord[2] -= centre[2];
+
+ //Now apply the rotation matrix
+ sp.coord = rotmat.vectorMultiply(sp.coord);
+
+ //Now translate back again
+ sp.coord[0] += centre[0];
+ sp.coord[1] += centre[1];
+ sp.coord[2] += centre[2];
+ }
+
+ for (int i = 0; i < 3; i++)
+ {
+ axes[i] = rotmat.vectorMultiply(axes[i]);
+ }
+ omx = mx;
+ omy = my;
+
+ paint(this.getGraphics());
+ }
+
+ public void rectSelect(int x1, int y1, int x2, int y2)
+ {
+ //boolean changedSel = false;
+ for (int i = 0; i < npoint; i++)
+ {
+ SequencePoint sp = (SequencePoint) points.elementAt(i);
+ int tmp1 = (int) ( (sp.coord[0] - centre[0]) * scale +
+ (float) getSize().width / 2.0);
+ int tmp2 = (int) ( (sp.coord[1] - centre[1]) * scale +
+ (float) getSize().height / 2.0);
+
+ if (tmp1 > x1 && tmp1 < x2 && tmp2 > y1 && tmp2 < y2)
+ {
+ if (av != null)
+ {
+ if (!av.getSelectionGroup().getSequences(false).contains(sp.sequence))
+ {
+ av.getSelectionGroup().addSequence(sp.sequence, true);
+ }
+ }
+ }
+ }
+ }
+
+ public SequenceI findPoint(int x, int y)
+ {
+
+ int halfwidth = getSize().width / 2;
+ int halfheight = getSize().height / 2;
+
+ int found = -1;
+
+ for (int i = 0; i < npoint; i++)
+ {
+
+ SequencePoint sp = (SequencePoint) points.elementAt(i);
+ int px = (int) ( (float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
+ int py = (int) ( (float) (sp.coord[1] - centre[1]) * scale) + halfheight;
+
+ if (Math.abs(px - x) < 3 && Math.abs(py - y) < 3)
+ {
+ found = i;
+ }
+ }
+ if (found != -1)
+ {
+ return ( (SequencePoint) points.elementAt(found)).sequence;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+}
diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java
index af226f3..54d533e 100755
--- a/src/jalview/appletgui/ScalePanel.java
+++ b/src/jalview/appletgui/ScalePanel.java
@@ -1,218 +1,424 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-
-public class ScalePanel
- extends Panel
-{
-
- protected int offy = 4;
- public int width;
-
- protected AlignViewport av;
- AlignmentPanel ap;
-
- boolean stretchingGroup = false;
-
- public ScalePanel(AlignViewport av, AlignmentPanel ap)
- {
- setLayout(null);
- this.av = av;
- this.ap = ap;
-
- addMouseListener(new MouseAdapter()
- {
- public void mousePressed(MouseEvent evt)
- {
- doMousePressed(evt);
- }
-
- public void mouseReleased(MouseEvent evt)
- {
- doMouseReleased(evt);
- }
-
- });
- addMouseMotionListener(new MouseMotionAdapter()
- {
- public void mouseDragged(MouseEvent evt)
- {
- doMouseDragged(evt);
- }
- });
-
- }
-
- public void doMousePressed(MouseEvent evt)
- {
- int x = evt.getX();
- int res = x / av.getCharWidth() + av.getStartRes();
- SequenceGroup sg = null;
-
- if (av.getColumnSelection().contains(res))
- {
- av.getColumnSelection().removeElement(res);
- }
- else
- {
- av.getColumnSelection().addElement(res);
-
- sg = new SequenceGroup();
- for (int i = 0; i < av.alignment.getSequences().size(); i++)
- {
- sg.addSequence(av.alignment.getSequenceAt(i), false);
- }
-
- sg.setStartRes(res);
- sg.setEndRes(res);
-
- ap.annotationPanel.addEditableColumn(res);
- }
- av.setSelectionGroup(sg);
- ap.repaint();
- }
-
- public void doMouseReleased(MouseEvent evt)
- {
- if (!stretchingGroup)
- {
- return;
- }
-
- int x = evt.getX();
- int res = x / av.getCharWidth() + av.getStartRes();
-
- if (!av.getColumnSelection().contains(res))
- {
- av.getColumnSelection().addElement(res);
- }
-
- SequenceGroup sg = av.getSelectionGroup();
-
- if (res > sg.getStartRes())
- {
- sg.setEndRes(res);
- }
- else if (res < sg.getStartRes())
- {
- sg.setStartRes(res);
- }
-
- stretchingGroup = false;
- ap.repaint();
- }
-
- public void doMouseDragged(MouseEvent evt)
- {
- int x = evt.getX();
- int res = x / av.getCharWidth() + av.getStartRes();
-
- SequenceGroup sg = av.getSelectionGroup();
- if (sg != null)
- {
- stretchingGroup = true;
- if (res > sg.getStartRes())
- {
- sg.setEndRes(res);
- }
- else if (res < sg.getStartRes())
- {
- sg.setStartRes(res);
- }
-
- ap.annotationPanel.addEditableColumn(res);
- ap.repaint();
- }
- }
-
- public void update(Graphics g)
- {
- paint(g);
- }
-
- public void paint(Graphics g)
- {
- drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
- getSize().height);
- }
-
-// scalewidth will normally be screenwidth,
- public void drawScale(Graphics gg, int startx, int endx, int width,
- int height)
- {
- gg.setFont(av.getFont());
-
- //Fill in the background
- gg.setColor(Color.white);
- gg.fillRect(0, 0, width, height);
- gg.setColor(Color.black);
-
- //Fill the selected columns
- ColumnSelection cs = av.getColumnSelection();
- gg.setColor(new Color(220, 0, 0));
- for (int i = 0; i < cs.size(); i++)
- {
- int sel = cs.columnAt(i);
- if (sel >= startx && sel <= endx)
- {
- gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,
- getSize().height);
- }
- }
-
- // Draw the scale numbers
- gg.setColor(Color.black);
- int scalestartx = (startx / 10) * 10;
-
- FontMetrics fm = gg.getFontMetrics(av.getFont());
- int y = av.charHeight - fm.getDescent();
-
- if (scalestartx % 10 == 0)
- {
- scalestartx += 5;
- }
-
- for (int i = scalestartx; i < endx; i += 5)
- {
- if (i % 10 == 0)
- {
- gg.drawString(String.valueOf(i), (i - startx - 1) * av.charWidth, y);
- gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
- y + 2,
- (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
- y + fm.getDescent() * 2);
- }
- else
- {
- gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
- y + fm.getDescent(),
- (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
- y + fm.getDescent() * 2);
- }
-
- }
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+
+public class ScalePanel
+ extends Panel implements MouseMotionListener, MouseListener
+{
+
+ protected int offy = 4;
+ public int width;
+
+ protected AlignViewport av;
+ AlignmentPanel ap;
+
+ boolean stretchingGroup = false;
+ int min; //used by mouseDragged to see if user
+ int max; //used by mouseDragged to see if user
+ boolean mouseDragging = false;
+ int [] reveal;
+
+ public ScalePanel(AlignViewport av, AlignmentPanel ap)
+ {
+ setLayout(null);
+ this.av = av;
+ this.ap = ap;
+
+ addMouseListener(this);
+ addMouseMotionListener(this);
+
+ }
+
+ public void mousePressed(MouseEvent evt)
+ {
+ int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();
+ final int res;
+
+ if (av.hasHiddenColumns)
+ res = av.getColumnSelection().adjustForHiddenColumns(x);
+ else
+ res = x;
+
+ min = res;
+ max = res;
+ if ((evt.getModifiers() & InputEvent.BUTTON3_MASK)
+ == InputEvent.BUTTON3_MASK)
+ {
+ PopupMenu pop = new PopupMenu();
+ if (reveal != null)
+ {
+ MenuItem item = new MenuItem("Reveal");
+ item.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ av.showColumn(reveal[0]);
+ reveal = null;
+ ap.repaint();
+ if (ap.overviewPanel != null)
+ ap.overviewPanel.updateOverviewImage();
+ }
+ });
+ pop.add(item);
+
+ if (av.getColumnSelection().getHiddenColumns().size() > 1)
+ {
+ item = new MenuItem("Reveal All");
+ item.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ av.showAllHiddenColumns();
+ reveal = null;
+ ap.repaint();
+ if (ap.overviewPanel != null)
+ ap.overviewPanel.updateOverviewImage();
+ }
+ });
+ pop.add(item);
+ }
+ this.add(pop);
+ pop.show(this, evt.getX(), evt.getY());
+ }
+ else if (av.getColumnSelection().contains(res))
+ {
+ MenuItem item = new MenuItem("Hide Columns");
+ item.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ av.hideColumns(res, res);
+ if (av.getSelectionGroup() != null
+ &&
+ av.getSelectionGroup().getSize(false) == av.alignment.getHeight())
+ av.setSelectionGroup(null);
+
+ ap.repaint();
+ if (ap.overviewPanel != null)
+ ap.overviewPanel.updateOverviewImage();
+ }
+ });
+ pop.add(item);
+ this.add(pop);
+ pop.show(this, evt.getX(), evt.getY());
+ }
+ }
+ else // LEFT MOUSE TO SELECT
+ {
+ if (!evt.isControlDown() && !evt.isShiftDown())
+ {
+ av.getColumnSelection().clear();
+ }
+
+ av.getColumnSelection().addElement(res);
+ SequenceGroup sg = new SequenceGroup();
+ for (int i = 0; i < av.alignment.getSequences().size(); i++)
+ {
+ sg.addSequence(av.alignment.getSequenceAt(i), false);
+ }
+
+ sg.setStartRes(res);
+ sg.setEndRes(res);
+ av.setSelectionGroup(sg);
+
+ if(evt.isShiftDown())
+ {
+ int min = Math.min(av.getColumnSelection().getMin(), res);
+ int max = Math.max(av.getColumnSelection().getMax(), res);
+ for (int i = min; i av.alignment.getWidth())
+ {
+ res = av.alignment.getWidth()-1;
+ }
+
+ if(av.hasHiddenColumns)
+ res = av.getColumnSelection().adjustForHiddenColumns(res);
+
+ if (!stretchingGroup)
+ {
+ ap.repaint();
+
+ return;
+ }
+
+ SequenceGroup sg = av.getSelectionGroup();
+
+ if (res > sg.getStartRes())
+ {
+ sg.setEndRes(res);
+ }
+ else if (res < sg.getStartRes())
+ {
+ sg.setStartRes(res);
+ }
+
+ stretchingGroup = false;
+ ap.repaint();
+ }
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ mouseDragging = true;
+
+ int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
+ if (res < 0)
+ res = 0;
+
+ if (av.hasHiddenColumns)
+ res = av.getColumnSelection().adjustForHiddenColumns(res);
+
+ if (res > av.alignment.getWidth())
+ {
+ res = av.alignment.getWidth() - 1;
+ }
+
+ if (res < min)
+ {
+ min = res;
+ }
+
+ if (res > max)
+ {
+ max = res;
+ }
+
+ SequenceGroup sg = av.getSelectionGroup();
+
+ if (sg != null)
+ {
+ stretchingGroup = true;
+
+ if (!av.getColumnSelection().contains(res))
+ {
+ av.getColumnSelection().addElement(res);
+ }
+
+ if (res > sg.getStartRes())
+ {
+ sg.setEndRes(res);
+ }
+ if (res < sg.getStartRes())
+ {
+ sg.setStartRes(res);
+ }
+
+ for (int i = min; i <= max; i++)
+ {
+ if ( (i < sg.getStartRes()) || (i > sg.getEndRes()))
+ {
+ av.getColumnSelection().removeElement(i);
+ }
+ else
+ {
+ av.getColumnSelection().addElement(i);
+ }
+ }
+
+ ap.repaint();
+ }
+ }
+
+
+ public void mouseEntered(MouseEvent evt)
+ {
+ if (mouseDragging)
+ ap.seqPanel.scrollCanvas(null);
+ }
+
+ public void mouseExited(MouseEvent evt)
+ {
+ if (mouseDragging)
+ ap.seqPanel.scrollCanvas(evt);
+ }
+
+ public void mouseClicked(MouseEvent evt)
+ {
+
+ }
+
+ public void mouseMoved(MouseEvent evt)
+ {
+ if (!av.hasHiddenColumns)
+ return;
+
+ int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
+
+ res = av.getColumnSelection().adjustForHiddenColumns(res);
+
+ reveal = null;
+ for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
+ {
+ int[] region = (int[]) av.getColumnSelection().getHiddenColumns().
+ elementAt(i);
+ if (res + 1 == region[0] || res - 1 == region[1])
+ {
+ reveal = region;
+ break;
+ }
+ }
+
+ repaint();
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void paint(Graphics g)
+ {
+ drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
+ getSize().height);
+ }
+
+// scalewidth will normally be screenwidth,
+ public void drawScale(Graphics gg, int startx, int endx, int width,
+ int height)
+ {
+ gg.setFont(av.getFont());
+
+
+ //Fill in the background
+ gg.setColor(Color.white);
+ gg.fillRect(0, 0, width, height);
+ gg.setColor(Color.black);
+
+ //Fill the selected columns
+ ColumnSelection cs = av.getColumnSelection();
+ gg.setColor(new Color(220, 0, 0));
+
+ for (int i = 0; i < cs.size(); i++)
+ {
+ int sel = cs.columnAt(i);
+ if(av.hasHiddenColumns)
+ sel = av.getColumnSelection().findColumnPosition(sel);
+
+
+ if ((sel >= startx) && (sel <= endx))
+ {
+ gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
+ getSize().height);
+ }
+ }
+
+ // Draw the scale numbers
+ gg.setColor(Color.black);
+
+ int scalestartx = (startx / 10) * 10;
+
+ FontMetrics fm = gg.getFontMetrics(av.getFont());
+ int y = av.charHeight - fm.getDescent();
+
+ if ((scalestartx % 10) == 0)
+ {
+ scalestartx += 5;
+ }
+
+ String string;
+ int maxX=0;
+
+ for (int i = scalestartx; i < endx; i += 5)
+ {
+ if ((i % 10) == 0)
+ {
+ string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i));
+ if ( (i - startx - 1) * av.charWidth > maxX)
+ {
+ gg.drawString(string,
+ (i - startx - 1) * av.charWidth, y);
+ maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
+ }
+
+ gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
+ (av.charWidth / 2)), y + 2,
+ (int) ( ( (i - startx - 1) * av.charWidth) +
+ (av.charWidth / 2)),
+ y + (fm.getDescent() * 2));
+
+ }
+ else
+ {
+ gg.drawLine((int) (((i - startx - 1) * av.charWidth) +
+ (av.charWidth / 2)), y + fm.getDescent(),
+ (int) (((i - startx - 1) * av.charWidth) +
+ (av.charWidth / 2)), y + (fm.getDescent() * 2));
+ }
+ }
+
+ if (av.hasHiddenColumns)
+ {
+ gg.setColor(Color.blue);
+ int res;
+ if(av.getShowHiddenMarkers())
+ {
+ for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size();
+ i++)
+ {
+
+ res = av.getColumnSelection().findHiddenRegionPosition(i) -
+ startx;
+
+ if(res < 0 || res > endx-scalestartx)
+ continue;
+
+ gg.fillPolygon(new int[]
+ {res * av.charWidth - av.charHeight / 4,
+ res * av.charWidth + av.charHeight / 4,
+ res * av.charWidth},
+ new int[]
+ {
+ y - av.charHeight / 2, y - av.charHeight / 2,
+ y + 8
+ }, 3);
+
+ }
+ }
+
+ if (reveal != null && reveal[0] > startx && reveal[0] < endx)
+ {
+ gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0);
+ }
+ }
+
+ }
+
+}
diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java
index 465dd38..0cd2ae2 100755
--- a/src/jalview/appletgui/SeqCanvas.java
+++ b/src/jalview/appletgui/SeqCanvas.java
@@ -1,640 +1,790 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-
-import jalview.datamodel.*;
-
-public class SeqCanvas
- extends Panel
-{
- FeatureRenderer fr;
- SequenceRenderer sr;
- Image img;
- Graphics gg;
- int imgWidth;
- int imgHeight;
-
- AlignViewport av;
-
- SearchResults searchResults = null;
-
- int chunkHeight;
- int chunkWidth;
-
- boolean fastPaint = false;
-
-
- public SeqCanvas(AlignViewport av)
- {
- this.av = av;
- fr = new FeatureRenderer(av);
- sr = new SequenceRenderer(av);
- PaintRefresher.Register(this, av.alignment);
- }
-
- public AlignViewport getViewport()
- {
- return av;
- }
-
- public FeatureRenderer getFeatureRenderer()
- {
- return fr;
- }
-
- MCview.AppletPDBCanvas pdbCanvas;
- public SequenceRenderer getSequenceRenderer()
- {
- return sr;
- }
-
- public void setPDBCanvas(MCview.AppletPDBCanvas pc)
- {
- pdbCanvas = pc;
- }
-
-
- void drawNorthScale(Graphics g, int startx, int endx, int ypos)
- {
- int scalestartx = startx - startx % 10 + 10;
-
- g.setColor(Color.black);
-
- // NORTH SCALE
- for (int i = scalestartx; i < endx; i += 10)
- {
- String string = String.valueOf(i);
- g.drawString(string, (i - startx - 1) * av.charWidth,
- ypos - av.charHeight / 2);
-
- g.drawLine( (i - startx - 1) * av.charWidth + av.charWidth / 2,
- ypos + 2 - av.charHeight / 2,
- (i - startx - 1) * av.charWidth + av.charWidth / 2, ypos - 2);
-
- }
- }
-
- void drawWestScale(Graphics g, int startx, int endx, int ypos)
- {
- FontMetrics fm = getFontMetrics(av.getFont());
- ypos += av.charHeight;
- // EAST SCALE
- for (int i = 0; i < av.alignment.getHeight(); i++)
- {
- SequenceI seq = av.alignment.getSequenceAt(i);
- int index = startx;
- int value = -1;
- while (index < endx)
- {
- if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
- {
- index++;
- continue;
- }
-
- value = av.alignment.getSequenceAt(i).findPosition(index);
- break;
- }
- if (value != -1)
- {
- int x = LABEL_WEST - fm.stringWidth(String.valueOf(value))-av.charWidth/2;
- g.drawString(value + "", x,
- ypos + i * av.charHeight - av.charHeight / 5);
- }
- }
- }
-
- void drawEastScale(Graphics g, int startx, int endx, int ypos)
- {
- ypos += av.charHeight;
- // EAST SCALE
- for (int i = 0; i < av.alignment.getHeight(); i++)
- {
- SequenceI seq = av.alignment.getSequenceAt(i);
- int index = endx;
- int value = -1;
- while (index > startx)
- {
- if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
- {
- index--;
- continue;
- }
-
- value = av.alignment.getSequenceAt(i).findPosition(index);
- break;
- }
- if (value != -1)
- {
- g.drawString(value + "", av.charWidth/2,
- ypos + i * av.charHeight - av.charHeight / 5);
- }
- }
-
- }
-
- int lastsr=0;
- void fastPaint(int horizontal, int vertical)
- {
- if ( fastPaint || gg == null)
- {
- return;
- }
-
-
- // Its possible on certain browsers that the call to fastpaint
- // is faster than it can paint, so this check here catches
- // this possibility
- if(lastsr + horizontal != av.startRes)
- {
- horizontal = av.startRes - lastsr;
- }
-
- lastsr = av.startRes;
-
- fastPaint = true;
- gg.copyArea(horizontal * av.charWidth,
- vertical * av.charHeight,
- imgWidth - horizontal * av.charWidth,
- imgHeight - vertical * av.charHeight,
- -horizontal * av.charWidth,
- -vertical * av.charHeight);
-
-
-
- int sr = av.startRes, er = av.endRes, ss = av.startSeq, es = av.endSeq,
- transX = 0, transY = 0;
-
- if (horizontal > 0) // scrollbar pulled right, image to the left
- {
- transX = (er - sr - horizontal) * av.charWidth;
- sr = er - horizontal;
- }
- else if (horizontal < 0)
- {
- er = sr - horizontal;
- }
-
- else if (vertical > 0) // scroll down
- {
- ss = es - vertical;
- if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
- {
- ss = av.startSeq;
- }
- else
- {
- transY = imgHeight - vertical * av.charHeight;
- }
- }
- else if (vertical < 0)
- {
- es = ss - vertical;
- if (es > av.endSeq)
- {
- es = av.endSeq;
- }
- }
-
- gg.translate(transX, transY);
-
- drawPanel(gg, sr, er, ss, es, 0);
- gg.translate( -transX, -transY);
-
- repaint();
-
- }
-
- /**
- * Definitions of startx and endx (hopefully):
- * SMJS This is what I'm working towards!
- * startx is the first residue (starting at 0) to display.
- * endx is the last residue to display (starting at 0).
- * starty is the first sequence to display (starting at 0).
- * endy is the last sequence to display (starting at 0).
- * NOTE 1: The av limits are set in setFont in this class and
- * in the adjustment listener in SeqPanel when the scrollbars move.
- */
- public void update(Graphics g)
- {
- paint(g);
- }
-
- public void paint(Graphics g)
- {
-
- if (fastPaint)
- {
- g.drawImage(img, 0, 0, this);
- fastPaint = false;
- return;
- }
-
- // this draws the whole of the alignment
- imgWidth = this.getSize().width;
- imgHeight = this.getSize().height;
-
- imgWidth -= imgWidth % av.charWidth;
- imgHeight -= imgHeight % av.charHeight;
-
- if (imgWidth < 1 || imgHeight < 1)
- {
- return;
- }
-
- if (img == null || imgWidth != img.getWidth(this) ||
- imgHeight != img.getHeight(this))
- {
- img = createImage(imgWidth, imgHeight);
- gg = img.getGraphics();
- gg.setFont(av.getFont());
- }
-
- gg.setColor(Color.white);
- gg.fillRect(0, 0, imgWidth, imgHeight);
-
-
- if (av.getWrapAlignment())
- {
- drawWrappedPanel(gg, imgWidth, imgHeight, av.startRes);
- }
- else
- {
- drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, 0);
- }
-
- g.drawImage(img, 0, 0, this);
-
- if (pdbCanvas != null)
- {
- pdbCanvas.updateSeqColours();
- }
- }
-
- int LABEL_WEST, LABEL_EAST;
- public int getWrappedCanvasWidth(int cwidth)
- {
- FontMetrics fm = getFontMetrics(av.getFont());
-
- LABEL_EAST = 0;
- LABEL_WEST = 0;
-
- if (av.scaleRightWrapped)
- {
- LABEL_EAST = fm.stringWidth(getMask());
- }
-
- if (av.scaleLeftWrapped)
- {
- LABEL_WEST = fm.stringWidth(getMask());
- }
-
- return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth;
- }
-
-
- /**
- * Generates a string of zeroes.
- * @return String
- */
- String getMask()
- {
- String mask = "00";
- for (int i = av.alignment.getWidth(); i > 0; i /= 10)
- {
- mask += "0";
- }
- return mask;
- }
-
- public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight,
- int startRes)
- {
- AlignmentI al = av.getAlignment();
-
- FontMetrics fm = getFontMetrics(av.getFont());
-
- int LABEL_EAST = 0;
-
- if (av.scaleRightWrapped)
- {
- LABEL_EAST = fm.stringWidth(getMask());
- }
-
- int LABEL_WEST = 0;
-
- if (av.scaleLeftWrapped)
- {
- LABEL_WEST = fm.stringWidth(getMask());
- }
-
- int hgap = av.charHeight;
- if(av.scaleAboveWrapped)
- hgap += av.charHeight;
-
- int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth;
- int cHeight = av.getAlignment().getHeight() * av.charHeight;
-
- av.setWrappedWidth(cWidth);
-
- av.endRes = av.startRes + cWidth;
-
-
- int endx;
- int ypos = hgap;
-
-
- while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth()))
- {
- endx = startRes + cWidth;
-
- if (endx > al.getWidth())
- {
- endx = al.getWidth();
- }
-
- g.setColor(Color.black);
-
- if (av.scaleLeftWrapped)
- {
- drawWestScale(g, startRes, endx, ypos);
- }
-
- if (av.scaleRightWrapped)
- {
- g.translate(canvasWidth - LABEL_EAST, 0);
- drawEastScale(g, startRes, endx, ypos);
- g.translate(-(canvasWidth - LABEL_EAST), 0);
- }
-
- g.translate(LABEL_WEST, 0);
-
- if (av.scaleAboveWrapped)
- {
- drawNorthScale(g, startRes, endx, ypos);
- }
-
- if(g.getClip()==null)
- g.setClip(0, 0, cWidth * av.charWidth, canvasHeight);
-
- drawPanel(g, startRes, endx, 0, al.getHeight(), ypos);
- g.setClip(null);
-
-
- if(av.showAnnotation)
- {
- g.translate(0, cHeight + ypos+4);
- if(annotations==null)
- annotations = new AnnotationPanel(av);
-
- annotations.drawComponent( g, startRes, endx );
- g.translate(0, -cHeight - ypos-4);
- }
- g.translate(-LABEL_WEST, 0);
-
- ypos += cHeight+getAnnotationHeight()+hgap;
-
-
- startRes += cWidth;
- }
-
- }
-
- AnnotationPanel annotations;
- int getAnnotationHeight()
- {
- if(!av.showAnnotation)
- return 0;
-
- if(annotations==null)
- annotations = new AnnotationPanel(av);
-
- return annotations.adjustPanelHeight();
- }
-
- void drawPanel(Graphics g, int startRes, int endRes, int startSeq, int endSeq, int offset)
- {
-
- g.setFont(av.getFont());
- sr.renderGaps(av.renderGaps);
-
- SequenceI nextSeq;
- /// First draw the sequences
- /////////////////////////////
- for (int i = startSeq; i < endSeq; i++)
- {
- nextSeq = av.alignment.getSequenceAt(i);
-
- sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), startRes, endRes,
- offset + ( (i - startSeq) * av.charHeight));
-
- if (av.showSequenceFeatures)
- {
- fr.drawSequence(g, nextSeq, startRes, endRes,
- offset + ((i - startSeq) * av.charHeight),
- av.charWidth, av.charHeight);
- }
- /// Highlight search Results once all sequences have been drawn
- //////////////////////////////////////////////////////////
- if (searchResults != null)
- {
- int[] visibleResults = searchResults.getResults(nextSeq, startRes, endRes);
- if (visibleResults != null)
- for (int r = 0; r < visibleResults.length; r += 2)
- {
- sr.drawHighlightedText(nextSeq, visibleResults[r],
- visibleResults[r + 1],
- (visibleResults[r] - startRes) * av.charWidth,
- offset + ( (i - startSeq) * av.charHeight),
- av.charWidth, av.charHeight);
- }
- }
- }
-
- //
- /////////////////////////////////////
- // Now outline any areas if necessary
- /////////////////////////////////////
- SequenceGroup group = av.getSelectionGroup();
-
- int sx = -1;
- int sy = -1;
- int ex = -1;
- int groupIndex = -1;
-
- if ((group == null) && (av.alignment.getGroups().size() > 0))
- {
- group = (SequenceGroup) av.alignment.getGroups().elementAt(0);
- groupIndex = 0;
- }
-
- if ( group != null)
- {
- do
- {
- int oldY = -1;
- int i = 0;
- boolean inGroup = false;
- int top = -1;
- int bottom = -1;
-
- for (i = startSeq; i < endSeq; i++)
- {
- sx = (group.getStartRes() - startRes) * av.charWidth;
- sy = offset + ((i - startSeq) * av.charHeight);
- ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) -
- 1;
-
- if(sx+ex<0 || sx>imgWidth)
- {
- continue;
- }
-
- if ( (sx <= (endRes-startRes)*av.charWidth) &&
- group.sequences.contains(av.alignment.getSequenceAt(
- i)))
- {
- if (bottom == -1)
- {
- if(i == endSeq-1 || // Dont check for i+1 if on the bottom row
- !group.sequences.contains(av.alignment.getSequenceAt(i+1 )))
-
- bottom = sy + av.charHeight;
- }
-
- if (!inGroup)
- {
- if (((top == -1) && (i == 0)) ||
- !group.sequences.contains(
- av.alignment.getSequenceAt(i - 1)))
- {
- top = sy;
- }
-
- oldY = sy;
- inGroup = true;
-
- if (group == av.getSelectionGroup())
- {
- g.setColor(Color.red);
- }
- else
- {
- g.setColor(group.getOutlineColour());
- }
- }
- }
- else
- {
- if (inGroup)
- {
- if (sx >= 0 && sx < imgWidth)
- g.drawLine(sx, oldY, sx, sy);
-
- if (sx + ex < imgWidth)
- g.drawLine(sx + ex, oldY, sx + ex, sy);
-
- if (sx < 0)
- {
- ex += sx;
- sx = 0;
- }
-
- if (sx + ex > imgWidth)
- ex = imgWidth;
-
- else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
- ex = (endRes - startRes + 1) * av.charWidth;
-
- if (top != -1)
- {
- g.drawLine(sx, top, sx + ex, top);
- top = -1;
- }
-
- if (bottom != -1)
- {
- g.drawLine(sx, bottom, sx + ex, bottom);
- bottom = -1;
- }
-
- inGroup = false;
- }
- }
- }
-
- if (inGroup)
- {
- sy = offset + ( (i - startSeq) * av.charHeight);
- if (sx >= 0 && sx < imgWidth)
- g.drawLine(sx, oldY, sx, sy);
-
- if (sx + ex < imgWidth)
- g.drawLine(sx + ex, oldY, sx + ex, sy);
-
- if (sx < 0)
- {
- ex += sx;
- sx = 0;
- }
-
- if (sx + ex > imgWidth)
- ex = imgWidth;
- else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
- ex = (endRes - startRes + 1) * av.charWidth;
-
- if (top != -1)
- {
- g.drawLine(sx, top, sx + ex, top);
- top = -1;
- }
-
- if (bottom != -1)
- {
- g.drawLine(sx, bottom - 1, sx + ex, bottom - 1);
- bottom = -1;
- }
-
- inGroup = false;
- }
-
- groupIndex++;
-
- if (groupIndex >= av.alignment.getGroups().size())
- {
- break;
- }
-
- group = (SequenceGroup) av.alignment.getGroups().elementAt(groupIndex);
- }
- while (groupIndex < av.alignment.getGroups().size());
- }
- }
-
- public void highlightSearchResults(SearchResults results)
- {
- searchResults = results;
-
- repaint();
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+
+import jalview.datamodel.*;
+
+public class SeqCanvas
+ extends Panel
+{
+ FeatureRenderer fr;
+ SequenceRenderer sr;
+ Image img;
+ Graphics gg;
+ int imgWidth;
+ int imgHeight;
+
+ AlignViewport av;
+
+ SearchResults searchResults = null;
+
+ boolean fastPaint = false;
+
+
+ int cursorX = 0;
+ int cursorY = 0;
+
+
+ public SeqCanvas(AlignViewport av)
+ {
+ this.av = av;
+ fr = new FeatureRenderer(av);
+ sr = new SequenceRenderer(av);
+ PaintRefresher.Register(this, av.alignment);
+ }
+
+ public AlignViewport getViewport()
+ {
+ return av;
+ }
+
+ public FeatureRenderer getFeatureRenderer()
+ {
+ return fr;
+ }
+
+ MCview.AppletPDBCanvas pdbCanvas;
+ public SequenceRenderer getSequenceRenderer()
+ {
+ return sr;
+ }
+
+ public void setPDBCanvas(MCview.AppletPDBCanvas pc)
+ {
+ pdbCanvas = pc;
+ }
+
+
+ void drawNorthScale(Graphics g, int startx, int endx, int ypos)
+ {
+ int scalestartx = startx - startx % 10 + 10;
+
+ g.setColor(Color.black);
+
+ // NORTH SCALE
+ for (int i = scalestartx; i < endx; i += 10)
+ {
+ int value = i;
+ if(av.hasHiddenColumns)
+ value = av.getColumnSelection().adjustForHiddenColumns(value);
+
+ g.drawString( String.valueOf(value), (i - startx - 1) * av.charWidth,
+ ypos - (av.charHeight / 2));
+
+ g.drawLine(((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
+ (ypos + 2) - (av.charHeight / 2),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), ypos -
+ 2);
+ }
+ }
+
+ void drawWestScale(Graphics g, int startx, int endx, int ypos)
+ {
+ FontMetrics fm = getFontMetrics(av.getFont());
+ ypos += av.charHeight;
+ if (av.hasHiddenColumns)
+ {
+ startx = av.getColumnSelection().adjustForHiddenColumns(startx);
+ endx = av.getColumnSelection().adjustForHiddenColumns(endx);
+ }
+
+ int maxwidth = av.alignment.getWidth();
+ if (av.hasHiddenColumns)
+ maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+
+ // WEST SCALE
+ for (int i = 0; i < av.alignment.getHeight(); i++)
+ {
+ SequenceI seq = av.alignment.getSequenceAt(i);
+ int index = startx;
+ int value = -1;
+
+ while (index < endx)
+ {
+ if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
+ {
+ index++;
+
+ continue;
+ }
+
+ value = av.alignment.getSequenceAt(i).findPosition(index);
+
+ break;
+ }
+
+ if (value != -1)
+ {
+ int x = LABEL_WEST - fm.stringWidth(String.valueOf(value)) -
+ av.charWidth / 2;
+ g.drawString(value + "", x,
+ (ypos + (i * av.charHeight)) - (av.charHeight / 5));
+ }
+ }
+ }
+ void drawEastScale(Graphics g, int startx, int endx, int ypos)
+ {
+ ypos += av.charHeight;
+
+ if(av.hasHiddenColumns)
+ endx = av.getColumnSelection().adjustForHiddenColumns(endx);
+
+ SequenceI seq;
+ // EAST SCALE
+ for (int i = 0; i < av.alignment.getHeight(); i++)
+ {
+ seq = av.alignment.getSequenceAt(i);
+ int index = endx;
+ int value = -1;
+
+ while (index > startx)
+ {
+ if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
+ {
+ index--;
+
+ continue;
+ }
+
+ value = seq.findPosition(index);
+
+ break;
+ }
+
+ if (value != -1)
+ {
+ g.drawString(String.valueOf(value), 0,
+ (ypos + (i * av.charHeight)) - (av.charHeight / 5));
+ }
+ }
+ }
+
+ int lastsr=0;
+ void fastPaint(int horizontal, int vertical)
+ {
+ if ( fastPaint || gg == null)
+ {
+ return;
+ }
+
+
+ // Its possible on certain browsers that the call to fastpaint
+ // is faster than it can paint, so this check here catches
+ // this possibility
+ if(lastsr + horizontal != av.startRes)
+ {
+ horizontal = av.startRes - lastsr;
+ }
+
+ lastsr = av.startRes;
+
+ fastPaint = true;
+ gg.copyArea(horizontal * av.charWidth,
+ vertical * av.charHeight,
+ imgWidth - horizontal * av.charWidth,
+ imgHeight - vertical * av.charHeight,
+ -horizontal * av.charWidth,
+ -vertical * av.charHeight);
+
+
+
+ int sr = av.startRes, er = av.endRes, ss = av.startSeq, es = av.endSeq,
+ transX = 0, transY = 0;
+
+ if (horizontal > 0) // scrollbar pulled right, image to the left
+ {
+ transX = (er - sr - horizontal) * av.charWidth;
+ sr = er - horizontal;
+ }
+ else if (horizontal < 0)
+ {
+ er = sr - horizontal;
+ }
+
+ else if (vertical > 0) // scroll down
+ {
+ ss = es - vertical;
+ if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
+ {
+ ss = av.startSeq;
+ }
+ else
+ {
+ transY = imgHeight - vertical * av.charHeight;
+ }
+ }
+ else if (vertical < 0)
+ {
+ es = ss - vertical;
+ if (es > av.endSeq)
+ {
+ es = av.endSeq;
+ }
+ }
+
+ gg.translate(transX, transY);
+
+ drawPanel(gg, sr, er, ss, es, 0);
+ gg.translate( -transX, -transY);
+
+ repaint();
+
+ }
+
+ /**
+ * Definitions of startx and endx (hopefully):
+ * SMJS This is what I'm working towards!
+ * startx is the first residue (starting at 0) to display.
+ * endx is the last residue to display (starting at 0).
+ * starty is the first sequence to display (starting at 0).
+ * endy is the last sequence to display (starting at 0).
+ * NOTE 1: The av limits are set in setFont in this class and
+ * in the adjustment listener in SeqPanel when the scrollbars move.
+ */
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void paint(Graphics g)
+ {
+
+ if (img != null && (fastPaint
+ || (getSize().width != g.getClipBounds().width)
+ || (getSize().height != g.getClipBounds().height)))
+ {
+ g.drawImage(img, 0, 0, this);
+ fastPaint = false;
+ return;
+ }
+
+ if (fastPaint)
+ {
+ g.drawImage(img, 0, 0, this);
+ fastPaint = false;
+ return;
+ }
+
+ // this draws the whole of the alignment
+ imgWidth = this.getSize().width;
+ imgHeight = this.getSize().height;
+
+ imgWidth -= imgWidth % av.charWidth;
+ imgHeight -= imgHeight % av.charHeight;
+
+ if (imgWidth < 1 || imgHeight < 1)
+ {
+ return;
+ }
+
+ if (img == null || imgWidth != img.getWidth(this) ||
+ imgHeight != img.getHeight(this))
+ {
+ img = createImage(imgWidth, imgHeight);
+ gg = img.getGraphics();
+ gg.setFont(av.getFont());
+ }
+
+ gg.setColor(Color.white);
+ gg.fillRect(0, 0, imgWidth, imgHeight);
+
+
+ if (av.getWrapAlignment())
+ {
+ drawWrappedPanel(gg, imgWidth, imgHeight, av.startRes);
+ }
+ else
+ {
+ drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, 0);
+ }
+
+ g.drawImage(img, 0, 0, this);
+
+ if (pdbCanvas != null)
+ {
+ pdbCanvas.updateSeqColours();
+ }
+ }
+
+ int LABEL_WEST, LABEL_EAST;
+ public int getWrappedCanvasWidth(int cwidth)
+ {
+ cwidth -= cwidth % av.charWidth;
+
+ FontMetrics fm = getFontMetrics(av.getFont());
+
+ LABEL_EAST = 0;
+ LABEL_WEST = 0;
+
+ if (av.scaleRightWrapped)
+ {
+ LABEL_EAST = fm.stringWidth(getMask());
+ }
+
+ if (av.scaleLeftWrapped)
+ {
+ LABEL_WEST = fm.stringWidth(getMask());
+ }
+
+ return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth;
+ }
+
+
+ /**
+ * Generates a string of zeroes.
+ * @return String
+ */
+ String getMask()
+ {
+ String mask = "00";
+ for (int i = av.alignment.getWidth(); i > 0; i /= 10)
+ {
+ mask += "0";
+ }
+ return mask;
+ }
+
+ public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight,
+ int startRes)
+ {
+ AlignmentI al = av.getAlignment();
+
+ FontMetrics fm = getFontMetrics(av.getFont());
+
+
+ if (av.scaleRightWrapped)
+ {
+ LABEL_EAST = fm.stringWidth(getMask());
+ }
+
+ if (av.scaleLeftWrapped)
+ {
+ LABEL_WEST = fm.stringWidth(getMask());
+ }
+
+ int hgap = av.charHeight;
+ if(av.scaleAboveWrapped)
+ hgap += av.charHeight;
+
+ int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth;
+ int cHeight = av.getAlignment().getHeight() * av.charHeight;
+
+ av.setWrappedWidth(cWidth);
+
+ av.endRes = av.startRes + cWidth;
+
+
+ int endx;
+ int ypos = hgap;
+
+ int maxwidth = av.alignment.getWidth();
+
+ if(av.hasHiddenColumns)
+ maxwidth = av.getColumnSelection().findColumnPosition(maxwidth)-1;
+
+ while ((ypos <= canvasHeight) && (startRes < maxwidth))
+ {
+ endx = startRes + cWidth -1;
+
+ if (endx > maxwidth)
+ {
+ endx = maxwidth;
+ }
+
+ g.setColor(Color.black);
+
+ if (av.scaleLeftWrapped)
+ {
+ drawWestScale(g, startRes, endx, ypos);
+ }
+
+ if (av.scaleRightWrapped)
+ {
+ g.translate(canvasWidth - LABEL_EAST, 0);
+ drawEastScale(g, startRes, endx, ypos);
+ g.translate(-(canvasWidth - LABEL_EAST), 0);
+ }
+
+ g.translate(LABEL_WEST, 0);
+
+ if (av.scaleAboveWrapped)
+ {
+ drawNorthScale(g, startRes, endx, ypos);
+ }
+ if (av.hasHiddenColumns && av.showHiddenMarkers)
+ {
+ g.setColor(Color.blue);
+ int res;
+ for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size();
+ i++)
+ {
+ res = av.getColumnSelection().findHiddenRegionPosition(i) -
+ startRes;
+
+ if (res < 0 || res > endx - startRes)
+ continue;
+
+ gg.fillPolygon(new int[]
+ {res * av.charWidth - av.charHeight / 4,
+ res * av.charWidth + av.charHeight / 4,
+ res * av.charWidth},
+ new int[]
+ {
+ ypos - (av.charHeight / 2),
+ ypos - (av.charHeight / 2),
+ ypos - (av.charHeight / 2) + 8
+ }, 3);
+
+ }
+ }
+
+ if(g.getClip()==null)
+ g.setClip(0, 0, cWidth * av.charWidth, canvasHeight);
+
+ drawPanel(g, startRes, endx, 0, al.getHeight(), ypos);
+ g.setClip(null);
+
+
+ if(av.showAnnotation)
+ {
+ g.translate(0, cHeight + ypos+4);
+ if(annotations==null)
+ annotations = new AnnotationPanel(av);
+
+ annotations.drawComponent( g, startRes, endx+1 );
+ g.translate(0, -cHeight - ypos-4);
+ }
+ g.translate(-LABEL_WEST, 0);
+
+ ypos += cHeight+getAnnotationHeight()+hgap;
+
+
+ startRes += cWidth;
+ }
+
+ }
+
+ AnnotationPanel annotations;
+ int getAnnotationHeight()
+ {
+ if(!av.showAnnotation)
+ return 0;
+
+ if(annotations==null)
+ annotations = new AnnotationPanel(av);
+
+ return annotations.adjustPanelHeight();
+ }
+
+ void drawPanel(Graphics g1, int startRes, int endRes,
+ int startSeq, int endSeq, int offset)
+ {
+ if(!av.hasHiddenColumns)
+ {
+ draw(g1, startRes, endRes, startSeq, endSeq, offset);
+ }
+ else
+ {
+ java.util.Vector regions = av.getColumnSelection().getHiddenColumns();
+
+ int screenY = 0;
+ int blockStart = startRes;
+ int blockEnd = endRes;
+
+ for (int i = 0; i < regions.size(); i++)
+ {
+ int[] region = (int[]) regions.elementAt(i);
+ int hideStart = region[0];
+ int hideEnd = region[1];
+
+ if (hideStart <= blockStart)
+ {
+ blockStart += (hideEnd - hideStart) + 1;
+ continue;
+ }
+
+ blockEnd = hideStart - 1;
+
+ g1.translate(screenY * av.charWidth, 0);
+
+ draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
+
+ if(av.getShowHiddenMarkers())
+ {
+ g1.setColor(Color.blue);
+ g1.drawLine( (blockEnd - blockStart + 1) * av.charWidth - 1,
+ startSeq + offset,
+ (blockEnd - blockStart + 1) * av.charWidth - 1,
+ startSeq + (endSeq - startSeq) * av.charHeight + offset);
+ }
+
+ g1.translate( -screenY * av.charWidth, 0);
+ screenY += blockEnd - blockStart + 1;
+ blockStart = hideEnd + 1;
+ }
+
+ if (screenY <= (endRes - startRes))
+ {
+ blockEnd = blockStart + (endRes - startRes) - screenY;
+ g1.translate(screenY * av.charWidth, 0);
+ draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
+
+ g1.translate( -screenY * av.charWidth, 0);
+ }
+ }
+
+ }
+
+
+
+
+ //int startRes, int endRes, int startSeq, int endSeq, int x, int y,
+ // int x1, int x2, int y1, int y2, int startx, int starty,
+ void draw(Graphics g,
+ int startRes, int endRes,
+ int startSeq, int endSeq,
+ int offset)
+ {
+ g.setFont(av.getFont());
+ sr.prepare(g, av.renderGaps);
+
+ SequenceI nextSeq;
+
+ /// First draw the sequences
+ /////////////////////////////
+ for (int i = startSeq; i < endSeq; i++)
+ {
+ nextSeq = av.alignment.getSequenceAt(i);
+
+ sr.drawSequence(nextSeq, av.alignment.findAllGroups(nextSeq),
+ startRes, endRes,
+ offset + ( (i - startSeq) * av.charHeight));
+
+ if (av.showSequenceFeatures)
+ {
+ fr.drawSequence(g, nextSeq, startRes, endRes,
+ offset + ((i - startSeq) * av.charHeight));
+ }
+
+ /// Highlight search Results once all sequences have been drawn
+ //////////////////////////////////////////////////////////
+ if (searchResults != null)
+ {
+ int[] visibleResults = searchResults.getResults(nextSeq, startRes, endRes);
+ if (visibleResults != null)
+ for (int r = 0; r < visibleResults.length; r += 2)
+ {
+ sr.drawHighlightedText(nextSeq, visibleResults[r],
+ visibleResults[r + 1],
+ (visibleResults[r] - startRes) * av.charWidth,
+ offset + ( (i - startSeq) * av.charHeight));
+ }
+ }
+
+ if(av.cursorMode && cursorY==i
+ && cursorX>=startRes && cursorX<=endRes)
+ {
+ sr.drawCursor(nextSeq, cursorX, (cursorX - startRes) * av.charWidth,
+ offset + ( (i - startSeq) * av.charHeight));
+ }
+ }
+
+ if(av.getSelectionGroup()!=null || av.alignment.getGroups().size()>0)
+ drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
+
+ }
+
+ void drawGroupsBoundaries(Graphics g,
+ int startRes, int endRes,
+ int startSeq, int endSeq,
+ int offset)
+ {
+ //
+ /////////////////////////////////////
+ // Now outline any areas if necessary
+ /////////////////////////////////////
+ SequenceGroup group = av.getSelectionGroup();
+
+ int sx = -1;
+ int sy = -1;
+ int ex = -1;
+ int groupIndex = -1;
+
+ if ( (group == null) && (av.alignment.getGroups().size() > 0))
+ {
+ group = (SequenceGroup) av.alignment.getGroups().elementAt(0);
+ groupIndex = 0;
+ }
+
+ if (group != null)
+ {
+ do
+ {
+ int oldY = -1;
+ int i = 0;
+ boolean inGroup = false;
+ int top = -1;
+ int bottom = -1;
+ int alHeight = av.alignment.getHeight()-1;
+
+ for (i = startSeq; i < endSeq; i++)
+ {
+ sx = (group.getStartRes() - startRes) * av.charWidth;
+ sy = offset + ( (i - startSeq) * av.charHeight);
+ ex = ( ( (group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) -
+ 1;
+
+ if (sx + ex < 0 || sx > imgWidth)
+ {
+ continue;
+ }
+
+ if ( (sx <= (endRes - startRes) * av.charWidth) &&
+ group.getSequences(false).
+ contains(av.alignment.getSequenceAt(i)))
+ {
+ if ( (bottom == -1) &&
+ (i >= alHeight ||
+ !group.getSequences(false).contains(
+ av.alignment.getSequenceAt(i + 1))))
+ {
+ bottom = sy + av.charHeight;
+ }
+
+ if (!inGroup)
+ {
+ if ( ( (top == -1) && (i == 0)) ||
+ !group.getSequences(false).contains(
+ av.alignment.getSequenceAt(i - 1)))
+ {
+ top = sy;
+ }
+
+ oldY = sy;
+ inGroup = true;
+
+ if (group == av.getSelectionGroup())
+ {
+ g.setColor(Color.red);
+ }
+ else
+ {
+ g.setColor(group.getOutlineColour());
+ }
+ }
+ }
+ else
+ {
+ if (inGroup)
+ {
+ if (sx >= 0 && sx < imgWidth)
+ g.drawLine(sx, oldY, sx, sy);
+
+ if (sx + ex < imgWidth)
+ g.drawLine(sx + ex, oldY, sx + ex, sy);
+
+ if (sx < 0)
+ {
+ ex += sx;
+ sx = 0;
+ }
+
+ if (sx + ex > imgWidth)
+ ex = imgWidth;
+
+ else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
+ ex = (endRes - startRes + 1) * av.charWidth;
+
+ if (top != -1)
+ {
+ g.drawLine(sx, top, sx + ex, top);
+ top = -1;
+ }
+
+ if (bottom != -1)
+ {
+ g.drawLine(sx, bottom, sx + ex, bottom);
+ bottom = -1;
+ }
+
+ inGroup = false;
+ }
+ }
+ }
+
+ if (inGroup)
+ {
+ sy = offset + ( (i - startSeq) * av.charHeight);
+ if (sx >= 0 && sx < imgWidth)
+ g.drawLine(sx, oldY, sx, sy);
+
+ if (sx + ex < imgWidth)
+ g.drawLine(sx + ex, oldY, sx + ex, sy);
+
+ if (sx < 0)
+ {
+ ex += sx;
+ sx = 0;
+ }
+
+ if (sx + ex > imgWidth)
+ ex = imgWidth;
+ else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
+ ex = (endRes - startRes + 1) * av.charWidth;
+
+ if (top != -1)
+ {
+ g.drawLine(sx, top, sx + ex, top);
+ top = -1;
+ }
+
+ if (bottom != -1)
+ {
+ g.drawLine(sx, bottom - 1, sx + ex, bottom - 1);
+ bottom = -1;
+ }
+
+ inGroup = false;
+ }
+
+ groupIndex++;
+
+ if (groupIndex >= av.alignment.getGroups().size())
+ {
+ break;
+ }
+
+ group = (SequenceGroup) av.alignment.getGroups().elementAt(groupIndex);
+ }
+ while (groupIndex < av.alignment.getGroups().size());
+
+ }
+ }
+
+ public void highlightSearchResults(SearchResults results)
+ {
+ searchResults = results;
+
+ repaint();
+ }
+
+}
diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java
index e29f4e1..9439dba 100755
--- a/src/jalview/appletgui/SeqPanel.java
+++ b/src/jalview/appletgui/SeqPanel.java
@@ -1,841 +1,1465 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-import jalview.schemes.*;
-
-public class SeqPanel
- extends Panel implements MouseMotionListener, MouseListener
-{
-
- public SeqCanvas seqCanvas;
- public AlignmentPanel ap;
-
- protected int lastres;
- protected int startseq;
- int startEdit = -1;
- int endEdit = -1;
-
- protected AlignViewport av;
-
- // if character is inserted or deleted, we will need to recalculate the conservation
- int seqEditOccurred = -1;
-
- ScrollThread scrollThread = null;
- boolean mouseDragging = false;
-
- boolean editingSeqs = false;
- boolean groupEditing = false;
-
- public SeqPanel(AlignViewport avp, AlignmentPanel p)
- {
- this.av = avp;
-
- seqCanvas = new SeqCanvas(avp);
- setLayout(new BorderLayout());
- add(seqCanvas);
-
- ap = p;
-
- seqCanvas.addMouseMotionListener(this);
- seqCanvas.addMouseListener(this);
-
- seqCanvas.repaint();
- }
-
-
- public void mousePressed(MouseEvent evt)
- {
- if (evt.isShiftDown() || evt.isAltDown() || evt.isControlDown())
- {
- if (evt.isAltDown() || evt.isControlDown())
- {
- groupEditing = true;
- }
-
- editingSeqs = true;
- doMousePressed(evt);
- }
- else
- {
- doMousePressedDefineMode(evt);
- }
- }
-
- public void mouseClicked(MouseEvent evt){}
-
-
- public void mouseReleased(MouseEvent evt)
- {
- if (!editingSeqs)
- {
- doMouseReleasedDefineMode(evt);
- return;
- }
-
-
- if (seqEditOccurred > -1)
- {
- editOccurred(seqEditOccurred);
- }
-
- startseq = -1;
- lastres = -1;
- seqEditOccurred = -1;
- editingSeqs = false;
- groupEditing = false;
- ap.repaint();
- }
-
- int startWrapBlock=-1;
- int wrappedBlock=-1;
- int findRes(MouseEvent evt)
- {
- int res = 0;
- int x = evt.getX();
-
- if (av.wrapAlignment)
- {
-
- int hgap = av.charHeight;
- if (av.scaleAboveWrapped)
- hgap += av.charHeight;
-
- int cHeight = av.getAlignment().getHeight() * av.charHeight
- + hgap + seqCanvas.getAnnotationHeight();
-
- int y = evt.getY();
- y -= hgap;
- x -= seqCanvas.LABEL_WEST;
-
-
- int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
-
- wrappedBlock = y / cHeight;
- wrappedBlock += av.getStartRes() / cwidth;
-
- res = wrappedBlock * cwidth + x / av.getCharWidth();
-
- }
- else
- {
- res = (x / av.getCharWidth()) + av.getStartRes();
- }
-
- return res;
-
- }
-
- int findSeq(MouseEvent evt)
- {
-
- int seq = 0;
- int y = evt.getY();
-
- if (av.wrapAlignment)
- {
- int hgap = av.charHeight;
- if (av.scaleAboveWrapped)
- hgap += av.charHeight;
-
- int cHeight = av.getAlignment().getHeight() * av.charHeight
- + hgap + seqCanvas.getAnnotationHeight();
-
- y -= hgap;
-
- seq = ( (y % cHeight) / av.getCharHeight());
- }
- else
- {
- seq = (y / av.getCharHeight()) + av.getStartSeq();
- }
-
- return seq;
- }
-
-
- public void doMousePressed(MouseEvent evt)
- {
- ap.alignFrame.addHistoryItem(new HistoryItem(
- "Edit Sequence", av.alignment, HistoryItem.EDIT));
-
- int seq = findSeq(evt);
- int res = findRes(evt);
-
- if (seq < av.getAlignment().getHeight() &&
- res < av.getAlignment().getSequenceAt(seq).getLength())
- {
- //char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
- // Find the residue's position in the sequence (res is the position
- // in the alignment
-
- startseq = seq;
- lastres = res;
- }
- else
- {
- startseq = -1;
- lastres = -1;
- }
-
- return;
- }
-
- public void mouseMoved(MouseEvent evt)
- {
- int res = findRes(evt);
- int seq = findSeq(evt);
-
- if (seq >= av.getAlignment().getHeight() || seq<0 || res<0)
- {
- return;
- }
-
- SequenceI sequence = av.getAlignment().getSequenceAt(seq);
- if (res > sequence.getLength())
- {
- return;
- }
-
- StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
- sequence.getName());
-
- Object obj = null;
- if (av.alignment.isNucleotide())
- {
- obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
- "");
- if(obj!=null)
- text.append(" Nucleotide: ");
- }
- else
- {
- obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
- if(obj!=null)
- text.append(" Residue: ");
- }
-
- if (obj != null)
- {
-
- if (obj != "")
- {
- text.append(obj + " (" +
- av.getAlignment().getSequenceAt(seq).findPosition(res) + ")");
- }
- }
-
- if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)
- {
- seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));
- }
-
-
- // use aa to see if the mouse pointer is on a
- if (av.showSequenceFeatures
- && sequence.getSequenceFeatures()!=null
- && av.featuresDisplayed!=null)
- {
- int index = 0;
- sequence.getSequenceFeatures();
- boolean first = true;
- while (index < sequence.getSequenceFeatures().length)
- {
- SequenceFeature sf = sequence.getSequenceFeatures()[index];
- if (sf.getBegin() <= sequence.findPosition(res) &&
- sf.getEnd() >= sequence.findPosition(res))
- {
- if(!av.featuresDisplayed.containsKey(sf.getType()))
- {
- index++;
- continue;
- }
-
- if(first)
- {
- text.append(" Sequence Feature:");
- first = false;
- }
-
- text.append(" "+sf.getType());
-
- if(sf.getDescription()!=null)
- text.append(" "+sf.getDescription());
-
- if (sf.getStatus()!=null && sf.getStatus().length() > 0)
- {
- text.append(" (" + sf.getStatus() + ")");
- }
- text.append("; ");
- }
-
- index++;
-
- }
- }
-
- ap.alignFrame.statusBar.setText(text.toString());
-
- }
-
- public void mouseDragged(MouseEvent evt)
- {
- if (!editingSeqs)
- {
- doMouseDraggedDefineMode(evt);
- return;
- }
-
- // If we're dragging we're editing
- int res = findRes(evt);
- if (res < 0)
- {
- res = 0;
- }
-
- if (lastres == -1 || lastres == res)
- {
- return;
- }
-
- boolean dragRight = true;
- if (res < av.getAlignment().getWidth() && res < lastres)
- {
- dragRight = false;
- }
-
- if (res != lastres)
- {
- // Group editing
- if (groupEditing)
- {
- SequenceGroup sg = av.getSelectionGroup();
- if (sg == null)
- {
- lastres = -1;
- return;
- }
-
- // drag to right
- if (dragRight)
- {
- sg.setEndRes(sg.getEndRes() + (res - lastres));
- }
-
- // drag to left
- else
- {
- /// Are we able to delete?
- // ie are all columns blank?
- boolean deleteAllowed = false;
- for (int s = 0; s < sg.getSize(); s++)
- {
- SequenceI seq = sg.getSequenceAt(s);
- for (int j = res; j < lastres; j++)
- {
- if (seq.getSequence().length() <= j)
- {
- continue;
- }
-
- if (!jalview.util.Comparison.isGap(seq.getSequence().charAt(j)))
- {
- // Not a gap, block edit not valid
- res = j + 1;
- deleteAllowed = false;
- continue;
- }
- deleteAllowed = true;
- }
- }
-
- if (!deleteAllowed)
- {
- lastres = -1;
- return;
- }
-
- sg.setEndRes(sg.getEndRes() - (lastres - res));
- }
-
- for (int i = 0; i < sg.getSize(); i++)
- {
- SequenceI s = sg.getSequenceAt(i);
- int k = av.alignment.findIndex(s);
-
- // drag to right
- if (dragRight)
- {
- for (int j = lastres; j < res; j++)
- {
- insertChar(j, k);
- }
- }
-
- // drag to left
- else
- {
- for (int j = res; j < lastres; j++)
- {
- if (s.getLength() > j)
- {
- deleteChar(res, k);
- }
- }
- }
- }
- }
- else /////Editing a single sequence///////////
- {
- if (res < av.getAlignment().getWidth() && res > lastres)
- {
- // dragging to the right
- for (int j = lastres; j < res; j++)
- {
- insertChar(j, startseq);
- }
- }
- else if (res < av.getAlignment().getWidth() && res < lastres)
- {
- // dragging to the left
- for (int j = lastres; j > res; j--)
- {
- if (jalview.util.Comparison.isGap(
- av.alignment.getSequenceAt(startseq).getSequence().charAt(res)))
- {
-
- deleteChar(res, startseq);
- }
- else
- {
- if(scrollThread!=null)
- {
- scrollThread.running = false;
- scrollThread = null;
- }
- break;
- }
- }
- }
-
- }
- }
-
- mouseDragging = true;
- if (res > av.endRes || res < av.startRes)
- {
- mouseExited(evt);
- }
-
- if (scrollThread != null)
- scrollThread.setEvent(evt);
-
-
- endEdit = res;
- lastres = res;
- seqCanvas.repaint();
- }
-
- public void insertChar(int j, int seq)
- {
- av.alignment.getSequenceAt(seq).insertCharAt(j, av.getGapCharacter());
- seqEditOccurred = seq;
- }
-
- public void deleteChar(int j, int seq)
- {
-
- av.alignment.getSequenceAt(seq).deleteCharAt(j);
- seqEditOccurred = seq;
- av.alignment.getWidth();
- repaint();
- }
-
- void editOccurred(int i)
- {
- if (endEdit == startEdit)
- {
- ap.alignFrame.historyList.pop();
- ap.alignFrame.updateEditMenuBar();
- }
-
- av.firePropertyChange("alignment", null,av.getAlignment().getSequences());
- }
-
-//////////////////////////////////////////
-/////Everything below this is for defining the boundary of the rubberband
-//////////////////////////////////////////
- int oldSeq = -1;
- public void doMousePressedDefineMode(MouseEvent evt)
- {
- if (scrollThread != null)
- {
- scrollThread.running = false;
- scrollThread = null;
- }
-
- int res = findRes(evt);
- int seq = findSeq(evt);
- oldSeq = seq;
- startWrapBlock=wrappedBlock;
-
- if(seq==-1)
- return;
-
- SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
-
- if (sequence == null || res > sequence.getLength())
- {
- return;
- }
-
- stretchGroup = av.getSelectionGroup();
-
- if (stretchGroup == null)
- {
- stretchGroup = av.alignment.findGroup(sequence);
- if (stretchGroup != null && res > stretchGroup.getStartRes() &&
- res < stretchGroup.getEndRes())
- {
- av.setSelectionGroup(stretchGroup);
- }
- else
- {
- stretchGroup = null;
- }
- }
-
- else if (!stretchGroup.sequences.contains(sequence)
- || stretchGroup.getStartRes() > res
- || stretchGroup.getEndRes() < res)
- {
- stretchGroup = null;
-
- SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
-
- if (allGroups != null)
- {
- for (int i = 0; i < allGroups.length; i++)
- {
- if (allGroups[i].getStartRes() <= res &&
- allGroups[i].getEndRes() >= res)
- {
- stretchGroup = allGroups[i];
- av.setSelectionGroup(stretchGroup);
- break;
- }
- }
- }
- }
-
- if (stretchGroup == null)
- {
- // define a new group here
- SequenceGroup sg = new SequenceGroup();
- sg.setStartRes(res);
- sg.setEndRes(res);
- sg.addSequence(sequence, false);
- av.setSelectionGroup(sg);
- stretchGroup = sg;
-
- if (av.getConservationSelected())
- {
- SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
- "Background");
- }
- if (av.getAbovePIDThreshold())
- {
- SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
- "Background");
- }
-
- }
-
- // DETECT RIGHT MOUSE BUTTON IN AWT
- else if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) ==
- InputEvent.BUTTON3_MASK)
- {
- APopupMenu popup = new APopupMenu(ap, null, null);
- this.add(popup);
- popup.show(this, evt.getX(), evt.getY());
- }
-
- if (stretchGroup != null && stretchGroup.getEndRes() == res)
- {
- // Edit end res position of selected group
- changeEndRes = true;
- }
-
- else if (stretchGroup != null && stretchGroup.getStartRes() == res)
- {
- // Edit end res position of selected group
- changeStartRes = true;
- }
-
- }
-
- boolean changeEndSeq = false;
- boolean changeStartSeq = false;
- boolean changeEndRes = false;
- boolean changeStartRes = false;
- SequenceGroup stretchGroup = null;
-
- public void doMouseReleasedDefineMode(MouseEvent evt)
- {
- if (stretchGroup == null)
- {
- return;
- }
-
- if(stretchGroup.cs!=null)
- {
- if (stretchGroup.cs instanceof ClustalxColourScheme)
- {
- ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(stretchGroup.
- sequences,
- stretchGroup.getWidth());
- }
-
- if (stretchGroup.cs.conservationApplied())
- {
- SliderPanel.setConservationSlider(ap, stretchGroup.cs,
- stretchGroup.getName());
- stretchGroup.recalcConservation();
- }
- else
- {
- SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
- stretchGroup.getName());
- }
- }
- changeEndRes = false;
- changeStartRes = false;
- stretchGroup = null;
- PaintRefresher.Refresh(av.alignment);
- ap.repaint();
- }
-
- public void doMouseDraggedDefineMode(MouseEvent evt)
- {
- int res = findRes(evt);
- int y = findSeq(evt);
-
- if(wrappedBlock!=startWrapBlock)
- return;
-
- if (stretchGroup == null)
- {
- return;
- }
-
- mouseDragging = true;
-
-
- if(y > av.alignment.getHeight())
- {
- y = av.alignment.getHeight() -1;
- }
-
- if(res>av.alignment.getWidth())
- res = av.alignment.getWidth()-1;
-
- if (stretchGroup.getEndRes() == res)
- {
- // Edit end res position of selected group
- changeEndRes = true;
- }
- else if (stretchGroup.getStartRes() == res)
- {
- // Edit start res position of selected group
- changeStartRes = true;
- }
-
- if (res < 0)
- {
- res = 0;
- }
-
- if (changeEndRes)
- {
- if (res > (stretchGroup.getStartRes() - 1))
- {
- stretchGroup.setEndRes(res);
- }
- }
- else if (changeStartRes)
- {
- if (res < (stretchGroup.getEndRes() + 1))
- {
- stretchGroup.setStartRes(res);
- }
- }
-
- int dragDirection = 0;
-
- if (y > oldSeq)
- {
- dragDirection = 1;
- }
- else if (y < oldSeq)
- {
- dragDirection = -1;
- }
-
-
- while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
- {
- // This routine ensures we don't skip any sequences, as the
- // selection is quite slow.
- Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
-
- oldSeq += dragDirection;
-
- if(oldSeq<0)
- break;
-
- Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
-
- if (stretchGroup.sequences.contains(nextSeq))
- {
- stretchGroup.deleteSequence(seq, false);
- }
- else
- {
- if (seq != null)
- {
- stretchGroup.addSequence(seq, false);
- }
-
- stretchGroup.addSequence(nextSeq, false);
- }
- }
-
- if(oldSeq < 0)
- oldSeq = -1;
-
-
- if(res>av.endRes || resav.endSeq)
- {
- mouseExited(evt);
- }
-
- if (scrollThread != null)
- {
- scrollThread.setEvent(evt);
- }
-
- seqCanvas.repaint();
- }
-
- public void mouseEntered(MouseEvent e)
- {
- if (oldSeq < 0)
- oldSeq = 0;
-
- if (scrollThread != null)
- {
- scrollThread.running = false;
- scrollThread = null;
- }
- }
-
- public void mouseExited(MouseEvent e)
- {
- if (av.getWrapAlignment())
- {
- return;
- }
-
- if (mouseDragging && scrollThread==null)
- {
- scrollThread = new ScrollThread();
- }
- }
-
- // this class allows scrolling off the bottom of the visible alignment
- class ScrollThread
- extends Thread
- {
- MouseEvent evt;
- boolean running = false;
- public ScrollThread()
- {
- start();
- }
-
- public void setEvent(MouseEvent e)
- {
- evt = e;
- }
-
- public void stopScrolling()
- {
- running = false;
- }
-
- public void run()
- {
- running = true;
- while (running)
- {
-
- if (evt != null)
- {
-
- if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
- {
- running = ap.scrollUp(true);
- }
-
- if (mouseDragging && evt.getY() >= getSize().height &&
- av.alignment.getHeight() > av.getEndSeq())
- {
- running = ap.scrollUp(false);
- }
-
- if (mouseDragging && evt.getX() < 0)
- {
- running = ap.scrollRight(true);
- }
-
- else if (mouseDragging && evt.getX() >= getSize().width)
- {
- running = ap.scrollRight(false);
- }
- }
-
- try
- {
- Thread.sleep(75);
- }
- catch (Exception ex)
- {}
- }
- }
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+import jalview.schemes.*;
+
+import java.util.Vector;
+
+public class SeqPanel
+ extends Panel implements MouseMotionListener, MouseListener
+{
+
+ public SeqCanvas seqCanvas;
+ public AlignmentPanel ap;
+
+ protected int lastres;
+ protected int startseq;
+
+ protected AlignViewport av;
+
+ // if character is inserted or deleted, we will need to recalculate the conservation
+ boolean seqEditOccurred = false;
+
+ ScrollThread scrollThread = null;
+ boolean mouseDragging = false;
+ boolean editingSeqs = false;
+ boolean groupEditing = false;
+
+ int oldSeq = -1;
+ boolean changeEndSeq = false;
+ boolean changeStartSeq = false;
+ boolean changeEndRes = false;
+ boolean changeStartRes = false;
+ SequenceGroup stretchGroup = null;
+
+ StringBuffer keyboardNo1;
+ StringBuffer keyboardNo2;
+
+ boolean mouseWheelPressed = false;
+ Point lastMousePress;
+
+ public SeqPanel(AlignViewport avp, AlignmentPanel p)
+ {
+ this.av = avp;
+
+ seqCanvas = new SeqCanvas(avp);
+ setLayout(new BorderLayout());
+ add(seqCanvas);
+
+ ap = p;
+
+ seqCanvas.addMouseMotionListener(this);
+ seqCanvas.addMouseListener(this);
+
+ seqCanvas.repaint();
+ }
+
+ void endEditing()
+ {
+ startseq = -1;
+ lastres = -1;
+ seqEditOccurred = false;
+ editingSeqs = false;
+ groupEditing = false;
+ keyboardNo1 = null;
+ keyboardNo2 = null;
+ }
+
+ void setCursorRow()
+ {
+ seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1;
+ scrollToVisible();
+ }
+
+ void setCursorColumn()
+ {
+ seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-1;
+ scrollToVisible();
+ }
+
+ void setCursorRowAndColumn()
+ {
+ if(keyboardNo2==null)
+ {
+ keyboardNo2 = new StringBuffer();
+ }
+ else
+ {
+ seqCanvas.cursorX = getKeyboardNo(keyboardNo1) - 1;
+ seqCanvas.cursorY = getKeyboardNo(keyboardNo2) - 1;
+ scrollToVisible();
+ }
+ }
+
+ void setCursorPosition()
+ {
+ SequenceI sequence =
+ (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
+
+ seqCanvas.cursorX = sequence.findIndex(
+ getKeyboardNo(keyboardNo1)-1
+ );
+ scrollToVisible();
+ }
+
+ void moveCursor(int dx, int dy)
+ {
+ seqCanvas.cursorX += dx;
+ seqCanvas.cursorY += dy;
+ scrollToVisible();
+ }
+
+ void scrollToVisible()
+ {
+ if (seqCanvas.cursorX < 0)
+ seqCanvas.cursorX = 0;
+ else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
+ seqCanvas.cursorX = av.alignment.getWidth() - 1;
+
+ if (seqCanvas.cursorY < 0)
+ seqCanvas.cursorY = 0;
+ else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
+ seqCanvas.cursorY = av.alignment.getHeight() - 1;
+
+
+ endEditing();
+ if (av.wrapAlignment)
+ {
+ ap.scrollToWrappedVisible(seqCanvas.cursorX);
+ }
+ else
+ {
+ while (seqCanvas.cursorY < av.startSeq)
+ {
+ ap.scrollUp(true);
+ }
+ while (seqCanvas.cursorY + 1 > av.endSeq)
+ {
+ ap.scrollUp(false);
+ }
+ while (seqCanvas.cursorX < av.startRes)
+ {
+
+ if (!ap.scrollRight(false))
+ break;
+ }
+ while (seqCanvas.cursorX > av.endRes)
+ {
+ if (!ap.scrollRight(true))
+ break;
+ }
+ }
+ setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
+ seqCanvas.cursorX, seqCanvas.cursorY);
+
+ seqCanvas.repaint();
+ }
+
+ void setSelectionAreaAtCursor(boolean topLeft)
+ {
+ SequenceI sequence =
+ (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
+
+ if(av.getSelectionGroup()!=null)
+ {
+ SequenceGroup sg = av.selectionGroup;
+ //Find the top and bottom of this group
+ int min = av.alignment.getHeight(), max = 0;
+ for(int i=0; i max)
+ max = index;
+ if(index < min)
+ min = index;
+ }
+
+ max ++;
+
+ if(topLeft)
+ {
+ sg.setStartRes(seqCanvas.cursorX);
+ if(sg.getEndRes()seqCanvas.cursorX)
+ sg.setStartRes(seqCanvas.cursorX);
+
+ max = seqCanvas.cursorY+1;
+ }
+
+ if(min>max)
+ {
+ // Only the user can do this
+ av.setSelectionGroup(null);
+ }
+ else
+ {
+ // Now add any sequences between min and max
+ sg.getSequences(false).removeAllElements();
+ for (int i = min; i < max; i++)
+ {
+ sg.addSequence(av.alignment.getSequenceAt(i), false);
+ }
+ }
+ }
+
+ if (av.getSelectionGroup() == null)
+ {
+ SequenceGroup sg = new SequenceGroup();
+ sg.setStartRes(seqCanvas.cursorX);
+ sg.setEndRes(seqCanvas.cursorX);
+ sg.addSequence(sequence, false);
+ av.setSelectionGroup(sg);
+ }
+
+
+ ap.repaint();
+ }
+
+ void insertGapAtCursor(boolean group)
+ {
+ ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
+ av.alignment, HistoryItem.EDIT));
+ groupEditing = group;
+ startseq = seqCanvas.cursorY;
+ lastres = seqCanvas.cursorX;
+ editSequence(true, seqCanvas.cursorX+getKeyboardNo(keyboardNo1));
+ editOccurred();
+ }
+
+ void deleteGapAtCursor(boolean group)
+ {
+ ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
+ av.alignment, HistoryItem.EDIT));
+ groupEditing = group;
+ startseq = seqCanvas.cursorY;
+ lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1);
+ editSequence(false, seqCanvas.cursorX);
+ editOccurred();
+ }
+
+ void numberPressed(char value)
+ {
+ if(keyboardNo1==null)
+ keyboardNo1 = new StringBuffer();
+
+ if(keyboardNo2!=null)
+ keyboardNo2.append(value);
+ else
+ keyboardNo1.append(value);
+ }
+
+ int getKeyboardNo(StringBuffer kb)
+ {
+ if(kb==null)
+ return 1;
+ else
+ return Integer.parseInt(kb.toString());
+ }
+
+ void setStatusMessage(SequenceI sequence, int res, int seq)
+ {
+ StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
+ sequence.getName());
+
+ Object obj = null;
+ if (av.alignment.isNucleotide())
+ {
+ obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
+ "");
+ if (obj != null)
+ text.append(" Nucleotide: ");
+ }
+ else
+ {
+ obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
+ if (obj != null)
+ text.append(" Residue: ");
+ }
+
+ if (obj != null)
+ {
+
+ if (obj != "")
+ {
+ text.append(obj + " (" + sequence.findPosition(res) +
+ ")");
+ }
+ }
+
+ ap.alignFrame.statusBar.setText(text.toString());
+
+ }
+ public void mousePressed(MouseEvent evt)
+ {
+ lastMousePress = evt.getPoint();
+
+ if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) ==
+ InputEvent.BUTTON2_MASK && !av.MAC)
+ {
+ mouseWheelPressed = true;
+ return;
+ }
+
+ if (evt.isShiftDown() || evt.isControlDown())
+ {
+ if (evt.isControlDown())
+ {
+ groupEditing = true;
+ }
+ editingSeqs = true;
+ }
+ else
+ {
+ doMousePressedDefineMode(evt);
+ return;
+ }
+
+
+ int seq = findSeq(evt);
+ int res = findRes(evt);
+
+ if(seq<0 || res<0)
+ return;
+
+ ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
+ av.alignment, HistoryItem.EDIT));
+
+ if ((seq < av.getAlignment().getHeight()) &&
+ (res < av.getAlignment().getSequenceAt(seq).getLength()))
+ {
+ startseq = seq;
+ lastres = res;
+ }
+ else
+ {
+ startseq = -1;
+ lastres = -1;
+ }
+
+ return;
+ }
+
+ public void mouseClicked(MouseEvent evt){}
+
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ mouseDragging = false;
+ mouseWheelPressed = false;
+
+ if (!editingSeqs)
+ {
+ doMouseReleasedDefineMode(evt);
+ return;
+ }
+
+ editOccurred();
+
+ endEditing();
+ ap.repaint();
+ }
+
+ int startWrapBlock=-1;
+ int wrappedBlock=-1;
+ int findRes(MouseEvent evt)
+ {
+ int res = 0;
+ int x = evt.getX();
+
+ if (av.wrapAlignment)
+ {
+
+ int hgap = av.charHeight;
+ if (av.scaleAboveWrapped)
+ hgap += av.charHeight;
+
+ int cHeight = av.getAlignment().getHeight() * av.charHeight
+ + hgap + seqCanvas.getAnnotationHeight();
+
+ int y = evt.getY();
+ y -= hgap;
+ x -= seqCanvas.LABEL_WEST;
+
+
+ int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
+
+ wrappedBlock = y / cHeight;
+ wrappedBlock += av.getStartRes() / cwidth;
+
+ res = wrappedBlock * cwidth + x / av.getCharWidth();
+
+ }
+ else
+ {
+ res = (x / av.getCharWidth()) + av.getStartRes();
+ }
+
+ if(av.hasHiddenColumns)
+ res = av.getColumnSelection().adjustForHiddenColumns(res);
+
+ return res;
+
+ }
+
+ int findSeq(MouseEvent evt)
+ {
+
+ int seq = 0;
+ int y = evt.getY();
+
+ if (av.wrapAlignment)
+ {
+ int hgap = av.charHeight;
+ if (av.scaleAboveWrapped)
+ hgap += av.charHeight;
+
+ int cHeight = av.getAlignment().getHeight() * av.charHeight
+ + hgap + seqCanvas.getAnnotationHeight();
+
+ y -= hgap;
+
+ seq = Math.min( (y % cHeight) / av.getCharHeight(),
+ av.alignment.getHeight() -1);
+ if(seq<0)
+ seq = 0;
+ }
+ else
+ {
+ seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),
+ av.alignment.getHeight() -1);
+ if(seq<0)
+ seq = 0;
+ }
+
+ return seq;
+ }
+
+
+ public void doMousePressed(MouseEvent evt)
+ {
+ ap.alignFrame.addHistoryItem(new HistoryItem(
+ "Edit Sequence", av.alignment, HistoryItem.EDIT));
+
+ int seq = findSeq(evt);
+ int res = findRes(evt);
+
+ if (seq < av.getAlignment().getHeight() &&
+ res < av.getAlignment().getSequenceAt(seq).getLength())
+ {
+ //char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
+ // Find the residue's position in the sequence (res is the position
+ // in the alignment
+
+ startseq = seq;
+ lastres = res;
+ }
+ else
+ {
+ startseq = -1;
+ lastres = -1;
+ }
+
+ return;
+ }
+
+ public void mouseMoved(MouseEvent evt)
+ {
+ int res = findRes(evt);
+ int seq = findSeq(evt);
+
+ if (seq >= av.getAlignment().getHeight() || seq<0 || res<0)
+ {
+ return;
+ }
+
+ SequenceI sequence = av.getAlignment().getSequenceAt(seq);
+ if (res > sequence.getLength())
+ {
+ return;
+ }
+
+ StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
+ sequence.getName());
+
+ Object obj = null;
+ if (av.alignment.isNucleotide())
+ {
+ obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
+ "");
+ if(obj!=null)
+ text.append(" Nucleotide: ");
+ }
+ else
+ {
+ obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
+ if(obj!=null)
+ text.append(" Residue: ");
+ }
+
+ if (obj != null)
+ {
+ if (obj != "")
+ {
+ text.append(obj + " (" + sequence.findPosition(res) + ")");
+ }
+ }
+
+ if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)
+ {
+ seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));
+ }
+
+ ap.alignFrame.statusBar.setText(text.toString());
+
+
+ // use aa to see if the mouse pointer is on a
+ if (av.showSequenceFeatures
+ && sequence.getSequenceFeatures()!=null
+ && av.featuresDisplayed!=null)
+ {
+ StringBuffer featureText = new StringBuffer();
+ Vector allFeatures = getAllFeaturesAtRes(sequence, sequence.findPosition(res));
+
+ int index = 0;
+ while (index < allFeatures.size())
+ {
+ SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index);
+
+ featureText.append(sf.getType()+" "+sf.begin+":"+sf.end);
+
+ if (sf.getDescription() != null)
+ featureText.append(" " + sf.getDescription());
+
+ if (sf.getValue("status") != null )
+ {
+ featureText.append(" (" + sf.getValue("status") + ")");
+ }
+ featureText.append("\n");
+
+ index++;
+ }
+
+
+ if (tooltip == null)
+ tooltip = new Tooltip(featureText.toString(), seqCanvas);
+ else
+ tooltip.setTip(featureText.toString());
+
+ tooltip.repaint();
+
+ }
+ }
+
+ Vector getAllFeaturesAtRes(SequenceI seq, int res)
+ {
+ Vector allFeatures = new Vector();
+ int index = 0;
+ if(seq.getSequenceFeatures()!=null)
+ {
+ while (index < seq.getSequenceFeatures().length)
+ {
+ SequenceFeature sf = seq.getSequenceFeatures()[index];
+ if (sf.getBegin() <= res &&
+ sf.getEnd() >= res)
+ {
+ if (av.featuresDisplayed.containsKey(sf.getType()))
+ {
+ allFeatures.addElement(sf);
+ }
+ }
+ index++;
+ }
+ }
+ return allFeatures;
+ }
+
+ Tooltip tooltip;
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ if (mouseWheelPressed)
+ {
+ int oldWidth = av.charWidth;
+
+ //Which is bigger, left-right or up-down?
+ if (Math.abs(evt.getY() - lastMousePress.y)
+ > Math.abs(evt.getX() - lastMousePress.x))
+ {
+ int fontSize = av.font.getSize();
+
+ if (evt.getY() < lastMousePress.y && av.charHeight > 1)
+ {
+ fontSize--;
+ }
+ else if (evt.getY() > lastMousePress.y)
+ {
+ fontSize++;
+ }
+
+
+ if(fontSize<1)
+ fontSize = 1;
+
+ av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
+ av.charWidth = oldWidth;
+ }
+ else
+ {
+ if (evt.getX() < lastMousePress.x && av.charWidth > 1)
+ {
+ av.charWidth--;
+ }
+ else if (evt.getX() > lastMousePress.x)
+ {
+ av.charWidth++;
+ }
+
+ if(av.charWidth<1)
+ {
+ av.charWidth = 1;
+ }
+ }
+
+ ap.fontChanged();
+
+ FontMetrics fm = getFontMetrics(av.getFont());
+ av.validCharWidth = fm.charWidth('M') <= av.charWidth;
+
+ lastMousePress = evt.getPoint();
+
+ ap.repaint();
+ ap.annotationPanel.image = null;
+ return;
+ }
+
+ if (!editingSeqs)
+ {
+ doMouseDraggedDefineMode(evt);
+ return;
+ }
+
+ int res = findRes(evt);
+
+ if (res < 0)
+ {
+ res = 0;
+ }
+
+ if ((lastres == -1) || (lastres == res))
+ {
+ return;
+ }
+
+ if ( (res < av.getAlignment().getWidth()) && (res < lastres))
+ {
+ // dragLeft, delete gap
+ editSequence(false, res);
+ }
+ else
+ editSequence(true, res);
+
+ mouseDragging = true;
+ if(scrollThread!=null)
+ scrollThread.setEvent(evt);
+
+ }
+
+ synchronized void editSequence(boolean insertGap, int startres)
+ {
+ int fixedLeft = -1;
+ int fixedRight = -1;
+ boolean fixedColumns = false;
+ SequenceGroup sg = av.getSelectionGroup();
+
+
+ if (!groupEditing && av.hasHiddenRows)
+ {
+ if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)
+ {
+ groupEditing = true;
+ }
+ }
+
+ //No group, but the sequence may represent a group
+ if (groupEditing
+ && sg == null
+ && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null)
+ {
+ groupEditing = false;
+ }
+
+ SequenceI seq = av.alignment.getSequenceAt(startseq);
+ StringBuffer message = new StringBuffer();
+ if (groupEditing)
+ message.append("Edit group:");
+ else
+ message.append("Edit sequence: "+seq.getName());
+
+ if(insertGap)
+ message.append(" insert ");
+ else
+ message.append(" delete ");
+
+ message.append(Math.abs(startres-lastres)+" gaps.");
+ ap.alignFrame.statusBar.setText(message.toString());
+
+
+ //Are we editing within a selection group?
+ if (groupEditing
+ || (sg != null && sg.getSequences(true).contains(seq)))
+ {
+ fixedColumns = true;
+
+ //sg might be null as the user may only see 1 sequence,
+ //but the sequence represents a group
+ if (sg == null)
+ {
+ sg = new SequenceGroup(null, null, false, false, false, 0,
+ av.alignment.getWidth()-1);
+ sg.addSequence(av.alignment.getSequenceAt(startseq), false);
+ }
+
+ fixedLeft = sg.getStartRes();
+ fixedRight = sg.getEndRes();
+
+ if ( (startres < fixedLeft && lastres >= fixedLeft)
+ || (startres >= fixedLeft && lastres < fixedLeft)
+ || (startres > fixedRight && lastres <=fixedRight)
+ || (startres <= fixedRight && lastres > fixedRight))
+ {
+ endEditing();
+ return;
+ }
+
+ if (fixedLeft > startres)
+ {
+ fixedRight = fixedLeft - 1;
+ fixedLeft = 0;
+ }
+ else if (fixedRight < startres)
+ {
+ fixedLeft = fixedRight;
+ fixedRight = -1;
+ }
+ }
+
+
+ if(av.hasHiddenColumns )
+ {
+ fixedColumns = true;
+ int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
+ int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
+
+ if ( (insertGap && startres > y1 && lastres < y1)
+ || (!insertGap && startres < y2 && lastres > y2))
+ {
+ endEditing();
+ return;
+ }
+
+ //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
+ //Selection spans a hidden region
+ if(fixedLefty2 || fixedRight==-1))
+ {
+ if(startres>=y2)
+ {
+ fixedLeft = y2;
+ }
+ else
+ {
+ fixedRight = y2 - 1;
+ }
+ }
+ }
+
+
+ if (groupEditing)
+ {
+ // drag to right
+ if (insertGap)
+ {
+ //If the user has selected the whole sequence, and is dragging to
+ // the right, we can still extend the alignment and selectionGroup
+ if( sg.getStartRes() == 0
+ && sg.getEndRes() == fixedRight
+ && sg.getEndRes() == av.alignment.getWidth()-1
+ )
+ {
+ sg.setEndRes(av.alignment.getWidth() + startres - lastres);
+ fixedRight = sg.getEndRes();
+ }
+
+ // Is it valid with fixed columns??
+ // Find the next gap before the end
+ // of the visible region boundary
+ boolean blank = false;
+ for (fixedRight = fixedRight;
+ fixedRight > lastres;
+ fixedRight--)
+ {
+ blank = true;
+ for (int s = 0; s < sg.getSize(true); s++)
+ {
+ seq = (SequenceI)sg.getSequences(true).elementAt(s);
+ for (int j = 0; j < startres - lastres; j++)
+ {
+ if (!jalview.util.Comparison.isGap(
+ seq.getCharAt(fixedRight - j)))
+ {
+ blank = false;
+ break;
+ }
+ }
+ }
+ if (blank)
+ break;
+ }
+
+ if (!blank)
+ {
+ if(sg.getSize(false) == av.alignment.getHeight() )
+ {
+ if((av.hasHiddenColumns
+ && startresalWidth)
+ alWidth = hwidth;
+ }
+ //We can still insert gaps if the selectionGroup
+ //contains all the sequences
+ sg.setEndRes(sg.getEndRes()+startres-lastres);
+ fixedRight = alWidth+startres-lastres;
+ }
+ else
+ {
+ endEditing();
+ return;
+ }
+ }
+ }
+
+
+ // drag to left
+ else if(!insertGap)
+ {
+ /// Are we able to delete?
+ // ie are all columns blank?
+
+ for (int s = 0; s < sg.getSize(true); s++)
+ {
+ seq = (SequenceI)sg.getSequences(true).elementAt(s);
+
+ for (int j = startres; j < lastres; j++)
+ {
+ if (seq.getSequence().length() <= j)
+ {
+ continue;
+ }
+
+ if (!jalview.util.Comparison.isGap(
+ seq.getSequence().charAt(j)))
+ {
+ // Not a gap, block edit not valid
+ endEditing();
+ return;
+ }
+ }
+ }
+ }
+
+
+ for (int i = 0; i < sg.getSize(true); i++)
+ {
+ seq = (SequenceI) sg.getSequences(true).elementAt(i);
+
+ if (insertGap)
+ {
+ // dragging to the right
+ for (int j = lastres; j < startres; j++)
+ {
+ if (fixedColumns && fixedRight != -1)
+ {
+ insertChar(j, seq, fixedRight);
+ }
+ else
+ insertChar(j, seq);
+ }
+ }
+ else
+ {
+ // dragging to the left
+ for (int j = lastres; j > startres; j--)
+ {
+ if (fixedColumns && fixedRight != -1)
+ {
+ deleteChar(startres, seq, fixedRight);
+ }
+ else
+ {
+ deleteChar(startres, seq);
+ }
+ }
+ }
+ }
+ }
+ else /////Editing a single sequence///////////
+ {
+ if (insertGap)
+ {
+ // dragging to the right
+ for (int j = lastres; j < startres; j++)
+ {
+ if (fixedColumns && fixedRight != -1)
+ {
+ insertChar(j, seq, fixedRight);
+ }
+ else
+ insertChar(j, seq);
+ }
+ }
+ else
+ {
+ // dragging to the left
+ for (int j = lastres; j > startres; j--)
+ {
+ if (fixedColumns && fixedRight != -1)
+ {
+ deleteChar(startres, seq, fixedRight);
+ }
+ else
+ {
+ deleteChar(startres, seq);
+ }
+ }
+ }
+ }
+
+ lastres = startres;
+ seqCanvas.repaint();
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param j DOCUMENT ME!
+ * @param seq DOCUMENT ME!
+ */
+ void insertChar(int j, SequenceI seq)
+ {
+ seq.insertCharAt(j, av.getGapCharacter());
+ seqEditOccurred = true;
+ }
+
+ void insertChar(int j, SequenceI seq, int fixedColumn)
+ {
+ //Find the next gap before the end of the visible region boundary
+ //If lastCol > j, theres a boundary after the gap insertion
+ int blankColumn = fixedColumn;
+ for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
+ {
+ if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
+ {
+ //Theres a space, so break and insert the gap
+ break;
+ }
+ }
+
+ if (blankColumn <= j)
+ {
+ endEditing();
+ return;
+ }
+
+ if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
+ {
+ //Just Checking
+ System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));
+ return;
+ }
+
+ seq.deleteCharAt(blankColumn);
+ seq.insertCharAt(j, av.getGapCharacter());
+ seqEditOccurred = true;
+ }
+
+ void deleteChar(int j, SequenceI seq, int fixedColumn)
+ {
+ if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
+ {
+ ap.alignFrame.statusBar.setText(
+ "End editing: Tried removing residue " + seq.getCharAt(j));
+ return;
+ }
+
+ seq.deleteCharAt(j);
+ seq.insertCharAt(fixedColumn, av.getGapCharacter());
+ seqEditOccurred = true;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param j DOCUMENT ME!
+ * @param seq DOCUMENT ME!
+ */
+ void deleteChar(int j, SequenceI seq)
+ {
+ if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
+ {
+ ap.alignFrame.statusBar.setText(
+ "End editing: Tried removing residue " + seq.getCharAt(j));
+ return;
+ }
+
+ seq.deleteCharAt(j);
+ seqEditOccurred = true;
+ seqCanvas.repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ void editOccurred()
+ {
+ if (!seqEditOccurred)
+ {
+ ap.alignFrame.historyList.pop();
+ ap.alignFrame.updateEditMenuBar();
+ }
+
+ endEditing();
+
+ av.firePropertyChange("alignment", null,av.getAlignment().getSequences());
+
+ }
+
+//////////////////////////////////////////
+/////Everything below this is for defining the boundary of the rubberband
+//////////////////////////////////////////
+ public void doMousePressedDefineMode(MouseEvent evt)
+ {
+
+
+ if (scrollThread != null)
+ {
+ scrollThread.running = false;
+ scrollThread = null;
+ }
+
+ int res = findRes(evt);
+ int seq = findSeq(evt);
+ oldSeq = seq;
+ startWrapBlock=wrappedBlock;
+
+ if(seq==-1)
+ return;
+
+ SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
+
+ if (sequence == null || res > sequence.getLength())
+ {
+ return;
+ }
+
+ stretchGroup = av.getSelectionGroup();
+
+ if (stretchGroup == null)
+ {
+ stretchGroup = av.alignment.findGroup(sequence);
+ if (stretchGroup != null && res > stretchGroup.getStartRes() &&
+ res < stretchGroup.getEndRes())
+ {
+ av.setSelectionGroup(stretchGroup);
+ }
+ else
+ {
+ stretchGroup = null;
+ }
+ }
+
+ else if (!stretchGroup.getSequences(false).contains(sequence)
+ || stretchGroup.getStartRes() > res
+ || stretchGroup.getEndRes() < res)
+ {
+ stretchGroup = null;
+
+ SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
+
+ if (allGroups != null)
+ {
+ for (int i = 0; i < allGroups.length; i++)
+ {
+ if (allGroups[i].getStartRes() <= res &&
+ allGroups[i].getEndRes() >= res)
+ {
+ stretchGroup = allGroups[i];
+ break;
+ }
+ }
+ }
+ av.setSelectionGroup(stretchGroup);
+ }
+
+
+ // DETECT RIGHT MOUSE BUTTON IN AWT
+ if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) ==
+ InputEvent.BUTTON3_MASK)
+ {
+ Vector allFeatures = getAllFeaturesAtRes(sequence,
+ sequence.findPosition(res));
+
+ Vector links = null;
+ if(allFeatures!=null)
+ {
+ for (int i = 0; i < allFeatures.size(); i++)
+ {
+ SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
+ if (sf.links != null)
+ {
+ links = new Vector();
+ for (int j = 0; j < sf.links.size(); j++)
+ {
+ links.addElement(sf.links.elementAt(j));
+ }
+ }
+ }
+ }
+ APopupMenu popup = new APopupMenu(ap, null, links);
+ this.add(popup);
+ popup.show(this, evt.getX(), evt.getY());
+ ap.repaint();
+ return;
+ }
+
+ if (av.cursorMode)
+ {
+ seqCanvas.cursorX = findRes(evt);
+ seqCanvas.cursorY = findSeq(evt);
+ seqCanvas.repaint();
+ return;
+ }
+
+ //Only if left mouse button do we want to change group sizes
+
+ if (stretchGroup == null)
+ {
+ // define a new group here
+ SequenceGroup sg = new SequenceGroup();
+ sg.setStartRes(res);
+ sg.setEndRes(res);
+ sg.addSequence(sequence, false);
+ av.setSelectionGroup(sg);
+ stretchGroup = sg;
+
+ if (av.getConservationSelected())
+ {
+ SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
+ "Background");
+ }
+ if (av.getAbovePIDThreshold())
+ {
+ SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
+ "Background");
+ }
+
+ }
+ }
+
+ public void doMouseReleasedDefineMode(MouseEvent evt)
+ {
+ if (stretchGroup == null)
+ {
+ return;
+ }
+
+ if(stretchGroup.cs!=null)
+ {
+ if (stretchGroup.cs instanceof ClustalxColourScheme)
+ {
+ ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
+ stretchGroup.getSequences(true),
+ stretchGroup.getWidth());
+ }
+
+ if (stretchGroup.cs.conservationApplied())
+ {
+ SliderPanel.setConservationSlider(ap, stretchGroup.cs,
+ stretchGroup.getName());
+ stretchGroup.recalcConservation();
+ }
+ else
+ {
+ SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
+ stretchGroup.getName());
+ }
+ }
+ changeEndRes = false;
+ changeStartRes = false;
+ stretchGroup = null;
+ PaintRefresher.Refresh(av.alignment);
+ ap.repaint();
+ }
+
+ public void doMouseDraggedDefineMode(MouseEvent evt)
+ {
+ int res = findRes(evt);
+ int y = findSeq(evt);
+
+ if(wrappedBlock!=startWrapBlock)
+ return;
+
+ if (stretchGroup == null)
+ {
+ return;
+ }
+
+ mouseDragging = true;
+
+
+ if(y > av.alignment.getHeight())
+ {
+ y = av.alignment.getHeight() -1;
+ }
+
+ if(res>av.alignment.getWidth())
+ res = av.alignment.getWidth()-1;
+
+ if (stretchGroup.getEndRes() == res)
+ {
+ // Edit end res position of selected group
+ changeEndRes = true;
+ }
+ else if (stretchGroup.getStartRes() == res)
+ {
+ // Edit start res position of selected group
+ changeStartRes = true;
+ }
+
+ if (res < 0)
+ {
+ res = 0;
+ }
+
+ if (changeEndRes)
+ {
+ if (res > (stretchGroup.getStartRes() - 1))
+ {
+ stretchGroup.setEndRes(res);
+ }
+ }
+ else if (changeStartRes)
+ {
+ if (res < (stretchGroup.getEndRes() + 1))
+ {
+ stretchGroup.setStartRes(res);
+ }
+ }
+
+ int dragDirection = 0;
+
+ if (y > oldSeq)
+ {
+ dragDirection = 1;
+ }
+ else if (y < oldSeq)
+ {
+ dragDirection = -1;
+ }
+
+
+ while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
+ {
+ // This routine ensures we don't skip any sequences, as the
+ // selection is quite slow.
+ Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
+
+ oldSeq += dragDirection;
+
+ if(oldSeq<0)
+ break;
+
+ Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
+
+ if (stretchGroup.getSequences(false).contains(nextSeq))
+ {
+ stretchGroup.deleteSequence(seq, false);
+ }
+ else
+ {
+ if (seq != null)
+ {
+ stretchGroup.addSequence(seq, false);
+ }
+
+ stretchGroup.addSequence(nextSeq, false);
+ }
+ }
+
+ if(oldSeq < 0)
+ oldSeq = -1;
+
+
+ if(res>av.endRes || resav.endSeq)
+ {
+ mouseExited(evt);
+ }
+
+ if (scrollThread != null)
+ {
+ scrollThread.setEvent(evt);
+ }
+
+ seqCanvas.repaint();
+ }
+
+ public void mouseEntered(MouseEvent e)
+ {
+ if (oldSeq < 0)
+ oldSeq = 0;
+
+ if (scrollThread != null)
+ {
+ scrollThread.running = false;
+ scrollThread = null;
+ }
+ }
+
+ public void mouseExited(MouseEvent e)
+ {
+ if (av.getWrapAlignment())
+ {
+ return;
+ }
+
+ if (mouseDragging && scrollThread==null)
+ {
+ scrollThread = new ScrollThread();
+ }
+ }
+
+ void scrollCanvas(MouseEvent evt)
+ {
+ if(evt==null)
+ {
+ if(scrollThread!=null)
+ {
+ scrollThread.running = false;
+ scrollThread = null;
+ }
+ mouseDragging = false;
+ }
+ else
+ {
+ if (scrollThread == null)
+ scrollThread = new ScrollThread();
+
+ mouseDragging = true;
+ scrollThread.setEvent(evt);
+ }
+
+ }
+
+ // this class allows scrolling off the bottom of the visible alignment
+ class ScrollThread
+ extends Thread
+ {
+ MouseEvent evt;
+ boolean running = false;
+ public ScrollThread()
+ {
+ start();
+ }
+
+ public void setEvent(MouseEvent e)
+ {
+ evt = e;
+ }
+
+ public void stopScrolling()
+ {
+ running = false;
+ }
+
+ public void run()
+ {
+ running = true;
+ while (running)
+ {
+
+ if (evt != null)
+ {
+
+ if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
+ {
+ running = ap.scrollUp(true);
+ }
+
+ if (mouseDragging && evt.getY() >= getSize().height &&
+ av.alignment.getHeight() > av.getEndSeq())
+ {
+ running = ap.scrollUp(false);
+ }
+
+ if (mouseDragging && evt.getX() < 0)
+ {
+ running = ap.scrollRight(false);
+ }
+
+ else if (mouseDragging && evt.getX() >= getSize().width)
+ {
+ running = ap.scrollRight(true);
+ }
+ }
+
+ try
+ {
+ Thread.sleep(75);
+ }
+ catch (Exception ex)
+ {}
+ }
+ }
+ }
+
+}
diff --git a/src/jalview/appletgui/SequenceRenderer.java b/src/jalview/appletgui/SequenceRenderer.java
index 3f87b02..9546dcb 100755
--- a/src/jalview/appletgui/SequenceRenderer.java
+++ b/src/jalview/appletgui/SequenceRenderer.java
@@ -1,267 +1,297 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.awt.*;
-
-import jalview.datamodel.*;
-import jalview.schemes.*;
-
-public class SequenceRenderer
-{
- AlignViewport av;
- FontMetrics fm;
- boolean renderGaps = true;
- SequenceGroup currentSequenceGroup = null;
- SequenceGroup[] allGroups = null;
- Color resBoxColour;
- Graphics graphics;
- boolean forOverview = false;
-
- public SequenceRenderer(AlignViewport av)
- {
- this.av = av;
- }
-
- public void renderGaps(boolean b)
- {
- renderGaps = b;
- }
-
- public Color getResidueBoxColour(SequenceI seq, int i)
- {
- allGroups = av.alignment.findAllGroups(seq);
-
- if (inCurrentSequenceGroup(i))
- {
- if (currentSequenceGroup.getDisplayBoxes())
- {
- getBoxColour(currentSequenceGroup.cs, seq, i);
- }
- }
- else if (av.getShowBoxes())
- {
- getBoxColour(av.globalColourScheme, seq, i);
- }
-
- return resBoxColour;
- }
-
- void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
- {
- if (cs != null)
- {
- resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);
- }
- else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))
- {
- resBoxColour = Color.lightGray;
- }
- else
- {
- resBoxColour = Color.white;
- }
-
- }
-
- public Color findSequenceColour(SequenceI seq, int i)
- {
- allGroups = av.alignment.findAllGroups(seq);
- drawBoxes(seq, i,i, 0);
- return resBoxColour;
- }
-
- public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
- int start, int end, int y1)
- {
- allGroups = sg;
-
- graphics = g;
-
- drawBoxes(seq, start, end, y1);
-
- fm = g.getFontMetrics();
- drawText(seq, start, end, y1);
-
- }
-
- public void drawBoxes(SequenceI seq, int start, int end, int y1)
- {
- int i = start;
- int length = seq.getLength();
-
- int curStart = -1;
- int curWidth = av.charWidth;
-
- Color tempColour = null;
- while (i <= end)
- {
- resBoxColour = Color.white;
- if(i < length)
- {
- if (inCurrentSequenceGroup(i))
- {
- if (currentSequenceGroup.getDisplayBoxes())
- {
- getBoxColour(currentSequenceGroup.cs, seq, i);
- }
- }
- else if (av.getShowBoxes())
- {
- getBoxColour(av.getGlobalColourScheme(), seq, i);
- }
- }
-
-
- if (resBoxColour != tempColour)
- {
- if (tempColour != null)
- {
- graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth,
- av.charHeight);
- }
- graphics.setColor(resBoxColour);
-
- curStart = i;
- curWidth = av.charWidth;
- tempColour = resBoxColour;
-
- }
- else
- {
- curWidth += av.charWidth;
- }
-
- i++;
- }
-
- graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth, av.charHeight);
- }
-
- public void drawText(SequenceI seq, int start, int end, int y1)
- {
-
- y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady
-
- int charOffset = 0;
-
- // Need to find the sequence position here.
- if(end+1>=seq.getLength())
- end = seq.getLength()-1;
-
- char s = ' ';
-
- for (int i = start; i <= end; i++)
- {
- graphics.setColor(Color.black);
-
- s = seq.getCharAt(i);
- if (!renderGaps && jalview.util.Comparison.isGap(s))
- {
- continue;
- }
-
- if (inCurrentSequenceGroup(i))
- {
- if (!currentSequenceGroup.getDisplayText())
- {
- continue;
- }
-
- if (currentSequenceGroup.getColourText())
- {
- getBoxColour(currentSequenceGroup.cs, seq, i);
- graphics.setColor(resBoxColour.darker());
- }
- }
- else
- {
- if (!av.getShowText())
- {
- continue;
- }
-
- if (av.getColourText())
- {
- getBoxColour(av.getGlobalColourScheme(), seq, i);
- if (av.getShowBoxes())
- {
- graphics.setColor(resBoxColour.darker());
- }
- else
- {
- graphics.setColor(resBoxColour);
- }
- }
- }
-
- charOffset = (av.charWidth - fm.charWidth(s)) / 2;
- graphics.drawString(String.valueOf(s),
- charOffset + av.charWidth * (i - start),
- y1 );
- }
-
- }
-
- boolean inCurrentSequenceGroup(int res)
- {
- if (allGroups == null)
- {
- return false;
- }
-
- for (int i = 0; i < allGroups.length; i++)
- {
- if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)
- {
- currentSequenceGroup = allGroups[i];
- return true;
- }
- }
-
- return false;
- }
-
- public void drawHighlightedText(SequenceI seq, int start, int end, int x1,
- int y1, int width, int height)
- {
- int pady = height / 5;
- int charOffset = 0;
- graphics.setColor(Color.black);
- graphics.fillRect(x1, y1, width * (end - start + 1), height);
- graphics.setColor(Color.white);
-
- char s = '~';
- // Need to find the sequence position here.
- for (int i = start; i <= end; i++)
- {
- if (i < seq.getLength())
- {
- s = seq.getSequence().charAt(i);
- }
-
- charOffset = (width - fm.charWidth(s)) / 2;
- graphics.drawString(String.valueOf(s),
- charOffset + x1 + width * (i - start),
- y1 + height - pady);
- }
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+
+import jalview.datamodel.*;
+import jalview.schemes.*;
+
+public class SequenceRenderer
+{
+ AlignViewport av;
+ FontMetrics fm;
+ boolean renderGaps = true;
+ SequenceGroup currentSequenceGroup = null;
+ SequenceGroup[] allGroups = null;
+ Color resBoxColour;
+ Graphics graphics;
+ boolean forOverview = false;
+
+ public SequenceRenderer(AlignViewport av)
+ {
+ this.av = av;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void prepare(Graphics g, boolean renderGaps)
+ {
+ graphics = g;
+ fm = g.getFontMetrics();
+
+ this.renderGaps = renderGaps;
+ }
+
+ public Color getResidueBoxColour(SequenceI seq, int i)
+ {
+ allGroups = av.alignment.findAllGroups(seq);
+
+ if (inCurrentSequenceGroup(i))
+ {
+ if (currentSequenceGroup.getDisplayBoxes())
+ {
+ getBoxColour(currentSequenceGroup.cs, seq, i);
+ }
+ }
+ else if (av.getShowBoxes())
+ {
+ getBoxColour(av.globalColourScheme, seq, i);
+ }
+
+ return resBoxColour;
+ }
+
+ void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
+ {
+ if (cs != null)
+ {
+ resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);
+ }
+ else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))
+ {
+ resBoxColour = Color.lightGray;
+ }
+ else
+ {
+ resBoxColour = Color.white;
+ }
+
+ }
+
+ public Color findSequenceColour(SequenceI seq, int i)
+ {
+ allGroups = av.alignment.findAllGroups(seq);
+ drawBoxes(seq, i,i, 0);
+ return resBoxColour;
+ }
+
+ public void drawSequence(SequenceI seq, SequenceGroup[] sg,
+ int start, int end, int y1)
+ {
+ allGroups = sg;
+
+ drawBoxes(seq, start, end, y1);
+
+ if(av.validCharWidth)
+ {
+ drawText(seq, start, end, y1);
+ }
+ }
+
+ public void drawBoxes(SequenceI seq, int start, int end, int y1)
+ {
+ int i = start;
+ int length = seq.getLength();
+
+ int curStart = -1;
+ int curWidth = av.charWidth;
+
+ Color tempColour = null;
+ while (i <= end)
+ {
+ resBoxColour = Color.white;
+ if(i < length)
+ {
+ if (inCurrentSequenceGroup(i))
+ {
+ if (currentSequenceGroup.getDisplayBoxes())
+ {
+ getBoxColour(currentSequenceGroup.cs, seq, i);
+ }
+ }
+ else if (av.getShowBoxes())
+ {
+ getBoxColour(av.getGlobalColourScheme(), seq, i);
+ }
+ }
+
+
+ if (resBoxColour != tempColour)
+ {
+ if (tempColour != null)
+ {
+ graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth,
+ av.charHeight);
+ }
+ graphics.setColor(resBoxColour);
+
+ curStart = i;
+ curWidth = av.charWidth;
+ tempColour = resBoxColour;
+
+ }
+ else
+ {
+ curWidth += av.charWidth;
+ }
+
+ i++;
+ }
+
+ graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth, av.charHeight);
+ }
+
+ public void drawText(SequenceI seq, int start, int end, int y1)
+ {
+
+ y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady
+
+ int charOffset = 0;
+
+ // Need to find the sequence position here.
+ if(end+1>=seq.getLength())
+ end = seq.getLength()-1;
+
+ char s = ' ';
+
+ for (int i = start; i <= end; i++)
+ {
+ graphics.setColor(Color.black);
+
+ s = seq.getCharAt(i);
+ if (!renderGaps && jalview.util.Comparison.isGap(s))
+ {
+ continue;
+ }
+
+ if (inCurrentSequenceGroup(i))
+ {
+ if (!currentSequenceGroup.getDisplayText())
+ {
+ continue;
+ }
+
+ if (currentSequenceGroup.getColourText())
+ {
+ getBoxColour(currentSequenceGroup.cs, seq, i);
+ graphics.setColor(resBoxColour.darker());
+ }
+ }
+ else
+ {
+ if (!av.getShowText())
+ {
+ continue;
+ }
+
+ if (av.getColourText())
+ {
+ getBoxColour(av.getGlobalColourScheme(), seq, i);
+ if (av.getShowBoxes())
+ {
+ graphics.setColor(resBoxColour.darker());
+ }
+ else
+ {
+ graphics.setColor(resBoxColour);
+ }
+ }
+ }
+
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;
+ graphics.drawString(String.valueOf(s),
+ charOffset + av.charWidth * (i - start),
+ y1 );
+ }
+
+ }
+
+ boolean inCurrentSequenceGroup(int res)
+ {
+ if (allGroups == null)
+ {
+ return false;
+ }
+
+ for (int i = 0; i < allGroups.length; i++)
+ {
+ if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)
+ {
+ currentSequenceGroup = allGroups[i];
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public void drawHighlightedText(SequenceI seq, int start, int end, int x1, int y1)
+ {
+ int pady = av.charHeight / 5;
+ int charOffset = 0;
+ graphics.setColor(Color.black);
+ graphics.fillRect(x1, y1, av.charWidth * (end - start + 1), av.charHeight);
+ graphics.setColor(Color.white);
+
+ char s = '~';
+ // Need to find the sequence position here.
+ if(av.validCharWidth)
+ {
+ for (int i = start; i <= end; i++)
+ {
+ if (i < seq.getLength())
+ {
+ s = seq.getSequence().charAt(i);
+ }
+
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;
+ graphics.drawString(String.valueOf(s),
+ charOffset + x1 + av.charWidth * (i - start),
+ y1 + av.charHeight - pady);
+ }
+ }
+ }
+
+ public void drawCursor(SequenceI seq, int res, int x1, int y1)
+ {
+ int pady = av.charHeight / 5;
+ int charOffset = 0;
+ graphics.setColor(Color.black);
+ graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
+ graphics.setColor(Color.white);
+
+ graphics.setColor(Color.white);
+
+ char s = seq.getCharAt(res);
+ if (av.validCharWidth)
+ {
+
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;
+ graphics.drawString(String.valueOf(s),
+ charOffset + x1,
+ (y1 + av.charHeight) - pady);
+ }
+ }
+
+}
diff --git a/src/jalview/appletgui/SliderPanel.java b/src/jalview/appletgui/SliderPanel.java
index c343df9..450bf29 100755
--- a/src/jalview/appletgui/SliderPanel.java
+++ b/src/jalview/appletgui/SliderPanel.java
@@ -1,334 +1,351 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-import jalview.schemes.*;
-
-public class SliderPanel extends Panel implements ActionListener, AdjustmentListener
-{
- AlignmentPanel ap;
- boolean forConservation = true;
- ColourSchemeI cs;
-
- static Frame conservationSlider;
- static Frame PIDSlider;
-
- public static int setConservationSlider(AlignmentPanel ap, ColourSchemeI cs,
- String source)
- {
- SliderPanel sp = null;
-
- if (conservationSlider == null)
- {
- sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
- conservationSlider = new Frame();
- conservationSlider.add(sp);
- }
- else
- {
- sp = (SliderPanel) conservationSlider.getComponent(0);
- sp.cs = cs;
- }
-
- conservationSlider.setTitle("Conservation Colour Increment (" + source +
- ")");
- if (ap.av.alignment.getGroups() != null)
- {
- sp.setAllGroupsCheckEnabled(true);
- }
- else
- {
- sp.setAllGroupsCheckEnabled(false);
- }
-
- return sp.getValue();
- }
-
- public static void showConservationSlider()
- {
- try
- {
- PIDSlider.setVisible(false);
- PIDSlider = null;
- }
- catch (Exception ex)
- {}
-
- if (!conservationSlider.isVisible())
- {
- jalview.bin.JalviewLite.addFrame(conservationSlider,
- conservationSlider.getTitle(), 420, 100);
- conservationSlider.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- conservationSlider = null;
- }
- });
-
- }
-
- }
-
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
- String source)
- {
- SliderPanel pid = null;
- if (PIDSlider == null)
- {
- pid = new SliderPanel(ap, 50, false, cs);
- PIDSlider = new Frame();
- PIDSlider.add(pid);
- }
- else
- {
- pid = (SliderPanel) PIDSlider.getComponent(0);
- pid.cs = cs;
- }
- PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
-
- if (ap.av.alignment.getGroups() != null)
- {
- pid.setAllGroupsCheckEnabled(true);
- }
- else
- {
- pid.setAllGroupsCheckEnabled(false);
- }
-
- return pid.getValue();
-
- }
-
- public static void showPIDSlider()
- {
- try
- {
- conservationSlider.setVisible(false);
- conservationSlider = null;
- }
- catch (Exception ex)
- {}
-
- if (!PIDSlider.isVisible())
- {
- jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(), 420,
- 100);
- PIDSlider.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- PIDSlider = null;
- }
- });
- }
-
- }
-
- public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
- ColourSchemeI cs)
- {
- try {
- jbInit();
- } catch (Exception e) {
- e.printStackTrace();
- }
- this.ap = ap;
- this.cs = cs;
- forConservation = forConserve;
- undoButton.setVisible(false);
- applyButton.setVisible(false);
- if (forConservation)
- {
- label.setText("Modify conservation visibility");
- slider.setMinimum(0);
- slider.setMaximum(50 + slider.getVisibleAmount());
- slider.setUnitIncrement(1);
- }
- else
- {
- label.setText("Colour residues above % occurence");
- slider.setMinimum(0);
- slider.setMaximum(100 + slider.getVisibleAmount());
- slider.setBlockIncrement(1);
- }
-
- slider.addAdjustmentListener(this);
-
- slider.setValue(value);
- valueField.setText(value + "");
- }
-
- public void valueChanged(int i)
- {
- if (cs == null)
- {
- return;
- }
-
- ColourSchemeI toChange = null;
- Vector allGroups = null;
- int groupIndex = 0;
-
- if (allGroupsCheck.getState())
- {
- allGroups = ap.av.alignment.getGroups();
- groupIndex = allGroups.size() - 1;
- }
- else
- {
- toChange = cs;
- }
-
- while (groupIndex > -1)
- {
- if (allGroups != null)
- {
- toChange = ( (SequenceGroup) allGroups.elementAt(groupIndex)).cs;
- }
-
- if (forConservation)
- {
- toChange.setConservationInc(i);
- }
- else
- {
- toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
- }
-
- groupIndex--;
- }
-
- ap.seqPanel.seqCanvas.repaint();
-
- }
-
- public void setAllGroupsCheckEnabled(boolean b)
- {
- allGroupsCheck.setEnabled(b);
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource()==applyButton)
- applyButton_actionPerformed();
- else if(evt.getSource()==undoButton)
- undoButton_actionPerformed();
- else if(evt.getSource()==valueField)
- valueField_actionPerformed();
- }
-
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- valueField.setText(slider.getValue() + "");
- valueChanged(slider.getValue());
- }
-
-
- public void valueField_actionPerformed()
- {
- try
- {
- int i = Integer.parseInt(valueField.getText());
- slider.setValue(i);
- }
- catch (Exception ex)
- {
- valueField.setText(slider.getValue() + "");
- }
- }
-
- public void setValue(int value)
- {
- slider.setValue(value);
- }
-
- public int getValue()
- {
- return Integer.parseInt(valueField.getText());
- }
-
- // this is used for conservation colours, PID colours and redundancy threshold
- protected Scrollbar slider = new Scrollbar();
- protected TextField valueField = new TextField();
- protected Label label = new Label();
- Panel jPanel1 = new Panel();
- Panel jPanel2 = new Panel();
- protected Button applyButton = new Button();
- protected Button undoButton = new Button();
- FlowLayout flowLayout1 = new FlowLayout();
- protected Checkbox allGroupsCheck = new Checkbox();
- BorderLayout borderLayout1 = new BorderLayout();
- BorderLayout borderLayout2 = new BorderLayout();
- FlowLayout flowLayout2 = new FlowLayout();
-
- private void jbInit() throws Exception {
- this.setLayout(borderLayout2);
-
- // slider.setMajorTickSpacing(10);
- // slider.setMinorTickSpacing(1);
- // slider.setPaintTicks(true);
- slider.setBackground(Color.white);
- slider.setFont(new java.awt.Font("Verdana", 0, 11));
- slider.setOrientation(0);
- valueField.setFont(new java.awt.Font("Verdana", 0, 11));
- valueField.setText(" ");
- valueField.addActionListener(this);
- label.setFont(new java.awt.Font("Verdana", 0, 11));
- label.setText("set this label text");
- jPanel1.setLayout(borderLayout1);
- jPanel2.setLayout(flowLayout1);
- applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
- applyButton.setLabel("Apply");
- applyButton.addActionListener(this);
- undoButton.setEnabled(false);
- undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
- undoButton.setLabel("Undo");
- undoButton.addActionListener(this);
- allGroupsCheck.setEnabled(false);
- allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
- allGroupsCheck.setLabel("Apply threshold to all groups");
- allGroupsCheck.setName("Apply to all Groups");
- this.setBackground(Color.white);
- this.setForeground(Color.black);
- jPanel2.add(label, null);
- jPanel2.add(applyButton, null);
- jPanel2.add(undoButton, null);
- jPanel2.add(allGroupsCheck);
- jPanel1.add(valueField, java.awt.BorderLayout.EAST);
- jPanel1.add(slider, java.awt.BorderLayout.CENTER);
- this.add(jPanel1, java.awt.BorderLayout.SOUTH);
- this.add(jPanel2, java.awt.BorderLayout.CENTER);
- }
-
- protected void applyButton_actionPerformed()
- {
- }
-
- protected void undoButton_actionPerformed()
- {
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+import jalview.schemes.*;
+
+public class SliderPanel extends Panel
+ implements ActionListener,
+ AdjustmentListener,
+ MouseListener
+{
+ AlignmentPanel ap;
+ boolean forConservation = true;
+ ColourSchemeI cs;
+
+ static Frame conservationSlider;
+ static Frame PIDSlider;
+
+ public static int setConservationSlider(AlignmentPanel ap, ColourSchemeI cs,
+ String source)
+ {
+ SliderPanel sp = null;
+
+ if (conservationSlider == null)
+ {
+ sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
+ conservationSlider = new Frame();
+ conservationSlider.add(sp);
+ }
+ else
+ {
+ sp = (SliderPanel) conservationSlider.getComponent(0);
+ sp.cs = cs;
+ }
+
+ conservationSlider.setTitle("Conservation Colour Increment (" + source +
+ ")");
+ if (ap.av.alignment.getGroups() != null)
+ {
+ sp.setAllGroupsCheckEnabled(true);
+ }
+ else
+ {
+ sp.setAllGroupsCheckEnabled(false);
+ }
+
+ return sp.getValue();
+ }
+
+ public static void showConservationSlider()
+ {
+ try
+ {
+ PIDSlider.setVisible(false);
+ PIDSlider = null;
+ }
+ catch (Exception ex)
+ {}
+
+ if (!conservationSlider.isVisible())
+ {
+ jalview.bin.JalviewLite.addFrame(conservationSlider,
+ conservationSlider.getTitle(), 420, 100);
+ conservationSlider.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ conservationSlider = null;
+ }
+ });
+
+ }
+
+ }
+
+ public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
+ String source)
+ {
+ SliderPanel pid = null;
+ if (PIDSlider == null)
+ {
+ pid = new SliderPanel(ap, 50, false, cs);
+ PIDSlider = new Frame();
+ PIDSlider.add(pid);
+ }
+ else
+ {
+ pid = (SliderPanel) PIDSlider.getComponent(0);
+ pid.cs = cs;
+ }
+ PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
+
+ if (ap.av.alignment.getGroups() != null)
+ {
+ pid.setAllGroupsCheckEnabled(true);
+ }
+ else
+ {
+ pid.setAllGroupsCheckEnabled(false);
+ }
+
+ return pid.getValue();
+
+ }
+
+ public static void showPIDSlider()
+ {
+ try
+ {
+ conservationSlider.setVisible(false);
+ conservationSlider = null;
+ }
+ catch (Exception ex)
+ {}
+
+ if (!PIDSlider.isVisible())
+ {
+ jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(), 420,
+ 100);
+ PIDSlider.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ PIDSlider = null;
+ }
+ });
+ }
+
+ }
+
+ public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
+ ColourSchemeI cs)
+ {
+ try {
+ jbInit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ this.ap = ap;
+ this.cs = cs;
+ forConservation = forConserve;
+ undoButton.setVisible(false);
+ applyButton.setVisible(false);
+ if (forConservation)
+ {
+ label.setText("Modify conservation visibility");
+ slider.setMinimum(0);
+ slider.setMaximum(50 + slider.getVisibleAmount());
+ slider.setUnitIncrement(1);
+ }
+ else
+ {
+ label.setText("Colour residues above % occurence");
+ slider.setMinimum(0);
+ slider.setMaximum(100 + slider.getVisibleAmount());
+ slider.setBlockIncrement(1);
+ }
+
+ slider.addAdjustmentListener(this);
+ slider.addMouseListener(this);
+
+ slider.setValue(value);
+ valueField.setText(value + "");
+ }
+
+ public void valueChanged(int i)
+ {
+ if (cs == null)
+ {
+ return;
+ }
+
+ ColourSchemeI toChange = null;
+ Vector allGroups = null;
+ int groupIndex = 0;
+
+ if (allGroupsCheck.getState())
+ {
+ allGroups = ap.av.alignment.getGroups();
+ groupIndex = allGroups.size() - 1;
+ }
+ else
+ {
+ toChange = cs;
+ }
+
+ while (groupIndex > -1)
+ {
+ if (allGroups != null)
+ {
+ toChange = ( (SequenceGroup) allGroups.elementAt(groupIndex)).cs;
+ }
+
+ if (forConservation)
+ {
+ toChange.setConservationInc(i);
+ }
+ else
+ {
+ toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
+ }
+
+ groupIndex--;
+ }
+
+ ap.seqPanel.seqCanvas.repaint();
+
+ }
+
+ public void setAllGroupsCheckEnabled(boolean b)
+ {
+ allGroupsCheck.setEnabled(b);
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource()==applyButton)
+ applyButton_actionPerformed();
+ else if(evt.getSource()==undoButton)
+ undoButton_actionPerformed();
+ else if(evt.getSource()==valueField)
+ valueField_actionPerformed();
+ }
+
+ public void adjustmentValueChanged(AdjustmentEvent evt)
+ {
+ valueField.setText(slider.getValue() + "");
+ valueChanged(slider.getValue());
+ }
+
+
+ public void valueField_actionPerformed()
+ {
+ try
+ {
+ int i = Integer.parseInt(valueField.getText());
+ slider.setValue(i);
+ }
+ catch (Exception ex)
+ {
+ valueField.setText(slider.getValue() + "");
+ }
+ }
+
+ public void setValue(int value)
+ {
+ slider.setValue(value);
+ }
+
+ public int getValue()
+ {
+ return Integer.parseInt(valueField.getText());
+ }
+
+ // this is used for conservation colours, PID colours and redundancy threshold
+ protected Scrollbar slider = new Scrollbar();
+ protected TextField valueField = new TextField();
+ protected Label label = new Label();
+ Panel jPanel1 = new Panel();
+ Panel jPanel2 = new Panel();
+ protected Button applyButton = new Button();
+ protected Button undoButton = new Button();
+ FlowLayout flowLayout1 = new FlowLayout();
+ protected Checkbox allGroupsCheck = new Checkbox();
+ BorderLayout borderLayout1 = new BorderLayout();
+ BorderLayout borderLayout2 = new BorderLayout();
+ FlowLayout flowLayout2 = new FlowLayout();
+
+ private void jbInit() throws Exception {
+ this.setLayout(borderLayout2);
+
+ // slider.setMajorTickSpacing(10);
+ // slider.setMinorTickSpacing(1);
+ // slider.setPaintTicks(true);
+ slider.setBackground(Color.white);
+ slider.setFont(new java.awt.Font("Verdana", 0, 11));
+ slider.setOrientation(0);
+ valueField.setFont(new java.awt.Font("Verdana", 0, 11));
+ valueField.setText(" ");
+ valueField.addActionListener(this);
+ label.setFont(new java.awt.Font("Verdana", 0, 11));
+ label.setText("set this label text");
+ jPanel1.setLayout(borderLayout1);
+ jPanel2.setLayout(flowLayout1);
+ applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
+ applyButton.setLabel("Apply");
+ applyButton.addActionListener(this);
+ undoButton.setEnabled(false);
+ undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
+ undoButton.setLabel("Undo");
+ undoButton.addActionListener(this);
+ allGroupsCheck.setEnabled(false);
+ allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
+ allGroupsCheck.setLabel("Apply threshold to all groups");
+ allGroupsCheck.setName("Apply to all Groups");
+ this.setBackground(Color.white);
+ this.setForeground(Color.black);
+ jPanel2.add(label, null);
+ jPanel2.add(applyButton, null);
+ jPanel2.add(undoButton, null);
+ jPanel2.add(allGroupsCheck);
+ jPanel1.add(valueField, java.awt.BorderLayout.EAST);
+ jPanel1.add(slider, java.awt.BorderLayout.CENTER);
+ this.add(jPanel1, java.awt.BorderLayout.SOUTH);
+ this.add(jPanel2, java.awt.BorderLayout.CENTER);
+ }
+
+ protected void applyButton_actionPerformed()
+ { }
+
+ protected void undoButton_actionPerformed()
+ { }
+
+ public void mousePressed(MouseEvent evt)
+ { }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ if (ap.overviewPanel != null)
+ ap.overviewPanel.updateOverviewImage();
+ }
+ public void mouseClicked(MouseEvent evt)
+ {}
+ public void mouseEntered(MouseEvent evt)
+ {}
+ public void mouseExited(MouseEvent evt)
+ {}
+}
diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java
index e3f6c3c..23a5021 100755
--- a/src/jalview/appletgui/TreeCanvas.java
+++ b/src/jalview/appletgui/TreeCanvas.java
@@ -1,566 +1,567 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.analysis.*;
-import jalview.datamodel.*;
-import jalview.schemes.*;
-import jalview.util.*;
-
-public class TreeCanvas
- extends Panel implements MouseListener
-{
- NJTree tree;
- ScrollPane scrollPane;
- AlignViewport av;
- public static final String PLACEHOLDER = " * ";
- Font font;
- boolean fitToWindow = true;
- boolean showDistances = false;
- boolean showBootstrap = false;
- boolean markPlaceholders = false;
-
- int offx = 20;
- int offy;
-
- float threshold;
-
- String longestName;
- int labelLength = -1;
-
- //RubberbandRectangle rubberband;
-
- Vector listeners;
-
- Hashtable nameHash = new Hashtable();
- Hashtable nodeHash = new Hashtable();
-
- public TreeCanvas(AlignViewport av, ScrollPane scroller)
- {
- this.av = av;
- font = av.getFont();
- scrollPane = scroller;
- addMouseListener(this);
- setLayout(null);
-
- PaintRefresher.Register(this, av.alignment);
- }
-
- public void TreeSelectionChanged(Sequence sequence)
- {
- SequenceGroup selected = av.getSelectionGroup();
- if (selected == null)
- {
- selected = new SequenceGroup();
- av.setSelectionGroup(selected);
- }
-
- selected.setEndRes(av.alignment.getWidth()-1);
- selected.addOrRemove(sequence, true);
-
- PaintRefresher.Refresh(this, av.alignment);
- repaint();
- }
-
- public void setTree(NJTree tree)
- {
- this.tree = tree;
- tree.findHeight(tree.getTopNode());
-
- // Now have to calculate longest name based on the leaves
- Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector());
- boolean has_placeholders = false;
- longestName = "";
-
- for (int i = 0; i < leaves.size(); i++)
- {
- SequenceNode lf = (SequenceNode) leaves.elementAt(i);
-
- if (lf.isPlaceholder())
- {
- has_placeholders = true;
- }
-
- if (longestName.length() < ( (Sequence) lf.element()).getName()
- .length())
- {
- longestName = TreeCanvas.PLACEHOLDER +
- ( (Sequence) lf.element()).getName();
- }
- }
-
- setMarkPlaceholders(has_placeholders);
- }
-
- public void drawNode(Graphics g, SequenceNode node, float chunk, float scale,
- int width, int offx, int offy)
- {
- if (node == null)
- {
- return;
- }
-
- if (node.left() == null && node.right() == null)
- {
- // Drawing leaf node
-
- float height = node.height;
- float dist = node.dist;
-
- int xstart = (int) ( (height - dist) * scale) + offx;
- int xend = (int) (height * scale) + offx;
-
- int ypos = (int) (node.ycount * chunk) + offy;
-
- if (node.element() instanceof SequenceI)
- {
- if ( ( (SequenceI) ( (SequenceNode) node).element()).getColor() ==
- Color.white)
- {
- g.setColor(Color.black);
- }
- else
- {
- g.setColor( ( (SequenceI) ( (SequenceNode) node).element()).getColor().
- darker());
- }
-
- }
- else
- {
- g.setColor(Color.black);
- }
-
- // Draw horizontal line
- g.drawLine(xstart, ypos, xend, ypos);
-
- String nodeLabel = "";
- if (showDistances && node.dist > 0)
- {
- nodeLabel = new Format("%-.2f").form(node.dist);
- }
- if (showBootstrap)
- {
- if (showDistances)
- {
- nodeLabel = nodeLabel + " : ";
- }
- nodeLabel = nodeLabel + String.valueOf(node.getBootstrap());
- }
- if (!nodeLabel.equals(""))
- {
- g.drawString(nodeLabel, xstart+2, ypos - 2);
- }
-
- String name = (markPlaceholders && node.isPlaceholder()) ?
- (PLACEHOLDER + node.getName()) : node.getName();
- FontMetrics fm = g.getFontMetrics(font);
- int charWidth = fm.stringWidth(name) + 3;
- int charHeight = fm.getHeight();
-
- Rectangle rect = new Rectangle(xend + 10, ypos - charHeight,
- charWidth, charHeight);
-
- nameHash.put( (SequenceI) node.element(), rect);
-
- // Colour selected leaves differently
- SequenceGroup selected = av.getSelectionGroup();
- if (selected != null &&
- selected.sequences.contains( (SequenceI) node.element()))
- {
- g.setColor(Color.gray);
-
- g.fillRect(xend + 10, ypos - charHeight + 3, charWidth, charHeight);
- g.setColor(Color.white);
- }
- g.drawString(name, xend + 10, ypos);
- g.setColor(Color.black);
- }
- else
- {
- drawNode(g, (SequenceNode) node.left(), chunk, scale, width, offx, offy);
- drawNode(g, (SequenceNode) node.right(), chunk, scale, width, offx, offy);
-
- float height = node.height;
- float dist = node.dist;
-
- int xstart = (int) ( (height - dist) * scale) + offx;
- int xend = (int) (height * scale) + offx;
- int ypos = (int) (node.ycount * chunk) + offy;
-
- g.setColor( ( (SequenceNode) node).color.darker());
-
- // Draw horizontal line
- g.drawLine(xstart, ypos, xend, ypos);
- g.fillRect(xend - 2, ypos - 2, 4, 4);
-
- int ystart = (int) ( ( (SequenceNode) node.left()).ycount * chunk) + offy;
- int yend = (int) ( ( (SequenceNode) node.right()).ycount * chunk) + offy;
-
- Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
- nodeHash.put(node, pos);
-
- g.drawLine( (int) (height * scale) + offx, ystart,
- (int) (height * scale) + offx, yend);
-
- if (showDistances && node.dist > 0)
- {
- g.drawString(new Format("%-.2f").form(node.dist), xstart+2, ypos - 2);
- }
-
- }
- }
-
- public Object findElement(int x, int y)
- {
- Enumeration keys = nameHash.keys();
-
- while (keys.hasMoreElements())
- {
- Object ob = keys.nextElement();
- Rectangle rect = (Rectangle) nameHash.get(ob);
-
- if (x >= rect.x && x <= (rect.x + rect.width) &&
- y >= rect.y && y <= (rect.y + rect.height))
- {
- return ob;
- }
- }
- keys = nodeHash.keys();
-
- while (keys.hasMoreElements())
- {
- Object ob = keys.nextElement();
- Rectangle rect = (Rectangle) nodeHash.get(ob);
-
- if (x >= rect.x && x <= (rect.x + rect.width) &&
- y >= rect.y && y <= (rect.y + rect.height))
- {
- return ob;
- }
- }
- return null;
-
- }
-
- public void pickNodes(Rectangle pickBox)
- {
- int width = getSize().width;
- int height = getSize().height;
-
- SequenceNode top = tree.getTopNode();
-
- float wscale = (float) (width * .8 - offx * 2) / tree.getMaxHeight()
- ;
- if (top.count == 0)
- {
- top.count = ( (SequenceNode) top.left()).count +
- ( (SequenceNode) top.right()).count;
- }
- float chunk = (float) (height - offy) / top.count;
-
- pickNode(pickBox, top, chunk, wscale, width, offx, offy);
- }
-
- public void pickNode(Rectangle pickBox, SequenceNode node, float chunk,
- float scale, int width, int offx, int offy)
- {
- if (node == null)
- {
- return;
- }
-
- if (node.left() == null && node.right() == null)
- {
- float height = node.height;
- //float dist = node.dist;
-
- //int xstart = (int) ( (height - dist) * scale) + offx;
- int xend = (int) (height * scale) + offx;
-
- int ypos = (int) (node.ycount * chunk) + offy;
-
- if (pickBox.contains(new Point(xend, ypos)))
- {
- if (node.element() instanceof SequenceI)
- {
- SequenceI seq = (SequenceI) node.element();
- SequenceGroup sg = av.getSelectionGroup();
- if (sg != null)
- {
- sg.addOrRemove(seq, true);
- }
- }
- }
- }
- else
- {
- pickNode(pickBox, (SequenceNode) node.left(), chunk, scale, width, offx,
- offy);
- pickNode(pickBox, (SequenceNode) node.right(), chunk, scale, width, offx,
- offy);
- }
- }
-
- public void setColor(SequenceNode node, Color c)
- {
- if (node == null)
- {
- return;
- }
-
- if (node.left() == null && node.right() == null)
- {
- node.color = c;
-
- if (node.element() instanceof SequenceI)
- {
- ( (SequenceI) node.element()).setColor(c);
- }
- }
- else
- {
- node.color = c;
- setColor( (SequenceNode) node.left(), c);
- setColor( (SequenceNode) node.right(), c);
- }
- }
-
- public void paint(Graphics g)
- {
-
- if(tree==null)
- return;
-
- g.setFont(font);
-
-
- FontMetrics fm = g.getFontMetrics(font);
-
- if (nameHash.size() == 0)
- {
- repaint();
- }
-
- if (fitToWindow ||
- (!fitToWindow &&
- scrollPane.getSize().height > fm.getHeight() * nameHash.size() + offy))
- {
- draw(g, scrollPane.getSize().width, scrollPane.getSize().height);
- }
- else
- {
- setSize(new Dimension(scrollPane.getSize().width,
- fm.getHeight() * nameHash.size()));
- draw(g, scrollPane.getSize().width, fm.getHeight() * nameHash.size());
- }
-
- scrollPane.validate();
- }
-
-
- public void draw(Graphics g, int width, int height)
- {
- offy = font.getSize()+10;
-
- g.setColor(Color.white);
- g.fillRect(0, 0, width, height);
-
- labelLength = g.getFontMetrics(font).stringWidth(longestName) + 20; //20 allows for scrollbar
-
- float wscale = (float) (width - labelLength - offx * 2) / tree.getMaxHeight();
-
- SequenceNode top = tree.getTopNode();
-
- if (top.count == 0)
- {
- top.count = ( (SequenceNode) top.left()).count +
- ( (SequenceNode) top.right()).count;
- }
- float chunk = (float) (height - offy) / top.count;
-
- drawNode(g, tree.getTopNode(), chunk, wscale, width, offx, offy);
-
- if (threshold != 0)
- {
- if (av.getCurrentTree() == tree)
- {
- g.setColor(Color.red);
- }
- else
- {
- g.setColor(Color.gray);
- }
-
- int x = (int) (threshold *
- (float) (getSize().width - labelLength - 2 * offx) + offx);
-
- g.drawLine(x, 0, x, getSize().height);
- }
-
- }
-
- public void mouseReleased(MouseEvent e)
- {}
-
- public void mouseEntered(MouseEvent e)
- {}
-
- public void mouseExited(MouseEvent e)
- {}
-
- public void mouseClicked(MouseEvent e)
- {
- }
-
- public void mousePressed(MouseEvent e)
- {
- av.setCurrentTree(tree);
-
- int x = e.getX();
- int y = e.getY();
-
- Object ob = findElement(x, y);
-
- if (ob instanceof SequenceI)
- {
- TreeSelectionChanged( (Sequence) ob);
- repaint();
- return;
-
- }
- else if (ob instanceof SequenceNode)
- {
- SequenceNode tmpnode = (SequenceNode) ob;
- tree.swapNodes(tmpnode);
- tree.reCount(tree.getTopNode());
- tree.findHeight(tree.getTopNode());
- }
- else
- {
- // Find threshold
-
- if (tree.getMaxHeight() != 0)
- {
- threshold = (float) (x - offx) /
- (float) (getSize().width - labelLength - 2 * offx);
-
- tree.getGroups().removeAllElements();
- tree.groupNodes(tree.getTopNode(), threshold);
- setColor(tree.getTopNode(), Color.black);
-
- av.setSelectionGroup(null);
- av.alignment.deleteAllGroups();
-
- for (int i = 0; i < tree.getGroups().size(); i++)
- {
-
- Color col = new Color( (int) (Math.random() * 255),
- (int) (Math.random() * 255),
- (int) (Math.random() * 255));
- setColor( (SequenceNode) tree.getGroups().elementAt(i), col.brighter());
-
- Vector l = tree.findLeaves( (SequenceNode) tree.getGroups().elementAt(
- i), new Vector());
-
- Vector sequences = new Vector();
- for (int j = 0; j < l.size(); j++)
- {
- SequenceI s1 = (SequenceI) ( (SequenceNode) l.elementAt(j)).element();
- if(!sequences.contains(s1))
- sequences.addElement(s1);
- }
-
- ColourSchemeI cs = null;
-
- if (av.getGlobalColourScheme() != null)
- {
- if (av.getGlobalColourScheme() instanceof UserColourScheme)
- {
- cs = new UserColourScheme(
- ( (UserColourScheme) av.getGlobalColourScheme()).getColours());
-
- }
- else
- cs = ColourSchemeProperty.getColour(sequences,
- av.alignment.getWidth(),
- ColourSchemeProperty.getColourName(
- av.getGlobalColourScheme()));
-
- cs.setThreshold(av.getGlobalColourScheme().getThreshold(),
- av.getIgnoreGapsConsensus());
- }
-
- SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup",
- cs, true, true,
- false, 0, av.alignment.getWidth()-1);
-
-
- if ( av.getGlobalColourScheme()!=null
- && av.getGlobalColourScheme().conservationApplied())
- {
- Conservation c = new Conservation("Group",
- ResidueProperties.propHash, 3,
- sg.sequences, sg.getStartRes(),
- sg.getEndRes());
-
- c.calculate();
- c.verdict(false, av.ConsPercGaps);
- cs.setConservation(c);
-
- sg.cs = cs;
-
- }
-
- av.alignment.addGroup(sg);
-
- }
- }
- }
-
- PaintRefresher.Refresh(this, av.alignment);
- repaint();
-
- }
-
- public void setShowDistances(boolean state)
- {
- this.showDistances = state;
- repaint();
- }
-
- public void setShowBootstrap(boolean state)
- {
- this.showBootstrap = state;
- repaint();
- }
-
- public void setMarkPlaceholders(boolean state)
- {
- this.markPlaceholders = state;
- repaint();
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import jalview.schemes.*;
+import jalview.util.*;
+
+public class TreeCanvas
+ extends Panel implements MouseListener
+{
+ NJTree tree;
+ ScrollPane scrollPane;
+ AlignViewport av;
+ public static final String PLACEHOLDER = " * ";
+ Font font;
+ boolean fitToWindow = true;
+ boolean showDistances = false;
+ boolean showBootstrap = false;
+ boolean markPlaceholders = false;
+
+ int offx = 20;
+ int offy;
+
+ float threshold;
+
+ String longestName;
+ int labelLength = -1;
+
+ //RubberbandRectangle rubberband;
+
+ Vector listeners;
+
+ Hashtable nameHash = new Hashtable();
+ Hashtable nodeHash = new Hashtable();
+
+ public TreeCanvas(AlignViewport av, ScrollPane scroller)
+ {
+ this.av = av;
+ font = av.getFont();
+ scrollPane = scroller;
+ addMouseListener(this);
+ setLayout(null);
+
+ PaintRefresher.Register(this, av.alignment);
+ }
+
+ public void TreeSelectionChanged(Sequence sequence)
+ {
+ SequenceGroup selected = av.getSelectionGroup();
+ if (selected == null)
+ {
+ selected = new SequenceGroup();
+ av.setSelectionGroup(selected);
+ }
+
+ selected.setEndRes(av.alignment.getWidth()-1);
+ selected.addOrRemove(sequence, true);
+
+ PaintRefresher.Refresh(this, av.alignment);
+ repaint();
+ }
+
+ public void setTree(NJTree tree)
+ {
+ this.tree = tree;
+ tree.findHeight(tree.getTopNode());
+
+ // Now have to calculate longest name based on the leaves
+ Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector());
+ boolean has_placeholders = false;
+ longestName = "";
+
+ for (int i = 0; i < leaves.size(); i++)
+ {
+ SequenceNode lf = (SequenceNode) leaves.elementAt(i);
+
+ if (lf.isPlaceholder())
+ {
+ has_placeholders = true;
+ }
+
+ if (longestName.length() < ( (Sequence) lf.element()).getName()
+ .length())
+ {
+ longestName = TreeCanvas.PLACEHOLDER +
+ ( (Sequence) lf.element()).getName();
+ }
+ }
+
+ setMarkPlaceholders(has_placeholders);
+ }
+
+ public void drawNode(Graphics g, SequenceNode node, float chunk, float scale,
+ int width, int offx, int offy)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ if (node.left() == null && node.right() == null)
+ {
+ // Drawing leaf node
+
+ float height = node.height;
+ float dist = node.dist;
+
+ int xstart = (int) ( (height - dist) * scale) + offx;
+ int xend = (int) (height * scale) + offx;
+
+ int ypos = (int) (node.ycount * chunk) + offy;
+
+ if (node.element() instanceof SequenceI)
+ {
+ if ( ( (SequenceI) ( (SequenceNode) node).element()).getColor() ==
+ Color.white)
+ {
+ g.setColor(Color.black);
+ }
+ else
+ {
+ g.setColor( ( (SequenceI) ( (SequenceNode) node).element()).getColor().
+ darker());
+ }
+
+ }
+ else
+ {
+ g.setColor(Color.black);
+ }
+
+ // Draw horizontal line
+ g.drawLine(xstart, ypos, xend, ypos);
+
+ String nodeLabel = "";
+ if (showDistances && node.dist > 0)
+ {
+ nodeLabel = new Format("%-.2f").form(node.dist);
+ }
+ if (showBootstrap)
+ {
+ if (showDistances)
+ {
+ nodeLabel = nodeLabel + " : ";
+ }
+ nodeLabel = nodeLabel + String.valueOf(node.getBootstrap());
+ }
+ if (!nodeLabel.equals(""))
+ {
+ g.drawString(nodeLabel, xstart+2, ypos - 2);
+ }
+
+ String name = (markPlaceholders && node.isPlaceholder()) ?
+ (PLACEHOLDER + node.getName()) : node.getName();
+ FontMetrics fm = g.getFontMetrics(font);
+ int charWidth = fm.stringWidth(name) + 3;
+ int charHeight = fm.getHeight();
+
+ Rectangle rect = new Rectangle(xend + 10, ypos - charHeight,
+ charWidth, charHeight);
+
+ nameHash.put( (SequenceI) node.element(), rect);
+
+ // Colour selected leaves differently
+ SequenceGroup selected = av.getSelectionGroup();
+ if (selected != null &&
+ selected.getSequences(false).contains( (SequenceI) node.element()))
+ {
+ g.setColor(Color.gray);
+
+ g.fillRect(xend + 10, ypos - charHeight + 3, charWidth, charHeight);
+ g.setColor(Color.white);
+ }
+ g.drawString(name, xend + 10, ypos);
+ g.setColor(Color.black);
+ }
+ else
+ {
+ drawNode(g, (SequenceNode) node.left(), chunk, scale, width, offx, offy);
+ drawNode(g, (SequenceNode) node.right(), chunk, scale, width, offx, offy);
+
+ float height = node.height;
+ float dist = node.dist;
+
+ int xstart = (int) ( (height - dist) * scale) + offx;
+ int xend = (int) (height * scale) + offx;
+ int ypos = (int) (node.ycount * chunk) + offy;
+
+ g.setColor( ( (SequenceNode) node).color.darker());
+
+ // Draw horizontal line
+ g.drawLine(xstart, ypos, xend, ypos);
+ g.fillRect(xend - 2, ypos - 2, 4, 4);
+
+ int ystart = (int) ( ( (SequenceNode) node.left()).ycount * chunk) + offy;
+ int yend = (int) ( ( (SequenceNode) node.right()).ycount * chunk) + offy;
+
+ Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
+ nodeHash.put(node, pos);
+
+ g.drawLine( (int) (height * scale) + offx, ystart,
+ (int) (height * scale) + offx, yend);
+
+ if (showDistances && node.dist > 0)
+ {
+ g.drawString(new Format("%-.2f").form(node.dist), xstart+2, ypos - 2);
+ }
+
+ }
+ }
+
+ public Object findElement(int x, int y)
+ {
+ Enumeration keys = nameHash.keys();
+
+ while (keys.hasMoreElements())
+ {
+ Object ob = keys.nextElement();
+ Rectangle rect = (Rectangle) nameHash.get(ob);
+
+ if (x >= rect.x && x <= (rect.x + rect.width) &&
+ y >= rect.y && y <= (rect.y + rect.height))
+ {
+ return ob;
+ }
+ }
+ keys = nodeHash.keys();
+
+ while (keys.hasMoreElements())
+ {
+ Object ob = keys.nextElement();
+ Rectangle rect = (Rectangle) nodeHash.get(ob);
+
+ if (x >= rect.x && x <= (rect.x + rect.width) &&
+ y >= rect.y && y <= (rect.y + rect.height))
+ {
+ return ob;
+ }
+ }
+ return null;
+
+ }
+
+ public void pickNodes(Rectangle pickBox)
+ {
+ int width = getSize().width;
+ int height = getSize().height;
+
+ SequenceNode top = tree.getTopNode();
+
+ float wscale = (float) (width * .8 - offx * 2) / tree.getMaxHeight()
+ ;
+ if (top.count == 0)
+ {
+ top.count = ( (SequenceNode) top.left()).count +
+ ( (SequenceNode) top.right()).count;
+ }
+ float chunk = (float) (height - offy) / top.count;
+
+ pickNode(pickBox, top, chunk, wscale, width, offx, offy);
+ }
+
+ public void pickNode(Rectangle pickBox, SequenceNode node, float chunk,
+ float scale, int width, int offx, int offy)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ if (node.left() == null && node.right() == null)
+ {
+ float height = node.height;
+ //float dist = node.dist;
+
+ //int xstart = (int) ( (height - dist) * scale) + offx;
+ int xend = (int) (height * scale) + offx;
+
+ int ypos = (int) (node.ycount * chunk) + offy;
+
+ if (pickBox.contains(new Point(xend, ypos)))
+ {
+ if (node.element() instanceof SequenceI)
+ {
+ SequenceI seq = (SequenceI) node.element();
+ SequenceGroup sg = av.getSelectionGroup();
+ if (sg != null)
+ {
+ sg.addOrRemove(seq, true);
+ }
+ }
+ }
+ }
+ else
+ {
+ pickNode(pickBox, (SequenceNode) node.left(), chunk, scale, width, offx,
+ offy);
+ pickNode(pickBox, (SequenceNode) node.right(), chunk, scale, width, offx,
+ offy);
+ }
+ }
+
+ public void setColor(SequenceNode node, Color c)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ if (node.left() == null && node.right() == null)
+ {
+ node.color = c;
+
+ if (node.element() instanceof SequenceI)
+ {
+ ( (SequenceI) node.element()).setColor(c);
+ }
+ }
+ else
+ {
+ node.color = c;
+ setColor( (SequenceNode) node.left(), c);
+ setColor( (SequenceNode) node.right(), c);
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+
+ if(tree==null)
+ return;
+
+ g.setFont(font);
+
+
+ FontMetrics fm = g.getFontMetrics(font);
+
+ if (nameHash.size() == 0)
+ {
+ repaint();
+ }
+
+ if (fitToWindow ||
+ (!fitToWindow &&
+ scrollPane.getSize().height > fm.getHeight() * nameHash.size() + offy))
+ {
+ draw(g, scrollPane.getSize().width, scrollPane.getSize().height);
+ }
+ else
+ {
+ setSize(new Dimension(scrollPane.getSize().width,
+ fm.getHeight() * nameHash.size()));
+ draw(g, scrollPane.getSize().width, fm.getHeight() * nameHash.size());
+ }
+
+ scrollPane.validate();
+ }
+
+
+ public void draw(Graphics g, int width, int height)
+ {
+ offy = font.getSize()+10;
+
+ g.setColor(Color.white);
+ g.fillRect(0, 0, width, height);
+
+ labelLength = g.getFontMetrics(font).stringWidth(longestName) + 20; //20 allows for scrollbar
+
+ float wscale = (float) (width - labelLength - offx * 2) / tree.getMaxHeight();
+
+ SequenceNode top = tree.getTopNode();
+
+ if (top.count == 0)
+ {
+ top.count = ( (SequenceNode) top.left()).count +
+ ( (SequenceNode) top.right()).count;
+ }
+ float chunk = (float) (height - offy) / top.count;
+
+ drawNode(g, tree.getTopNode(), chunk, wscale, width, offx, offy);
+
+ if (threshold != 0)
+ {
+ if (av.getCurrentTree() == tree)
+ {
+ g.setColor(Color.red);
+ }
+ else
+ {
+ g.setColor(Color.gray);
+ }
+
+ int x = (int) (threshold *
+ (float) (getSize().width - labelLength - 2 * offx) + offx);
+
+ g.drawLine(x, 0, x, getSize().height);
+ }
+
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {}
+
+ public void mouseEntered(MouseEvent e)
+ {}
+
+ public void mouseExited(MouseEvent e)
+ {}
+
+ public void mouseClicked(MouseEvent e)
+ {
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ av.setCurrentTree(tree);
+
+ int x = e.getX();
+ int y = e.getY();
+
+ Object ob = findElement(x, y);
+
+ if (ob instanceof SequenceI)
+ {
+ TreeSelectionChanged( (Sequence) ob);
+ repaint();
+ return;
+
+ }
+ else if (ob instanceof SequenceNode)
+ {
+ SequenceNode tmpnode = (SequenceNode) ob;
+ tree.swapNodes(tmpnode);
+ tree.reCount(tree.getTopNode());
+ tree.findHeight(tree.getTopNode());
+ }
+ else
+ {
+ // Find threshold
+
+ if (tree.getMaxHeight() != 0)
+ {
+ threshold = (float) (x - offx) /
+ (float) (getSize().width - labelLength - 2 * offx);
+
+ tree.getGroups().removeAllElements();
+ tree.groupNodes(tree.getTopNode(), threshold);
+ setColor(tree.getTopNode(), Color.black);
+
+ av.setSelectionGroup(null);
+ av.alignment.deleteAllGroups();
+
+ for (int i = 0; i < tree.getGroups().size(); i++)
+ {
+
+ Color col = new Color( (int) (Math.random() * 255),
+ (int) (Math.random() * 255),
+ (int) (Math.random() * 255));
+ setColor( (SequenceNode) tree.getGroups().elementAt(i), col.brighter());
+
+ Vector l = tree.findLeaves( (SequenceNode) tree.getGroups().elementAt(
+ i), new Vector());
+
+ Vector sequences = new Vector();
+ for (int j = 0; j < l.size(); j++)
+ {
+ SequenceI s1 = (SequenceI) ( (SequenceNode) l.elementAt(j)).element();
+ if(!sequences.contains(s1))
+ sequences.addElement(s1);
+ }
+
+ ColourSchemeI cs = null;
+
+ if (av.getGlobalColourScheme() != null)
+ {
+ if (av.getGlobalColourScheme() instanceof UserColourScheme)
+ {
+ cs = new UserColourScheme(
+ ( (UserColourScheme) av.getGlobalColourScheme()).getColours());
+
+ }
+ else
+ cs = ColourSchemeProperty.getColour(sequences,
+ av.alignment.getWidth(),
+ ColourSchemeProperty.getColourName(
+ av.getGlobalColourScheme()));
+
+ cs.setThreshold(av.getGlobalColourScheme().getThreshold(),
+ av.getIgnoreGapsConsensus());
+ }
+
+ SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup",
+ cs, true, true,
+ false, 0, av.alignment.getWidth()-1);
+
+
+ if ( av.getGlobalColourScheme()!=null
+ && av.getGlobalColourScheme().conservationApplied())
+ {
+ Conservation c = new Conservation("Group",
+ ResidueProperties.propHash, 3,
+ sg.getSequences(false),
+ sg.getStartRes(),
+ sg.getEndRes());
+
+ c.calculate();
+ c.verdict(false, av.ConsPercGaps);
+ cs.setConservation(c);
+
+ sg.cs = cs;
+
+ }
+
+ av.alignment.addGroup(sg);
+
+ }
+ }
+ }
+
+ PaintRefresher.Refresh(this, av.alignment);
+ repaint();
+
+ }
+
+ public void setShowDistances(boolean state)
+ {
+ this.showDistances = state;
+ repaint();
+ }
+
+ public void setShowBootstrap(boolean state)
+ {
+ this.showBootstrap = state;
+ repaint();
+ }
+
+ public void setMarkPlaceholders(boolean state)
+ {
+ this.markPlaceholders = state;
+ repaint();
+ }
+
+}
diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java
index 61b0546..1f31ce3 100755
--- a/src/jalview/appletgui/TreePanel.java
+++ b/src/jalview/appletgui/TreePanel.java
@@ -1,255 +1,314 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.appletgui;
-
-import java.util.*;
-
-import java.awt.event.*;
-import java.awt.*;
-
-import jalview.analysis.*;
-import jalview.datamodel.*;
-import jalview.io.*;
-
-public class TreePanel extends Frame implements ActionListener, ItemListener
-{
- SequenceI[] seq;
- String type;
- String pwtype;
- int start;
- int end;
- TreeCanvas treeCanvas;
- NJTree tree;
-
- public NJTree getTree()
- {
- return tree;
- }
-
- /**
- * Creates a new TreePanel object.
- *
- * @param av DOCUMENT ME!
- * @param seqVector DOCUMENT ME!
- * @param type DOCUMENT ME!
- * @param pwtype DOCUMENT ME!
- * @param s DOCUMENT ME!
- * @param e DOCUMENT ME!
- */
- public TreePanel(AlignViewport av, Vector seqVector, String type,
- String pwtype, int s, int e)
- {
- try
- {
- jbInit();
- this.setMenuBar(jMenuBar1);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
-
- initTreePanel(av, seqVector, type, pwtype, s, e, null);
- }
-
- /**
- * Creates a new TreePanel object.
- *
- * @param av DOCUMENT ME!
- * @param seqVector DOCUMENT ME!
- * @param newtree DOCUMENT ME!
- * @param type DOCUMENT ME!
- * @param pwtype DOCUMENT ME!
- */
- public TreePanel(AlignViewport av, Vector seqVector, NewickFile newtree,
- String type, String pwtype)
- {
- try
- {
- jbInit();
- this.setMenuBar(jMenuBar1);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- initTreePanel(av, seqVector, type, pwtype, 0, seqVector.size(), newtree);
- }
-
-
- void initTreePanel(AlignViewport av, Vector seqVector, String type,
- String pwtype, int s, int e, NewickFile newTree)
- {
-
- this.type = type;
- this.pwtype = pwtype;
-
- start = s;
- end = e;
-
- seq = new Sequence[seqVector.size()];
- for(int i=0; i
Current properties include:
- *
logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)
- *
logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization)
- *
logs.Jalview.Level - Cache.log stringified level.
- *
DISCOVERY_START - Boolean - controls if discovery services are queried on startup
- *
DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
- *
SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_Y=285,SCREEN_X=371,SHOW_FULLSCREEN
- * FONT_NAME,FONT_SIZE,FONT_STYLE,GAP_SYMBOL,LAST_DIRECTORY,USER_DEFINED_COLOUR
- * SHOW_FULL_ID,SHOW_IDENTITY,SHOW_QUALITY,SHOW_ANNOTATIONS,SHOW_CONSERVATION,
- * DEFAULT_COLOUR,DEFAULT_FILE_FORMAT,STARTUP_FILE,SHOW_STARTUP_FILE
-
- * @author $author$
- * @version $Revision$
- */
-public class Cache
-{
- /**
- * Initialises the Apache Axis logger
- */
- public static Logger log;
-
- /** Jalview Properties */
- public static Properties applicationProperties = new Properties();
-
- /** Default file is ~/.jalview_properties */
- static String propertiesFile;
-
- public static void initLogger()
- {
- try
- {
- Logger laxis = Logger.getLogger("org.apache.axis");
- Logger lcastor = Logger.getLogger("org.exolab.castor");
- jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
-
- laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
- Level.INFO.toString())));
- lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
- Level.INFO.toString())));
- jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
- "logs.Jalview.level",
- Level.INFO.toString())));
- ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
- "System.err");
- ap.setName("JalviewLogger");
-
- laxis.addAppender(ap);
- lcastor.addAppender(ap);
- jalview.bin.Cache.log.addAppender(ap);
- // Tell the user that debug is enabled
- jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
- }
- catch (Exception ex)
- {
- System.err.println("Problems initializing the log4j system\n");
- }
- }
-
-
- /** Called when Jalview is started */
- public static void loadProperties(String propsFile)
- {
- propertiesFile = propsFile;
- if (propsFile == null)
- {
- propertiesFile = System.getProperty("user.home") + "/.jalview_properties";
- }
-
- try
- {
- FileInputStream fis = new FileInputStream(propertiesFile);
- applicationProperties.load(fis);
- applicationProperties.remove("LATEST_VERSION");
- applicationProperties.remove("VERSION");
- fis.close();
- }
- catch (Exception ex)
- {
- System.out.println("Error reading properties file: "+ex);
- }
-
- if(getDefault("USE_PROXY", false))
- {
- System.out.println("Using proxyServer: "+getDefault("PROXY_SERVER", null)+
- " proxyPort: "+getDefault("PROXY_PORT", null));
- System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
- System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
- }
-
- // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
- // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
- // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
- try
- {
- String buildDetails = "jar:"
- .concat(
- Cache.class.getProtectionDomain().getCodeSource().getLocation().toString()
- .concat("!/.build_properties")
- );
-
- java.net.URL localJarFileURL = new java.net.URL(buildDetails);
-
- InputStream in = localJarFileURL.openStream();
- applicationProperties.load(in);
- in.close();
- }
- catch (Exception ex)
- {
- System.out.println("Error reading build details: "+ex);
- applicationProperties.remove("VERSION");
- }
-
- String jnlpVersion = System.getProperty("jalview.version");
- String codeVersion = getProperty("VERSION");
-
-
- if(codeVersion==null)
- {
- // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
- codeVersion = "Test";
- jnlpVersion = "Test";
- }
-
-
- System.out.println("Jalview Version: "+codeVersion);
-
-
- // jnlpVersion will be null if we're using InstallAnywhere
- // Dont do this check if running in headless mode
- if(jnlpVersion==null && (
- System.getProperty("java.awt.headless")==null
- || System.getProperty("java.awt.headless").equals("false")))
- {
-
- class VersionChecker
- extends Thread
- {
- public void run()
- {
- String jnlpVersion = null;
- try
- {
- java.net.URL url = new java.net.URL(
- "http://www.jalview.org/webstart/jalview.jnlp");
- BufferedReader in = new BufferedReader(new InputStreamReader(url.
- openStream()));
- String line = null;
- while ( (line = in.readLine()) != null)
- {
- if (line.indexOf("jalview.version") == -1)
- continue;
-
- line = line.substring(line.indexOf("value=") + 7);
- line = line.substring(0, line.lastIndexOf("\""));
- jnlpVersion = line;
- break;
- }
- }
- catch (Exception ex)
- {
- System.out.println(ex);
- jnlpVersion = getProperty("VERSION");
- }
-
- setProperty("LATEST_VERSION", jnlpVersion);
- }
- }
-
- VersionChecker vc = new VersionChecker();
- vc.start();
- }
- else
- {
- if(jnlpVersion!=null)
- setProperty("LATEST_VERSION", jnlpVersion);
- else
- applicationProperties.remove("LATEST_VERSION");
- }
-
- setProperty("VERSION", codeVersion);
-
- //LOAD USERDEFINED COLOURS
- jalview.gui.UserDefinedColours.initUserColourSchemes( getProperty("USER_DEFINED_COLOURS"));
- }
-
-
-
- /**
- * Gets Jalview application property of given key. Returns null
- * if key not found
- *
- * @param key Name of property
- *
- * @return Property value
- */
- public static String getProperty(String key)
- {
- return applicationProperties.getProperty(key);
- }
-
-
- /** These methods are used when checking if the saved preference
- * is different to the default setting
- */
-
- public static boolean getDefault(String property, boolean def)
- {
- String string = getProperty(property);
- if (string != null)
- {
- def = Boolean.valueOf(string).booleanValue();
- }
-
- return def;
- }
-
- /** These methods are used when checking if the saved preference
- * is different to the default setting
- */
- public static String getDefault(String property, String def)
- {
- String string = getProperty(property);
- if (string != null)
- {
- return string;
- }
-
- return def;
- }
-
-
- /**
- * Stores property in the file "HOME_DIR/.jalview_properties"
- *
- * @param key Name of object
- * @param obj String value of property
- *
- * @return String value of property
- */
- public static String setProperty(String key, String obj)
- {
- try
- {
- FileOutputStream out = new FileOutputStream(propertiesFile);
- applicationProperties.setProperty(key, obj);
- applicationProperties.store(out, "---JalviewX Properties File---");
- out.close();
- }
- catch (Exception ex)
- { System.out.println("Error setting property: "+key+" "+obj+"\n"+ex); }
- return obj;
- }
-
- public static void saveProperties()
- {
- try
- {
- FileOutputStream out = new FileOutputStream(propertiesFile);
- applicationProperties.store(out, "---JalviewX Properties File---");
- out.close();
- }
- catch (Exception ex)
- { System.out.println("Error saving properties: "+ex); }
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.bin;
+
+import java.io.*;
+
+import java.util.*;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.Level;
+import org.apache.log4j.ConsoleAppender;
+
+
+/**
+ * Stores and retrieves Jalview Application Properties
+ *
Current properties include:
+ *
logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)
+ *
logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization)
+ *
logs.Jalview.Level - Cache.log stringified level.
+ *
DISCOVERY_START - Boolean - controls if discovery services are queried on startup
+ *
DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
+ *
SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_Y=285,SCREEN_X=371,SHOW_FULLSCREEN
+ * FONT_NAME,FONT_SIZE,FONT_STYLE,GAP_SYMBOL,LAST_DIRECTORY,USER_DEFINED_COLOUR
+ * SHOW_FULL_ID,SHOW_IDENTITY,SHOW_QUALITY,SHOW_ANNOTATIONS,SHOW_CONSERVATION,
+ * DEFAULT_COLOUR,DEFAULT_FILE_FORMAT,STARTUP_FILE,SHOW_STARTUP_FILE
+
+ * @author $author$
+ * @version $Revision$
+ */
+public class Cache
+{
+ /**
+ * Initialises the Apache Axis logger
+ */
+ public static Logger log;
+
+ /** Jalview Properties */
+ public static Properties applicationProperties = new Properties();
+
+ /** Default file is ~/.jalview_properties */
+ static String propertiesFile;
+
+ public static void initLogger()
+ {
+ try
+ {
+ Logger laxis = Logger.getLogger("org.apache.axis");
+ Logger lcastor = Logger.getLogger("org.exolab.castor");
+ jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
+
+ laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
+ Level.INFO.toString())));
+ lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
+ Level.INFO.toString())));
+ jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
+ "logs.Jalview.level",
+ Level.INFO.toString())));
+ ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
+ "System.err");
+ ap.setName("JalviewLogger");
+
+ laxis.addAppender(ap);
+ lcastor.addAppender(ap);
+ jalview.bin.Cache.log.addAppender(ap);
+ // Tell the user that debug is enabled
+ jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
+ }
+ catch (Exception ex)
+ {
+ System.err.println("Problems initializing the log4j system\n");
+ }
+ }
+
+
+ /** Called when Jalview is started */
+ public static void loadProperties(String propsFile)
+ {
+ propertiesFile = propsFile;
+ if (propsFile == null)
+ {
+ propertiesFile = System.getProperty("user.home") + "/.jalview_properties";
+ }
+
+ try
+ {
+ FileInputStream fis = new FileInputStream(propertiesFile);
+ applicationProperties.load(fis);
+ applicationProperties.remove("LATEST_VERSION");
+ applicationProperties.remove("VERSION");
+ fis.close();
+ }
+ catch (Exception ex)
+ {
+ System.out.println("Error reading properties file: "+ex);
+ }
+
+ if(getDefault("USE_PROXY", false))
+ {
+ System.out.println("Using proxyServer: "+getDefault("PROXY_SERVER", null)+
+ " proxyPort: "+getDefault("PROXY_PORT", null));
+ System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
+ System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
+ }
+
+ // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
+ // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
+ // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
+ try
+ {
+ String buildDetails = "jar:"
+ .concat(
+ Cache.class.getProtectionDomain().getCodeSource().getLocation().toString()
+ .concat("!/.build_properties")
+ );
+
+ java.net.URL localJarFileURL = new java.net.URL(buildDetails);
+
+ InputStream in = localJarFileURL.openStream();
+ applicationProperties.load(in);
+ in.close();
+ }
+ catch (Exception ex)
+ {
+ System.out.println("Error reading build details: "+ex);
+ applicationProperties.remove("VERSION");
+ }
+
+ String jnlpVersion = System.getProperty("jalview.version");
+ String codeVersion = getProperty("VERSION");
+
+
+ if(codeVersion==null)
+ {
+ // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
+ codeVersion = "Test";
+ jnlpVersion = "Test";
+ }
+
+
+ System.out.println("Jalview Version: "+codeVersion);
+
+
+ // jnlpVersion will be null if we're using InstallAnywhere
+ // Dont do this check if running in headless mode
+ if(jnlpVersion==null && (
+ System.getProperty("java.awt.headless")==null
+ || System.getProperty("java.awt.headless").equals("false")))
+ {
+
+ class VersionChecker
+ extends Thread
+ {
+ public void run()
+ {
+ String jnlpVersion = null;
+ try
+ {
+ java.net.URL url = new java.net.URL(
+ "http://www.jalview.org/webstart/jalview.jnlp");
+ BufferedReader in = new BufferedReader(new InputStreamReader(url.
+ openStream()));
+ String line = null;
+ while ( (line = in.readLine()) != null)
+ {
+ if (line.indexOf("jalview.version") == -1)
+ continue;
+
+ line = line.substring(line.indexOf("value=") + 7);
+ line = line.substring(0, line.lastIndexOf("\""));
+ jnlpVersion = line;
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ System.out.println(ex);
+ jnlpVersion = getProperty("VERSION");
+ }
+
+ setProperty("LATEST_VERSION", jnlpVersion);
+ }
+ }
+
+ VersionChecker vc = new VersionChecker();
+ vc.start();
+ }
+ else
+ {
+ if(jnlpVersion!=null)
+ setProperty("LATEST_VERSION", jnlpVersion);
+ else
+ applicationProperties.remove("LATEST_VERSION");
+ }
+
+ setProperty("VERSION", codeVersion);
+
+ //LOAD USERDEFINED COLOURS
+ jalview.gui.UserDefinedColours.initUserColourSchemes( getProperty("USER_DEFINED_COLOURS"));
+ jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", false);
+ }
+
+
+
+ /**
+ * Gets Jalview application property of given key. Returns null
+ * if key not found
+ *
+ * @param key Name of property
+ *
+ * @return Property value
+ */
+ public static String getProperty(String key)
+ {
+ return applicationProperties.getProperty(key);
+ }
+
+
+ /** These methods are used when checking if the saved preference
+ * is different to the default setting
+ */
+
+ public static boolean getDefault(String property, boolean def)
+ {
+ String string = getProperty(property);
+ if (string != null)
+ {
+ def = Boolean.valueOf(string).booleanValue();
+ }
+
+ return def;
+ }
+
+ /** These methods are used when checking if the saved preference
+ * is different to the default setting
+ */
+ public static String getDefault(String property, String def)
+ {
+ String string = getProperty(property);
+ if (string != null)
+ {
+ return string;
+ }
+
+ return def;
+ }
+
+
+ /**
+ * Stores property in the file "HOME_DIR/.jalview_properties"
+ *
+ * @param key Name of object
+ * @param obj String value of property
+ *
+ * @return String value of property
+ */
+ public static String setProperty(String key, String obj)
+ {
+ try
+ {
+ FileOutputStream out = new FileOutputStream(propertiesFile);
+ applicationProperties.setProperty(key, obj);
+ applicationProperties.store(out, "---JalviewX Properties File---");
+ out.close();
+ }
+ catch (Exception ex)
+ { System.out.println("Error setting property: "+key+" "+obj+"\n"+ex); }
+ return obj;
+ }
+
+ public static void saveProperties()
+ {
+ try
+ {
+ FileOutputStream out = new FileOutputStream(propertiesFile);
+ applicationProperties.store(out, "---JalviewX Properties File---");
+ out.close();
+ }
+ catch (Exception ex)
+ { System.out.println("Error saving properties: "+ex); }
+ }
+}
diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java
index a734054..a31a971 100755
--- a/src/jalview/bin/Jalview.java
+++ b/src/jalview/bin/Jalview.java
@@ -1,297 +1,334 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.bin;
-
-import jalview.gui.*;
-
-import javax.swing.*;
-
-import java.util.Vector;
-
-
-/**
- * Main class for Jalview Application
- *
- *
start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
- *
- * @author $author$
- * @version $Revision$
- */
-public class Jalview
-{
-
- /**
- * main class for Jalview application
- *
- * @param args open filename
- */
- public static void main(String[] args)
- {
- System.out.println("Java version: "+System.getProperty("java.version"));
- System.out.println(System.getProperty("os.arch")+" "
- +System.getProperty("os.name")+" "
- +System.getProperty("os.version"));
-
-
- ArgsParser aparser = new ArgsParser(args);
- boolean headless = false;
-
- if( aparser.contains("help") || aparser.contains("h") )
- {
- System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
- +"-nodisplay\tRun Jalview without User Interface.\n"
- +"-props FILE\tUse the given Jalview properties file instead of users default.\n"
- +"-groups FILE\tUse the given file to mark groups on the alignment."
- +"\nThe first lines of the groups file lists the GroupName and GroupColours"
- +" to be used in the alignment. Use the GROUPNAME label for each of your sequences. "
- +"\nGROUPNAMEGROUPCOLOUR\n"
- +"TEXTSEQUENCE_IDSEQUENCE_INDEXSTART_RESIDUEEND_RESIDUEGROUPNAME\n"
- +"SequenceID is used in preference to SequenceIndex if both are provided.\n"
- +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n"
- +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n"
- +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
- +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
- +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
- +"-msf FILE\tCreate alignment file FILE in MSF format.\n"
- +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"
- +"-pir FILE\tCreate alignment file FILE in PIR format.\n"
- +"-blc FILE\tCreate alignment file FILE in BLC format.\n"
- +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
- +"-png FILE\tCreate PNG image FILE from alignment.\n"
- +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
- +"-eps FILE\tCreate EPS file FILE from alignment.");
- System.exit(0);
- }
-
- Cache.loadProperties(aparser.getValue("props")); // must do this before anything else!
-
- if (aparser.contains("nodisplay"))
- {
- System.setProperty("java.awt.headless", "true");
- }
- if (System.getProperty("java.awt.headless") != null
- && System.getProperty("java.awt.headless").equals("true"))
- {
- headless = true;
- }
-
- try
- {
- Cache.initLogger();
- }
- catch (java.lang.NoClassDefFoundError error)
- {
- error.printStackTrace();
- System.out.println(
- "\nEssential logging libraries not found."
- +"\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
- System.exit(0);
- }
-
- Desktop desktop = null;
- if( !headless )
- {
- try
- {
- UIManager.setLookAndFeel(
- UIManager.getSystemLookAndFeelClassName()
- // UIManager.getCrossPlatformLookAndFeelClassName()
-//"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
-//"javax.swing.plaf.metal.MetalLookAndFeel"
-//"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
-//"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
-
- );
- }
- catch (Exception ex)
- {
- }
-
- desktop = new Desktop();
- desktop.setVisible(true);
- desktop.discoverer.start();
- }
-
-
- String file = null, protocol = null, format = null, groups=null;
- jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
-
- file = aparser.getValue("open");
-
- if (file == null && desktop==null)
- {
- System.out.println("No files to open!");
- System.exit(1);
- }
-
- if(file!=null)
- {
-
- if (!file.startsWith("http://"))
- {
- if (! (new java.io.File(file)).exists())
- {
- System.out.println("Can't find " + file);
- if(headless)
- System.exit(1);
- }
- }
-
- protocol = "File";
-
- if (file.indexOf("http:") > -1)
- {
- protocol = "URL";
- }
-
- if (file.endsWith(".jar"))
- format = "Jalview";
- else
- format = new jalview.io.IdentifyFile().Identify(file, protocol);
-
- System.out.println("Opening: " + format + " file " + file);
-
- AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
-
- groups = aparser.getValue("groups");
- if (groups != null)
- {
- af.parseGroupsFile(groups);
- }
-
- String imageName = "unnamed.png";
- while (aparser.getSize() > 1)
- {
- format = aparser.nextValue();
- file = aparser.nextValue();
-
- if (format.equalsIgnoreCase("png"))
- {
- af.createPNG(new java.io.File(file));
- imageName = (new java.io.File(file)).getName();
- System.out.println("Creating PNG image: " + file);
- continue;
- }
- else if (format.equalsIgnoreCase("imgMap"))
- {
- af.createImageMap(new java.io.File(file), imageName);
- System.out.println("Creating image map: " + file);
- continue;
- }
- else if (format.equalsIgnoreCase("eps"))
- {
- System.out.println("Creating EPS file: " + file);
- af.createEPS(new java.io.File(file));
- continue;
- }
-
- if (af.saveAlignment(file, format))
- System.out.println("Written alignment in " + format +
- " format to " + file);
- else
- System.out.println("Error writing file " + file + " in " + format +
- " format!!");
-
- }
-
- while (aparser.getSize() > 0)
- {
- System.out.println("Unknown arg: " + aparser.nextValue());
- }
- }
-
- // We'll only open the default file if the desktop is visible.
- //////////////////////
- if (
- !headless &&
- jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
- {
-
- file = jalview.bin.Cache.getDefault("STARTUP_FILE",
- "http://www.jalview.org/examples/exampleFile.jar");
- protocol = "File";
-
- if (file.indexOf("http:") > -1)
- {
- protocol = "URL";
- }
-
- if (file.endsWith(".jar"))
- {
- Jalview2XML.LoadJalviewAlign(file);
- }
- else
- {
- format = new jalview.io.IdentifyFile().Identify(file, protocol);
- desktop.LoadFile(file, protocol, format);
- }
- }
- }
-}
-
- class ArgsParser
- {
- Vector vargs = null;
- public ArgsParser(String [] args)
- {
- vargs = new Vector();
- for (int i = 0; i < args.length; i++)
- {
- String arg = args[i].trim();
- if (arg.charAt(0) == '-')
- arg = arg.substring(1);
- vargs.addElement(arg);
- }
- }
-
- public String getValue(String arg)
- {
- int index = vargs.indexOf(arg);
- String ret = null;
- if (index != -1)
- {
- ret = vargs.elementAt(index + 1).toString();
- vargs.removeElementAt(index);
- vargs.removeElementAt(index);
- }
- return ret;
- }
-
- public boolean contains(String arg)
- {
- if(vargs.contains(arg))
- {
- vargs.removeElement(arg);
- return true;
- }
- else
- return false;
- }
-
- public String nextValue()
- {
- return vargs.remove(0).toString();
- }
-
- public int getSize()
- {
- return vargs.size();
- }
-
- }
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.bin;
+
+import jalview.gui.*;
+
+import javax.swing.*;
+
+import java.util.Vector;
+
+
+/**
+ * Main class for Jalview Application
+ *
+ *
start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Jalview
+{
+
+ /**
+ * main class for Jalview application
+ *
+ * @param args open filename
+ */
+ public static void main(String[] args)
+ {
+ System.out.println("Java version: "+System.getProperty("java.version"));
+ System.out.println(System.getProperty("os.arch")+" "
+ +System.getProperty("os.name")+" "
+ +System.getProperty("os.version"));
+
+
+ ArgsParser aparser = new ArgsParser(args);
+ boolean headless = false;
+
+ if( aparser.contains("help") || aparser.contains("h") )
+ {
+ System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
+ +"-nodisplay\tRun Jalview without User Interface.\n"
+ +"-props FILE\tUse the given Jalview properties file instead of users default.\n"
+ +"-annotations FILE\tAdd precalculated annotations to the alignment.\n"
+ +"-features FILE\tUse the given file to mark features on the alignment.\n"
+ +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
+ +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
+ +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
+ +"-msf FILE\tCreate alignment file FILE in MSF format.\n"
+ +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"
+ +"-pir FILE\tCreate alignment file FILE in PIR format.\n"
+ +"-blc FILE\tCreate alignment file FILE in BLC format.\n"
+ +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
+ +"-png FILE\tCreate PNG image FILE from alignment.\n"
+ +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
+ +"-eps FILE\tCreate EPS file FILE from alignment."
+ +"\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
+ System.exit(0);
+ }
+
+ Cache.loadProperties(aparser.getValue("props")); // must do this before anything else!
+
+ if (aparser.contains("nodisplay"))
+ {
+ System.setProperty("java.awt.headless", "true");
+ }
+ if (System.getProperty("java.awt.headless") != null
+ && System.getProperty("java.awt.headless").equals("true"))
+ {
+ headless = true;
+ }
+
+ try
+ {
+ Cache.initLogger();
+ }
+ catch (java.lang.NoClassDefFoundError error)
+ {
+ error.printStackTrace();
+ System.out.println(
+ "\nEssential logging libraries not found."
+ +"\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
+ System.exit(0);
+ }
+
+ Desktop desktop = null;
+ if( !headless )
+ {
+ try
+ {
+ UIManager.setLookAndFeel(
+ UIManager.getSystemLookAndFeelClassName()
+ // UIManager.getCrossPlatformLookAndFeelClassName()
+//"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
+//"javax.swing.plaf.metal.MetalLookAndFeel"
+//"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
+//"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
+
+ );
+ }
+ catch (Exception ex)
+ {
+ }
+
+ desktop = new Desktop();
+ desktop.setVisible(true);
+ desktop.discoverer.start();
+ }
+
+
+ String file = null, protocol = null, format = null, data=null;
+ jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
+
+ file = aparser.getValue("open");
+
+ if (file == null && desktop==null)
+ {
+ System.out.println("No files to open!");
+ System.exit(1);
+ }
+
+ if(file!=null)
+ {
+
+ if (!file.startsWith("http://"))
+ {
+ if (! (new java.io.File(file)).exists())
+ {
+ System.out.println("Can't find " + file);
+ if(headless)
+ System.exit(1);
+ }
+ }
+
+ protocol = "File";
+
+ if (file.indexOf("http:") > -1 || file.indexOf("file:") >-1)
+ {
+ protocol = "URL";
+ }
+
+ if (file.endsWith(".jar"))
+ format = "Jalview";
+ else
+ format = new jalview.io.IdentifyFile().Identify(file, protocol);
+
+ System.out.println("Opening: " + format + " file " + file);
+
+ AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
+
+ data = aparser.getValue("colour");
+ if(data!=null)
+ {
+ data.replaceAll("%20", " ");
+
+ jalview.schemes.ColourSchemeI cs =
+ jalview.schemes.ColourSchemeProperty.getColour(af.getViewport().
+ getAlignment(), data);
+
+ if(cs == null)
+ {
+ jalview.schemes.UserColourScheme ucs
+ = new jalview.schemes.UserColourScheme("white");
+ ucs.parseAppletParameter(data);
+ cs = ucs;
+ }
+
+ System.out.println("colour is " + data);
+ af.changeColour( cs );
+ }
+
+
+ // Must maintain ability to use the groups flag
+ data = aparser.getValue("groups");
+ if (data != null)
+ {
+ af.parseFeaturesFile(data, protocol);
+ System.out.println("Added "+data);
+ }
+ data = aparser.getValue("features");
+ if (data != null)
+ {
+ af.parseFeaturesFile(data, protocol);
+ System.out.println("Added "+data);
+ }
+
+ data = aparser.getValue("annotations");
+ if (data != null)
+ {
+ af.loadJalviewDataFile(data);
+ System.out.println("Added "+data);
+ }
+
+
+ String imageName = "unnamed.png";
+ while (aparser.getSize() > 1)
+ {
+ format = aparser.nextValue();
+ file = aparser.nextValue();
+
+ if (format.equalsIgnoreCase("png"))
+ {
+ af.createPNG(new java.io.File(file));
+ imageName = (new java.io.File(file)).getName();
+ System.out.println("Creating PNG image: " + file);
+ continue;
+ }
+ else if (format.equalsIgnoreCase("imgMap"))
+ {
+ af.createImageMap(new java.io.File(file), imageName);
+ System.out.println("Creating image map: " + file);
+ continue;
+ }
+ else if (format.equalsIgnoreCase("eps"))
+ {
+ System.out.println("Creating EPS file: " + file);
+ af.createEPS(new java.io.File(file));
+ continue;
+ }
+
+ if (af.saveAlignment(file, format))
+ System.out.println("Written alignment in " + format +
+ " format to " + file);
+ else
+ System.out.println("Error writing file " + file + " in " + format +
+ " format!!");
+
+ }
+
+ while (aparser.getSize() > 0)
+ {
+ System.out.println("Unknown arg: " + aparser.nextValue());
+ }
+ }
+
+ // We'll only open the default file if the desktop is visible.
+ // And the user
+ //////////////////////
+ if (
+ !headless
+ && file==null
+ && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)
+ )
+ {
+
+ file = jalview.bin.Cache.getDefault("STARTUP_FILE",
+ "http://www.jalview.org/examples/exampleFile.jar");
+
+ protocol = "File";
+
+ if (file.indexOf("http:") > -1)
+ {
+ protocol = "URL";
+ }
+
+ if (file.endsWith(".jar"))
+ {
+ new Jalview2XML().LoadJalviewAlign(file);
+ }
+ else
+ {
+ format = new jalview.io.IdentifyFile().Identify(file, protocol);
+ new jalview.io.FileLoader().LoadFile(file, protocol, format);
+ }
+ }
+ }
+}
+
+ class ArgsParser
+ {
+ Vector vargs = null;
+ public ArgsParser(String [] args)
+ {
+ vargs = new Vector();
+ for (int i = 0; i < args.length; i++)
+ {
+ String arg = args[i].trim();
+ if (arg.charAt(0) == '-')
+ arg = arg.substring(1);
+ vargs.addElement(arg);
+ }
+ }
+
+ public String getValue(String arg)
+ {
+ int index = vargs.indexOf(arg);
+ String ret = null;
+ if (index != -1)
+ {
+ ret = vargs.elementAt(index + 1).toString();
+ vargs.removeElementAt(index);
+ vargs.removeElementAt(index);
+ }
+ return ret;
+ }
+
+ public boolean contains(String arg)
+ {
+ if(vargs.contains(arg))
+ {
+ vargs.removeElement(arg);
+ return true;
+ }
+ else
+ return false;
+ }
+
+ public String nextValue()
+ {
+ return vargs.remove(0).toString();
+ }
+
+ public int getSize()
+ {
+ return vargs.size();
+ }
+
+ }
diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java
index 199a843..9730eb2 100755
--- a/src/jalview/bin/JalviewLite.java
+++ b/src/jalview/bin/JalviewLite.java
@@ -1,406 +1,464 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.bin;
-
-import jalview.appletgui.AlignFrame;
-
-import jalview.datamodel.*;
-
-import jalview.io.*;
-
-import java.applet.*;
-
-import java.awt.*;
-import java.awt.event.*;
-import jalview.appletgui.TreePanel;
-
-
-/**
- * Jalview Applet. Runs in Java 1.18 runtime
- *
- * @author $author$
- * @version $Revision$
- */
-public class JalviewLite extends Applet
-{
- static int lastFrameX = 200;
- static int lastFrameY = 200;
- boolean fileFound = true;
- String file = "No file";
- Button launcher = new Button("Start Jalview");
-
- //The currentAlignFrame is static, it will change
- //if and when the user selects a new window
- static AlignFrame currentAlignFrame;
-
- //This is the first frame to be displayed, and does not change
- AlignFrame initialAlignFrame;
-
- boolean embedded = false;
-
-
- /**
- * init method for Jalview Applet
- */
- public void init()
- {
- int r = 255;
- int g = 255;
- int b = 255;
- String param = getParameter("RGB");
-
- if (param != null)
- {
- try
- {
- r = Integer.parseInt(param.substring(0, 2), 16);
- g = Integer.parseInt(param.substring(2, 4), 16);
- b = Integer.parseInt(param.substring(4, 6), 16);
- }
- catch (Exception ex)
- {
- r = 255;
- g = 255;
- b = 255;
- }
- }
-
- param = getParameter("label");
- if(param != null)
- launcher.setLabel(param);
-
- this.setBackground(new Color(r, g, b));
-
- file = getParameter("file");
-
- final JalviewLite applet = this;
- if(getParameter("embedded")!=null
- && getParameter("embedded").equalsIgnoreCase("true"))
- {
- embedded = true;
- LoadingThread loader = new LoadingThread(file, applet);
- loader.start();
- }
- else if (file != null)
- {
- add(launcher);
-
- launcher.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- LoadingThread loader = new LoadingThread(file,
- applet);
- loader.start();
- }
- });
- }
- else
- {
- file = "NO FILE";
- fileFound = false;
- }
- }
-
-
- public static void main(String [] args)
- {
- if(args.length!=1)
- {
- System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
- System.exit(1);
- }
-
- String format = new jalview.io.IdentifyFile().Identify(args[0],AppletFormatAdapter.FILE);
-
- SequenceI[] sequences = null;
- try{
- sequences = new AppletFormatAdapter().readFile(args[0], AppletFormatAdapter.FILE, format);
- }catch(java.io.IOException ex)
- {
- ex.printStackTrace();
- }
- if ( (sequences != null) && (sequences.length > 0))
- {
- AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0], false);
- af.statusBar.setText("Successfully loaded file " + args[0]);
- }
- }
-
-
- /**
- * Initialises and displays a new java.awt.Frame
- *
- * @param frame java.awt.Frame to be displayed
- * @param title title of new frame
- * @param width width if new frame
- * @param height height of new frame
- */
- public static void addFrame(final Frame frame, String title, int width,
- int height)
- {
- frame.setLocation(lastFrameX, lastFrameY);
- lastFrameX += 40;
- lastFrameY += 40;
- frame.setSize(width, height);
- frame.setTitle(title);
- frame.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- if(currentAlignFrame == frame)
- {
- currentAlignFrame = null;
- }
- lastFrameX -=40;
- lastFrameY -=40;
- frame.setMenuBar(null);
- frame.dispose();
- }
- public void windowActivated(WindowEvent e)
- {
- if(frame instanceof AlignFrame)
- currentAlignFrame = (AlignFrame)frame;
- }
-
- });
- frame.setVisible(true);
- }
-
- public String getSelectedSequences()
- {
- StringBuffer result = new StringBuffer("");
-
- if(initialAlignFrame.viewport.getSelectionGroup()!=null)
- {
- SequenceI[] seqs = initialAlignFrame.viewport.getSelectionGroup().
- getSequencesInOrder(
- initialAlignFrame.viewport.getAlignment());
-
- for (int i = 0; i < seqs.length; i++)
- result.append(seqs[i].getName() + "¬");
- }
-
- return result.toString();
- }
-
- public String getAlignment(String format)
- {
- return getAlignment(format, "true");
- }
-
- public String getAlignment(String format, String suffix)
- {
- try
- {
- boolean seqlimits = suffix.equalsIgnoreCase("true");
-
- String reply = new AppletFormatAdapter().formatSequences(format,
- currentAlignFrame.viewport.getAlignment().getSequences(), seqlimits);
- return reply;
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- return "Error retrieving alignment in " + format + " format. ";
- }
- }
-
- /**
- * This paints the background surrounding the "Launch Jalview button"
- *
- *
If file given in parameter not found, displays error message
- *
- * @param g graphics context
- */
- public void paint(Graphics g)
- {
- if (!fileFound)
- {
- g.setColor(new Color(200, 200, 200));
- g.setColor(Color.cyan);
- g.fillRect(0, 0, getSize().width, getSize().height);
- g.setColor(Color.red);
- g.drawString("Jalview can't open file", 5, 15);
- g.drawString("\"" + file + "\"", 5, 30);
- }
- else if(embedded)
- {
- g.setColor(Color.black);
- g.setFont(new Font("Arial", Font.BOLD, 24));
- g.drawString("Jalview Applet", 50, this.size().height/2 -30);
- g.drawString("Loading Data...", 50, this.size().height/2);
- }
-
-
- }
-
- class LoadingThread extends Thread
- {
- String file;
- String protocol;
- String format;
- JalviewLite applet;
-
- public LoadingThread(String _file,
- JalviewLite _applet)
- {
- file = _file;
- if(inArchive(file))
- protocol = AppletFormatAdapter.CLASSLOADER;
- else
- {
- file = addProtocol(file);
- protocol = AppletFormatAdapter.URL;
- }
- format = new jalview.io.IdentifyFile().Identify(file, protocol);
- applet = _applet;
- }
-
- public void run()
- {
- SequenceI[] sequences = null;
- try{
- sequences = new AppletFormatAdapter().readFile(file, protocol,
- format);
- }catch(java.io.IOException ex)
- {
- ex.printStackTrace();
- }
- if ((sequences != null) && (sequences.length > 0))
- {
- currentAlignFrame = new AlignFrame(new Alignment(sequences),
- applet,
- file,
- embedded);
-
- initialAlignFrame = currentAlignFrame;
-
- currentAlignFrame.statusBar.setText("Successfully loaded file " + file);
-
-
- String treeFile = applet.getParameter("treeFile");
- if (treeFile != null)
- {
- try
- {
- if(inArchive(treeFile))
- protocol = AppletFormatAdapter.CLASSLOADER;
- else
- {
- protocol = AppletFormatAdapter.URL;
- treeFile = addProtocol(treeFile);
- }
-
- jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile, protocol);
-
- fin.parse();
-
- if (fin.getTree() != null)
- {
- currentAlignFrame.loadTree(fin, treeFile);
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- String param = getParameter("features");
- if (param != null)
- {
- if( !inArchive(param) )
- param = addProtocol( param );
-
- currentAlignFrame.parseFeaturesFile(param);
- }
-
- param = getParameter("annotations");
- if (param != null)
- {
- if( !inArchive(param) )
- param = addProtocol( param );
-
- new AnnotationReader().readAnnotationFile(
- currentAlignFrame.viewport.getAlignment(),
- param);
-
- currentAlignFrame.alignPanel.fontChanged();
- }
-
-
- String pdbfile = applet.getParameter("PDBFILE");
- if(pdbfile!=null)
- {
- if( inArchive(pdbfile) )
- protocol = AppletFormatAdapter.CLASSLOADER;
- else
- {
- protocol = AppletFormatAdapter.URL;
- pdbfile = addProtocol(pdbfile);
- }
-
- String sequence = applet.getParameter("PDBSEQ");
-
- if(sequence!=null)
- {
- new MCview.AppletPDBViewer(pdbfile, protocol,
- (Sequence)currentAlignFrame.getAlignViewport().getAlignment().findName(sequence),
- currentAlignFrame.getSeqcanvas());
- }
-
- }
- }
- else
- {
- fileFound = false;
- remove(launcher);
- repaint();
- }
- }
-
- /**
- * Discovers whether the given file is in the Applet Archive
- * @param file String
- * @return boolean
- */
- boolean inArchive(String file)
- {
- //This might throw a security exception in certain browsers
- //Netscape Communicator for instance.
- try{
- return (getClass().getResourceAsStream("/" + file) != null);
- }catch(Exception ex)
- {
- System.out.println("Exception checking resources: "+file+" "+ex);
- return false;
- }
- }
-
- String addProtocol(String file)
- {
- if (file.indexOf("://") == -1)
- file = getCodeBase() + file;
-
- return file;
- }
-
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.bin;
+
+import jalview.appletgui.AlignFrame;
+
+import jalview.datamodel.*;
+
+import jalview.io.*;
+
+import java.applet.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+
+/**
+ * Jalview Applet. Runs in Java 1.18 runtime
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class JalviewLite extends Applet
+{
+ static int lastFrameX = 200;
+ static int lastFrameY = 200;
+ boolean fileFound = true;
+ String file = "No file";
+ Button launcher = new Button("Start Jalview");
+
+ //The currentAlignFrame is static, it will change
+ //if and when the user selects a new window
+ static AlignFrame currentAlignFrame;
+
+ //This is the first frame to be displayed, and does not change
+ AlignFrame initialAlignFrame;
+
+ boolean embedded = false;
+
+
+ /**
+ * init method for Jalview Applet
+ */
+ public void init()
+ {
+ int r = 255;
+ int g = 255;
+ int b = 255;
+ String param = getParameter("RGB");
+
+ if (param != null)
+ {
+ try
+ {
+ r = Integer.parseInt(param.substring(0, 2), 16);
+ g = Integer.parseInt(param.substring(2, 4), 16);
+ b = Integer.parseInt(param.substring(4, 6), 16);
+ }
+ catch (Exception ex)
+ {
+ r = 255;
+ g = 255;
+ b = 255;
+ }
+ }
+
+ param = getParameter("label");
+ if(param != null)
+ launcher.setLabel(param);
+
+ this.setBackground(new Color(r, g, b));
+
+ file = getParameter("file");
+
+ if(file==null)
+ {
+ //Maybe the sequences are added as parameters
+ StringBuffer data = new StringBuffer("PASTE");
+ int i=1;
+ while( (file=getParameter("sequence"+i))!=null)
+ {
+ data.append(file.toString()+"\n");
+ i++;
+ }
+ if(data.length()>5)
+ file = data.toString();
+ }
+
+ final JalviewLite applet = this;
+ if(getParameter("embedded")!=null
+ && getParameter("embedded").equalsIgnoreCase("true"))
+ {
+ embedded = true;
+ LoadingThread loader = new LoadingThread(file, applet);
+ loader.start();
+ }
+ else if (file != null)
+ {
+ add(launcher);
+
+ launcher.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ LoadingThread loader = new LoadingThread(file,
+ applet);
+ loader.start();
+ }
+ });
+ }
+ else
+ {
+ file = "NO FILE";
+ fileFound = false;
+ }
+ }
+
+
+ public static void main(String [] args)
+ {
+ if(args.length!=1)
+ {
+ System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
+ System.exit(1);
+ }
+
+ String format = new jalview.io.IdentifyFile().Identify(args[0],AppletFormatAdapter.FILE);
+
+ SequenceI[] sequences = null;
+ try{
+ sequences = new AppletFormatAdapter().readFile(args[0], AppletFormatAdapter.FILE, format);
+ }catch(java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ if ( (sequences != null) && (sequences.length > 0))
+ {
+ AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0], false);
+ af.statusBar.setText("Successfully loaded file " + args[0]);
+ }
+ }
+
+
+ /**
+ * Initialises and displays a new java.awt.Frame
+ *
+ * @param frame java.awt.Frame to be displayed
+ * @param title title of new frame
+ * @param width width if new frame
+ * @param height height of new frame
+ */
+ public static void addFrame(final Frame frame, String title, int width,
+ int height)
+ {
+ frame.setLocation(lastFrameX, lastFrameY);
+ lastFrameX += 40;
+ lastFrameY += 40;
+ frame.setSize(width, height);
+ frame.setTitle(title);
+ frame.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ if(currentAlignFrame == frame)
+ {
+ currentAlignFrame = null;
+ }
+ lastFrameX -=40;
+ lastFrameY -=40;
+ frame.setMenuBar(null);
+ frame.dispose();
+ }
+ public void windowActivated(WindowEvent e)
+ {
+ if(frame instanceof AlignFrame)
+ currentAlignFrame = (AlignFrame)frame;
+ }
+
+ });
+ frame.setVisible(true);
+ }
+
+ public String getSelectedSequences()
+ {
+ StringBuffer result = new StringBuffer("");
+
+ if(initialAlignFrame.viewport.getSelectionGroup()!=null)
+ {
+ SequenceI[] seqs = initialAlignFrame.viewport.getSelectionGroup().
+ getSequencesInOrder(
+ initialAlignFrame.viewport.getAlignment());
+
+ for (int i = 0; i < seqs.length; i++)
+ result.append(seqs[i].getName() + "¬");
+ }
+
+ return result.toString();
+ }
+
+ public String getAlignment(String format)
+ {
+ return getAlignment(format, "true");
+ }
+
+ public String getAlignment(String format, String suffix)
+ {
+ try
+ {
+ boolean seqlimits = suffix.equalsIgnoreCase("true");
+
+ String reply = new AppletFormatAdapter().formatSequences(format,
+ currentAlignFrame.viewport.getAlignment().getSequences(), seqlimits);
+ return reply;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ return "Error retrieving alignment in " + format + " format. ";
+ }
+ }
+
+ /**
+ * This paints the background surrounding the "Launch Jalview button"
+ *
+ *
If file given in parameter not found, displays error message
+ *
+ * @param g graphics context
+ */
+ public void paint(Graphics g)
+ {
+ if (!fileFound)
+ {
+ g.setColor(new Color(200, 200, 200));
+ g.setColor(Color.cyan);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+ g.setColor(Color.red);
+ g.drawString("Jalview can't open file", 5, 15);
+ g.drawString("\"" + file + "\"", 5, 30);
+ }
+ else if(embedded)
+ {
+ g.setColor(Color.black);
+ g.setFont(new Font("Arial", Font.BOLD, 24));
+ g.drawString("Jalview Applet", 50, this.size().height/2 -30);
+ g.drawString("Loading Data...", 50, this.size().height/2);
+ }
+
+
+ }
+
+ class LoadingThread extends Thread
+ {
+ String file;
+ String protocol;
+ String format;
+ JalviewLite applet;
+
+ public LoadingThread(String _file,
+ JalviewLite _applet)
+ {
+ file = _file;
+ if(file.startsWith("PASTE"))
+ {
+ file = file.substring(5);
+ protocol = AppletFormatAdapter.PASTE;
+ }
+ else if(inArchive(file))
+ protocol = AppletFormatAdapter.CLASSLOADER;
+ else
+ {
+ file = addProtocol(file);
+ protocol = AppletFormatAdapter.URL;
+ }
+ format = new jalview.io.IdentifyFile().Identify(file, protocol);
+ applet = _applet;
+ }
+
+ public void run()
+ {
+ SequenceI[] sequences = null;
+ try{
+ sequences = new AppletFormatAdapter().readFile(file, protocol,
+ format);
+ }catch(java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ if ((sequences != null) && (sequences.length > 0))
+ {
+ currentAlignFrame = new AlignFrame(new Alignment(sequences),
+ applet,
+ file,
+ embedded);
+
+ if(protocol==jalview.io.AppletFormatAdapter.PASTE)
+ currentAlignFrame.setTitle("Sequences from "+getDocumentBase());
+
+ initialAlignFrame = currentAlignFrame;
+
+ currentAlignFrame.statusBar.setText("Successfully loaded file " + file);
+
+
+ String treeFile = applet.getParameter("tree");
+ if(treeFile==null)
+ treeFile = applet.getParameter("treeFile");
+
+ if (treeFile != null)
+ {
+ try
+ {
+ if(inArchive(treeFile))
+ protocol = AppletFormatAdapter.CLASSLOADER;
+ else
+ {
+ protocol = AppletFormatAdapter.URL;
+ treeFile = addProtocol(treeFile);
+ }
+
+ jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile, protocol);
+
+ fin.parse();
+
+ if (fin.getTree() != null)
+ {
+ currentAlignFrame.loadTree(fin, treeFile);
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ String param = getParameter("features");
+ if (param != null)
+ {
+ if( !inArchive(param) )
+ param = addProtocol( param );
+
+ currentAlignFrame.parseFeaturesFile(param, protocol);
+ }
+
+ param = getParameter("showFeatureSettings");
+ if(param !=null && param.equalsIgnoreCase("true"))
+ {
+ currentAlignFrame.viewport.showSequenceFeatures(true);
+ currentAlignFrame.featureSettings_actionPerformed();
+ }
+
+ param = getParameter("annotations");
+ if (param != null)
+ {
+ if( !inArchive(param) )
+ param = addProtocol( param );
+
+ new AnnotationFile().readAnnotationFile(
+ currentAlignFrame.viewport.getAlignment(),
+ param);
+
+ currentAlignFrame.alignPanel.fontChanged();
+ currentAlignFrame.alignPanel.setScrollValues(0,0);
+
+ }
+
+ param = getParameter("jnetfile");
+ if (param != null)
+ {
+ try
+ {
+ if (inArchive(param))
+ protocol = AppletFormatAdapter.CLASSLOADER;
+ else
+ {
+ protocol = AppletFormatAdapter.URL;
+ param = addProtocol(param);
+ }
+
+ jalview.io.JPredFile predictions = new jalview.io.JPredFile(
+ param, protocol);
+ new JnetAnnotationMaker().add_annotation(predictions,
+ currentAlignFrame.viewport.getAlignment(),
+ 0,false); // do not add sequence profile from concise output
+ currentAlignFrame.alignPanel.fontChanged();
+ currentAlignFrame.alignPanel.setScrollValues(0, 0);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+
+ String pdbfile = applet.getParameter("PDBFILE");
+ if(pdbfile!=null)
+ {
+ if( inArchive(pdbfile) )
+ protocol = AppletFormatAdapter.CLASSLOADER;
+ else
+ {
+ protocol = AppletFormatAdapter.URL;
+ pdbfile = addProtocol(pdbfile);
+ }
+
+ String sequence = applet.getParameter("PDBSEQ");
+
+ if(sequence!=null)
+ {
+ new MCview.AppletPDBViewer(pdbfile, protocol,
+ (Sequence)currentAlignFrame.getAlignViewport().getAlignment().findName(sequence),
+ currentAlignFrame.getSeqcanvas());
+ }
+
+ }
+ }
+ else
+ {
+ fileFound = false;
+ remove(launcher);
+ repaint();
+ }
+ }
+
+ /**
+ * Discovers whether the given file is in the Applet Archive
+ * @param file String
+ * @return boolean
+ */
+ boolean inArchive(String file)
+ {
+ //This might throw a security exception in certain browsers
+ //Netscape Communicator for instance.
+ try{
+ return (getClass().getResourceAsStream("/" + file) != null);
+ }catch(Exception ex)
+ {
+ System.out.println("Exception checking resources: "+file+" "+ex);
+ return false;
+ }
+ }
+
+ String addProtocol(String file)
+ {
+ if (file.indexOf("://") == -1)
+ file = getCodeBase() + file;
+
+ return file;
+ }
+
+ }
+}
diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java
index 00d1be8..90a8b31 100755
--- a/src/jalview/datamodel/Alignment.java
+++ b/src/jalview/datamodel/Alignment.java
@@ -1,834 +1,850 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import jalview.analysis.*;
-
-import jalview.util.*;
-
-import java.util.*;
-
-/** Data structure to hold and manipulate a multiple sequence alignment
- */
-public class Alignment implements AlignmentI
-{
- protected Alignment dataset;
- protected Vector sequences;
- protected Vector groups = new Vector();
- protected Vector superGroup = new Vector();
- protected char gapCharacter = '-';
- protected int type = NUCLEOTIDE;
- public static final int PROTEIN = 0;
- public static final int NUCLEOTIDE = 1;
-
- /** DOCUMENT ME!! */
- public AlignmentAnnotation[] annotations;
-
- HiddenSequences hiddenSequences = new HiddenSequences(this);
-
-
- /** Make an alignment from an array of Sequences.
- *
- * @param sequences
- */
- public Alignment(SequenceI[] seqs)
- {
- int i=0;
-
- if( jalview.util.Comparison.isNucleotide(seqs))
- type = NUCLEOTIDE;
- else
- type = PROTEIN;
-
- sequences = new Vector();
-
- for (i = 0; i < seqs.length; i++)
- {
- sequences.addElement(seqs[i]);
-
- if(seqs[i].getDatasetSequence()!=null
- && seqs[i].getDatasetSequence().getAnnotation()!=null)
- {
-
- for(int a=0; a i)
- {
- /* MC Should move this to a method somewhere */
- if (!jalview.util.Comparison.isGap(current.getCharAt(i)))
- {
- delete = false;
- }
- }
- }
-
- if (delete)
- {
- deleteColumns(i, i);
- iSize--;
- i--;
- }
- }
- }
-
- /** Removes a range of columns (start to end inclusive).
- *
- * @param start Start column in the alignment
- * @param end End column in the alignment
- */
- public void deleteColumns(int start, int end)
- {
- deleteColumns(0, getHeight() - 1, start, end);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param seq1 DOCUMENT ME!
- * @param seq2 DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- */
- public void deleteColumns(int seq1, int seq2, int start, int end)
- {
- for (int i = 0; i <= (end - start); i++)
- {
- for (int j = seq1; j <= seq2; j++)
- {
- getSequenceAt(j).deleteCharAt(start);
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void trimLeft(int i)
- {
- int j, jSize = getHeight();
- for (j = 0; j < jSize; j++)
- {
- SequenceI s = getSequenceAt(j);
- int newstart = s.findPosition(i);
-
- if(i>s.getLength())
- {
- sequences.removeElement(s);
- j--;
- jSize--;
- }
- else
- {
- s.setStart(newstart);
- s.setSequence(s.getSequence().substring(i));
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void trimRight(int i)
- {
- for (int j = 0; j < getHeight(); j++)
- {
- SequenceI s = getSequenceAt(j);
- int newend = s.findPosition(i);
-
- s.setEnd(newend);
- if(s.getLength()>i)
- s.setSequence(s.getSequence().substring(0, i + 1));
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param s DOCUMENT ME!
- */
- public void deleteSequence(SequenceI s)
- {
- for (int i = 0; i < getHeight(); i++)
- {
- if (getSequenceAt(i) == s)
- {
- deleteSequence(i);
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void deleteSequence(int i)
- {
- sequences.removeElementAt(i);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param threshold DOCUMENT ME!
- * @param sel DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector removeRedundancy(float threshold, Vector sel)
- {
- Vector del = new Vector();
-
- for (int i = 1; i < sel.size(); i++)
- {
- for (int j = 0; j < i; j++)
- {
- // Only do the comparison if either have not been deleted
- if (!del.contains((SequenceI) sel.elementAt(i)) ||
- !del.contains((SequenceI) sel.elementAt(j)))
- {
- // use PID instead of Comparison (which is really not pleasant)
- float pid = Comparison.PID((SequenceI) sel.elementAt(j),
- (SequenceI) sel.elementAt(i));
-
- if (pid >= threshold)
- {
- // Delete the shortest one
- if (((SequenceI) sel.elementAt(j)).getSequence().length() > ((SequenceI) sel
- .elementAt(
- i)).getSequence().length())
- {
- del.addElement(sel.elementAt(i));
- }
- else
- {
- del.addElement(sel.elementAt(i));
- }
- }
- }
- }
- }
-
- // Now delete the sequences
- for (int i = 0; i < del.size(); i++)
- {
- deleteSequence((SequenceI) del.elementAt(i));
- }
-
- return del;
- }
-
- /** */
- public SequenceGroup findGroup(int i)
- {
- return findGroup(getSequenceAt(i));
- }
-
- /** */
- public SequenceGroup findGroup(SequenceI s)
- {
- for (int i = 0; i < this.groups.size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
-
- if (sg.sequences.contains(s))
- {
- return sg;
- }
- }
-
- return null;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param s DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceGroup[] findAllGroups(SequenceI s)
- {
- Vector temp = new Vector();
-
- int gSize = groups.size();
- for (int i = 0; i < gSize; i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
- if(sg==null || sg.sequences==null)
- {
- this.deleteGroup(sg);
- gSize--;
- continue;
- }
-
- if (sg.sequences.contains(s))
- {
- temp.addElement(sg);
- }
- }
-
- SequenceGroup[] ret = new SequenceGroup[temp.size()];
-
- for (int i = 0; i < temp.size(); i++)
- {
- ret[i] = (SequenceGroup) temp.elementAt(i);
- }
-
- return ret;
- }
-
-
-
- /** */
- public void addGroup(SequenceGroup sg)
- {
- if (!groups.contains(sg))
- {
- groups.addElement(sg);
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- public void deleteAllGroups()
- {
- groups.removeAllElements();
- superGroup.removeAllElements();
-
- int i = 0;
-
- while (i < sequences.size())
- {
- SequenceI s = getSequenceAt(i);
- s.setColor(java.awt.Color.white);
- i++;
- }
- }
-
- /** */
- public void deleteGroup(SequenceGroup g)
- {
- if (groups.contains(g))
- {
- groups.removeElement(g);
- }
- }
-
- /** */
- public SequenceI findName(String name)
- {
- int i = 0;
-
- while (i < sequences.size())
- {
- if (getSequenceAt(i).getName().equals(name))
- {
- return getSequenceAt(i);
- }
-
- i++;
- }
-
- return null;
- }
-
-
- /** */
- public int findIndex(SequenceI s)
- {
- int i = 0;
-
- while (i < sequences.size())
- {
- if (s == getSequenceAt(i))
- {
- return i;
- }
-
- i++;
- }
-
- return -1;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getHeight()
- {
- return sequences.size();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getWidth()
- {
- int maxLength = -1;
-
- for (int i = 0; i < sequences.size(); i++)
- {
- if (getSequenceAt(i).getLength() > maxLength)
- {
- maxLength = getSequenceAt(i).getLength();
- }
- }
-
- return maxLength;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getMaxIdLength()
- {
- int max = 0;
- int i = 0;
-
- while (i < sequences.size())
- {
- SequenceI seq = getSequenceAt(i);
- String tmp = seq.getName() + "/" + seq.getStart() + "-" +
- seq.getEnd();
-
- if (tmp.length() > max)
- {
- max = tmp.length();
- }
-
- i++;
- }
-
- return max;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param gc DOCUMENT ME!
- */
- public void setGapCharacter(char gc)
- {
- gapCharacter = gc;
-
- for (int i = 0; i < sequences.size(); i++)
- {
- Sequence seq = (Sequence) sequences.elementAt(i);
- seq.sequence = seq.sequence.replace('.', gc);
- seq.sequence = seq.sequence.replace('-', gc);
- seq.sequence = seq.sequence.replace(' ', gc);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public char getGapCharacter()
- {
- return gapCharacter;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector getAAFrequency()
- {
- return AAFrequency.calculate(sequences, 0, getWidth());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean isAligned()
- {
- int width = getWidth();
-
- for (int i = 0; i < sequences.size(); i++)
- {
- if (getSequenceAt(i).getLength() != width)
- {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param aa DOCUMENT ME!
- */
- public void deleteAnnotation(AlignmentAnnotation aa)
- {
- int aSize = 1;
-
- if (annotations != null)
- {
- aSize = annotations.length;
- }
-
- AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1];
-
- int tIndex = 0;
-
- for (int i = 0; i < aSize; i++)
- {
- if (annotations[i] == aa)
- {
- continue;
- }
-
- temp[tIndex] = annotations[i];
- tIndex++;
- }
-
- annotations = temp;
- }
-
- /**
- *
- * @param aa AlignmentAnnotation
- * @param seqRef The sequence to associate this annotation with
- * @return The adjusted AlignmentAnnotation, with dataset sequence and annotation added
- */
- public AlignmentAnnotation addAnnotation(AlignmentAnnotation aa, SequenceI seqRef)
- {
- if(seqRef!=null)
- {
- //We can only add Annotations to the dataset sequences
- if(seqRef.getDatasetSequence()==null)
- {
- setDataset(null);
- }
-
- AlignmentAnnotation [] old = seqRef.getDatasetSequence().getAnnotation();
-
- //First check if this is a new annotation or not. If it is new,
- //we must add the annotation to the dataset
- boolean newAnnotation = true;
- if(seqRef.getDatasetSequence().getAnnotation()!=null)
- {
- for(int a=0; a 0)
- copy = new AlignmentAnnotation(
- aa.label, aa.description, aa.annotations, aa.graphMin,
- aa.graphMax, aa.graph
- );
- else
- copy = new AlignmentAnnotation(
- aa.label, aa.description, aa.annotations
- );
-
- copy.datasetAnnotation = aa;
-
- addAnnotation(copy);
-
- copy.sequenceRef = seqRef;
-
- return copy;
- }
- else
- {
- addAnnotation(aa);
- return aa;
- }
- }
-
- public void adjustSequenceAnnotations()
- {
- if(annotations!=null)
- {
- for (int a = 0; a < annotations.length; a++)
- {
- if (annotations[a].sequenceRef != null)
- {
- annotations[a].adjustForAlignment();
- }
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param aa DOCUMENT ME!
- */
- public void addAnnotation(AlignmentAnnotation aa)
- {
- int aSize = 1;
- if (annotations != null)
- {
- aSize = annotations.length + 1;
- }
-
- AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize];
-
- temp[aSize-1] = aa;
-
- int i = 0;
-
- if (aSize > 1)
- {
- for (i = 0; i < (aSize-1); i++)
- {
- temp[i] = annotations[i];
- }
- }
-
- annotations = temp;
- }
-
- public void setAnnotationIndex(AlignmentAnnotation aa, int index)
- {
- if(aa==null || annotations==null || annotations.length-1 width)
+ {
+ width = seqs[i].getLength();
+ }
+ }
+
+ int startCol = -1, endCol = -1;
+ boolean delete = true;
+ for (int i = 0; i < width; i++)
+ {
+ delete = true;
+
+ for (j = 0; j < jSize; j++)
+ {
+ if (seqs[j].getLength() > i)
+ {
+ if (!jalview.util.Comparison.isGap(seqs[j].getCharAt(i)))
+ {
+ if(delete)
+ endCol = i;
+
+ delete = false;
+ break;
+ }
+ }
+ }
+
+ if(delete && startCol==-1)
+ {
+ startCol = i;
+ }
+
+
+ if (!delete && startCol > -1)
+ {
+ deleteColumns(seqs, startCol, endCol);
+ if (shiftrecord!=null) {
+ shiftrecord.addShift(startCol, 1+endCol-startCol);
+ }
+ width -= (endCol - startCol);
+ i -= (endCol - startCol);
+ startCol = -1;
+ endCol = -1;
+ }
+ }
+
+ if (delete && startCol > -1)
+ {
+ deleteColumns(seqs, startCol, endCol);
+ if (shiftrecord!=null) {
+ shiftrecord.addShift(startCol, 1+endCol-startCol);
+ }
+ }
+ }
+
+ /** Removes a range of columns (start to end inclusive).
+ *
+ * @param seqs Sequences to remove columns from
+ * @param start Start column in the alignment
+ * @param end End column in the alignment
+ */
+ public void deleteColumns(SequenceI [] seqs, int start, int end)
+ {
+ for(int i=0; iseqs[j].getLength())
+ {
+ sequences.removeElement(seqs[j]);
+ j--;
+ jSize--;
+ }
+ else
+ {
+ seqs[j].setStart(newstart);
+ seqs[j].setSequence(seqs[j].getSequence().substring(i));
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ public void trimRight(int i)
+ {
+ SequenceI[] seqs = getVisibleAndRepresentedSeqs();
+ int j, jSize = seqs.length;
+ for (j = 0; j < jSize; j++)
+ {
+ int newend = seqs[j].findPosition(i);
+
+ seqs[j].setEnd(newend);
+ if(seqs[j].getLength()>i)
+ seqs[j].setSequence(seqs[j].getSequence().substring(0, i + 1));
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param s DOCUMENT ME!
+ */
+ public void deleteSequence(SequenceI s)
+ {
+ for (int i = 0; i < getHeight(); i++)
+ {
+ if (getSequenceAt(i) == s)
+ {
+ deleteSequence(i);
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ public void deleteSequence(int i)
+ {
+ sequences.removeElementAt(i);
+ }
+
+
+ /** */
+ public SequenceGroup findGroup(SequenceI s)
+ {
+ for (int i = 0; i < this.groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
+
+ if (sg.getSequences(false).contains(s))
+ {
+ return sg;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param s DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceGroup[] findAllGroups(SequenceI s)
+ {
+ Vector temp = new Vector();
+
+ int gSize = groups.size();
+ for (int i = 0; i < gSize; i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
+ if(sg==null || sg.getSequences(false)==null)
+ {
+ this.deleteGroup(sg);
+ gSize--;
+ continue;
+ }
+
+ if (sg.getSequences(false).contains(s))
+ {
+ temp.addElement(sg);
+ }
+ }
+
+ SequenceGroup[] ret = new SequenceGroup[temp.size()];
+
+ for (int i = 0; i < temp.size(); i++)
+ {
+ ret[i] = (SequenceGroup) temp.elementAt(i);
+ }
+
+ return ret;
+ }
+
+
+
+ /** */
+ public void addGroup(SequenceGroup sg)
+ {
+ if (!groups.contains(sg))
+ {
+ groups.addElement(sg);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void deleteAllGroups()
+ {
+ groups.removeAllElements();
+
+ int i = 0;
+
+ while (i < sequences.size())
+ {
+ SequenceI s = getSequenceAt(i);
+ s.setColor(java.awt.Color.white);
+ i++;
+ }
+ }
+
+ /** */
+ public void deleteGroup(SequenceGroup g)
+ {
+ if (groups.contains(g))
+ {
+ groups.removeElement(g);
+ }
+ }
+
+ /** */
+ public SequenceI findName(String name)
+ {
+ int i = 0;
+
+ while (i < sequences.size())
+ {
+ if (getSequenceAt(i).getName().equals(name))
+ {
+ return getSequenceAt(i);
+ }
+
+ i++;
+ }
+
+ return null;
+ }
+
+ public SequenceI [] findSequenceMatch(String name)
+ {
+ Vector matches = new Vector();
+ int i = 0;
+
+ while (i < sequences.size())
+ {
+ if (getSequenceAt(i).getName().equals(name))
+ {
+ matches.addElement(getSequenceAt(i));
+ }
+ i++;
+ }
+
+ SequenceI [] result = new SequenceI[matches.size()];
+ for(i=0; i maxLength)
+ {
+ maxLength = getSequenceAt(i).getLength();
+ }
+ }
+
+ return maxLength;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getMaxIdLength()
+ {
+ int max = 0;
+ int i = 0;
+
+ while (i < sequences.size())
+ {
+ SequenceI seq = getSequenceAt(i);
+ String tmp = seq.getName() + "/" + seq.getStart() + "-" +
+ seq.getEnd();
+
+ if (tmp.length() > max)
+ {
+ max = tmp.length();
+ }
+
+ i++;
+ }
+
+ return max;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param gc DOCUMENT ME!
+ */
+ public void setGapCharacter(char gc)
+ {
+ gapCharacter = gc;
+
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ Sequence seq = (Sequence) sequences.elementAt(i);
+ seq.setSequence( seq.getSequence().replace('.', gc) );
+ seq.setSequence( seq.getSequence().replace('-', gc) );
+ seq.setSequence( seq.getSequence().replace(' ', gc) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public char getGapCharacter()
+ {
+ return gapCharacter;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Vector getAAFrequency()
+ {
+ return AAFrequency.calculate(sequences, 0, getWidth());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean isAligned()
+ {
+ int width = getWidth();
+
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ if (getSequenceAt(i).getLength() != width)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param aa DOCUMENT ME!
+ */
+ public void deleteAnnotation(AlignmentAnnotation aa)
+ {
+ int aSize = 1;
+
+ if (annotations != null)
+ {
+ aSize = annotations.length;
+ }
+
+ AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1];
+
+ int tIndex = 0;
+
+ for (int i = 0; i < aSize; i++)
+ {
+ if (annotations[i] == aa)
+ {
+ continue;
+ }
+
+ temp[tIndex] = annotations[i];
+ tIndex++;
+ }
+
+ annotations = temp;
+ }
+
+
+ public void adjustSequenceAnnotations()
+ {
+ if(annotations!=null)
+ {
+ for (int a = 0; a < annotations.length; a++)
+ {
+ if (annotations[a].sequenceRef != null)
+ {
+ annotations[a].adjustForAlignment();
+ }
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param aa DOCUMENT ME!
+ */
+ public void addAnnotation(AlignmentAnnotation aa)
+ {
+ int aSize = 1;
+ if (annotations != null)
+ {
+ aSize = annotations.length + 1;
+ }
+
+ AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize];
+
+ temp[aSize-1] = aa;
+
+ int i = 0;
+
+ if (aSize > 1)
+ {
+ for (i = 0; i < (aSize-1); i++)
+ {
+ temp[i] = annotations[i];
+ }
+ }
+
+ annotations = temp;
+ }
+
+ public void setAnnotationIndex(AlignmentAnnotation aa, int index)
+ {
+ if(aa==null || annotations==null || annotations.length-1 maxLength; j--)
+ {
+ if (j > maxLength && !jalview.util.Comparison.isGap(
+ current.getCharAt(j)))
+ {
+ maxLength = j;
+ break;
+ }
+ }
+ }
+
+ maxLength++;
+
+ for (int i = 0; i < sequences.size();
+ i++)
+ {
+ current = getSequenceAt(i);
+
+ if (current.getLength() < maxLength)
+ {
+ current.insertCharAt(maxLength - 1, gapCharacter);
+ modified=true;
+ }
+ else if(current.getLength() > maxLength)
+ {
+ current.deleteChars(maxLength, current.getLength());
+ }
+ }
+ return modified;
+ }
+
+ public HiddenSequences getHiddenSequences()
+ {
+ return hiddenSequences;
+ }
+ SequenceI [] getVisibleAndRepresentedSeqs()
+ {
+ if(hiddenSequences==null || hiddenSequences.getSize()<1)
+ return getSequencesArray();
+
+ Vector seqs = new Vector();
+ SequenceI seq;
+ SequenceGroup hidden;
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ seq = (SequenceI) sequences.elementAt(i);
+ seqs.addElement(seq);
+ hidden = seq.getHiddenSequences();
+ if(hidden!=null)
+ {
+ for(int j=0; j 0))
- {
- hasText = true;
- }
- }
- }
-
- /**
- * Creates a new AlignmentAnnotation object.
- *
- * @param label DOCUMENT ME!
- * @param description DOCUMENT ME!
- * @param annotations DOCUMENT ME!
- * @param min DOCUMENT ME!
- * @param max DOCUMENT ME!
- * @param winLength DOCUMENT ME!
- */
- public AlignmentAnnotation(String label, String description,
- Annotation[] annotations, float min, float max, int graphType)
- {
- // graphs are not editable
- this.label = label;
- this.description = description;
- this.annotations = annotations;
- graph = graphType;
-
- if (min == max)
- {
- min = 999999999;
- for (int i = 0; i < annotations.length; i++)
- {
- if (annotations[i] == null)
- {
- continue;
- }
-
- if (annotations[i].value > max)
- {
- max = annotations[i].value;
- }
-
- if (annotations[i].value < min)
- {
- min = annotations[i].value;
- }
- }
- }
-
- graphMin = min;
- graphMax = max;
-
- for (int i = 0; i < annotations.length; i++)
- {
- if ((annotations[i] != null) &&
- ((annotations[i].secondaryStructure == 'H') ||
- (annotations[i].secondaryStructure == 'E')))
- {
- hasIcons = true;
- }
-
- if ((annotations[i] != null) &&
- (annotations[i].displayCharacter.length() > 0))
- {
- hasText = true;
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String toString()
- {
- StringBuffer buffer = new StringBuffer();
-
- for (int i = 0; i < annotations.length; i++)
- {
- if (annotations[i] != null)
- {
- if (graph!=0)
- {
- buffer.append(annotations[i].value);
- }
- else if (hasIcons)
- {
- buffer.append(annotations[i].secondaryStructure);
- }
- else
- {
- buffer.append(annotations[i].displayCharacter);
- }
- }
-
- buffer.append(", ");
- }
-
- if (label.equals("Consensus"))
- {
- buffer.append("\n");
-
- for (int i = 0; i < annotations.length; i++)
- {
- if (annotations[i] != null)
- {
- buffer.append(annotations[i].description);
- }
-
- buffer.append(", ");
- }
- }
-
- return buffer.toString();
- }
-
- public void setThreshold(GraphLine line)
- {
- threshold = line;
- }
-
- public GraphLine getThreshold()
- {
- return threshold;
- }
-
- public void adjustForAlignment()
- {
- int a=0, aSize = sequenceRef.getLength();
-
- int index = 0;
- Annotation[] temp = new Annotation[aSize];
-
- for (a = 0; a < aSize; a++)
- {
- if (!jalview.util.Comparison.isGap(sequenceRef.getCharAt(a)))
- {
- index = sequenceRef.findPosition(a);
- if(datasetAnnotation.annotations.length>index)
- temp[a] = datasetAnnotation.annotations[index];
- }
- }
-
- annotations = temp;
- }
-}
-
-
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.datamodel;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AlignmentAnnotation
+{
+ public SequenceI sequenceRef;
+
+ /** DOCUMENT ME!! */
+ public String label;
+
+ /** DOCUMENT ME!! */
+ public String description;
+
+ /** DOCUMENT ME!! */
+ public Annotation[] annotations;
+
+ public java.util.Hashtable sequenceMapping;
+
+ /** DOCUMENT ME!! */
+ public float graphMin;
+
+ /** DOCUMENT ME!! */
+ public float graphMax;
+
+ public GraphLine threshold;
+
+ // Graphical hints and tips
+
+ /** DOCUMENT ME!! */
+ public boolean editable = false;
+
+ /** DOCUMENT ME!! */
+ public boolean hasIcons; //
+
+ /** DOCUMENT ME!! */
+ public boolean hasText;
+
+ /** DOCUMENT ME!! */
+ public boolean visible = true;
+
+ public int graphGroup = -1;
+
+ /** DOCUMENT ME!! */
+ public int height = 0;
+
+ public int graph = 0;
+
+ public int graphHeight = 40;
+
+ public static final int NO_GRAPH = 0;
+
+ public static final int BAR_GRAPH = 1;
+
+ public static final int LINE_GRAPH = 2;
+
+ public static int getGraphValueFromString(String string)
+ {
+ if(string.equalsIgnoreCase("BAR_GRAPH"))
+ return BAR_GRAPH;
+ else if(string.equalsIgnoreCase("LINE_GRAPH"))
+ return LINE_GRAPH;
+ else
+ return NO_GRAPH;
+ }
+
+ /**
+ * Creates a new AlignmentAnnotation object.
+ *
+ * @param label DOCUMENT ME!
+ * @param description DOCUMENT ME!
+ * @param annotations DOCUMENT ME!
+ */
+ public AlignmentAnnotation(String label, String description,
+ Annotation[] annotations)
+ {
+ // always editable?
+ editable = true;
+ this.label = label;
+ this.description = description;
+ this.annotations = annotations;
+
+ for (int i = 0; i < annotations.length; i++)
+ {
+ if ((annotations[i] != null) &&
+ ((annotations[i].secondaryStructure == 'H') ||
+ (annotations[i].secondaryStructure == 'E')))
+ {
+ hasIcons = true;
+ }
+
+ if ((annotations[i] != null) &&
+ (annotations[i].displayCharacter.length() > 0))
+ {
+ hasText = true;
+ }
+ }
+ }
+
+ /**
+ * Creates a new AlignmentAnnotation object.
+ *
+ * @param label DOCUMENT ME!
+ * @param description DOCUMENT ME!
+ * @param annotations DOCUMENT ME!
+ * @param min DOCUMENT ME!
+ * @param max DOCUMENT ME!
+ * @param winLength DOCUMENT ME!
+ */
+ public AlignmentAnnotation(String label, String description,
+ Annotation[] annotations, float min, float max, int graphType)
+ {
+ // graphs are not editable
+ this.label = label;
+ this.description = description;
+ this.annotations = annotations;
+ graph = graphType;
+
+ boolean drawValues = true;
+
+ if (min == max)
+ {
+ min = 999999999;
+ for (int i = 0; i < annotations.length; i++)
+ {
+ if (annotations[i] == null)
+ {
+ continue;
+ }
+
+ if(drawValues && annotations[i].displayCharacter.length() > 1 )
+ {
+ drawValues = false;
+ }
+
+ if (annotations[i].value > max)
+ {
+ max = annotations[i].value;
+ }
+
+ if (annotations[i].value < min)
+ {
+ min = annotations[i].value;
+ }
+ }
+ }
+
+ graphMin = min;
+ graphMax = max;
+
+ for (int i = 0; i < annotations.length; i++)
+ {
+ if (!hasIcons
+ && annotations[i] != null
+ && ((annotations[i].secondaryStructure == 'H') ||
+ (annotations[i].secondaryStructure == 'E')))
+ {
+ hasIcons = true;
+ }
+
+ if (!hasText
+ && annotations[i]!=null
+ && annotations[i].displayCharacter.length() > 0)
+ {
+ hasText = true;
+ }
+ }
+
+ if(!drawValues && graphType!=NO_GRAPH)
+ {
+ for (int i = 0; i < annotations.length; i++)
+ {
+ if (annotations[i] != null)
+ annotations[i].displayCharacter = "";
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ for (int i = 0; i < annotations.length; i++)
+ {
+ if (annotations[i] != null)
+ {
+ if (graph!=0)
+ {
+ buffer.append(annotations[i].value);
+ }
+ else if (hasIcons)
+ {
+ buffer.append(annotations[i].secondaryStructure);
+ }
+ else
+ {
+ buffer.append(annotations[i].displayCharacter);
+ }
+ }
+
+ buffer.append(", ");
+ }
+
+ if (label.equals("Consensus"))
+ {
+ buffer.append("\n");
+
+ for (int i = 0; i < annotations.length; i++)
+ {
+ if (annotations[i] != null)
+ {
+ buffer.append(annotations[i].description);
+ }
+
+ buffer.append(", ");
+ }
+ }
+
+ return buffer.toString();
+ }
+
+ public void setThreshold(GraphLine line)
+ {
+ threshold = line;
+ }
+
+ public GraphLine getThreshold()
+ {
+ return threshold;
+ }
+
+ /**
+ * Attach the annotation to seqRef, starting from startRes position.
+ * @param seqRef
+ * @param startRes
+ */
+ public void createSequenceMapping(SequenceI seqRef,
+ int startRes,
+ boolean alreadyMapped)
+ {
+ if(seqRef == null)
+ return;
+
+ sequenceMapping = new java.util.Hashtable();
+
+ sequenceRef = seqRef;
+ int seqPos;
+
+ for(int i = 0; i < annotations.length; i++)
+ {
+ if (annotations[i] != null)
+ {
+ if(alreadyMapped)
+ seqPos = seqRef.findPosition(i);
+ else
+ seqPos = i+startRes;
+
+ sequenceMapping.put(new Integer(seqPos), annotations[i]);
+ }
+ }
+
+ adjustForAlignment();
+ }
+
+ public void adjustForAlignment()
+ {
+ int a=0, aSize = sequenceRef.getLength();
+
+ if(aSize == 0)
+ {
+ //Its been deleted
+ return;
+ }
+
+ int position;
+ Annotation[] temp = new Annotation[aSize];
+ Integer index;
+
+ for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
+ {
+ index = new Integer(a);
+ if(sequenceMapping.containsKey(index))
+ {
+ position = sequenceRef.findIndex(a)-1;
+
+ temp[position] = (Annotation)sequenceMapping.get(index);
+ }
+ }
+
+ annotations = temp;
+ }
+}
+
+
diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java
index 7fe4627..bcfcc81 100755
--- a/src/jalview/datamodel/AlignmentI.java
+++ b/src/jalview/datamodel/AlignmentI.java
@@ -1,299 +1,284 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.datamodel;
-
-import java.util.*;
-
-
-/** Data structure to hold and manipulate a multiple sequence alignment
- */
-public interface AlignmentI
-{
- /**
- * Calculates the number of sequences in an alignment
- *
- * @return Number of sequences in alignment
- */
- public int getHeight();
-
- /**
- * Calculates the maximum width of the alignment, including gaps.
- *
- * @return Greatest sequence length within alignment.
- */
- public int getWidth();
-
- /**
- * Calculates the longest sequence Id of the alignment
- *
- * @return Number of characters in longest sequence Id.
- */
- public int getMaxIdLength();
-
- /**
- * Calculates if this set of sequences is all the same length
- *
- * @return true if all sequences in alignment are the same length
- */
- public boolean isAligned();
-
- /**
- * Gets sequences as a Vector
- *
- * @return All sequences in alignment.
- */
- public Vector getSequences();
-
- /**
- * Find a specific sequence in this alignment.
- *
- * @param i Index of required sequence.
- *
- * @return SequenceI at given index.
- */
- public SequenceI getSequenceAt(int i);
-
- /**
- * Add a new sequence to this alignment.
- *
- * @param seq New sequence will be added at end of alignment.
- */
- public void addSequence(SequenceI seq);
-
- /**
- * Used to set a particular index of the alignment with the given sequence.
- *
- * @param i Index of sequence to be updated.
- * @param seq New sequence to be inserted.
- */
- public void setSequenceAt(int i, SequenceI seq);
-
- /**
- * Deletes a sequence from the alignment.
- *
- * @param s Sequence to be deleted.
- */
- public void deleteSequence(SequenceI s);
-
- /**
- * Deletes a sequence from the alignment.
- *
- * @param i Index of sequence to be deleted.
- */
- public void deleteSequence(int i);
-
- /**
- * Deletes all residues in every sequence of alignment within given columns.
- *
- * @param start Start index of columns to delete.
- * @param end End index to columns to delete.
- */
- public void deleteColumns(int start, int end);
-
- /**
- * Deletes all residues in every sequence of alignment within given columns.
- *
- * @param seq1 Index of first sequence to delete columns from.
- * @param seq2 Index of last sequence to delete columns from.
- * @param start Start index of columns to delete.
- * @param end End index of columns to delete.
- */
- public void deleteColumns(int seq1, int seq2, int start, int end);
-
- /**
- * Finds sequence in alignment using sequence name as query.
- *
- * @param name Id of sequence to search for.
- *
- * @return Sequence matching query, if found. If not found returns null.
- */
- public SequenceI findName(String name);
-
-
- /**
- * Finds index of a given sequence in the alignment.
- *
- * @param s Sequence to look for.
- *
- * @return Index of sequence within the alignment.
- */
- public int findIndex(SequenceI s);
-
- /**
- * All sequences will be cut from beginning to given index.
- *
- * @param i Remove all residues in sequences up to this column.
- */
- public void trimLeft(int i);
-
- /**
- * All sequences will be cut from given index.
- *
- * @param i Remove all residues in sequences beyond this column.
- */
- public void trimRight(int i);
-
- /**
- * Removes all columns containing entirely gap characters.
- */
- public void removeGaps();
-
- /**
- * Removes redundant sequences from alignment.
- *
- * @param threshold Remove all sequences above the given threshold.
- * @param sel Set of sequences which will have redundant sequences removed from.
- *
- * @return All sequences below redundancy threshold.
- */
- public Vector removeRedundancy(float threshold, Vector sel);
-
- /**
- * Finds group that sequence at index i in alignment is part of.
- *
- * @param i Index in alignment.
- *
- * @return First group found for sequence at position i. WARNING :
- * Sequences may be members of several groups. This method is incomplete.
- */
- public SequenceGroup findGroup(int i);
-
- /**
- * Finds group that given sequence is part of.
- *
- * @param s Sequence in alignment.
- *
- * @return First group found for sequence. WARNING :
- * Sequences may be members of several groups. This method is incomplete.
- */
- public SequenceGroup findGroup(SequenceI s);
-
- /**
- * Finds all groups that a given sequence is part of.
- *
- * @param s Sequence in alignment.
- *
- * @return All groups containing given sequence.
- */
- public SequenceGroup[] findAllGroups(SequenceI s);
-
- /**
- * Adds a new SequenceGroup to this alignment.
- *
- * @param sg New group to be added.
- */
- public void addGroup(SequenceGroup sg);
-
- /**
- * Deletes a specific SequenceGroup
- *
- * @param g Group will be deleted from alignment.
- */
- public void deleteGroup(SequenceGroup g);
-
- /**
- * Get all the groups associated with this alignment.
- *
- * @return All groups as a Vector.
- */
- public Vector getGroups();
-
- /**
- * Deletes all groups from this alignment.
- */
- public void deleteAllGroups();
-
-
- /**
- * Adds a new AlignmentAnnotation to this alignment
- */
- public void addAnnotation(AlignmentAnnotation aa);
-
- /**
- * Adds a new AlignmentAnnotation to this alignment,
- * associated to Sequence starting at sequence index
- */
- public AlignmentAnnotation addAnnotation(AlignmentAnnotation aa, SequenceI seqRef);
-
- public void setAnnotationIndex(AlignmentAnnotation aa, int index);
-
- /**
- * Deletes a specific AlignmentAnnotation from the alignment.
- *
- * @param aa DOCUMENT ME!
- */
- public void deleteAnnotation(AlignmentAnnotation aa);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public AlignmentAnnotation[] getAlignmentAnnotation();
-
- /**
- * DOCUMENT ME!
- *
- * @param gc DOCUMENT ME!
- */
- public void setGapCharacter(char gc);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public char getGapCharacter();
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector getAAFrequency();
-
- /**
- * Returns true if alignment is nucleotide sequence
- *
- * @return DOCUMENT ME!
- */
- public boolean isNucleotide();
-
- /**
- * Set true if the alignment is a nucleotide sequence
- *
- * @return
- */
- public void setNucleotide(boolean b);
-
-
- public Alignment getDataset();
-
- public void setDataset(Alignment dataset);
- /**
- * pads sequences with gaps (to ensure the set looks like an alignment)
- * @return boolean true if alignment was modified
- */
- public boolean padGaps();
-
- public void adjustSequenceAnnotations();
-
- public HiddenSequences getHiddenSequences();
-
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.datamodel;
+
+import jalview.util.ShiftList;
+
+import java.util.*;
+
+
+/** Data structure to hold and manipulate a multiple sequence alignment
+ */
+public interface AlignmentI
+{
+ /**
+ * Calculates the number of sequences in an alignment
+ *
+ * @return Number of sequences in alignment
+ */
+ public int getHeight();
+
+ /**
+ * Calculates the maximum width of the alignment, including gaps.
+ *
+ * @return Greatest sequence length within alignment.
+ */
+ public int getWidth();
+
+ /**
+ * Calculates the longest sequence Id of the alignment
+ *
+ * @return Number of characters in longest sequence Id.
+ */
+ public int getMaxIdLength();
+
+ /**
+ * Calculates if this set of sequences is all the same length
+ *
+ * @return true if all sequences in alignment are the same length
+ */
+ public boolean isAligned();
+
+ /**
+ * Gets sequences as a Vector
+ *
+ * @return All sequences in alignment.
+ */
+ public Vector getSequences();
+
+ /**
+ * Gets sequences as a SequenceI[]
+ *
+ * @return All sequences in alignment.
+ */
+ public SequenceI [] getSequencesArray();
+
+ /**
+ * Find a specific sequence in this alignment.
+ *
+ * @param i Index of required sequence.
+ *
+ * @return SequenceI at given index.
+ */
+ public SequenceI getSequenceAt(int i);
+
+ /**
+ * Add a new sequence to this alignment.
+ *
+ * @param seq New sequence will be added at end of alignment.
+ */
+ public void addSequence(SequenceI seq);
+
+ /**
+ * Used to set a particular index of the alignment with the given sequence.
+ *
+ * @param i Index of sequence to be updated.
+ * @param seq New sequence to be inserted.
+ */
+ public void setSequenceAt(int i, SequenceI seq);
+
+ /**
+ * Deletes a sequence from the alignment.
+ *
+ * @param s Sequence to be deleted.
+ */
+ public void deleteSequence(SequenceI s);
+
+ /**
+ * Deletes a sequence from the alignment.
+ *
+ * @param i Index of sequence to be deleted.
+ */
+ public void deleteSequence(int i);
+
+ /**
+ * Deletes all residues in every sequence of alignment within given columns.
+ *
+ * @param start Start index of columns to delete.
+ * @param end End index to columns to delete.
+ */
+ public void deleteColumns(SequenceI seqs [], int start, int end);
+
+
+ /**
+ * Finds sequence in alignment using sequence name as query.
+ *
+ * @param name Id of sequence to search for.
+ *
+ * @return Sequence matching query, if found. If not found returns null.
+ */
+ public SequenceI findName(String name);
+
+ public SequenceI [] findSequenceMatch(String name);
+
+ /**
+ * Finds index of a given sequence in the alignment.
+ *
+ * @param s Sequence to look for.
+ *
+ * @return Index of sequence within the alignment.
+ */
+ public int findIndex(SequenceI s);
+
+ /**
+ * All sequences will be cut from beginning to given index.
+ *
+ * @param i Remove all residues in sequences up to this column.
+ */
+ public void trimLeft(int i);
+
+ /**
+ * All sequences will be cut from given index.
+ *
+ * @param i Remove all residues in sequences beyond this column.
+ */
+ public void trimRight(int i);
+
+ /**
+ * Removes all columns containing entirely gap characters.
+ */
+ public void removeGaps();
+ /**
+ * remove gaps in alignment - recording any frame shifts in shiftrecord
+ * @param shiftrecord
+ */
+ public void removeGaps(ShiftList shiftrecord);
+
+ /**
+ * Finds group that given sequence is part of.
+ *
+ * @param s Sequence in alignment.
+ *
+ * @return First group found for sequence. WARNING :
+ * Sequences may be members of several groups. This method is incomplete.
+ */
+ public SequenceGroup findGroup(SequenceI s);
+
+ /**
+ * Finds all groups that a given sequence is part of.
+ *
+ * @param s Sequence in alignment.
+ *
+ * @return All groups containing given sequence.
+ */
+ public SequenceGroup[] findAllGroups(SequenceI s);
+
+ /**
+ * Adds a new SequenceGroup to this alignment.
+ *
+ * @param sg New group to be added.
+ */
+ public void addGroup(SequenceGroup sg);
+
+ /**
+ * Deletes a specific SequenceGroup
+ *
+ * @param g Group will be deleted from alignment.
+ */
+ public void deleteGroup(SequenceGroup g);
+
+ /**
+ * Get all the groups associated with this alignment.
+ *
+ * @return All groups as a Vector.
+ */
+ public Vector getGroups();
+
+ /**
+ * Deletes all groups from this alignment.
+ */
+ public void deleteAllGroups();
+
+
+ /**
+ * Adds a new AlignmentAnnotation to this alignment
+ */
+ public void addAnnotation(AlignmentAnnotation aa);
+
+
+ public void setAnnotationIndex(AlignmentAnnotation aa, int index);
+
+ /**
+ * Deletes a specific AlignmentAnnotation from the alignment.
+ *
+ * @param aa DOCUMENT ME!
+ */
+ public void deleteAnnotation(AlignmentAnnotation aa);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AlignmentAnnotation[] getAlignmentAnnotation();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param gc DOCUMENT ME!
+ */
+ public void setGapCharacter(char gc);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public char getGapCharacter();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Vector getAAFrequency();
+
+ /**
+ * Returns true if alignment is nucleotide sequence
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean isNucleotide();
+
+ /**
+ * Set true if the alignment is a nucleotide sequence
+ *
+ * @return
+ */
+ public void setNucleotide(boolean b);
+
+
+ public Alignment getDataset();
+
+ public void setDataset(Alignment dataset);
+ /**
+ * pads sequences with gaps (to ensure the set looks like an alignment)
+ * @return boolean true if alignment was modified
+ */
+ public boolean padGaps();
+
+ public void adjustSequenceAnnotations();
+
+ public HiddenSequences getHiddenSequences();
+ /**
+ * Compact representation of alignment
+ * @return CigarArray
+ */
+ public CigarArray getCompactAlignment();
+}
diff --git a/src/jalview/datamodel/AlignmentOrder.java b/src/jalview/datamodel/AlignmentOrder.java
index 1fa3b96..d113d92 100755
--- a/src/jalview/datamodel/AlignmentOrder.java
+++ b/src/jalview/datamodel/AlignmentOrder.java
@@ -1,184 +1,275 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import java.util.*;
-
-
-/**
- * Title:
- *
- * Description:
- *
- * Copyright: Copyright (c) 2004
- *
- * Company: Dundee University
- *
- * @author not attributable
- * @version 1.0
- */
-public class AlignmentOrder
-{
- // JBPNote : this method would return a vector containing all sequences in seqset
- // with those also contained in order at the beginning of the vector in the order
- // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method
- // should be here for completeness.
-
- /* public Vector getOrder(AlignmentI seqset)
- {
- Vector perm = new Vector(seqset.getHeight());
- for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); iTitle:
+ *
+ * Description:
+ *
+ * Copyright: Copyright (c) 2004
+ *
+ * Company: Dundee University
+ *
+ * @author not attributable
+ * @version 1.0
+ */
+public class AlignmentOrder
+{
+ // JBPNote : this method would return a vector containing all sequences in seqset
+ // with those also contained in order at the beginning of the vector in the order
+ // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method
+ // should be here for completeness.
+
+ /* public Vector getOrder(AlignmentI seqset)
+ {
+ Vector perm = new Vector(seqset.getHeight());
+ for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); i-1) {
+ Order.setElementAt(newref, found);
+ }
+ return found>-1;
+ }
+ /**
+ * Exact equivalence of two AlignmentOrders
+ * @param o
+ * @return true if o orders the same sequenceI objects in the same way
+ */
+ public boolean equals(AlignmentOrder o) {
+ return equals(o, true);
+ }
+ /**
+ * Exact equivalence of two AlignmentOrders
+ * // TODO: Weak SequenceI equivalence - will throw Error at moment
+ * @param o
+ * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
+ * @return true if o orders equivalent sequenceI objects in the same way
+ */
+ public boolean equals(AlignmentOrder o, boolean identity) {
+ if (o!=this) {
+ if (o==null)
+ return false;
+ if (Order!=null && o.Order!=null && Order.size()==o.Order.size()) {
+ if (!identity) {
+ throw new Error("Weak sequenceI equivalence not yet implemented.");
+ } else {
+ for (int i=0,j=o.Order.size(); iOrder.size()) {
+ c = o.Order;
+ s = Order;
+ } else {
+ c = Order;
+ s = o.Order;
+ }
+ if (!identity) {
+ throw new Error("Weak sequenceI equivalence not yet implemented.");
+ } else {
+ // test if c contains s and order in s is conserved in c
+ int last=-1;
+ for (int i=0,j=s.size(); ilast) {
+ last=pos;
+ } else
+ return false;
+ }
+ }
+ } else
+ return false;
+ }
+ return true;
+ }
+ /**
+ * AlignmentOrder
+ *
+ * @param orderThis AlignmentI
+ * @param byThat AlignmentI
+ */
+
+ /* public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat)
+ {
+ // Vector is an ordering of this alignment using the order of sequence objects in byThat,
+ // where ids and unaligned sequences must match
+
+ } */
+}
diff --git a/src/jalview/datamodel/Annotation.java b/src/jalview/datamodel/Annotation.java
index 2316d13..9aa8913 100755
--- a/src/jalview/datamodel/Annotation.java
+++ b/src/jalview/datamodel/Annotation.java
@@ -1,6 +1,6 @@
/*
* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+* Copyright (C) 2006 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
@@ -15,66 +15,66 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.datamodel;
-
-import java.awt.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class Annotation
-{
- /** DOCUMENT ME!! */
- public String displayCharacter = "";
-
- /** DOCUMENT ME!! */
- public String description = ""; // currently used as mouse over
-
- /** DOCUMENT ME!! */
- public char secondaryStructure = ' '; // recognises H and E
-
- /** DOCUMENT ME!! */
- public float value;
-
- // add visual cues here
-
- /** DOCUMENT ME!! */
- public Color colour = Color.black;
-
- /**
- * Creates a new Annotation object.
- *
- * @param displayChar DOCUMENT ME!
- * @param desc DOCUMENT ME!
- * @param ss DOCUMENT ME!
- * @param val DOCUMENT ME!
- */
- public Annotation(String displayChar, String desc, char ss, float val)
- {
- displayCharacter = displayChar;
- description = desc;
- secondaryStructure = ss;
- value = val;
- }
-
- /**
- * Creates a new Annotation object.
- *
- * @param displayChar DOCUMENT ME!
- * @param desc DOCUMENT ME!
- * @param ss DOCUMENT ME!
- * @param val DOCUMENT ME!
- * @param colour DOCUMENT ME!
- */
- public Annotation(String displayChar, String desc, char ss, float val,
- Color colour)
- {
- this(displayChar, desc, ss, val);
- this.colour = colour;
- }
-}
+*/
+package jalview.datamodel;
+
+import java.awt.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Annotation
+{
+ /** DOCUMENT ME!! */
+ public String displayCharacter = "";
+
+ /** DOCUMENT ME!! */
+ public String description = ""; // currently used as mouse over
+
+ /** DOCUMENT ME!! */
+ public char secondaryStructure = ' '; // recognises H and E
+
+ /** DOCUMENT ME!! */
+ public float value;
+
+ // add visual cues here
+
+ /** DOCUMENT ME!! */
+ public Color colour = Color.black;
+
+ /**
+ * Creates a new Annotation object.
+ *
+ * @param displayChar DOCUMENT ME!
+ * @param desc DOCUMENT ME!
+ * @param ss DOCUMENT ME!
+ * @param val DOCUMENT ME!
+ */
+ public Annotation(String displayChar, String desc, char ss, float val)
+ {
+ displayCharacter = displayChar;
+ description = desc;
+ secondaryStructure = ss;
+ value = val;
+ }
+
+ /**
+ * Creates a new Annotation object.
+ *
+ * @param displayChar DOCUMENT ME!
+ * @param desc DOCUMENT ME!
+ * @param ss DOCUMENT ME!
+ * @param val DOCUMENT ME!
+ * @param colour DOCUMENT ME!
+ */
+ public Annotation(String displayChar, String desc, char ss, float val,
+ Color colour)
+ {
+ this(displayChar, desc, ss, val);
+ this.colour = colour;
+ }
+}
diff --git a/src/jalview/datamodel/BinaryNode.java b/src/jalview/datamodel/BinaryNode.java
index cbec833..bb9a426 100755
--- a/src/jalview/datamodel/BinaryNode.java
+++ b/src/jalview/datamodel/BinaryNode.java
@@ -1,284 +1,284 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class BinaryNode
-{
- Object element;
- String name;
- BinaryNode left;
- BinaryNode right;
- BinaryNode parent;
-
- /** DOCUMENT ME!! */
- public int bootstrap;
-
- /**
- * Creates a new BinaryNode object.
- */
- public BinaryNode()
- {
- left = right = parent = null;
- bootstrap = 0;
- }
-
- /**
- * Creates a new BinaryNode object.
- *
- * @param element DOCUMENT ME!
- * @param parent DOCUMENT ME!
- * @param name DOCUMENT ME!
- */
- public BinaryNode(Object element, BinaryNode parent, String name)
- {
- this.element = element;
- this.parent = parent;
- this.name = name;
-
- left = right = null;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Object element()
- {
- return element;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param v DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Object setElement(Object v)
- {
- return element = v;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public BinaryNode left()
- {
- return left;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param n DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public BinaryNode setLeft(BinaryNode n)
- {
- return left = n;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public BinaryNode right()
- {
- return right;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param n DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public BinaryNode setRight(BinaryNode n)
- {
- return right = n;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public BinaryNode parent()
- {
- return parent;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param n DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public BinaryNode setParent(BinaryNode n)
- {
- return parent = n;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean isLeaf()
- {
- return (left == null) && (right == null);
- }
-
- /**
- * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references)
- * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use
- * setChild(null), or detach() for this.
- *
- */
- public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
- {
- if (leftchild != null)
- {
- this.setLeft(leftchild);
- leftchild.detach();
- leftchild.setParent(this);
- }
-
- if (rightchild != null)
- {
- this.setRight(rightchild);
- rightchild.detach();
- rightchild.setParent(this);
- }
- }
-
- /**
- * Detaches the node from the binary tree, along with all its child nodes.
- * @return BinaryNode The detached node.
- */
- public BinaryNode detach()
- {
- if (this.parent != null)
- {
- if (this.parent.left == this)
- {
- this.parent.left = null;
- }
- else
- {
- if (this.parent.right == this)
- {
- this.parent.right = null;
- }
- }
- }
-
- this.parent = null;
-
- return this;
- }
-
- /**
- * Traverses up through the tree until a node with a free leftchild is discovered.
- * @return BinaryNode
- */
- public BinaryNode ascendLeft()
- {
- BinaryNode c = this;
-
- do
- {
- c = c.parent();
- }
- while ((c != null) && (c.left() != null) && !c.left().isLeaf());
-
- return c;
- }
-
- /**
- * Traverses up through the tree until a node with a free rightchild is discovered.
- * Jalview builds trees by descent on the left, so this may be unused.
- * @return BinaryNode
- */
- public BinaryNode ascendRight()
- {
- BinaryNode c = this;
-
- do
- {
- c = c.parent();
- }
- while ((c != null) && (c.right() != null) && !c.right().isLeaf());
-
- return c;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param name DOCUMENT ME!
- */
- public void setName(String name)
- {
- this.name = name;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getName()
- {
- return this.name;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param boot DOCUMENT ME!
- */
- public void setBootstrap(int boot)
- {
- this.bootstrap = boot;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getBootstrap()
- {
- return bootstrap;
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class BinaryNode
+{
+ Object element;
+ String name;
+ BinaryNode left;
+ BinaryNode right;
+ BinaryNode parent;
+
+ /** DOCUMENT ME!! */
+ public int bootstrap;
+
+ /**
+ * Creates a new BinaryNode object.
+ */
+ public BinaryNode()
+ {
+ left = right = parent = null;
+ bootstrap = 0;
+ }
+
+ /**
+ * Creates a new BinaryNode object.
+ *
+ * @param element DOCUMENT ME!
+ * @param parent DOCUMENT ME!
+ * @param name DOCUMENT ME!
+ */
+ public BinaryNode(Object element, BinaryNode parent, String name)
+ {
+ this.element = element;
+ this.parent = parent;
+ this.name = name;
+
+ left = right = null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Object element()
+ {
+ return element;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param v DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Object setElement(Object v)
+ {
+ return element = v;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public BinaryNode left()
+ {
+ return left;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param n DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public BinaryNode setLeft(BinaryNode n)
+ {
+ return left = n;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public BinaryNode right()
+ {
+ return right;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param n DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public BinaryNode setRight(BinaryNode n)
+ {
+ return right = n;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public BinaryNode parent()
+ {
+ return parent;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param n DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public BinaryNode setParent(BinaryNode n)
+ {
+ return parent = n;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean isLeaf()
+ {
+ return (left == null) && (right == null);
+ }
+
+ /**
+ * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references)
+ * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use
+ * setChild(null), or detach() for this.
+ *
+ */
+ public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
+ {
+ if (leftchild != null)
+ {
+ this.setLeft(leftchild);
+ leftchild.detach();
+ leftchild.setParent(this);
+ }
+
+ if (rightchild != null)
+ {
+ this.setRight(rightchild);
+ rightchild.detach();
+ rightchild.setParent(this);
+ }
+ }
+
+ /**
+ * Detaches the node from the binary tree, along with all its child nodes.
+ * @return BinaryNode The detached node.
+ */
+ public BinaryNode detach()
+ {
+ if (this.parent != null)
+ {
+ if (this.parent.left == this)
+ {
+ this.parent.left = null;
+ }
+ else
+ {
+ if (this.parent.right == this)
+ {
+ this.parent.right = null;
+ }
+ }
+ }
+
+ this.parent = null;
+
+ return this;
+ }
+
+ /**
+ * Traverses up through the tree until a node with a free leftchild is discovered.
+ * @return BinaryNode
+ */
+ public BinaryNode ascendLeft()
+ {
+ BinaryNode c = this;
+
+ do
+ {
+ c = c.parent();
+ }
+ while ((c != null) && (c.left() != null) && !c.left().isLeaf());
+
+ return c;
+ }
+
+ /**
+ * Traverses up through the tree until a node with a free rightchild is discovered.
+ * Jalview builds trees by descent on the left, so this may be unused.
+ * @return BinaryNode
+ */
+ public BinaryNode ascendRight()
+ {
+ BinaryNode c = this;
+
+ do
+ {
+ c = c.parent();
+ }
+ while ((c != null) && (c.right() != null) && !c.right().isLeaf());
+
+ return c;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param boot DOCUMENT ME!
+ */
+ public void setBootstrap(int boot)
+ {
+ this.bootstrap = boot;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getBootstrap()
+ {
+ return bootstrap;
+ }
+}
diff --git a/src/jalview/datamodel/BinarySequence.java b/src/jalview/datamodel/BinarySequence.java
index 89d3971..c638bb3 100755
--- a/src/jalview/datamodel/BinarySequence.java
+++ b/src/jalview/datamodel/BinarySequence.java
@@ -1,180 +1,158 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.datamodel;
-
-import jalview.schemes.*;
-
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class BinarySequence extends Sequence
-{
- int[] binary;
- double[] dbinary;
-
- /**
- * Creates a new BinarySequence object.
- *
- * @param s DOCUMENT ME!
- */
- public BinarySequence(SequenceI s)
- {
- super(s.getName(), s.getSequence(), s.getStart(), s.getEnd());
- }
-
- /**
- * Creates a new BinarySequence object.
- *
- * @param name DOCUMENT ME!
- * @param sequence DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- */
- public BinarySequence(String name, String sequence, int start, int end)
- {
- super(name, sequence, start, end);
- }
-
- /**
- * DOCUMENT ME!
- */
- public void encode()
- {
- // Set all matrix to 0
- dbinary = new double[getSequence().length() * 21];
-
- int nores = 21;
-
- for (int i = 0; i < dbinary.length; i++)
- {
- dbinary[i] = 0.0;
- }
-
- for (int i = 0; i < getSequence().length(); i++)
- {
- int aanum = 20;
-
- try
- {
- aanum = ((Integer) ResidueProperties.getAAHash().get(getSequence()
- .substring(i,
- i + 1))).intValue();
- }
- catch (NullPointerException e)
- {
- aanum = 20;
- }
-
- if (aanum > 20)
- {
- aanum = 20;
- }
-
- dbinary[(i * nores) + aanum] = 1.0;
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- public void blosumEncode()
- {
- // Set all matrix to 0
- dbinary = new double[getSequence().length() * 21];
-
- int nores = 21;
-
- //for (int i = 0; i < dbinary.length; i++) {
- // dbinary[i] = 0.0;
- //}
- for (int i = 0; i < getSequence().length(); i++)
- {
- int aanum = 20;
-
- try
- {
- aanum = ((Integer) ResidueProperties.getAAHash().get(getSequence()
- .substring(i,
- i + 1))).intValue();
- }
- catch (NullPointerException e)
- {
- aanum = 20;
- }
-
- if (aanum > 20)
- {
- aanum = 20;
- }
-
- // Do the blosum thing
- for (int j = 0; j < 20; j++)
- {
- dbinary[(i * nores) + j] = ResidueProperties.getBLOSUM62()[aanum][j];
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String toBinaryString()
- {
- String out = "";
-
- for (int i = 0; i < binary.length; i++)
- {
- out += (new Integer(binary[i])).toString();
-
- if (i < (binary.length - 1))
- {
- out += " ";
- }
- }
-
- return out;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public double[] getDBinary()
- {
- return dbinary;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param rt DOCUMENT ME!
- */
- public static void printMemory(Runtime rt)
- {
- System.out.println("DEBUG: Free memory = " + rt.freeMemory()); // log.
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.datamodel;
+
+import jalview.schemes.*;
+
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class BinarySequence extends Sequence
+{
+ int[] binary;
+ double[] dbinary;
+
+ /**
+ * Creates a new BinarySequence object.
+ *
+ * @param s DOCUMENT ME!
+ */
+ public BinarySequence(String s)
+ {
+ super("", s, 0, s.length());
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void encode()
+ {
+ // Set all matrix to 0
+ dbinary = new double[getSequence().length() * 21];
+
+ int nores = 21;
+
+ for (int i = 0; i < dbinary.length; i++)
+ {
+ dbinary[i] = 0.0;
+ }
+
+ for (int i = 0; i < getSequence().length(); i++)
+ {
+ int aanum = 20;
+
+ try
+ {
+ aanum = ((Integer) ResidueProperties.getAAHash().get(getSequence()
+ .substring(i,
+ i + 1))).intValue();
+ }
+ catch (NullPointerException e)
+ {
+ aanum = 20;
+ }
+
+ if (aanum > 20)
+ {
+ aanum = 20;
+ }
+
+ dbinary[(i * nores) + aanum] = 1.0;
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void blosumEncode()
+ {
+ // Set all matrix to 0
+ dbinary = new double[getSequence().length() * 21];
+
+ int nores = 21;
+
+ //for (int i = 0; i < dbinary.length; i++) {
+ // dbinary[i] = 0.0;
+ //}
+ for (int i = 0; i < getSequence().length(); i++)
+ {
+ int aanum = 20;
+
+ try
+ {
+ aanum = ((Integer) ResidueProperties.getAAHash().get(getSequence()
+ .substring(i,
+ i + 1))).intValue();
+ }
+ catch (NullPointerException e)
+ {
+ aanum = 20;
+ }
+
+ if (aanum > 20)
+ {
+ aanum = 20;
+ }
+
+ // Do the blosum thing
+ for (int j = 0; j < 20; j++)
+ {
+ dbinary[(i * nores) + j] = ResidueProperties.getBLOSUM62()[aanum][j];
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String toBinaryString()
+ {
+ String out = "";
+
+ for (int i = 0; i < binary.length; i++)
+ {
+ out += (new Integer(binary[i])).toString();
+
+ if (i < (binary.length - 1))
+ {
+ out += " ";
+ }
+ }
+
+ return out;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public double[] getDBinary()
+ {
+ return dbinary;
+ }
+
+}
diff --git a/src/jalview/datamodel/DBRefEntry.java b/src/jalview/datamodel/DBRefEntry.java
index 57f6021..253136d 100755
--- a/src/jalview/datamodel/DBRefEntry.java
+++ b/src/jalview/datamodel/DBRefEntry.java
@@ -1,41 +1,41 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-public class DBRefEntry
-{
- String source, version, accessionId;
-
- public DBRefEntry(String source, String version, String accessionId)
- {
- this.source = source;
- this.version = version;
- this.accessionId = accessionId;
- }
-
- public String getSource()
- { return source; }
-
- public String getVersion()
- { return version; }
-
- public String getAccessionId()
- { return accessionId; }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+public class DBRefEntry
+{
+ String source, version, accessionId;
+
+ public DBRefEntry(String source, String version, String accessionId)
+ {
+ this.source = source;
+ this.version = version;
+ this.accessionId = accessionId;
+ }
+
+ public String getSource()
+ { return source; }
+
+ public String getVersion()
+ { return version; }
+
+ public String getAccessionId()
+ { return accessionId; }
+
+}
diff --git a/src/jalview/datamodel/GraphLine.java b/src/jalview/datamodel/GraphLine.java
index 2f484ac..1417542 100755
--- a/src/jalview/datamodel/GraphLine.java
+++ b/src/jalview/datamodel/GraphLine.java
@@ -1,37 +1,37 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.datamodel;
-
-public class GraphLine
-{
- public float value;
- public String label = "";
- public java.awt.Color colour = java.awt.Color.black;
- public boolean displayed = true;
-
- public GraphLine(float value, String label, java.awt.Color col)
- {
- this.value = value;
- if(label != null)
- this.label = label;
-
- if(col != null )
- this.colour = col;
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.datamodel;
+
+public class GraphLine
+{
+ public float value;
+ public String label = "";
+ public java.awt.Color colour = java.awt.Color.black;
+ public boolean displayed = true;
+
+ public GraphLine(float value, String label, java.awt.Color col)
+ {
+ this.value = value;
+ if(label != null)
+ this.label = label;
+
+ if(col != null )
+ this.colour = col;
+ }
+}
diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java
index 3a5946c..be7dbe2 100755
--- a/src/jalview/datamodel/HiddenSequences.java
+++ b/src/jalview/datamodel/HiddenSequences.java
@@ -1,114 +1,185 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package jalview.datamodel;
-
-import java.util.*;
-
-public class HiddenSequences
-{
- Hashtable hiddenSequences;
- AlignmentI alignment;
-
- public HiddenSequences(AlignmentI al)
- {
- alignment = al;
- }
-
- public int getSize()
- {
- return hiddenSequences == null ? 0 : hiddenSequences.size();
- }
-
- public void hideSequence(SequenceI sequence)
- {
- if(hiddenSequences==null)
- hiddenSequences = new Hashtable();
-
- int alignmentIndex = alignment.findIndex(sequence);
- alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
-
- hiddenSequences.put(new Integer(alignmentIndex), sequence);
-
- alignment.deleteSequence(sequence);
- }
-
- public void showSequence(int alignmentIndex)
- {
- SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
- if(repSequence.getHiddenSequences()==null && alignmentIndex>0)
- repSequence = alignment.getSequenceAt(alignmentIndex-1);
- if(repSequence.getHiddenSequences()==null)
- repSequence = null;
-
- int start = adjustForHiddenSeqs(alignmentIndex-1);
- int end = adjustForHiddenSeqs(alignmentIndex);
-
- for(int index = end; index > start; index--)
- {
- SequenceI seq = (SequenceI)hiddenSequences.remove(new Integer(
- index));
-
- if(seq!=null)
- {
- alignment.getSequences().insertElementAt(seq, alignmentIndex);
- if(repSequence!=null)
- {
- repSequence.showHiddenSequence(seq);
- }
- }
- }
- }
-
- public SequenceI getHiddenSequence(int alignmentIndex)
- {
- return (SequenceI)hiddenSequences.get(new Integer(alignmentIndex));
- }
-
- public int findIndexWithoutHiddenSeqs(int alignmentIndex)
- {
- int index = 0;
- int hiddenSeqs = 0;
- while(index <= alignmentIndex)
- {
- if(hiddenSequences.containsKey(new Integer(index)))
- {
- hiddenSeqs ++;
- }
- index ++;
- };
-
- return (alignmentIndex - hiddenSeqs) ;
- }
-
- public int adjustForHiddenSeqs(int alignmentIndex)
- {
- int index = 0;
- while(index <= alignmentIndex)
- {
- if(hiddenSequences.containsKey(new Integer(index)))
- {
- alignmentIndex ++;
- }
- index ++;
- };
-
- return alignmentIndex ;
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.datamodel;
+
+import java.util.*;
+
+public class HiddenSequences
+{
+ Hashtable hiddenSequences;
+ AlignmentI alignment;
+
+ public HiddenSequences(AlignmentI al)
+ {
+ alignment = al;
+ }
+
+ public int getSize()
+ {
+ return hiddenSequences == null ? 0 : hiddenSequences.size();
+ }
+
+ public int getWidth()
+ {
+ Enumeration en = hiddenSequences.elements();
+ int width = 0;
+ while(en.hasMoreElements())
+ {
+ SequenceI seq = (SequenceI)en.nextElement();
+ if(seq.getLength()>width)
+ width = seq.getLength();
+ }
+ return width;
+ }
+
+ public void hideSequence(SequenceI sequence)
+ {
+ if(hiddenSequences==null)
+ hiddenSequences = new Hashtable();
+
+ int alignmentIndex = alignment.findIndex(sequence);
+ alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
+
+ hiddenSequences.put(new Integer(alignmentIndex), sequence);
+
+ alignment.deleteSequence(sequence);
+ }
+
+ public Vector showAll()
+ {
+ Vector revealedSeqs = new Vector();
+ for(int i=0; i0)
+ repSequence = alignment.getSequenceAt(alignmentIndex-1);
+
+ if(repSequence!=null
+ && repSequence.getHiddenSequences()==null)
+ repSequence = null;
+
+ int start = adjustForHiddenSeqs(alignmentIndex-1);
+ int end = adjustForHiddenSeqs(alignmentIndex);
+
+ for(int index = end; index > start; index--)
+ {
+ SequenceI seq = (SequenceI)hiddenSequences.remove(new Integer(
+ index));
+
+
+ if(seq!=null)
+ {
+ revealedSeqs.addElement(seq);
+ alignment.getSequences().insertElementAt(seq, alignmentIndex);
+ if(repSequence!=null)
+ {
+ repSequence.showHiddenSequence(seq);
+ }
+ }
+ }
+
+ return revealedSeqs;
+ }
+
+ public Hashtable getHiddenSequences()
+ {
+ return hiddenSequences;
+ }
+
+ public SequenceI getHiddenSequence(int alignmentIndex)
+ {
+ return (SequenceI)hiddenSequences.get(new Integer(alignmentIndex));
+ }
+
+ public int findIndexWithoutHiddenSeqs(int alignmentIndex)
+ {
+ int index = 0;
+ int hiddenSeqs = 0;
+ while(index <= alignmentIndex)
+ {
+ if(hiddenSequences.containsKey(new Integer(index)))
+ {
+ hiddenSeqs ++;
+ }
+ index ++;
+ };
+
+ return (alignmentIndex - hiddenSeqs) ;
+ }
+
+ public int adjustForHiddenSeqs(int alignmentIndex)
+ {
+ int index = 0;
+ while(index <= alignmentIndex)
+ {
+ if(hiddenSequences.containsKey(new Integer(index)))
+ {
+ alignmentIndex ++;
+ }
+ index ++;
+ };
+
+ return alignmentIndex ;
+ }
+
+ public AlignmentI getFullAlignment()
+ {
+ int isize = alignment.getHeight()+hiddenSequences.size();
+ SequenceI [] seq = new Sequence[isize];
+
+ Enumeration en = hiddenSequences.keys();
+ while(en.hasMoreElements())
+ {
+ Integer key = (Integer)en.nextElement();
+ seq[key.intValue()] = (SequenceI)hiddenSequences.get(key);
+ }
+
+ int index = 0;
+ for(int i=0; i0)
- {
- hiddenSeqs = new Vector();
- hiddenSeqsAsString = new Vector();
- Enumeration en = alignment.getHiddenSequences().hiddenSequences.elements();
- while (en.hasMoreElements())
- {
- SequenceI key = (SequenceI) en.nextElement();
- hiddenSeqs.addElement(key);
- hiddenSeqsAsString.addElement(key.getSequence().toString());
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getDescription()
- {
- return description;
- }
-
-
- public void restore()
- {
- if (type == HistoryItem.SORT)
- {
- for (int i = 0; i < sequences.size(); i++)
- {
- alignment.getSequences().setElementAt(sequences.elementAt(i), i);
- }
- }
- else
- {
-
- for (int i = 0; i < sequences.size(); i++)
- {
- SequenceI restore = (SequenceI) sequences.elementAt(i);
-
- if (restore.getLength() == 0)
- {
- //This is for edits which remove all residues in a sequence
- restore.setSequence(seqAsString.elementAt(i).toString());
- alignment.getSequences().insertElementAt(restore,
- Integer.parseInt(alignIndex.elementAt(i).toString()));
- }
- else
- {
- restore.setSequence(seqAsString.elementAt(i).toString());
- }
- }
-
- if(hiddenSeqs!=null)
- {
- for(int hs=0; hs (sequences.size() - 1); i--)
- {
- alignment.deleteSequence(i);
- }
- }
- }
-
- }
-}
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.datamodel;
+
+import jalview.util.ShiftList;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class HistoryItem
+{
+ /** DOCUMENT ME!! */
+ public static final int EDIT = 0;
+
+ /** DOCUMENT ME!! */
+ public static final int SORT = 1;
+
+ /** DOCUMENT ME!! */
+ public static final int HIDE = 2;
+
+ /** DOCUMENT ME!! */
+ public static final int PASTE = 3;
+
+ final int type;
+
+ AlignmentI alignment;
+ String description;
+
+ Vector sequences;
+ Vector seqAsString;
+ Vector alignIndex;
+
+ Vector hiddenSeqs;
+ Vector hiddenSeqsAsString;
+ /**
+ * public field - set directly if history involves a frame shift
+ * should contain the inverse frame shift operations.
+ */
+ public ShiftList alColumnChanges=null;
+
+ /**
+ * Creates a new HistoryItem object.
+ *
+ * @param description DOCUMENT ME!
+ * @param al DOCUMENT ME!
+ * @param type DOCUMENT ME!
+ */
+ public HistoryItem(String description, AlignmentI al, int type)
+ {
+ alignment = al;
+ this.type = type;
+ this.description = description;
+ sequences = new Vector();
+ alignIndex = new Vector();
+ seqAsString = new Vector();
+
+ for (int i = 0; i < al.getHeight(); i++)
+ {
+ SequenceI seq = al.getSequenceAt(i);
+ sequences.addElement(seq);
+ alignIndex.addElement(i + "");
+ seqAsString.addElement(seq.getStart()
+ +" "+seq.getEnd()
+ +" "+seq.getSequence().toString());
+ }
+
+ if(alignment.getHiddenSequences()!=null
+ && alignment.getHiddenSequences().getSize()>0)
+ {
+ hiddenSeqs = new Vector();
+ hiddenSeqsAsString = new Vector();
+ Enumeration en = alignment.getHiddenSequences().hiddenSequences.elements();
+ while (en.hasMoreElements())
+ {
+ SequenceI key = (SequenceI) en.nextElement();
+ hiddenSeqs.addElement(key);
+ hiddenSeqsAsString.addElement(key.getSequence().toString());
+ }
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /**
+ * restore state - adjusting gui hiddenColumn view as necessary
+ * @param columnSelection
+ */
+ public void restore(ColumnSelection columnSelection)
+ {
+ if (type == HistoryItem.SORT)
+ {
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ alignment.getSequences().setElementAt(sequences.elementAt(i), i);
+ }
+ }
+ else
+ {
+ StringTokenizer st;
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ SequenceI restore = (SequenceI) sequences.elementAt(i);
+
+
+ if (restore.getLength() == 0)
+ {
+ //This is for edits which remove all residues in a sequence
+ alignment.getSequences().insertElementAt(restore,
+ Integer.parseInt(alignIndex.elementAt(i).toString()));
+ }
+
+ st = new StringTokenizer(seqAsString.elementAt(i).toString());
+ restore.setStart(Integer.parseInt(st.nextToken()));
+ restore.setEnd(Integer.parseInt(st.nextToken()));
+ restore.setSequence(st.nextToken());
+ }
+
+ if(hiddenSeqs!=null)
+ {
+ for(int hs=0; hs (sequences.size() - 1); i--)
+ {
+ alignment.deleteSequence(i);
+ }
+ }
+ if (alColumnChanges!=null) {
+ columnSelection.compensateForEdits(alColumnChanges);
+ }
+ }
+
+ }
+ /**
+ * note a frame shift that must be compensated for
+ * @param pos start position for shift (in original reference frame)
+ * @param shift length of shift
+ */
+ public void addShift(int pos, int shift) {
+ if (alColumnChanges==null)
+ alColumnChanges = new ShiftList();
+ alColumnChanges.addShift(pos, -shift);
+ }
+}
diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java
index 356a75f..5ca3400 100755
--- a/src/jalview/datamodel/PDBEntry.java
+++ b/src/jalview/datamodel/PDBEntry.java
@@ -1,54 +1,61 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import java.util.*;
-public class PDBEntry
-{
- String type;
- String id;
- Hashtable properties;
-
- public PDBEntry()
- { }
-
- public void setType(String type)
- { this.type = type; }
-
- public String getType()
- { return type; }
-
- public void setId(String id)
- { this.id = id; }
-
- public String getId()
- { return id; }
-
- public void setProperty(Hashtable property)
- {
- this.properties = property;
- }
-
- public Hashtable getProperty()
- {
- return properties;
- }
-
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import java.util.*;
+public class PDBEntry
+{
+ String file;
+ String type;
+ String id;
+ Hashtable properties;
+
+ public PDBEntry()
+ { }
+
+ public void setFile(String file)
+ { this.file = file; }
+
+ public String getFile()
+ { return file; }
+
+ public void setType(String type)
+ { this.type = type; }
+
+ public String getType()
+ { return type; }
+
+ public void setId(String id)
+ { this.id = id; }
+
+ public String getId()
+ { return id; }
+
+ public void setProperty(Hashtable property)
+ {
+ this.properties = property;
+ }
+
+ public Hashtable getProperty()
+ {
+ return properties;
+ }
+
+
+}
diff --git a/src/jalview/datamodel/Provenance.java b/src/jalview/datamodel/Provenance.java
index 52d3662..8b64998 100755
--- a/src/jalview/datamodel/Provenance.java
+++ b/src/jalview/datamodel/Provenance.java
@@ -1,44 +1,44 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-import java.util.*;
-
-public class Provenance
-{
- Vector entries = new Vector();
- public Provenance()
- {
-
- }
-
- public ProvenanceEntry[] getEntries()
- {
- ProvenanceEntry [] ret = new ProvenanceEntry[entries.size()];
- for(int i=0; i=start)
- {
- if(matchStartend)
- matchEnd = end;
-
-
- if(result==null)
- result = new int[]{matchStart, matchEnd};
- else
- {
- resultLength = result.length;
- tmp = new int[resultLength+2];
- System.arraycopy(result,0,tmp,0,resultLength);
- result = tmp;
- result[resultLength] = matchStart;
- result[resultLength+1] = matchEnd;
- }
- }
- }
- }
- return result;
- }
-
- public int getSize()
- {
- return matches==null ? 0 : matches.length;
- }
-
- public SequenceI getResultSequence(int index)
- { return matches[index].sequence; }
-
- public int getResultStart(int index)
- { return matches[index].start; }
-
- public int getResultEnd(int index)
- { return matches[index].end; }
-
- class Match
- {
- SequenceI sequence;
- int start;
- int end;
-
- public Match(SequenceI seq, int start, int end)
- {
- sequence = seq;
- this.start = start;
- this.end = end;
- }
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+public class SearchResults
+{
+
+ Match [] matches;
+
+ /**
+ * This method replaces the old search results which merely
+ * held an alignment index of search matches. This broke
+ * when sequences were moved around the alignment
+ * @param seq Sequence
+ * @param start int
+ * @param end int
+ */
+ public void addResult(SequenceI seq, int start, int end)
+ {
+ if(matches == null)
+ {
+ matches = new Match[]{new Match(seq, start, end)};
+ return;
+ }
+
+ int mSize = matches.length;
+
+ Match [] tmp = new Match[mSize+1];
+ int m;
+ for(m=0; m=start)
+ {
+ if(matchStartend)
+ matchEnd = end;
+
+
+ if(result==null)
+ result = new int[]{matchStart, matchEnd};
+ else
+ {
+ resultLength = result.length;
+ tmp = new int[resultLength+2];
+ System.arraycopy(result,0,tmp,0,resultLength);
+ result = tmp;
+ result[resultLength] = matchStart;
+ result[resultLength+1] = matchEnd;
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ public int getSize()
+ {
+ return matches==null ? 0 : matches.length;
+ }
+
+ public SequenceI getResultSequence(int index)
+ { return matches[index].sequence; }
+
+ public int getResultStart(int index)
+ { return matches[index].start; }
+
+ public int getResultEnd(int index)
+ { return matches[index].end; }
+
+ class Match
+ {
+ SequenceI sequence;
+ int start;
+ int end;
+
+ public Match(SequenceI seq, int start, int end)
+ {
+ sequence = seq;
+ this.start = start;
+ this.end = end;
+ }
+ }
+}
diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java
index f593226..635043b 100755
--- a/src/jalview/datamodel/Sequence.java
+++ b/src/jalview/datamodel/Sequence.java
@@ -1,641 +1,778 @@
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 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
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-*/
-package jalview.datamodel;
-
-import java.awt.*;
-
-import java.util.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class Sequence implements SequenceI
-{
- SequenceI datasetSequence;
- String name;
- String sequence;
- String description;
- int start;
- int end;
- Color color = Color.white;
- Vector pdbIds;
- String vamsasId;
- Vector dbrefs;
-
- /** This annotation is displayed below the alignment but the
- * positions are tied to the residues of this sequence */
- Vector annotation;
-
- /** DOCUMENT ME!! */
- public SequenceFeature [] sequenceFeatures;
-
- /** This array holds hidden sequences
- * of which this sequence is the representitive member of a group
- */
- SequenceGroup hiddenSequences;
-
- /**
- * Creates a new Sequence object.
- *
- * @param name DOCUMENT ME!
- * @param sequence DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- */
- public Sequence(String name, String sequence, int start, int end)
- {
- this.name = name;
- this.sequence = sequence;
- this.start = start;
- this.end = end;
-
- parseId();
-
- checkValidRange();
- }
-
- com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
- "[/][0-9]{1,}[-][0-9]{1,}$");
- com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex(
- "[0-9]{1,}$");
-
- void parseId()
- {
- // Does sequence have the /start-end signiature?
- if(limitrx.search(name))
- {
- name = limitrx.left();
- endrx.search(limitrx.stringMatched());
- setStart( Integer.parseInt( limitrx.stringMatched().substring(1,endrx.matchedFrom()-1 )));
- setEnd( Integer.parseInt( endrx.stringMatched() ));
- }
- }
-
- void checkValidRange()
- {
- if (end < 1)
- {
- int endRes = 0;
- char ch;
- for (int j = 0; j < sequence.length(); j++)
- {
- ch = sequence.charAt(j);
- if (!jalview.util.Comparison.isGap( (ch)))
- {
- endRes++;
- }
- }
- if (endRes > 0)
- {
- endRes += start - 1;
- }
-
- this.end = endRes;
- }
-
- }
-
- /**
- * Creates a new Sequence object.
- *
- * @param name DOCUMENT ME!
- * @param sequence DOCUMENT ME!
- */
- public Sequence(String name, String sequence)
- {
- this(name, sequence, 1, -1);
- }
-
- /**
- * Creates a new Sequence object.
- *
- * @param seq DOCUMENT ME!
- */
- public Sequence(SequenceI seq)
- {
- this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param v DOCUMENT ME!
- */
- public void setSequenceFeatures(SequenceFeature [] features)
- {
- sequenceFeatures = features;
- }
-
- public void addSequenceFeature(SequenceFeature sf)
- {
- if(sequenceFeatures==null)
- {
- sequenceFeatures = new SequenceFeature[0];
- }
-
- for(int i=0; i= sequence.length())
- {
- return "";
- }
-
- if (end >= sequence.length())
- {
- end = sequence.length();
- }
-
- return this.sequence.substring(start, end);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public char getCharAt(int i)
- {
- if (i < sequence.length())
- {
- return sequence.charAt(i);
- }
- else
- {
- return ' ';
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param desc DOCUMENT ME!
- */
- public void setDescription(String desc)
- {
- this.description = desc;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getDescription()
- {
- return this.description;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param pos DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int findIndex(int pos)
- {
- // returns the alignment position for a residue
- int j = start;
- int i = 0;
-
- while ((i < sequence.length()) && (j <= end) && (j <= pos))
- {
- if (!jalview.util.Comparison.isGap(sequence.charAt(i)))
- {
- j++;
- }
-
- i++;
- }
-
- if ((j == end) && (j < pos))
- {
- return end + 1;
- }
- else
- {
- return i;
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int findPosition(int i)
- {
- // Returns the sequence position for an alignment position
- int j = 0;
- int pos = start;
-
- while ((j < i) && (j < sequence.length()))
- {
- if (!jalview.util.Comparison.isGap((sequence.charAt(j))))
- {
- pos++;
- }
-
- j++;
- }
-
- return pos;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int[] gapMap()
- {
- // Returns an int array giving the position of each residue in the sequence in the alignment
- String seq = jalview.analysis.AlignSeq.extractGaps("-. ", sequence);
- int[] map = new int[seq.length()];
- int j = 0;
- int p = 0;
-
- while (j < sequence.length())
- {
- if (!jalview.util.Comparison.isGap(sequence.charAt(j)))
- {
- map[p++] = j;
- }
-
- j++;
- }
-
- return map;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void deleteCharAt(int i)
- {
- if (i >= sequence.length())
- {
- return;
- }
-
- sequence = sequence.substring(0, i) + sequence.substring(i + 1);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param j DOCUMENT ME!
- */
- public void deleteChars(int i, int j)
- {
- if (i >= sequence.length())
- {
- return;
- }
-
- if (j >= sequence.length())
- {
- sequence = sequence.substring(0, i);
- }
- else
- {
- sequence = sequence.substring(0, i) + sequence.substring(j);
- }
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param c DOCUMENT ME!
- * @param chop DOCUMENT ME!
- */
- public void insertCharAt(int i, char c)
- {
- String tmp = new String(sequence);
-
- if (i < sequence.length())
- {
- sequence = tmp.substring(0, i) + String.valueOf(c) +
- tmp.substring(i);
- }
- else
- {
- // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
- char[] ch = new char[(1 + i) - sequence.length()];
-
- for (int j = 0, k = ch.length; j < k; j++)
- ch[j] = c;
-
- sequence = tmp + String.valueOf(ch);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
- */
- public void setColor(Color c)
- {
- this.color = c;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Color getColor()
- {
- return color;
- }
-
- public String getVamsasId()
- {
- return vamsasId;
- }
-
- public void setVamsasId(String id)
- {
- vamsasId = id;
- }
-
- public void setDBRef(Vector dbref)
- {
- dbrefs = dbref;
- }
- public Vector getDBRef()
- {
- return dbrefs;
- }
-
- public void addDBRef(DBRefEntry entry)
- {
- if(dbrefs == null)
- dbrefs = new Vector();
-
- dbrefs.addElement(entry);
- }
-
- public void setDatasetSequence(SequenceI seq)
- {
- datasetSequence = seq;
- }
-
- public SequenceI getDatasetSequence()
- {
- return datasetSequence;
- }
-
- public AlignmentAnnotation [] getAnnotation()
- {
- if(annotation==null)
- return null;
-
- AlignmentAnnotation [] ret = new AlignmentAnnotation[annotation.size()];
- for(int r = 0; r 0)
+ {
+ endRes += start - 1;
+ }
+
+ this.end = endRes;
+ }
+
+ }
+
+ /**
+ * Creates a new Sequence object.
+ *
+ * @param name DOCUMENT ME!
+ * @param sequence DOCUMENT ME!
+ */
+ public Sequence(String name, String sequence)
+ {
+ this(name, sequence, 1, -1);
+ }
+
+ /**
+ * Creates a new Sequence object.
+ *
+ * @param seq DOCUMENT ME!
+ */
+ public Sequence(SequenceI seq)
+ {
+ this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param v DOCUMENT ME!
+ */
+ public void setSequenceFeatures(SequenceFeature [] features)
+ {
+ sequenceFeatures = features;
+ }
+
+ public synchronized void addSequenceFeature(SequenceFeature sf)
+ {
+ if(sequenceFeatures==null)
+ {
+ sequenceFeatures = new SequenceFeature[0];
+ }
+
+ for(int i=0; i= sequence.length())
+ {
+ return "";
+ }
+
+ if (end >= sequence.length())
+ {
+ end = sequence.length();
+ }
+
+ return this.sequence.substring(start, end);
+ }
+ /**
+ * make a new Sequence object from start to end (including gaps) over this seqeunce
+ * @param start int
+ * @param end int
+ * @return SequenceI
+ */
+ public SequenceI getSubSequence(int start, int end) {
+ if (start<0)
+ start = 0;
+ String seq = getSequence(start, end);
+ if (seq=="")
+ return null;
+ int nstart = findPosition(start);
+ int nend=findPosition(end)-1;
+ // JBPNote - this is an incomplete copy.
+ SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
+ nseq.setDatasetSequence(getDatasetSequence());
+ return nseq;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public char getCharAt(int i)
+ {
+ if (i < sequence.length())
+ {
+ return sequence.charAt(i);
+ }
+ else
+ {
+ return ' ';
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param desc DOCUMENT ME!
+ */
+ public void setDescription(String desc)
+ {
+ this.description = desc;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDescription()
+ {
+ return this.description;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param pos DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int findIndex(int pos)
+ {
+ // returns the alignment position for a residue
+ int j = start;
+ int i = 0;
+
+ while ((i < sequence.length()) && (j <= end) && (j <= pos))
+ {
+ if (!jalview.util.Comparison.isGap(sequence.charAt(i)))
+ {
+ j++;
+ }
+
+ i++;
+ }
+
+ if ((j == end) && (j < pos))
+ {
+ return end + 1;
+ }
+ else
+ {
+ return i;
+ }
+ }
+
+ /**
+ * Returns the sequence position for an alignment position
+ *
+ * @param i column index in alignment (from 1)
+ *
+ * @return residue number for residue (left of and) nearest ith column
+ */
+ public int findPosition(int i)
+ {
+ int j = 0;
+ int pos = start;
+ int seqlen=sequence.length();
+ while ((j < i) && (j < seqlen))
+ {
+ if (!jalview.util.Comparison.isGap((sequence.charAt(j))))
+ {
+ pos++;
+ }
+
+ j++;
+ }
+
+ return pos;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int[] gapMap()
+ {
+ // Returns an int array giving the position of each residue in the sequence in the alignment
+ String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sequence);
+ int[] map = new int[seq.length()];
+ int j = 0;
+ int p = 0;
+
+ while (j < sequence.length())
+ {
+ if (!jalview.util.Comparison.isGap(sequence.charAt(j)))
+ {
+ map[p++] = j;
+ }
+
+ j++;
+ }
+
+ return map;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ public void deleteCharAt(int i)
+ {
+ if (i >= sequence.length())
+ {
+ return;
+ }
+
+ sequence = sequence.substring(0, i) + sequence.substring(i + 1);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ */
+ public void deleteChars(int i, int j)
+ {
+ if (i >= sequence.length())
+ {
+ return;
+ }
+
+ if (j >= sequence.length())
+ {
+ sequence = sequence.substring(0, i);
+ }
+ else
+ {
+ sequence = sequence.substring(0, i) + sequence.substring(j);
+ }
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param c DOCUMENT ME!
+ * @param chop DOCUMENT ME!
+ */
+ public void insertCharAt(int i, char c)
+ {
+ String tmp = new String(sequence);
+
+ if (i < sequence.length())
+ {
+ sequence = tmp.substring(0, i) + String.valueOf(c) +
+ tmp.substring(i);
+ }
+ else
+ {
+ // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
+ char[] ch = new char[(1 + i) - sequence.length()];
+
+ for (int j = 0, k = ch.length; j < k; j++)
+ ch[j] = c;
+
+ sequence = tmp + String.valueOf(ch);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ */
+ public void setColor(Color c)
+ {
+ this.color = c;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Color getColor()
+ {
+ return color;
+ }
+
+ public String getVamsasId()
+ {
+ return vamsasId;
+ }
+
+ public void setVamsasId(String id)
+ {
+ vamsasId = id;
+ }
+
+ public void setDBRef(DBRefEntry [] dbref)
+ {
+ dbrefs = dbref;
+ }
+
+ public DBRefEntry [] getDBRef()
+ {
+ return dbrefs;
+ }
+
+ public void addDBRef(DBRefEntry entry)
+ {
+ if(dbrefs == null)
+ dbrefs = new DBRefEntry[0];
+
+ DBRefEntry [] temp = new DBRefEntry[dbrefs.length+1];
+ System.arraycopy(dbrefs, 0, temp, 0, dbrefs.length);
+
+ temp[temp.length-1] = entry;
+
+ dbrefs = temp;
+ }
+
+ public void setDatasetSequence(SequenceI seq)
+ {
+ datasetSequence = seq;
+ }
+
+ public SequenceI getDatasetSequence()
+ {
+ return datasetSequence;
+ }
+
+ public AlignmentAnnotation [] getAnnotation()
+ {
+ if(annotation==null)
+ return null;
+
+ AlignmentAnnotation [] ret = new AlignmentAnnotation[annotation.size()];
+ for(int r = 0; rsequence.length())
+ end = sequence.length();
+
+ if (start > 0)
+ {
+ newSeq.append(sequence.substring(0, start));
+ }
+
+ if (toUpper)
+ newSeq.append(sequence.substring(start, end).toUpperCase());
+ else
+ newSeq.append(sequence.substring(start, end).toLowerCase());
+
+ if (end < sequence.length())
+ newSeq.append(sequence.substring(end));
+
+ sequence = newSeq.toString();
+ }
+
+ public void toggleCase(int start, int end)
+ {
+ StringBuffer newSeq = new StringBuffer();
+
+ if(end>sequence.length())
+ end = sequence.length();
+
+ if (start > 0)
+ {
+ newSeq.append(sequence.substring(0, start));
+ }
+
+ char nextChar;
+ for(int c=start; c=e)
+ return null;
+ return getSubSequence(start, getLength());
+ }
+
+ public int removeGaps() {
+ if (sequence!=null)
+ return removeGaps(0, getLength());
+ return 0;
+ }
+
+ public int removeGaps(int start, int end) {
+ int jSize = getLength();
+ int oSize=jSize;
+ if (jSize<=start)
+ return 0;
+ if (end>jSize)
+ end = jSize;
+
+ // Removing a range is much quicker than removing gaps
+ // one by one for long sequences
+ int j = start;
+ int rangeStart=-1, rangeEnd=-1;
+
+ do
+ {
+ if (jalview.util.Comparison.isGap(getCharAt(j)))
+ {
+ if(rangeStart==-1)
+ {
+ rangeStart = j;
+ rangeEnd = j+1;
+ }
+ else
+ {
+ rangeEnd++;
+ }
+ j++;
+ }
+ else
+ {
+ if(rangeStart>-1)
+ {
+ deleteChars(rangeStart, rangeEnd);
+ j-=rangeEnd-rangeStart;
+ jSize-=rangeEnd-rangeStart;
+ rangeStart = -1;
+ rangeEnd = -1;
+ }
+ else
+ j++;
+ }
+ }
+ while (j < end && j < jSize);
+ if(rangeStart>-1)
+ {
+ deleteChars(rangeStart, rangeEnd);
+ jSize-=rangeEnd-rangeStart;
+ }
+ return oSize-jSize; // number of deleted characters.
+ }
+
+}
diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java
index f8444a0..7d644e8 100755
--- a/src/jalview/datamodel/SequenceFeature.java
+++ b/src/jalview/datamodel/SequenceFeature.java
@@ -1,172 +1,236 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class SequenceFeature
-{
- public int position;
- public int begin;
- public int end;
- public String type;
- public String description;
- public String status;
-
- // Feature group can be set from a features file
- // as a group of features between STARTGROUP and ENDGROUP markers
- public String featureGroup;
-
- public SequenceFeature()
- {}
-
- public SequenceFeature(String type,
- String desc,
- String status,
- int begin, int end,
- String featureGroup)
- {
- this.type = type;
- this.description = desc;
- this.status = status;
- this.position = begin;
- this.begin = begin;
- this.end = end;
- this.featureGroup = featureGroup;
- }
-
- public boolean equals(SequenceFeature sf)
- {
- if(begin != sf.begin
- || end != sf.end)
- return false;
-
-
- if(!(type+description+status).equals
- (sf.type+sf.description+sf.status))
- return false;
-
- return true;
- }
-
-
- public int getPosition()
- {
- return position;
- }
-
- public void setPosition(int pos)
- {
- position = pos;
- begin = pos;
- end = pos;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getBegin()
- {
- return begin;
- }
-
- public void setBegin(int start)
- {
- this.begin = start;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getEnd()
- {
- return end;
- }
-
- public void setEnd(int end)
- {
- this.end = end;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getType()
- {
- return type;
- }
-
- public void setType(String type)
- {
- this.type = type;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getDescription()
- {
- return description;
- }
-
- public void setDescription(String desc)
- {
- description = desc;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getStatus()
- {
- return status;
- }
-
- public void setStatus(String status)
- {
- this.status = status;
- }
-
- public String getFeatureGroup()
- {
- return featureGroup;
- }
-
- public void setFeatureGroup(String featureGroup)
- {
- this.featureGroup = featureGroup;
- }
-
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import java.util.Hashtable;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SequenceFeature
+{
+ public int begin;
+ public int end;
+ public float score;
+ public String type;
+ public String description;
+ public Hashtable otherDetails;
+ public java.util.Vector links;
+
+ // Feature group can be set from a features file
+ // as a group of features between STARTGROUP and ENDGROUP markers
+ public String featureGroup;
+
+ public SequenceFeature()
+ {}
+
+ public SequenceFeature(String type,
+ String desc,
+ String status,
+ int begin, int end,
+ String featureGroup)
+ {
+ this.type = type;
+ this.description = desc;
+ setValue("status", status);
+ this.begin = begin;
+ this.end = end;
+ this.featureGroup = featureGroup;
+ }
+
+ public SequenceFeature(String type,
+ String desc,
+ int begin, int end,
+ float score,
+ String featureGroup)
+ {
+ this.type = type;
+ this.description = desc;
+ this.begin = begin;
+ this.end = end;
+ this.score = score;
+ this.featureGroup = featureGroup;
+ }
+
+ public boolean equals(SequenceFeature sf)
+ {
+ if (begin != sf.begin
+ || end != sf.end
+ || score != sf.score)
+ return false;
+
+ if(!(type+description+featureGroup).equals
+ (sf.type+sf.description+sf.featureGroup))
+ return false;
+
+ return true;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getBegin()
+ {
+ return begin;
+ }
+
+ public void setBegin(int start)
+ {
+ this.begin = start;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getEnd()
+ {
+ return end;
+ }
+
+ public void setEnd(int end)
+ {
+ this.end = end;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String desc)
+ {
+ description = desc;
+ }
+
+ public String getFeatureGroup()
+ {
+ return featureGroup;
+ }
+
+ public void setFeatureGroup(String featureGroup)
+ {
+ this.featureGroup = featureGroup;
+ }
+
+ public void addLink(String labelLink)
+ {
+ if(links==null)
+ links = new java.util.Vector();
+
+ links.insertElementAt(labelLink,0);
+ }
+
+ public float getScore()
+ {
+ return score;
+ }
+
+ public void setScore(float value)
+ {
+ score = value;
+ }
+
+ /**
+ * Used for getting values which are not in the
+ * basic set. eg STRAND, FRAME for GFF file
+ * @param key String
+ */
+ public Object getValue(String key)
+ {
+ if(otherDetails==null)
+ return null;
+ else
+ return otherDetails.get(key);
+ }
+
+ /**
+ * Used for setting values which are not in the
+ * basic set. eg STRAND, FRAME for GFF file
+ * @param key eg STRAND
+ * @param value eg +
+ */
+ public void setValue(String key, Object value)
+ {
+ if(value!=null)
+ {
+ if (otherDetails == null)
+ otherDetails = new Hashtable();
+
+ otherDetails.put(key, value);
+ }
+ }
+
+
+ /*
+ * The following methods are added to maintain
+ * the castor Uniprot mapping file for the moment.
+ */
+ public void setStatus(String status)
+ {
+ setValue("status", status);
+ }
+
+ public String getStatus()
+ {
+ if (otherDetails != null)
+ return otherDetails.get("status").toString();
+ else
+ return null;
+ }
+
+ public void setPosition(int pos)
+ {
+ begin = pos;
+ end = pos;
+ }
+
+ public int getPosition()
+ {
+ return begin;
+ }
+
+}
diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java
index 6de42b9..7bb8ce0 100755
--- a/src/jalview/datamodel/SequenceGroup.java
+++ b/src/jalview/datamodel/SequenceGroup.java
@@ -1,502 +1,604 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import jalview.analysis.*;
-
-import jalview.schemes.*;
-
-import java.awt.*;
-
-import java.util.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class SequenceGroup
-{
- String groupName;
- Conservation conserve;
- Vector aaFrequency;
- boolean displayBoxes;
- boolean displayText;
- boolean colourText;
-
- /** DOCUMENT ME!! */
- public Vector sequences = new Vector();
- int width = -1;
-
- /** DOCUMENT ME!! */
- public ColourSchemeI cs;
- int startRes = 0;
- int endRes = 0;
- Color outlineColour = Color.black;
-
- /**
- * Creates a new SequenceGroup object.
- */
- public SequenceGroup()
- {
- groupName = "Group";
- this.displayBoxes = true;
- this.displayText = true;
- this.colourText = false;
- cs = null;
- }
-
- /**
- * Creates a new SequenceGroup object.
- *
- * @param sequences DOCUMENT ME!
- * @param groupName DOCUMENT ME!
- * @param scheme DOCUMENT ME!
- * @param displayBoxes DOCUMENT ME!
- * @param displayText DOCUMENT ME!
- * @param colourText DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- */
- public SequenceGroup(Vector sequences, String groupName,
- ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
- boolean colourText, int start, int end)
- {
- this.sequences = sequences;
- this.groupName = groupName;
- this.displayBoxes = displayBoxes;
- this.displayText = displayText;
- this.colourText = colourText;
- this.cs = scheme;
- startRes = start;
- endRes = end;
- recalcConservation();
- }
-
- /**
- * Creates a new SequenceGroup object.
- *
- * @param groupName DOCUMENT ME!
- * @param scheme DOCUMENT ME!
- * @param displayBoxes DOCUMENT ME!
- * @param displayText DOCUMENT ME!
- * @param colourText DOCUMENT ME!
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- */
- public SequenceGroup(String groupName, ColourSchemeI scheme,
- boolean displayBoxes, boolean displayText, boolean colourText,
- int start, int end)
- {
- this.groupName = groupName;
- this.displayBoxes = displayBoxes;
- this.displayText = displayText;
- this.colourText = colourText;
- this.cs = scheme;
- startRes = start;
- endRes = end;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param col DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean adjustForRemoveLeft(int col)
- {
- // return value is true if the group still exists
- if (startRes >= col)
- {
- startRes = startRes - col;
- }
-
- if (endRes >= col)
- {
- endRes = endRes - col;
-
- if (startRes > endRes)
- {
- startRes = 0;
- }
- }
- else
- {
- // must delete this group!!
- return false;
- }
-
- return true;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param col DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean adjustForRemoveRight(int col)
- {
- if (startRes > col)
- {
- // delete this group
- return false;
- }
-
- if (endRes >= col)
- {
- endRes = col;
- }
-
- return true;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getName()
- {
- return groupName;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param name DOCUMENT ME!
- */
- public void setName(String name)
- {
- groupName = name;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Conservation getConservation()
- {
- return conserve;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
- */
- public void setConservation(Conservation c)
- {
- conserve = c;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param s DOCUMENT ME!
- * @param recalc DOCUMENT ME!
- */
- public void addSequence(SequenceI s, boolean recalc)
- {
- if (!sequences.contains(s))
- {
- sequences.addElement(s);
- }
-
- if (recalc)
- {
- recalcConservation();
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- public void recalcConservation()
- {
- if(cs == null)
- return;
-
- cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
-
-
- if (cs instanceof ClustalxColourScheme)
- {
- ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth());
- }
-
-
- if (cs.conservationApplied())
- {
- Conservation c = new Conservation(groupName,
- ResidueProperties.propHash, 3, sequences, 0, getWidth());
- c.calculate();
- c.verdict(false, 25);
-
-
- cs.setConservation(c);
-
- if (cs instanceof ClustalxColourScheme)
- {
- ((ClustalxColourScheme) cs).resetClustalX(sequences,
- getWidth());
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param s DOCUMENT ME!
- * @param recalc DOCUMENT ME!
- */
- public void addOrRemove(SequenceI s, boolean recalc)
- {
- if (sequences.contains(s))
- {
- deleteSequence(s, recalc);
- }
- else
- {
- addSequence(s, recalc);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param s DOCUMENT ME!
- * @param recalc DOCUMENT ME!
- */
- public void deleteSequence(SequenceI s, boolean recalc)
- {
- sequences.removeElement(s);
-
- if (recalc)
- {
- recalcConservation();
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getStartRes()
- {
- return startRes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getEndRes()
- {
- return endRes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void setStartRes(int i)
- {
- startRes = i;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void setEndRes(int i)
- {
- endRes = i;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getSize()
- {
- return sequences.size();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceI getSequenceAt(int i)
- {
- return (SequenceI) sequences.elementAt(i);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setColourText(boolean state)
- {
- colourText = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getColourText()
- {
- return colourText;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setDisplayText(boolean state)
- {
- displayText = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getDisplayText()
- {
- return displayText;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setDisplayBoxes(boolean state)
- {
- displayBoxes = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getDisplayBoxes()
- {
- return displayBoxes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getWidth()
- {
- // MC This needs to get reset when characters are inserted and deleted
- if (sequences.size() > 0)
- {
- width = ((SequenceI) sequences.elementAt(0)).getLength();
- }
-
- for (int i = 1; i < sequences.size(); i++)
- {
- SequenceI seq = (SequenceI) sequences.elementAt(i);
-
- if (seq.getLength() > width)
- {
- width = seq.getLength();
- }
- }
-
- return width;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
- */
- public void setOutlineColour(Color c)
- {
- outlineColour = c;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Color getOutlineColour()
- {
- return outlineColour;
- }
-
- /**
- *
- * returns the sequences in the group ordered by the ordering given by al
- *
- * @param al Alignment
- * @return SequenceI[]
- */
- public SequenceI[] getSequencesInOrder(AlignmentI al)
- {
- int sz = sequences.size();
- java.util.Hashtable orderedSeqs = new java.util.Hashtable();
- SequenceI[] seqs = new SequenceI[sz];
-
- for (int i = 0; i < sz; i++)
- {
- SequenceI seq = (SequenceI) sequences.elementAt(i);
- int index = al.findIndex(seq);
- orderedSeqs.put(index + "", seq);
- }
-
- int index = 0;
-
- for (int i = 0; i < al.getHeight(); i++)
- {
- if (orderedSeqs.containsKey(i + ""))
- {
- seqs[index++] = (SequenceI) orderedSeqs.get(i + "");
- }
- }
-
- return seqs;
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import jalview.analysis.*;
+
+import jalview.schemes.*;
+
+import java.awt.*;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SequenceGroup
+{
+ String groupName;
+ Conservation conserve;
+ Vector aaFrequency;
+ boolean displayBoxes;
+ boolean displayText;
+ boolean colourText;
+ private Vector sequences = new Vector();
+ int width = -1;
+
+ /** DOCUMENT ME!! */
+ public ColourSchemeI cs;
+ int startRes = 0;
+ int endRes = 0;
+ Color outlineColour = Color.black;
+
+ /**
+ * Creates a new SequenceGroup object.
+ */
+ public SequenceGroup()
+ {
+ groupName = "Group";
+ this.displayBoxes = true;
+ this.displayText = true;
+ this.colourText = false;
+ cs = null;
+ }
+
+ /**
+ * Creates a new SequenceGroup object.
+ *
+ * @param sequences DOCUMENT ME!
+ * @param groupName DOCUMENT ME!
+ * @param scheme DOCUMENT ME!
+ * @param displayBoxes DOCUMENT ME!
+ * @param displayText DOCUMENT ME!
+ * @param colourText DOCUMENT ME!
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ */
+ public SequenceGroup(Vector sequences, String groupName,
+ ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
+ boolean colourText, int start, int end)
+ {
+ this.sequences = sequences;
+ this.groupName = groupName;
+ this.displayBoxes = displayBoxes;
+ this.displayText = displayText;
+ this.colourText = colourText;
+ this.cs = scheme;
+ startRes = start;
+ endRes = end;
+ recalcConservation();
+ }
+
+ /**
+ * Creates a new SequenceGroup object.
+ *
+ * @param groupName DOCUMENT ME!
+ * @param scheme DOCUMENT ME!
+ * @param displayBoxes DOCUMENT ME!
+ * @param displayText DOCUMENT ME!
+ * @param colourText DOCUMENT ME!
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ */
+ public SequenceGroup(String groupName, ColourSchemeI scheme,
+ boolean displayBoxes, boolean displayText, boolean colourText,
+ int start, int end)
+ {
+ this.groupName = groupName;
+ this.displayBoxes = displayBoxes;
+ this.displayText = displayText;
+ this.colourText = colourText;
+ this.cs = scheme;
+ startRes = start;
+ endRes = end;
+ }
+
+ public SequenceI [] getSelectionAsNewSequences(AlignmentI align)
+ {
+ int iSize = sequences.size();
+ SequenceI [] seqs = new SequenceI[iSize];
+ SequenceI [] inorder = getSequencesInOrder(align);
+
+ char ch;
+ int sres, eres;
+
+ for (int i = 0; i < iSize; i++)
+ {
+ SequenceI seq = inorder[i];
+
+ //FIND START RES
+ //Returns residue following index if gap
+ sres = seq.findPosition(startRes);
+
+ //FIND END RES
+ //Need to find the residue preceeding index if gap
+ eres = 0;
+
+ for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
+ {
+ ch = seq.getCharAt(j);
+ if (!jalview.util.Comparison.isGap( (ch)))
+ {
+ eres++;
+ }
+ }
+
+ if (eres > 0)
+ {
+ eres += seq.getStart() - 1;
+ }
+
+ seqs[i] = new Sequence(seq.getName(),
+ seq.getSequence(startRes, endRes + 1),
+ sres,
+ eres);
+ seqs[i].setDescription(seq.getDescription());
+ seqs[i].setDBRef(seq.getDBRef());
+ seqs[i].setSequenceFeatures(seq.getSequenceFeatures());
+ if (seq.getDatasetSequence() != null)
+ seqs[i].setDatasetSequence(seq.getDatasetSequence());
+
+ if(seq.getAnnotation()!=null)
+ {
+ for(int a=0; a= col)
+ {
+ startRes = startRes - col;
+ }
+
+ if (endRes >= col)
+ {
+ endRes = endRes - col;
+
+ if (startRes > endRes)
+ {
+ startRes = 0;
+ }
+ }
+ else
+ {
+ // must delete this group!!
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param col DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean adjustForRemoveRight(int col)
+ {
+ if (startRes > col)
+ {
+ // delete this group
+ return false;
+ }
+
+ if (endRes >= col)
+ {
+ endRes = col;
+ }
+
+ return true;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getName()
+ {
+ return groupName;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ */
+ public void setName(String name)
+ {
+ groupName = name;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Conservation getConservation()
+ {
+ return conserve;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ */
+ public void setConservation(Conservation c)
+ {
+ conserve = c;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param s DOCUMENT ME!
+ * @param recalc DOCUMENT ME!
+ */
+ public void addSequence(SequenceI s, boolean recalc)
+ {
+ if (!sequences.contains(s))
+ {
+ sequences.addElement(s);
+ }
+
+ if (recalc)
+ {
+ recalcConservation();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void recalcConservation()
+ {
+ if(cs == null)
+ return;
+
+ try
+ {
+ cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
+
+ if (cs instanceof ClustalxColourScheme)
+ {
+ ( (ClustalxColourScheme) cs).resetClustalX(sequences, getWidth());
+ }
+
+ if (cs.conservationApplied())
+ {
+ Conservation c = new Conservation(groupName,
+ ResidueProperties.propHash, 3, sequences,
+ 0, getWidth());
+ c.calculate();
+ c.verdict(false, 25);
+
+ cs.setConservation(c);
+
+ if (cs instanceof ClustalxColourScheme)
+ {
+ ( (ClustalxColourScheme) cs).resetClustalX(sequences,
+ getWidth());
+ }
+ }
+ }
+ catch (java.lang.OutOfMemoryError err)
+ {
+ System.out.println("Out of memory loading groups: " + err);
+ }
+
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param s DOCUMENT ME!
+ * @param recalc DOCUMENT ME!
+ */
+ public void addOrRemove(SequenceI s, boolean recalc)
+ {
+ if (sequences.contains(s))
+ {
+ deleteSequence(s, recalc);
+ }
+ else
+ {
+ addSequence(s, recalc);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param s DOCUMENT ME!
+ * @param recalc DOCUMENT ME!
+ */
+ public void deleteSequence(SequenceI s, boolean recalc)
+ {
+ sequences.removeElement(s);
+
+ if (recalc)
+ {
+ recalcConservation();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getStartRes()
+ {
+ return startRes;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getEndRes()
+ {
+ return endRes;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ public void setStartRes(int i)
+ {
+ startRes = i;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ public void setEndRes(int i)
+ {
+ endRes = i;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getSize(boolean includeHidden)
+ {
+ if(!includeHidden)
+ return sequences.size();
+ else
+ {
+ int total = sequences.size();
+ SequenceI seq;
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ seq = (SequenceI) sequences.elementAt(i);
+ if (seq.getHiddenSequences() != null)
+ {
+ total += seq.getHiddenSequences().getSize(false);
+ }
+ }
+ return total;
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceI getSequenceAt(int i)
+ {
+ return (SequenceI) sequences.elementAt(i);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setColourText(boolean state)
+ {
+ colourText = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getColourText()
+ {
+ return colourText;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setDisplayText(boolean state)
+ {
+ displayText = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getDisplayText()
+ {
+ return displayText;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setDisplayBoxes(boolean state)
+ {
+ displayBoxes = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getDisplayBoxes()
+ {
+ return displayBoxes;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getWidth()
+ {
+ // MC This needs to get reset when characters are inserted and deleted
+ if (sequences.size() > 0)
+ {
+ width = ((SequenceI) sequences.elementAt(0)).getLength();
+ }
+
+ for (int i = 1; i < sequences.size(); i++)
+ {
+ SequenceI seq = (SequenceI) sequences.elementAt(i);
+
+ if (seq.getLength() > width)
+ {
+ width = seq.getLength();
+ }
+ }
+
+ return width;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ */
+ public void setOutlineColour(Color c)
+ {
+ outlineColour = c;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Color getOutlineColour()
+ {
+ return outlineColour;
+ }
+
+ /**
+ *
+ * returns the sequences in the group ordered by the ordering given by al
+ *
+ * @param al Alignment
+ * @return SequenceI[]
+ */
+ public SequenceI[] getSequencesInOrder(AlignmentI al)
+ {
+ int sz = sequences.size();
+ java.util.Hashtable orderedSeqs = new java.util.Hashtable();
+ SequenceI[] seqs = new SequenceI[sz];
+
+ for (int i = 0; i < sz; i++)
+ {
+ SequenceI seq = (SequenceI) sequences.elementAt(i);
+ int index = al.findIndex(seq);
+ orderedSeqs.put(index + "", seq);
+ }
+
+ int index = 0;
+
+ for (int i = 0; i < al.getHeight(); i++)
+ {
+ if (orderedSeqs.containsKey(i + ""))
+ {
+ seqs[index++] = (SequenceI) orderedSeqs.get(i + "");
+ }
+ }
+
+ return seqs;
+ }
+}
diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java
index 1f7a232..f2d9e74 100755
--- a/src/jalview/datamodel/SequenceI.java
+++ b/src/jalview/datamodel/SequenceI.java
@@ -1,257 +1,286 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import java.awt.*;
-
-import java.util.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public interface SequenceI
-{
- /**
- * DOCUMENT ME!
- *
- * @param name DOCUMENT ME!
- */
- public void setName(String name);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getName();
-
-
- /**
- * DOCUMENT ME!
- *
- * @param start DOCUMENT ME!
- */
- public void setStart(int start);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getStart();
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getDisplayId(boolean jvsuffix);
-
- /**
- * DOCUMENT ME!
- *
- * @param end DOCUMENT ME!
- */
- public void setEnd(int end);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getEnd();
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getLength();
-
- /**
- * DOCUMENT ME!
- *
- * @param sequence DOCUMENT ME!
- */
- public void setSequence(String sequence);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getSequence();
-
- /**
- * DOCUMENT ME!
- *
- * @param start DOCUMENT ME!
- * @param end DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getSequence(int start, int end);
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public char getCharAt(int i);
-
- /**
- * DOCUMENT ME!
- *
- * @param desc DOCUMENT ME!
- */
- public void setDescription(String desc);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getDescription();
-
- /**
- * DOCUMENT ME!
- *
- * @param pos DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int findIndex(int pos);
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int findPosition(int i);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int[] gapMap();
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param j DOCUMENT ME!
- */
- public void deleteChars(int i, int j);
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void deleteCharAt(int i);
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- * @param c DOCUMENT ME!
- */
- public void insertCharAt(int i, char c);
-
-
- /**
- * DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
- */
- public void setColor(Color c);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Color getColor();
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceFeature[] getSequenceFeatures();
-
- /**
- * DOCUMENT ME!
- *
- * @param v DOCUMENT ME!
- */
- public void setSequenceFeatures(SequenceFeature [] features);
-
- /**
- * DOCUMENT ME!
- *
- * @param id DOCUMENT ME!
- */
- public void setPDBId(Vector ids);
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector getPDBId();
-
- public void addPDBId(PDBEntry entry);
-
- public String getVamsasId();
-
- public void setVamsasId(String id);
-
- public void setDBRef(Vector dbs);
-
- public Vector getDBRef();
-
- public void addDBRef(DBRefEntry entry);
-
- public void addSequenceFeature(SequenceFeature sf);
-
- public void setDatasetSequence(SequenceI seq);
-
- public SequenceI getDatasetSequence();
-
- public AlignmentAnnotation [] getAnnotation();
-
- public void addAlignmentAnnotation(AlignmentAnnotation annotation);
-
- public SequenceGroup getHiddenSequences();
-
- public void addHiddenSequence(SequenceI seq);
-
- public void showHiddenSequence(SequenceI seq);
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import java.util.*;
+
+import java.awt.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public interface SequenceI
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ */
+ public void setName(String name);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getName();
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param start DOCUMENT ME!
+ */
+ public void setStart(int start);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getStart();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDisplayId(boolean jvsuffix);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param end DOCUMENT ME!
+ */
+ public void setEnd(int end);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getEnd();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getLength();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param sequence DOCUMENT ME!
+ */
+ public void setSequence(String sequence);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getSequence();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getSequence(int start, int end);
+ /**
+ * create a new sequence object from start to end of this sequence
+ * @param start int
+ * @param end int
+ * @return SequenceI
+ */
+ public SequenceI getSubSequence(int start, int end);
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public char getCharAt(int i);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param desc DOCUMENT ME!
+ */
+ public void setDescription(String desc);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDescription();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param pos DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int findIndex(int pos);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int findPosition(int i);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int[] gapMap();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ */
+ public void deleteChars(int i, int j);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ public void deleteCharAt(int i);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param c DOCUMENT ME!
+ */
+ public void insertCharAt(int i, char c);
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ */
+ public void setColor(Color c);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Color getColor();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceFeature[] getSequenceFeatures();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param v DOCUMENT ME!
+ */
+ public void setSequenceFeatures(SequenceFeature [] features);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param id DOCUMENT ME!
+ */
+ public void setPDBId(Vector ids);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Vector getPDBId();
+
+ public void addPDBId(PDBEntry entry);
+
+ public String getVamsasId();
+
+ public void setVamsasId(String id);
+
+ public void setDBRef(DBRefEntry[] dbs);
+
+ public DBRefEntry [] getDBRef();
+
+ public void addDBRef(DBRefEntry entry);
+
+ public void addSequenceFeature(SequenceFeature sf);
+
+ public void setDatasetSequence(SequenceI seq);
+
+ public SequenceI getDatasetSequence();
+
+ public AlignmentAnnotation [] getAnnotation();
+
+ public void addAlignmentAnnotation(AlignmentAnnotation annotation);
+
+ public SequenceGroup getHiddenSequences();
+
+ public void addHiddenSequence(SequenceI seq);
+
+ public void showHiddenSequence(SequenceI seq);
+
+ public void changeCase(boolean toUpper, int start, int end);
+
+ public void toggleCase(int start, int end);
+
+ /**
+ * getSubSequence from start to end of sequence
+ * @param start first residue in subSequence
+ * @return SequenceI
+ */
+ public SequenceI getSubSequence(int start);
+ /**
+ * remove all gaps in the sequence
+ * @return number of gaps removed
+ */
+ public int removeGaps();
+ /**
+ * remove all gaps from start to end columns in sequence
+ * @param start
+ * @param end
+ * @return number of gaps removed
+ */
+ public int removeGaps(int start, int end);
+
+}
diff --git a/src/jalview/datamodel/SequenceNode.java b/src/jalview/datamodel/SequenceNode.java
index ac2e9e2..c29a6e0 100755
--- a/src/jalview/datamodel/SequenceNode.java
+++ b/src/jalview/datamodel/SequenceNode.java
@@ -1,149 +1,149 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import java.awt.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class SequenceNode extends BinaryNode
-{
- /** DOCUMENT ME!! */
- public float dist;
-
- /** DOCUMENT ME!! */
- public int count;
-
- /** DOCUMENT ME!! */
- public float height;
-
- /** DOCUMENT ME!! */
- public float ycount;
-
- /** DOCUMENT ME!! */
- public Color color = Color.black;
-
- /** DOCUMENT ME!! */
- public boolean dummy = false;
- private boolean placeholder = false;
-
- /**
- * Creates a new SequenceNode object.
- */
- public SequenceNode()
- {
- super();
- }
-
- /**
- * Creates a new SequenceNode object.
- *
- * @param val DOCUMENT ME!
- * @param parent DOCUMENT ME!
- * @param dist DOCUMENT ME!
- * @param name DOCUMENT ME!
- */
- public SequenceNode(Object val, SequenceNode parent, float dist, String name)
- {
- super(val, parent, name);
- this.dist = dist;
- }
-
- /**
- * Creates a new SequenceNode object.
- *
- * @param val DOCUMENT ME!
- * @param parent DOCUMENT ME!
- * @param name DOCUMENT ME!
- * @param dist DOCUMENT ME!
- * @param bootstrap DOCUMENT ME!
- * @param dummy DOCUMENT ME!
- */
- public SequenceNode(Object val, SequenceNode parent, String name,
- float dist, int bootstrap, boolean dummy)
- {
- super(val, parent, name);
- this.dist = dist;
- this.bootstrap = bootstrap;
- this.dummy = dummy;
- }
-
- /**
- * @param dummy true if node is created for the representation of polytomous trees
- */
- public boolean isDummy()
- {
- return dummy;
- }
-
- /* @param placeholder is true if the sequence refered to in the
- * element node is not actually present in the associated alignment
- */
- public boolean isPlaceholder()
- {
- return placeholder;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param newstate DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean setDummy(boolean newstate)
- {
- boolean oldstate = dummy;
- dummy = newstate;
-
- return oldstate;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param Placeholder DOCUMENT ME!
- */
- public void setPlaceholder(boolean Placeholder)
- {
- this.placeholder = Placeholder;
- }
-
- /**
- * ascends the tree but doesn't stop until a non-dummy node is discovered.
- * This will probably break if the tree is a mixture of BinaryNodes and SequenceNodes.
- */
- public SequenceNode AscendTree()
- {
- SequenceNode c = this;
-
- do
- {
- c = (SequenceNode) c.parent();
- }
- while ((c != null) && c.dummy);
-
- return c;
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import java.awt.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SequenceNode extends BinaryNode
+{
+ /** DOCUMENT ME!! */
+ public float dist;
+
+ /** DOCUMENT ME!! */
+ public int count;
+
+ /** DOCUMENT ME!! */
+ public float height;
+
+ /** DOCUMENT ME!! */
+ public float ycount;
+
+ /** DOCUMENT ME!! */
+ public Color color = Color.black;
+
+ /** DOCUMENT ME!! */
+ public boolean dummy = false;
+ private boolean placeholder = false;
+
+ /**
+ * Creates a new SequenceNode object.
+ */
+ public SequenceNode()
+ {
+ super();
+ }
+
+ /**
+ * Creates a new SequenceNode object.
+ *
+ * @param val DOCUMENT ME!
+ * @param parent DOCUMENT ME!
+ * @param dist DOCUMENT ME!
+ * @param name DOCUMENT ME!
+ */
+ public SequenceNode(Object val, SequenceNode parent, float dist, String name)
+ {
+ super(val, parent, name);
+ this.dist = dist;
+ }
+
+ /**
+ * Creates a new SequenceNode object.
+ *
+ * @param val DOCUMENT ME!
+ * @param parent DOCUMENT ME!
+ * @param name DOCUMENT ME!
+ * @param dist DOCUMENT ME!
+ * @param bootstrap DOCUMENT ME!
+ * @param dummy DOCUMENT ME!
+ */
+ public SequenceNode(Object val, SequenceNode parent, String name,
+ float dist, int bootstrap, boolean dummy)
+ {
+ super(val, parent, name);
+ this.dist = dist;
+ this.bootstrap = bootstrap;
+ this.dummy = dummy;
+ }
+
+ /**
+ * @param dummy true if node is created for the representation of polytomous trees
+ */
+ public boolean isDummy()
+ {
+ return dummy;
+ }
+
+ /* @param placeholder is true if the sequence refered to in the
+ * element node is not actually present in the associated alignment
+ */
+ public boolean isPlaceholder()
+ {
+ return placeholder;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param newstate DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean setDummy(boolean newstate)
+ {
+ boolean oldstate = dummy;
+ dummy = newstate;
+
+ return oldstate;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param Placeholder DOCUMENT ME!
+ */
+ public void setPlaceholder(boolean Placeholder)
+ {
+ this.placeholder = Placeholder;
+ }
+
+ /**
+ * ascends the tree but doesn't stop until a non-dummy node is discovered.
+ * This will probably break if the tree is a mixture of BinaryNodes and SequenceNodes.
+ */
+ public SequenceNode AscendTree()
+ {
+ SequenceNode c = this;
+
+ do
+ {
+ c = (SequenceNode) c.parent();
+ }
+ while ((c != null) && c.dummy);
+
+ return c;
+ }
+}
diff --git a/src/jalview/datamodel/SequencePoint.java b/src/jalview/datamodel/SequencePoint.java
index 2c5d2a3..546dc1a 100755
--- a/src/jalview/datamodel/SequencePoint.java
+++ b/src/jalview/datamodel/SequencePoint.java
@@ -1,43 +1,43 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class SequencePoint
-{
- // SMJS PUBLIC
-
- /** DOCUMENT ME!! */
- public SequenceI sequence;
-
- /** DOCUMENT ME!! */
- public float[] coord;
-
- // SMJS ENDPUBLIC
- public SequencePoint(SequenceI sequence, float[] coord)
- {
- this.sequence = sequence;
- this.coord = coord;
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SequencePoint
+{
+ // SMJS PUBLIC
+
+ /** DOCUMENT ME!! */
+ public SequenceI sequence;
+
+ /** DOCUMENT ME!! */
+ public float[] coord;
+
+ // SMJS ENDPUBLIC
+ public SequencePoint(SequenceI sequence, float[] coord)
+ {
+ this.sequence = sequence;
+ this.coord = coord;
+ }
+}
diff --git a/src/jalview/datamodel/UniprotEntry.java b/src/jalview/datamodel/UniprotEntry.java
index d2f4dcf..851cb7c 100755
--- a/src/jalview/datamodel/UniprotEntry.java
+++ b/src/jalview/datamodel/UniprotEntry.java
@@ -1,92 +1,93 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import java.util.*;
-
-public class UniprotEntry
-{
-
- UniprotSequence sequence;
- Vector name;
- Vector accession;
- Vector feature;
- Vector dbrefs;
- Vector proteinName;
-
- public void setAccession(Vector items)
- {
- accession = items;
- }
-
- public void setFeature(Vector items)
- {
- feature = items;
- }
-
- public Vector getFeature() {
- return feature;
- }
-
-
- public Vector getAccession()
- {
- return accession;
- }
-
- public void setProteinName(Vector items)
- {
- proteinName = items;
- }
-
- public Vector getProteinName()
- {
- return proteinName;
- }
-
- public void setName(Vector na)
- {
- name = na;
- }
- public Vector getName()
- {
- return name;
- }
-
- public UniprotSequence getUniprotSequence()
- {
- return sequence;
- }
-
- public void setUniprotSequence(UniprotSequence seq)
- {
- sequence = seq;
- }
-
- public Vector getDbReference()
- {
- return dbrefs;
- }
-
- public void setDbReference(Vector dbref)
- {
- this.dbrefs = dbref;
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import java.util.*;
+
+public class UniprotEntry
+{
+
+ UniprotSequence sequence;
+ Vector name;
+ Vector accession;
+ Vector feature;
+ Vector dbrefs;
+ UniprotProteinName protName;
+
+ public void setAccession(Vector items)
+ {
+ accession = items;
+ }
+
+ public void setFeature(Vector items)
+ {
+ feature = items;
+ }
+
+ public Vector getFeature() {
+ return feature;
+ }
+
+
+ public Vector getAccession()
+ {
+ return accession;
+ }
+
+ public void setProtein(UniprotProteinName names)
+ {
+ protName = names;
+ }
+
+
+ public UniprotProteinName getProtein()
+ {
+ return protName;
+ }
+
+ public void setName(Vector na)
+ {
+ name = na;
+ }
+ public Vector getName()
+ {
+ return name;
+ }
+
+ public UniprotSequence getUniprotSequence()
+ {
+ return sequence;
+ }
+
+ public void setUniprotSequence(UniprotSequence seq)
+ {
+ sequence = seq;
+ }
+
+ public Vector getDbReference()
+ {
+ return dbrefs;
+ }
+
+ public void setDbReference(Vector dbref)
+ {
+ this.dbrefs = dbref;
+ }
+
+}
diff --git a/src/jalview/datamodel/UniprotFile.java b/src/jalview/datamodel/UniprotFile.java
index fd15da4..22678ce 100755
--- a/src/jalview/datamodel/UniprotFile.java
+++ b/src/jalview/datamodel/UniprotFile.java
@@ -1,33 +1,33 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-import java.util.Vector;
-
-public class UniprotFile
-{
- Vector _items;
-
- public void setUniprotEntries(Vector items) {
- _items = items;
- }
-
- public Vector getUniprotEntries() {
- return _items;
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+import java.util.Vector;
+
+public class UniprotFile
+{
+ Vector _items;
+
+ public void setUniprotEntries(Vector items) {
+ _items = items;
+ }
+
+ public Vector getUniprotEntries() {
+ return _items;
+ }
+}
diff --git a/src/jalview/datamodel/UniprotSequence.java b/src/jalview/datamodel/UniprotSequence.java
index 96fe38e..8658855 100755
--- a/src/jalview/datamodel/UniprotSequence.java
+++ b/src/jalview/datamodel/UniprotSequence.java
@@ -1,42 +1,42 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-public class UniprotSequence
-{
- /**
- * internal content storage
- */
- private java.lang.String _content = "";
-
- public void setContent(String seq)
- {
- StringBuffer sb = new StringBuffer();
- for(int i=0; i -1)
- {
- shortName = shortName.substring(shortName.lastIndexOf(
- java.io.File.separatorChar) + 1);
- }
-
- Jalview2XML.SaveAlignment(this, file, shortName);
-
- // USE Jalview2XML to save this file
- return true;
- }
- else
- {
- String output = new FormatAdapter().formatSequences(format,
- viewport.getAlignment().
- getSequences());
- if (output == null)
- {
- return false;
- }
-
- try
- {
- java.io.PrintWriter out = new java.io.PrintWriter(
- new java.io.FileWriter(file));
-
- out.print(output);
- out.close();
- return true;
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- return false;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void outputText_actionPerformed(ActionEvent e)
- {
- CutAndPasteTransfer cap = new CutAndPasteTransfer();
- Desktop.addInternalFrame(cap,
- "Alignment output - " + e.getActionCommand(), 600,
- 500);
- cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
- viewport.getAlignment().
- getSequences()));
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void htmlMenuItem_actionPerformed(ActionEvent e)
- {
- new HTMLOutput(viewport,
- alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
- alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
- }
-
- public void createImageMap(File file, String image)
- {
- alignPanel.makePNGImageMap(file, image);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void createPNG(File f)
- {
- alignPanel.makePNG(f);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void createEPS(File f)
- {
- alignPanel.makeEPS(f);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void printMenuItem_actionPerformed(ActionEvent e)
- {
- //Putting in a thread avoids Swing painting problems
- PrintThread thread = new PrintThread();
- thread.start();
- }
-
- 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!
- *
- * @param e DOCUMENT ME!
- */
- public void closeMenuItem_actionPerformed(ActionEvent e)
- {
- try
- {
- PaintRefresher.components.remove(viewport.alignment);
- this.setClosed(true);
- }
- catch (Exception ex)
- {
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- void updateEditMenuBar()
- {
- if (historyList.size() > 0)
- {
- undoMenuItem.setEnabled(true);
-
- HistoryItem hi = (HistoryItem) historyList.peek();
- undoMenuItem.setText("Undo " + hi.getDescription());
- }
- else
- {
- undoMenuItem.setEnabled(false);
- undoMenuItem.setText("Undo");
- }
-
- if (redoList.size() > 0)
- {
- redoMenuItem.setEnabled(true);
-
- HistoryItem hi = (HistoryItem) redoList.peek();
- redoMenuItem.setText("Redo " + hi.getDescription());
- }
- else
- {
- redoMenuItem.setEnabled(false);
- redoMenuItem.setText("Redo");
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param hi DOCUMENT ME!
- */
- public void addHistoryItem(HistoryItem hi)
- {
- historyList.push(hi);
- updateEditMenuBar();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void undoMenuItem_actionPerformed(ActionEvent e)
- {
- HistoryItem hi = (HistoryItem) historyList.pop();
- redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment,
- HistoryItem.HIDE));
- restoreHistoryItem(hi);
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void redoMenuItem_actionPerformed(ActionEvent e)
- {
- HistoryItem hi = (HistoryItem) redoList.pop();
- restoreHistoryItem(hi);
- updateEditMenuBar();
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- // used by undo and redo
- void restoreHistoryItem(HistoryItem hi)
- {
-
- hi.restore();
-
- updateEditMenuBar();
-
- viewport.firePropertyChange("alignment", null,
- viewport.getAlignment().getSequences());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param up DOCUMENT ME!
- */
- public void moveSelectedSequences(boolean up)
- {
- SequenceGroup sg = viewport.getSelectionGroup();
-
- if (sg == null)
- {
- return;
- }
-
- if (up)
- {
- for (int i = 1; i < viewport.alignment.getHeight(); i++)
- {
- SequenceI seq = viewport.alignment.getSequenceAt(i);
-
- if (!sg.sequences.contains(seq))
- {
- continue;
- }
-
- SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
-
- if (sg.sequences.contains(temp))
- {
- continue;
- }
-
- viewport.alignment.getSequences().setElementAt(temp, i);
- viewport.alignment.getSequences().setElementAt(seq, i - 1);
- }
- }
- else
- {
- for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
- {
- SequenceI seq = viewport.alignment.getSequenceAt(i);
-
- if (!sg.sequences.contains(seq))
- {
- continue;
- }
-
- SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
-
- if (sg.sequences.contains(temp))
- {
- continue;
- }
-
- viewport.alignment.getSequences().setElementAt(temp, i);
- viewport.alignment.getSequences().setElementAt(seq, i + 1);
- }
- }
-
- alignPanel.repaint();
- }
-
- public void lostOwnership(Clipboard clipboard, Transferable contents)
- {
- Desktop.jalviewClipboard = null;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void copy_actionPerformed(ActionEvent e)
- {
- if (viewport.getSelectionGroup() == null)
- {
- return;
- }
-
- SequenceGroup sg = viewport.getSelectionGroup();
-
- Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
-
- Hashtable orderedSeqs = new Hashtable();
- SequenceI[] seqs = new SequenceI[sg.getSize()];
-
- for (int i = 0; i < sg.getSize(); i++)
- {
- SequenceI seq = sg.getSequenceAt(i);
- int index = viewport.alignment.findIndex(seq);
- orderedSeqs.put(index + "", seq);
- }
-
- int index = 0, startRes, endRes;
- char ch;
-
- for (int i = 0; i < sg.getSize(); i++)
- {
- SequenceI seq = null;
-
- while (seq == null)
- {
- if (orderedSeqs.containsKey(index + ""))
- {
- seq = (SequenceI) orderedSeqs.get(index + "");
- index++;
-
- break;
- }
- else
- {
- index++;
- }
- }
-
- //FIND START RES
- //Returns residue following index if gap
- startRes = seq.findPosition(sg.getStartRes());
-
- //FIND END RES
- //Need to find the residue preceeding index if gap
- endRes = 0;
-
- for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
- {
- ch = seq.getCharAt(j);
- if (!jalview.util.Comparison.isGap( (ch)))
- {
- endRes++;
- }
- }
-
- if (endRes > 0)
- {
- endRes += seq.getStart() - 1;
- }
-
- seqs[i] = new Sequence(seq.getName(),
- seq.getSequence(sg.getStartRes(), sg.getEndRes() + 1),
- startRes,
- endRes);
- seqs[i].setDescription(seq.getDescription());
- seqs[i].setDBRef(seq.getDBRef());
- seqs[i].setSequenceFeatures(seq.getSequenceFeatures());
- seqs[i].setDatasetSequence(seq.getDatasetSequence());
-
- }
-
- FastaFile ff = new FastaFile();
- ff.addJVSuffix( viewport.showJVSuffix );
- c.setContents(new StringSelection( ff.print(seqs)), this);
- Desktop.jalviewClipboard = new Object[]{seqs, viewport.alignment.getDataset()};
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void pasteNew_actionPerformed(ActionEvent e)
- {
- paste(true);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void pasteThis_actionPerformed(ActionEvent e)
- {
- addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
- HistoryItem.PASTE));
- paste(false);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param newAlignment DOCUMENT ME!
- */
- void paste(boolean newAlignment)
- {
- try
- {
- Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
- Transferable contents = c.getContents(this);
-
- if (contents == null)
- {
- return;
- }
-
- String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
- if(str.length()<1)
- return;
-
- String format = new IdentifyFile().Identify(str, "Paste");
- SequenceI[] sequences;
-
- 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];
- }
- else
- {
- sequences = new FormatAdapter().readFile(str, "Paste", format);
- }
-
- if (newAlignment)
- {
-
- Alignment alignment = new Alignment(sequences);
-
- if(Desktop.jalviewClipboard!=null)
- alignment.setDataset( (Alignment)Desktop.jalviewClipboard[1] );
- else
- alignment.setDataset( null );
-
-
- AlignFrame af = new AlignFrame(alignment);
- String newtitle = new String("Copied sequences");
-
- //>>>This is a fix for the moment, until a better solution is found!!<<<
- FeatureRenderer fr = af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
- fr.featureColours = alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
-
- if (title.startsWith("Copied sequences"))
- {
- newtitle = title;
- }
- else
- {
- newtitle = newtitle.concat("- from " + title);
- }
-
- Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH,
- NEW_WINDOW_HEIGHT);
- }
- else
- {
- //!newAlignment
- for (int i = 0; i < sequences.length; i++)
- {
- Sequence newseq = new Sequence(sequences[i].getName(),
- sequences[i].getSequence(), sequences[i].getStart(),
- sequences[i].getEnd());
- viewport.alignment.addSequence(newseq);
- if(sequences[i].getDatasetSequence()==null)
- {
- ////////////////////////////
- //Datset needs extension;
- /////////////////////////////
- Sequence ds = new Sequence(sequences[i].getName(),
- AlignSeq.extractGaps("-. ", sequences[i].getSequence()),
- sequences[i].getStart(),
- sequences[i].getEnd());
- newseq.setDatasetSequence(ds);
- viewport.alignment.getDataset().addSequence(ds);
- }
- else
- {
- newseq.setDatasetSequence(sequences[i].getDatasetSequence());
- if(sequences[i].getDatasetSequence().getAnnotation()!=null)
- {
- for(int aa=0; aa 0)
- {
- addHistoryItem(new HistoryItem("Remove Left", viewport.alignment,
- HistoryItem.HIDE));
-
- int min = colSel.getMin();
- viewport.getAlignment().trimLeft(min);
- colSel.compensateForEdit(0, min);
-
- if (viewport.getSelectionGroup() != null)
- {
- viewport.getSelectionGroup().adjustForRemoveLeft(min);
- }
-
- Vector groups = viewport.alignment.getGroups();
-
- for (int i = 0; i < groups.size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.get(i);
-
- if (!sg.adjustForRemoveLeft(min))
- {
- viewport.alignment.deleteGroup(sg);
- }
- }
-
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void remove2RightMenuItem_actionPerformed(ActionEvent e)
- {
- ColumnSelection colSel = viewport.getColumnSelection();
-
- if (colSel.size() > 0)
- {
- addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
- HistoryItem.HIDE));
-
- int max = colSel.getMax();
- viewport.getAlignment().trimRight(max);
-
- if (viewport.getSelectionGroup() != null)
- {
- viewport.getSelectionGroup().adjustForRemoveRight(max);
- }
-
- Vector groups = viewport.alignment.getGroups();
-
- for (int i = 0; i < groups.size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.get(i);
-
- if (!sg.adjustForRemoveRight(max))
- {
- viewport.alignment.deleteGroup(sg);
- }
- }
-
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
- {
- addHistoryItem(new HistoryItem("Remove Gapped Columns",
- viewport.alignment, HistoryItem.HIDE));
-
- //This is to maintain viewport position on first residue
- //of first sequence
- SequenceI seq = viewport.alignment.getSequenceAt(0);
- int startRes = seq.findPosition(viewport.startRes);
-
- viewport.getAlignment().removeGaps();
-
- viewport.setStartRes(seq.findIndex(startRes)-1);
-
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
- {
- addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
- HistoryItem.HIDE));
-
- //This is to maintain viewport position on first residue
- //of first sequence
- SequenceI seq = viewport.alignment.getSequenceAt(0);
- int startRes = seq.findPosition(viewport.startRes);
-
-
- SequenceI current;
- int jSize;
-
- Vector seqs = null;
-
- int start = 0;
- int end = viewport.alignment.getWidth();
-
- if (viewport.getSelectionGroup() != null
- && viewport.getSelectionGroup().sequences != null
- && viewport.getSelectionGroup().sequences.size() > 0)
- {
- seqs = viewport.getSelectionGroup().sequences;
- start = viewport.getSelectionGroup().getStartRes();
- end = viewport.getSelectionGroup().getEndRes()+1;
- }
- else
- {
- seqs = viewport.alignment.getSequences();
- }
-
- for (int i = 0; i < seqs.size(); i++)
- {
- current = (SequenceI) seqs.elementAt(i);
- jSize = current.getLength();
-
- // Removing a range is much quicker than removing gaps
- // one by one for long sequences
- int j = start;
- int rangeStart=-1, rangeEnd=-1;
-
- do
- {
- if (jalview.util.Comparison.isGap(current.getCharAt(j)))
- {
- if(rangeStart==-1)
- {
- rangeStart = j;
- rangeEnd = j+1;
- }
- else
- {
- rangeEnd++;
- }
- j++;
- }
- else
- {
- if(rangeStart>-1)
- {
- current.deleteChars(rangeStart, rangeEnd);
- j-=rangeEnd-rangeStart;
- jSize-=rangeEnd-rangeStart;
- rangeStart = -1;
- rangeEnd = -1;
- }
- else
- j++;
- }
- }
- while (j < end && j < jSize);
- if(rangeStart>-1)
- {
- current.deleteChars(rangeStart, rangeEnd);
- }
- }
-
- viewport.setStartRes(seq.findIndex(startRes)-1);
-
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
- }
-
- public void alignmentChanged()
- {
- if(viewport.vconsensus!=null)
- {
- viewport.updateConsensus();
- viewport.updateConservation();
- }
- resetAllColourSchemes();
- if(alignPanel.overviewPanel!=null)
- alignPanel.overviewPanel.updateOverviewImage();
-
- viewport.alignment.adjustSequenceAnnotations();
-
- alignPanel.repaint();
- }
-
- void resetAllColourSchemes()
- {
- ColourSchemeI cs = viewport.globalColourScheme;
- if(cs!=null)
- {
- if (cs instanceof ClustalxColourScheme)
- {
- ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
- resetClustalX(viewport.alignment.getSequences(),
- viewport.alignment.getWidth());
- }
-
- cs.setConsensus(viewport.vconsensus);
- if (cs.conservationApplied())
- {
- Alignment al = (Alignment) viewport.alignment;
- Conservation c = new Conservation("All",
- ResidueProperties.propHash, 3,
- al.getSequences(), 0,
- al.getWidth() - 1);
- c.calculate();
- c.verdict(false, viewport.ConsPercGaps);
-
- cs.setConservation(c);
- }
- }
-
- int s, sSize = viewport.alignment.getGroups().size();
- for(s=0; s 0)) ||
- (viewport.getAlignment().getHeight() < 4))
- {
- JOptionPane.showInternalMessageDialog(this,
- "Principal component analysis must take\n" +
- "at least 4 input sequences.",
- "Sequence selection insufficient",
- JOptionPane.WARNING_MESSAGE);
-
- return;
- }
-
- new PCAPanel(viewport);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
- {
- NewTreePanel("AV", "PID", "Average distance tree using PID");
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
- {
- NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
- {
- NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
- {
- NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param type DOCUMENT ME!
- * @param pwType DOCUMENT ME!
- * @param title DOCUMENT ME!
- */
- void NewTreePanel(String type, String pwType, String title)
- {
- final TreePanel tp;
-
- if ( (viewport.getSelectionGroup() != null) &&
- (viewport.getSelectionGroup().getSize() > 3))
- {
- int s = 0;
- SequenceGroup sg = viewport.getSelectionGroup();
-
- /* Decide if the selection is a column region */
- while (s < sg.sequences.size())
- {
- if ( ( (SequenceI) sg.sequences.elementAt(s++)).getLength() <
- sg.getEndRes())
- {
- JOptionPane.showMessageDialog(Desktop.desktop,
- "The selected region to create a tree may\nonly contain residues or gaps.\n" +
- "Try using the Pad function in the edit menu,\n" +
- "or one of the multiple sequence alignment web services.",
- "Sequences in selection are not aligned",
- JOptionPane.WARNING_MESSAGE);
-
- return;
- }
- }
-
- title = title + " on region";
- tp = new TreePanel(viewport,
- viewport.getSelectionGroup().sequences, type, pwType,
- sg.getStartRes(), sg.getEndRes());
- }
- else
- {
- //are the sequences aligned?
- if (!viewport.alignment.isAligned())
- {
- JOptionPane.showMessageDialog(Desktop.desktop,
- "The sequences must be aligned before creating a tree.\n" +
- "Try using the Pad function in the edit menu,\n" +
- "or one of the multiple sequence alignment web services.",
- "Sequences not aligned",
- JOptionPane.WARNING_MESSAGE);
-
- return;
- }
-
- tp = new TreePanel(viewport,
- viewport.getAlignment().getSequences(), type, pwType,
- 0,
- viewport.alignment.getWidth());
- }
-
- addTreeMenuItem(tp, title);
- viewport.setCurrentTree(tp.getTree());
-
- Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param title DOCUMENT ME!
- * @param order DOCUMENT ME!
- */
- public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
- {
- final JMenuItem item = new JMenuItem("by " + title);
- sort.add(item);
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- addHistoryItem(new HistoryItem("Sort", viewport.alignment,
- HistoryItem.SORT));
-
- // TODO: JBPNote - have to map order entries to curent SequenceI pointers
- AlignmentSorter.sortBy(viewport.getAlignment(), order);
- alignPanel.repaint();
- }
- });
- }
-
- /**
- * Maintain the Order by->Displayed Tree menu.
- * Creates a new menu item for a TreePanel with an appropriate
- * jalview.analysis.AlignmentSorter
call. Listeners are added
- * to remove the menu item when the treePanel is closed, and adjust
- * the tree leaf to sequence mapping when the alignment is modified.
- * @param treePanel Displayed tree window.
- * @param title SortBy menu item title.
- */
- void addTreeMenuItem(final TreePanel treePanel, String title)
- {
- final JMenuItem item = new JMenuItem(title);
-
- treeCount++;
-
- if (treeCount == 1)
- {
- sort.add(sortByTreeMenu);
- }
-
- sortByTreeMenu.add(item);
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- addHistoryItem(new HistoryItem("Tree Sort",
- viewport.alignment, HistoryItem.SORT));
- AlignmentSorter.sortByTree(viewport.getAlignment(),
- treePanel.getTree());
- alignPanel.repaint();
- }
- });
-
- treePanel.addInternalFrameListener(new javax.swing.event.
- InternalFrameAdapter()
- {
- public void internalFrameClosed(
- javax.swing.event.InternalFrameEvent evt)
- {
- treeCount--;
- sortByTreeMenu.remove(item);
-
- if (treeCount == 0)
- {
- sort.remove(sortByTreeMenu);
- }
- }
- ;
- });
- }
-
- /**
- * Work out whether the whole set of sequences
- * or just the selected set will be submitted for multiple alignment.
- *
- */
- private SequenceI[] gatherSequencesForAlignment()
- {
- // Now, check we have enough sequences
- SequenceI[] msa = null;
-
- if ( (viewport.getSelectionGroup() != null) &&
- (viewport.getSelectionGroup().getSize() > 1))
- {
- // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
- SequenceGroup seqs = viewport.getSelectionGroup();
- int sz;
- msa = new SequenceI[sz = seqs.getSize()];
-
- for (int i = 0; i < sz; i++)
- {
- msa[i] = (SequenceI) seqs.getSequenceAt(i);
- }
- }
- else
- {
- Vector seqs = viewport.getAlignment().getSequences();
-
- if (seqs.size() > 1)
- {
- msa = new SequenceI[seqs.size()];
-
- for (int i = 0; i < seqs.size(); i++)
- {
- msa[i] = (SequenceI) seqs.elementAt(i);
- }
- }
- }
- return msa;
- }
-
- /**
- * Decides what is submitted to a secondary structure prediction service,
- * the currently selected sequence, or the currently selected alignment
- * (where the first sequence in the set is the one that the prediction
- * will be for).
- */
- SequenceI[] gatherSeqOrMsaForSecStrPrediction()
- {
- SequenceI seq = null;
- SequenceI[] msa = null;
-
- if ( (viewport.getSelectionGroup() != null) &&
- (viewport.getSelectionGroup().getSize() > 0))
- {
- // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
- SequenceGroup seqs = viewport.getSelectionGroup();
-
- if ( (seqs.getSize() == 1) || !viewport.alignment.isAligned())
- {
- seq = (SequenceI) seqs.getSequenceAt(0);
- }
- else
- {
- int sz;
- msa = new SequenceI[sz = seqs.getSize()];
-
- for (int i = 0; i < sz; i++)
- {
- msa[i] = (SequenceI) seqs.getSequenceAt(i);
- }
- }
- }
- else
- {
- Vector seqs = viewport.getAlignment().getSequences();
-
- if ( (seqs.size() == 1) || !viewport.alignment.isAligned())
- {
- seq = (SequenceI) seqs.elementAt(0);
- }
- else
- {
- msa = new SequenceI[seqs.size()];
-
- for (int i = 0; i < seqs.size(); i++)
- {
- msa[i] = (SequenceI) seqs.elementAt(i);
- }
- }
- }
- if (msa != null)
- {
- return msa;
- }
- else
- {
- if (seq != null)
- {
- return new SequenceI[]
- {
- seq};
- }
- }
- return null;
- }
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
- {
- // Pick the tree file
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
- getProperty(
- "LAST_DIRECTORY"));
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle("Select a newick-like tree file");
- chooser.setToolTipText("Load a tree file");
-
- int value = chooser.showOpenDialog(null);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- String choice = chooser.getSelectedFile().getPath();
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-
- try
- {
- jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
- "File");
- viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
- }
- catch (Exception ex)
- {
- JOptionPane.showMessageDialog(Desktop.desktop,
- "Problem reading tree file",
- ex.getMessage(),
- JOptionPane.WARNING_MESSAGE);
- ex.printStackTrace();
- }
- }
- }
-
-
- public TreePanel ShowNewickTree(NewickFile nf, String title)
- {
- return ShowNewickTree(nf,title,600,500,4,5);
- }
- /**
- * DOCUMENT ME!
- *
- * @param nf DOCUMENT ME!
- * @param title DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y)
- {
- TreePanel tp = null;
-
- try
- {
- nf.parse();
-
- if (nf.getTree() != null)
- {
- tp = new TreePanel(viewport,
- viewport.getAlignment().getSequences(), nf,
- "FromFile",
- title);
-
- 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)
- {
- ex.printStackTrace();
- }
-
- 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
- *
- */
- public void BuildWebServiceMenu()
- {
- if ( (Discoverer.services != null)
- && (Discoverer.services.size() > 0))
- {
- Vector msaws = (Vector) Discoverer.services.get("MsaWS");
- Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
- Vector wsmenu = new Vector();
- if (msaws != null)
- {
- // Add any Multiple Sequence Alignment Services
- final JMenu msawsmenu = new JMenu("Alignment");
- for (int i = 0, j = msaws.size(); i < j; i++)
- {
- final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
- get(i);
- final JMenuItem method = new JMenuItem(sh.getName());
- method.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- SequenceI[] msa = gatherSequencesForAlignment();
- new jalview.ws.MsaWSClient(sh, title, msa,
- false, true, viewport.getAlignment().getDataset());
-
- }
-
- });
- msawsmenu.add(method);
- // Deal with services that we know accept partial alignments.
- if (sh.getName().indexOf("lustal") > -1)
- {
- // We know that ClustalWS can accept partial alignments for refinement.
- final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
- methodR.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- SequenceI[] msa = gatherSequencesForAlignment();
- new jalview.ws.MsaWSClient(sh, title, msa,
- true, true, viewport.getAlignment().getDataset());
-
- }
-
- });
- msawsmenu.add(methodR);
-
- }
- }
- wsmenu.add(msawsmenu);
- }
- if (secstrpr != null)
- {
- // Add any secondary structure prediction services
- final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
- for (int i = 0, j = secstrpr.size(); i < j; i++)
- {
- final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
- secstrpr.get(i);
- final JMenuItem method = new JMenuItem(sh.getName());
- method.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- SequenceI[] msa = gatherSeqOrMsaForSecStrPrediction();
- if (msa.length == 1)
- {
- // Single Sequence prediction
- new jalview.ws.JPredClient(sh,title, msa[0]);
- }
- else
- {
- if (msa.length > 1)
- {
- // Single Sequence prediction
- jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh,
- title, msa);
- }
- }
- }
- });
- secstrmenu.add(method);
- }
- wsmenu.add(secstrmenu);
- }
- this.webService.removeAll();
- for (int i = 0, j = wsmenu.size(); i < j; i++)
- {
- webService.add( (JMenu) wsmenu.get(i));
- }
- }
- else
- {
- this.webService.removeAll();
- this.webService.add(this.webServiceNoServices);
- }
- // TODO: add in rediscovery function
- // TODO: reduce code redundancy.
- // TODO: group services by location as well as function.
- }
-
- /* public void vamsasStore_actionPerformed(ActionEvent e)
- {
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
- getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle("Export to Vamsas file");
- chooser.setToolTipText("Export");
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
- //vs.store(chooser.getSelectedFile().getAbsolutePath() );
- vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
- }
- }*/
-
-
-
-
-
-public void showTranslation_actionPerformed(ActionEvent e)
-{
- int s, sSize = viewport.alignment.getHeight();
- SequenceI [] newSeq = new SequenceI[sSize];
-
- int res, resSize;
- StringBuffer protein;
- String seq;
- for(s=0; s 0)
+ {
+ alignPanel.seqPanel.seqCanvas.fr.featuresAdded();
+ alignPanel.repaint();
+ }
+ }
+
+ Hashtable progressBars;
+ public void setProgressBar(String message, long id)
+ {
+ if(progressBars == null)
+ progressBars = new Hashtable();
+
+ JPanel progressPanel;
+ GridLayout layout = (GridLayout) statusPanel.getLayout();
+ if(progressBars.get( new Long(id) )!=null)
+ {
+ progressPanel = (JPanel)progressBars.get( new Long(id) );
+ statusPanel.remove(progressPanel);
+ progressBars.remove( progressPanel );
+ progressPanel = null;
+ if(message!=null)
+ statusBar.setText(message);
+
+ layout.setRows(layout.getRows() - 1);
+ }
+ else
+ {
+ progressPanel = new JPanel(new BorderLayout(10, 5));
+
+ JProgressBar progressBar = new JProgressBar();
+ progressBar.setIndeterminate(true);
+
+ progressPanel.add(new JLabel(message), BorderLayout.WEST);
+ progressPanel.add(progressBar, BorderLayout.CENTER);
+
+ layout.setRows(layout.getRows() + 1);
+ statusPanel.add(progressPanel);
+
+ progressBars.put(new Long(id), progressPanel);
+ }
+
+ validate();
+ }
+
+
+ /*
+ Added so Castor Mapping file can obtain Jalview Version
+ */
+ public String getVersion()
+ {
+ return jalview.bin.Cache.getProperty("VERSION");
+ }
+
+ public FeatureRenderer getFeatureRenderer()
+ {
+ return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
+ }
+
+
+ public void fetchSequence_actionPerformed(ActionEvent e)
+ {
+ new SequenceFetcher(this);
+ }
+
+ public void addFromFile_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
+ }
+
+ public void addFromText_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
+ }
+
+ public void addFromURL_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void saveAlignmentMenu_actionPerformed(ActionEvent e)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty( "LAST_DIRECTORY"),
+ new String[]
+ { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
+ new String[]
+ { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
+ currentFileFormat,
+ false);
+
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Save Alignment to file");
+ chooser.setToolTipText("Save");
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ currentFileFormat = chooser.getSelectedFormat();
+
+ if (currentFileFormat == null)
+ {
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "You must select a file format before saving!",
+ "File format not specified",
+ JOptionPane.WARNING_MESSAGE);
+ value = chooser.showSaveDialog(this);
+ return;
+ }
+
+ jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
+ currentFileFormat);
+
+ String choice = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+
+ saveAlignment(choice, currentFileFormat);
+ }
+ }
+
+ public boolean saveAlignment(String file, String format)
+ {
+ if (format.equalsIgnoreCase("Jalview"))
+ {
+ String shortName = title;
+
+ if (shortName.indexOf(java.io.File.separatorChar) > -1)
+ {
+ shortName = shortName.substring(shortName.lastIndexOf(
+ java.io.File.separatorChar) + 1);
+ }
+
+ new Jalview2XML().SaveAlignment(this, file, shortName);
+
+ // USE Jalview2XML to save this file
+ return true;
+ }
+ else
+ {
+
+ String[] omitHidden = null;
+
+ if (viewport.hasHiddenColumns)
+ {
+ int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ "The Alignment contains hidden columns."
+ + "\nDo you want to save only the visible alignment?",
+ "Save / Omit Hidden Columns",
+ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+
+ if (reply == JOptionPane.YES_OPTION)
+ omitHidden = viewport.getViewAsString(false);
+ }
+
+ String output = new FormatAdapter().formatSequences(
+ format,
+ viewport.alignment.getSequencesArray(),
+ omitHidden);
+
+ 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);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void outputText_actionPerformed(ActionEvent e)
+ {
+ String [] omitHidden = null;
+
+ if(viewport.hasHiddenColumns)
+ {
+ int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ "The Alignment contains hidden columns."
+ +"\nDo you want to output only the visible alignment?",
+ "Save / Omit Hidden Columns",
+ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+
+ if(reply==JOptionPane.YES_OPTION)
+ {
+ omitHidden = viewport.getViewAsString(false);
+ }
+ }
+
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ Desktop.addInternalFrame(cap,
+ "Alignment output - " + e.getActionCommand(), 600,
+ 500);
+
+
+ cap.setText(new FormatAdapter().formatSequences(
+ e.getActionCommand(),
+ viewport.alignment.getSequencesArray(),
+ omitHidden));
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void htmlMenuItem_actionPerformed(ActionEvent e)
+ {
+ new HTMLOutput(viewport,
+ alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
+ alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
+ }
+
+ public void createImageMap(File file, String image)
+ {
+ alignPanel.makePNGImageMap(file, image);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void createPNG(File f)
+ {
+ alignPanel.makePNG(f);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void createEPS(File f)
+ {
+ alignPanel.makeEPS(f);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void printMenuItem_actionPerformed(ActionEvent e)
+ {
+ //Putting in a thread avoids Swing painting problems
+ PrintThread thread = new PrintThread();
+ 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!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void closeMenuItem_actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ PaintRefresher.components.remove(viewport.alignment);
+ this.setClosed(true);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ void updateEditMenuBar()
+ {
+ if (historyList.size() > 0)
+ {
+ undoMenuItem.setEnabled(true);
+
+ HistoryItem hi = (HistoryItem) historyList.peek();
+ undoMenuItem.setText("Undo " + hi.getDescription());
+ }
+ else
+ {
+ undoMenuItem.setEnabled(false);
+ undoMenuItem.setText("Undo");
+ }
+
+ if (redoList.size() > 0)
+ {
+ redoMenuItem.setEnabled(true);
+
+ HistoryItem hi = (HistoryItem) redoList.peek();
+ redoMenuItem.setText("Redo " + hi.getDescription());
+ }
+ else
+ {
+ redoMenuItem.setEnabled(false);
+ redoMenuItem.setText("Redo");
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param hi DOCUMENT ME!
+ */
+ public void addHistoryItem(HistoryItem hi)
+ {
+ historyList.push(hi);
+ redoList.clear();
+ updateEditMenuBar();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void undoMenuItem_actionPerformed(ActionEvent e)
+ {
+ HistoryItem nh,hi = (HistoryItem) historyList.pop();
+ redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
+ HistoryItem.HIDE));
+ if (hi.alColumnChanges!=null)
+ nh.alColumnChanges = hi.alColumnChanges.getInverse();
+ restoreHistoryItem(hi);
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void redoMenuItem_actionPerformed(ActionEvent e)
+ {
+ HistoryItem nh,hi = (HistoryItem) redoList.pop();
+ historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
+ HistoryItem.HIDE));
+ if (hi.alColumnChanges!=null)
+ nh.alColumnChanges=hi.alColumnChanges.getInverse();
+ restoreHistoryItem(hi);
+ updateEditMenuBar();
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ // used by undo and redo
+ void restoreHistoryItem(HistoryItem hi)
+ {
+
+ hi.restore(viewport.getColumnSelection());
+
+ updateEditMenuBar();
+
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param up DOCUMENT ME!
+ */
+ public void moveSelectedSequences(boolean up)
+ {
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ if (sg == null)
+ {
+ return;
+ }
+
+ if (up)
+ {
+ for (int i = 1; i < viewport.alignment.getHeight(); i++)
+ {
+ SequenceI seq = viewport.alignment.getSequenceAt(i);
+
+ if (!sg.getSequences(false).contains(seq))
+ {
+ continue;
+ }
+
+ SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
+
+ if (sg.getSequences(false).contains(temp))
+ {
+ continue;
+ }
+
+ viewport.alignment.getSequences().setElementAt(temp, i);
+ viewport.alignment.getSequences().setElementAt(seq, i - 1);
+ }
+ }
+ else
+ {
+ for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
+ {
+ SequenceI seq = viewport.alignment.getSequenceAt(i);
+
+ if (!sg.getSequences(false).contains(seq))
+ {
+ continue;
+ }
+
+ SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
+
+ if (sg.getSequences(false).contains(temp))
+ {
+ continue;
+ }
+
+ viewport.alignment.getSequences().setElementAt(temp, i);
+ viewport.alignment.getSequences().setElementAt(seq, i + 1);
+ }
+ }
+
+ alignPanel.repaint();
+ }
+
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void copy_actionPerformed(ActionEvent e)
+ {
+ if (viewport.getSelectionGroup() == null)
+ {
+ return;
+ }
+
+ SequenceI [] seqs = viewport.getSelectionAsNewSequence();
+ String[] omitHidden = null;
+
+ if (viewport.hasHiddenColumns)
+ {
+ omitHidden = viewport.getViewAsString(true);
+ }
+
+ String output = new FormatAdapter().formatSequences(
+ "Fasta",
+ seqs,
+ omitHidden);
+
+
+ Toolkit.getDefaultToolkit().getSystemClipboard()
+ .setContents(new StringSelection(output), Desktop.instance);
+
+ Vector hiddenColumns = null;
+ if(viewport.hasHiddenColumns)
+ {
+ hiddenColumns =new Vector();
+ int hiddenOffset = viewport.getSelectionGroup().getStartRes();
+ for(int i=0; i>>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
+ }
+
+
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void cut_actionPerformed(ActionEvent e)
+ {
+ copy_actionPerformed(null);
+ delete_actionPerformed(null);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void delete_actionPerformed(ActionEvent e)
+ {
+
+ if (viewport.getSelectionGroup() == null)
+ {
+ return;
+ }
+
+
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+
+
+ //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)
+ {
+ 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.getSize(false); 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 (sg.getSize(false) == viewport.alignment.getHeight())
+ {
+ viewport.getColumnSelection().removeElements(sg.getStartRes(),
+ sg.getEndRes() + 1);
+ }
+
+ if (seq.getSequence().length() < 1)
+ {
+ viewport.getAlignment().deleteSequence(seq);
+ }
+ else
+ {
+ viewport.getAlignment().getSequences().setElementAt(seq, index);
+ }
+ }
+
+ viewport.setSelectionGroup(null);
+ viewport.alignment.deleteGroup(sg);
+
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+
+
+
+ if (viewport.getAlignment().getHeight() < 1)
+ {
+ try
+ {
+ this.setClosed(true);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void deleteGroups_actionPerformed(ActionEvent e)
+ {
+ viewport.alignment.deleteAllGroups();
+ viewport.setSelectionGroup(null);
+ alignPanel.repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
+ {
+ SequenceGroup sg = new SequenceGroup();
+
+ for (int i = 0; i < viewport.getAlignment().getSequences().size();
+ i++)
+ {
+ sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
+ }
+
+ sg.setEndRes(viewport.alignment.getWidth() - 1);
+ viewport.setSelectionGroup(sg);
+ PaintRefresher.Refresh(null, viewport.alignment);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ 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.idPanel.idCanvas.searchResults = null;
+ alignPanel.repaint();
+ PaintRefresher.Refresh(null, viewport.alignment);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
+ {
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ if (sg == null)
+ {
+ selectAllSequenceMenuItem_actionPerformed(null);
+
+ return;
+ }
+
+ for (int i = 0; i < viewport.getAlignment().getSequences().size();
+ i++)
+ {
+ sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
+ }
+
+ PaintRefresher.Refresh(null, viewport.alignment);
+ }
+
+ public void invertColSel_actionPerformed(ActionEvent e)
+ {
+ viewport.invertColumnSelection();
+ alignPanel.repaint();
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
+ {
+ ColumnSelection colSel = viewport.getColumnSelection();
+
+ if (colSel.size() > 0)
+ {
+ HistoryItem edit;
+ addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,
+ HistoryItem.HIDE));
+
+ int min = colSel.getMin();
+ viewport.getAlignment().trimLeft(min);
+ colSel.compensateForEdit(0, min);
+ edit.addShift(0,min);
+ if (viewport.getSelectionGroup() != null)
+ {
+ viewport.getSelectionGroup().adjustForRemoveLeft(min);
+ }
+
+ Vector groups = viewport.alignment.getGroups();
+
+ for (int i = 0; i < groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.get(i);
+
+ if (!sg.adjustForRemoveLeft(min))
+ {
+ viewport.alignment.deleteGroup(sg);
+ }
+ }
+
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void remove2RightMenuItem_actionPerformed(ActionEvent e)
+ {
+ ColumnSelection colSel = viewport.getColumnSelection();
+
+ if (colSel.size() > 0)
+ {
+ addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
+ HistoryItem.HIDE));
+
+ int max = colSel.getMax();
+ viewport.getAlignment().trimRight(max);
+ // TODO: delete hidden column entries in colSel to right of max
+ // TODO: record hidden columns in history for undo.
+ if (viewport.getSelectionGroup() != null)
+ {
+ viewport.getSelectionGroup().adjustForRemoveRight(max);
+ }
+
+ Vector groups = viewport.alignment.getGroups();
+
+ for (int i = 0; i < groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.get(i);
+
+ if (!sg.adjustForRemoveRight(max))
+ {
+ viewport.alignment.deleteGroup(sg);
+ }
+ }
+
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
+ {
+ HistoryItem edit;
+ addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",
+ viewport.alignment, HistoryItem.HIDE));
+
+ //This is to maintain viewport position on first residue
+ //of first sequence
+ SequenceI seq = viewport.alignment.getSequenceAt(0);
+ int startRes = seq.findPosition(viewport.startRes);
+ ShiftList shifts;
+ viewport.getAlignment().removeGaps(shifts=new ShiftList());
+ edit.alColumnChanges=shifts.getInverse();
+ if (viewport.hasHiddenColumns)
+ viewport.getColumnSelection().compensateForEdits(shifts);
+ viewport.setStartRes(seq.findIndex(startRes)-1);
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
+ {
+ // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences
+ // TODO: columnSelection.compensateforedits should be called (and passed to history item)
+ addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
+ HistoryItem.HIDE));
+
+ //This is to maintain viewport position on first residue
+ //of first sequence
+ SequenceI seq = viewport.alignment.getSequenceAt(0);
+ int startRes = seq.findPosition(viewport.startRes);
+
+
+ SequenceI current;
+ int jSize;
+
+ Vector seqs = null;
+
+ int start = 0;
+ int end = viewport.alignment.getWidth();
+
+ if (viewport.getSelectionGroup() != null
+ && viewport.getSelectionGroup().getSequences(true) != null
+ && viewport.getSelectionGroup().getSize(true) > 0)
+ {
+ seqs = viewport.getSelectionGroup().getSequences(true);
+ start = viewport.getSelectionGroup().getStartRes();
+ end = viewport.getSelectionGroup().getEndRes()+1;
+ }
+ else
+ {
+ seqs = viewport.alignment.getSequences();
+ }
+ /* Commented out regions below are partial implementation of todo above.
+ * divide start,end into visible chunks, and for each:
+ int diff=end-start+1;
+ int diffmax=0;
+ int dr[] = new int[seqs.size()];
+ */
+ for (int i = 0; i < seqs.size(); i++)
+ {
+ current = (SequenceI) seqs.elementAt(i);
+ //dr[i]=
+ current.removeGaps(start, end);
+ /*if (d0) {
+ // record shift for history.
+ editgaps.addShift(start, diff);
+ if (viewport.hasHiddenColumns && diffmax>diff) {
+ // pad sequence
+ StringBuffer gaps=new StringBuffer(diffmax);
+ for (int i=0,j=diffmax-diff; i0) {
+ String sq = current.getSequence();
+ current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());
+ }
+ }
+ }
+ }*/
+
+ viewport.setStartRes(seq.findIndex(startRes)-1);
+
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
+ }
+
+ public void alignmentChanged()
+ {
+ if(viewport.padGaps)
+ viewport.getAlignment().padGaps();
+
+ if(viewport.vconsensus!=null && viewport.autoCalculateConsensus)
+ {
+ viewport.updateConsensus();
+ viewport.updateConservation();
+ }
+
+ resetAllColourSchemes();
+ if(alignPanel.overviewPanel!=null)
+ alignPanel.overviewPanel.updateOverviewImage();
+
+ viewport.alignment.adjustSequenceAnnotations();
+
+ if(alignPanel.overviewPanel!=null)
+ alignPanel.overviewPanel.updateOverviewImage();
+ // JBPNote: could push a vamsas document update here.
+ alignPanel.repaint();
+ }
+
+ void resetAllColourSchemes()
+ {
+ ColourSchemeI cs = viewport.globalColourScheme;
+ if(cs!=null)
+ {
+ if (cs instanceof ClustalxColourScheme)
+ {
+ ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
+ resetClustalX(viewport.alignment.getSequences(),
+ viewport.alignment.getWidth());
+ }
+
+ cs.setConsensus(viewport.vconsensus);
+ if (cs.conservationApplied())
+ {
+ Alignment al = (Alignment) viewport.alignment;
+ Conservation c = new Conservation("All",
+ ResidueProperties.propHash, 3,
+ al.getSequences(), 0,
+ al.getWidth() - 1);
+ c.calculate();
+ c.verdict(false, viewport.ConsPercGaps);
+
+ cs.setConservation(c);
+ }
+ }
+
+ int s, sSize = viewport.alignment.getGroups().size();
+ for(s=0; s 0)) ||
+ (viewport.getAlignment().getHeight() < 4))
+ {
+ JOptionPane.showInternalMessageDialog(this,
+ "Principal component analysis must take\n" +
+ "at least 4 input sequences.",
+ "Sequence selection insufficient",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+
+ new PCAPanel(viewport);
+ }
+
+
+ public void autoCalculate_actionPerformed(ActionEvent e)
+ {
+ viewport.autoCalculateConsensus = autoCalculate.isSelected();
+ if(viewport.autoCalculateConsensus)
+ {
+ alignmentChanged();
+ }
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("AV", "PID", "Average distance tree using PID");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param type DOCUMENT ME!
+ * @param pwType DOCUMENT ME!
+ * @param title DOCUMENT ME!
+ */
+ void NewTreePanel(String type, String pwType, String title)
+ {
+ TreePanel tp;
+
+ if ( (viewport.getSelectionGroup() != null) &&
+ (viewport.getSelectionGroup().getSize(false) > 3))
+ {
+ int s = 0;
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ /* Decide if the selection is a column region */
+ while (s < sg.getSize(false))
+ {
+ if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
+ sg.getEndRes())
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "The selected region to create a tree may\nonly contain residues or gaps.\n" +
+ "Try using the Pad function in the edit menu,\n" +
+ "or one of the multiple sequence alignment web services.",
+ "Sequences in selection are not aligned",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+ }
+
+ title = title + " on region";
+ tp = new TreePanel(viewport, type, pwType);
+ }
+ else
+ {
+ //are the sequences aligned?
+ if (!viewport.alignment.isAligned())
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "The sequences must be aligned before creating a tree.\n" +
+ "Try using the Pad function in the edit menu,\n" +
+ "or one of the multiple sequence alignment web services.",
+ "Sequences not aligned",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+
+ if(viewport.alignment.getHeight()<2)
+ return;
+
+ tp = new TreePanel(viewport, type, pwType);
+ }
+
+ addTreeMenuItem(tp, title);
+
+ Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param title DOCUMENT ME!
+ * @param order DOCUMENT ME!
+ */
+ public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
+ {
+ final JMenuItem item = new JMenuItem("by " + title);
+ sort.add(item);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ addHistoryItem(new HistoryItem("Sort", viewport.alignment,
+ HistoryItem.SORT));
+
+ // TODO: JBPNote - have to map order entries to curent SequenceI pointers
+ AlignmentSorter.sortBy(viewport.getAlignment(), order);
+ alignPanel.repaint();
+ }
+ });
+ }
+
+ /**
+ * Maintain the Order by->Displayed Tree menu.
+ * Creates a new menu item for a TreePanel with an appropriate
+ * jalview.analysis.AlignmentSorter
call. Listeners are added
+ * to remove the menu item when the treePanel is closed, and adjust
+ * the tree leaf to sequence mapping when the alignment is modified.
+ * @param treePanel Displayed tree window.
+ * @param title SortBy menu item title.
+ */
+ void addTreeMenuItem(final TreePanel treePanel, String title)
+ {
+ final JMenuItem item = new JMenuItem(title);
+
+ treeCount++;
+
+ if (treeCount == 1)
+ {
+ sort.add(sortByTreeMenu);
+ }
+
+ sortByTreeMenu.add(item);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ addHistoryItem(new HistoryItem("Tree Sort",
+ viewport.alignment, HistoryItem.SORT));
+ AlignmentSorter.sortByTree(viewport.getAlignment(),
+ treePanel.getTree());
+ alignPanel.repaint();
+ }
+ });
+
+ treePanel.addInternalFrameListener(new javax.swing.event.
+ InternalFrameAdapter()
+ {
+ public void internalFrameClosed(
+ javax.swing.event.InternalFrameEvent evt)
+ {
+ treeCount--;
+ sortByTreeMenu.remove(item);
+
+ if (treeCount == 0)
+ {
+ sort.remove(sortByTreeMenu);
+ }
+ }
+ ;
+ });
+ }
+
+ /**
+ * Work out whether the whole set of sequences
+ * or just the selected set will be submitted for multiple alignment.
+ *
+ */
+ private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
+ {
+ // Now, check we have enough sequences
+ AlignmentView msa = null;
+
+ if ( (viewport.getSelectionGroup() != null) &&
+ (viewport.getSelectionGroup().getSize(false) > 1))
+ {
+ // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
+ /*SequenceGroup seqs = viewport.getSelectionGroup();
+ int sz;
+ msa = new SequenceI[sz = seqs.getSize(false)];
+
+ for (int i = 0; i < sz; i++)
+ {
+ msa[i] = (SequenceI) seqs.getSequenceAt(i);
+ } */
+ msa = viewport.getAlignmentView(true);
+ }
+ else
+ {
+ /*Vector seqs = viewport.getAlignment().getSequences();
+
+ if (seqs.size() > 1)
+ {
+ msa = new SequenceI[seqs.size()];
+
+ for (int i = 0; i < seqs.size(); i++)
+ {
+ msa[i] = (SequenceI) seqs.elementAt(i);
+ }
+ }*/
+ msa = viewport.getAlignmentView(false);
+ }
+ return msa;
+ }
+
+ /**
+ * Decides what is submitted to a secondary structure prediction service,
+ * the currently selected sequence, or the currently selected alignment
+ * (where the first sequence in the set is the one that the prediction
+ * will be for).
+ */
+ AlignmentView gatherSeqOrMsaForSecStrPrediction()
+ {
+ AlignmentView seqs = null;
+
+ if ( (viewport.getSelectionGroup() != null) &&
+ (viewport.getSelectionGroup().getSize(false) > 0))
+ {
+ seqs = viewport.getAlignmentView(true);
+ }
+ else
+ {
+ seqs = viewport.getAlignmentView(false);
+ }
+ // limit sequences - JBPNote in future - could spawn multiple prediction jobs
+ // 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] } );
+ }
+ return seqs;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
+ {
+ // Pick the tree file
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty(
+ "LAST_DIRECTORY"));
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Select a newick-like tree file");
+ chooser.setToolTipText("Load a tree file");
+
+ int value = chooser.showOpenDialog(null);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ String choice = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+
+ try
+ {
+ jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
+ "File");
+ viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
+ }
+ catch (Exception ex)
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "Problem reading tree file",
+ ex.getMessage(),
+ JOptionPane.WARNING_MESSAGE);
+ ex.printStackTrace();
+ }
+ }
+ }
+
+
+ public TreePanel ShowNewickTree(NewickFile nf, String title)
+ {
+ return ShowNewickTree(nf,title,600,500,4,5);
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param nf DOCUMENT ME!
+ * @param title DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y)
+ {
+ TreePanel tp = null;
+
+ try
+ {
+ nf.parse();
+
+ if (nf.getTree() != null)
+ {
+ tp = new TreePanel(viewport,
+ "FromFile",
+ title,
+ nf);
+
+ 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)
+ {
+ ex.printStackTrace();
+ }
+
+ 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
+ *
+ */
+ public void BuildWebServiceMenu()
+ {
+ if ( (Discoverer.services != null)
+ && (Discoverer.services.size() > 0))
+ {
+ Vector msaws = (Vector) Discoverer.services.get("MsaWS");
+ Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
+ Vector wsmenu = new Vector();
+ final AlignFrame af = this;
+ if (msaws != null)
+ {
+ // Add any Multiple Sequence Alignment Services
+ final JMenu msawsmenu = new JMenu("Alignment");
+ for (int i = 0, j = msaws.size(); i < j; i++)
+ {
+ final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
+ get(i);
+ final JMenuItem method = new JMenuItem(sh.getName());
+ method.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentView msa = gatherSequencesForAlignment();
+ new jalview.ws.MsaWSClient(sh, title, msa,
+ false, true, viewport.getAlignment().getDataset(), af);
+
+ }
+
+ });
+ msawsmenu.add(method);
+ // Deal with services that we know accept partial alignments.
+ if (sh.getName().indexOf("lustal") > -1)
+ {
+ // We know that ClustalWS can accept partial alignments for refinement.
+ final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
+ methodR.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentView msa = gatherSequencesForAlignment();
+ new jalview.ws.MsaWSClient(sh, title, msa,
+ true, true, viewport.getAlignment().getDataset(), af);
+
+ }
+
+ });
+ msawsmenu.add(methodR);
+
+ }
+ }
+ wsmenu.add(msawsmenu);
+ }
+ if (secstrpr != null)
+ {
+ // Add any secondary structure prediction services
+ final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
+ for (int i = 0, j = secstrpr.size(); i < j; i++)
+ {
+ final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
+ secstrpr.get(i);
+ final JMenuItem method = new JMenuItem(sh.getName());
+ method.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
+ if (msa.getSequences().length == 1)
+ {
+ // Single Sequence prediction
+ new jalview.ws.JPredClient(sh, title, false, msa, af);
+ }
+ else
+ {
+ if (msa.getSequences().length > 1)
+ {
+ // Sequence profile based prediction
+ new jalview.ws.JPredClient(sh,
+ title, true, msa, af);
+ }
+ }
+ }
+ });
+ secstrmenu.add(method);
+ }
+ wsmenu.add(secstrmenu);
+ }
+ this.webService.removeAll();
+ for (int i = 0, j = wsmenu.size(); i < j; i++)
+ {
+ webService.add( (JMenu) wsmenu.get(i));
+ }
+ }
+ else
+ {
+ this.webService.removeAll();
+ this.webService.add(this.webServiceNoServices);
+ }
+ // TODO: add in rediscovery function
+ // TODO: reduce code redundancy.
+ // TODO: group services by location as well as function.
+ }
+
+ /* public void vamsasStore_actionPerformed(ActionEvent e)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty("LAST_DIRECTORY"));
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Export to Vamsas file");
+ chooser.setToolTipText("Export");
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
+ //vs.store(chooser.getSelectedFile().getAbsolutePath() );
+ vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
+ }
+ }*/
+
+
+
+
+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 -1 || file.indexOf("file:") > -1)
+ {
+ protocol = "URL";
+ }
+
+ boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
+ alignment, file);
+
+ if (!isAnnotation)
+ {
+ boolean isGroupsFile = parseFeaturesFile(file,protocol);
+ if (!isGroupsFile)
+ {
+ String format = new IdentifyFile().Identify(file, protocol);
+
+ if(format.equalsIgnoreCase("JnetFile"))
+ {
+ jalview.io.JPredFile predictions = new jalview.io.JPredFile(
+ file, protocol);
+ new JnetAnnotationMaker().add_annotation(predictions,
+ viewport.getAlignment(),
+ 0, false);
+ alignPanel.adjustAnnotationHeight();
+ alignPanel.repaint();
+ }
+ else
+ new FileLoader().LoadFile(viewport, file, protocol, format);
+ }
+ }
+ else
+ {
+ // (isAnnotation)
+ alignPanel.adjustAnnotationHeight();
+ }
+
+ }catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java
index a92517c..5edb65b 100755
--- a/src/jalview/gui/AlignViewport.java
+++ b/src/jalview/gui/AlignViewport.java
@@ -1,1116 +1,1411 @@
- /*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.gui;
-
-import jalview.analysis.*;
-
-import jalview.bin.*;
-
-import jalview.datamodel.*;
-
-import jalview.schemes.*;
-
-import java.awt.*;
-
-import java.util.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class AlignViewport
-{
- int startRes;
- int endRes;
- int startSeq;
- int endSeq;
- boolean showJVSuffix = true;
- boolean showText = true;
- boolean showColourText = false;
- boolean showBoxes = true;
- boolean wrapAlignment = false;
- boolean renderGaps = true;
- boolean showSequenceFeatures = false;
- boolean showAnnotation = true;
- boolean showConservation = true;
- boolean showQuality = true;
- boolean showIdentity = true;
- boolean colourAppliesToAllGroups = true;
- ColourSchemeI globalColourScheme = null;
- boolean conservationColourSelected = false;
- boolean abovePIDThreshold = false;
- SequenceGroup selectionGroup;
- int charHeight;
- int charWidth;
- int wrappedWidth;
- Font font = new Font("SansSerif", Font.PLAIN, 10);
- AlignmentI alignment;
- ColumnSelection colSel = new ColumnSelection();
- int threshold;
- int increment;
- NJTree currentTree = null;
- boolean scaleAboveWrapped = false;
- boolean scaleLeftWrapped = true;
- boolean scaleRightWrapped = true;
- boolean hasHiddenColumns = false;
- boolean hasHiddenRows = false;
-
- boolean cursorMode = false;
-
- // The following vector holds the features which are
- // currently visible, in the correct order or rendering
- Hashtable featuresDisplayed = null;
-
-
- /** DOCUMENT ME!! */
- public Vector vconsensus;
- AlignmentAnnotation consensus;
- AlignmentAnnotation conservation;
- AlignmentAnnotation quality;
-
- /** DOCUMENT ME!! */
- public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
-
- // JBPNote Prolly only need this in the applet version.
- private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
-
- boolean ignoreGapsInConsensusCalculation = false;
-
- boolean isDataset = false;
-
- boolean antiAlias = false;
-
-
- public AlignViewport(AlignmentI al, boolean dataset)
- {
- isDataset = dataset;
- setAlignment(al);
- init();
- }
- /**
- * Creates a new AlignViewport object.
- *
- * @param al DOCUMENT ME!
- */
- public AlignViewport(AlignmentI al)
- {
- setAlignment(al);
- init();
- }
-
- void init()
- {
- this.startRes = 0;
- this.endRes = alignment.getWidth() - 1;
- this.startSeq = 0;
- this.endSeq = alignment.getHeight() - 1;
-
- antiAlias = Cache.getDefault("ANTI_ALIAS", false);
-
- showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
- showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
- showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
-
- showQuality = Cache.getDefault("SHOW_QUALITY", true);
- showIdentity = Cache.getDefault("SHOW_IDENTITY", true);
-
- String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
- String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
- String fontSize = Cache.getDefault("FONT_SIZE", "10");
-
- int style = 0;
-
- if (fontStyle.equals("bold"))
- {
- style = 1;
- }
- else if (fontStyle.equals("italic"))
- {
- style = 2;
- }
-
- setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
-
-
- alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
-
-
- // We must set conservation and consensus before setting colour,
- // as Blosum and Clustal require this to be done
- if(vconsensus==null && !isDataset)
- {
- updateConservation();
- updateConsensus();
- }
-
- if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
- {
- globalColourScheme = ColourSchemeProperty.getColour(alignment,
- jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
-
- if (globalColourScheme instanceof UserColourScheme)
- {
- globalColourScheme = UserDefinedColours.loadDefaultColours();
- ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
- }
-
- if (globalColourScheme != null)
- {
- globalColourScheme.setConsensus(vconsensus);
- }
- }
- }
-
-
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setShowSequenceFeatures(boolean b)
- {
- showSequenceFeatures = b;
- }
-
- public boolean getShowSequenceFeatures()
- {
- return showSequenceFeatures;
- }
-
- /**
- * DOCUMENT ME!
- */
- public void updateConservation()
- {
- if(alignment.isNucleotide())
- return;
-
- try{
- Conservation cons = new jalview.analysis.Conservation("All",
- jalview.schemes.ResidueProperties.propHash, 3,
- alignment.getSequences(), 0, alignment.getWidth() - 1);
- cons.calculate();
- cons.verdict(false, ConsPercGaps);
- cons.findQuality();
-
- int alWidth = alignment.getWidth();
- Annotation[] annotations = new Annotation[alWidth];
- Annotation[] qannotations = new Annotation[alWidth];
- String sequence = cons.getConsSequence().getSequence();
- float minR;
- float minG;
- float minB;
- float maxR;
- float maxG;
- float maxB;
- minR = 0.3f;
- minG = 0.0f;
- minB = 0f;
- maxR = 1.0f - minR;
- maxG = 0.9f - minG;
- maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
-
- float min = 0f;
- float max = 11f;
- float qmin = cons.qualityRange[0].floatValue();
- float qmax = cons.qualityRange[1].floatValue();
-
- for (int i = 0; i < alWidth; i++)
- {
- float value = 0;
-
- try
- {
- value = Integer.parseInt(sequence.charAt(i) + "");
- }
- catch (Exception ex)
- {
- if (sequence.charAt(i) == '*')
- {
- value = 11;
- }
-
- if (sequence.charAt(i) == '+')
- {
- value = 10;
- }
- }
-
- float vprop = value - min;
- vprop /= max;
- annotations[i] = new Annotation(sequence.charAt(i) + "",
- String.valueOf(value), ' ', value,
- new Color(minR + (maxR * vprop),
- minG + (maxG * vprop),
- minB + (maxB * vprop)));
-
- // Quality calc
- value = ( (Double) cons.quality.get(i)).floatValue();
- vprop = value - qmin;
- vprop /= qmax;
- qannotations[i] = new Annotation(" ", String.valueOf(value), ' ',
- value,
- new Color(minR + (maxR * vprop),
- minG + (maxG * vprop),
- minB + (maxB * vprop)));
- }
-
- if (conservation == null)
- {
- conservation = new AlignmentAnnotation("Conservation",
- "Conservation of total alignment less than " +
- ConsPercGaps + "% gaps",
- annotations, 0f, // cons.qualityRange[0].floatValue(),
- 11f, // cons.qualityRange[1].floatValue()
- AlignmentAnnotation.BAR_GRAPH);
-
- if (showConservation)
- {
- alignment.addAnnotation(conservation);
- }
-
- quality = new AlignmentAnnotation("Quality",
- "Alignment Quality based on Blosum62 scores",
- qannotations,
- cons.qualityRange[0].floatValue(),
- cons.qualityRange[1].floatValue(),
- AlignmentAnnotation.BAR_GRAPH);
-
- if (showQuality)
- {
- alignment.addAnnotation(quality);
- }
- }
- else
- {
- conservation.annotations = annotations;
- quality.annotations = qannotations;
- quality.graphMax = cons.qualityRange[1].floatValue();
- }
- }
- catch (OutOfMemoryError error)
- {
- javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "Out of memory calculating conservation!!"
- +
- "\nSee help files for increasing Java Virtual Machine memory."
- , "Out of memory",
- javax.swing.JOptionPane.WARNING_MESSAGE);
- System.out.println("Conservation calculation: " + error);
- System.gc();
-
- }
- }
-
- /**
- * DOCUMENT ME!
- */
- public void updateConsensus()
- {
- try{
- Annotation[] annotations = new Annotation[alignment.getWidth()];
-
- // this routine prevents vconsensus becoming a new object each time
- // consenus is calculated. Important for speed of Blosum62
- // and PID colouring of alignment
- if (vconsensus == null)
- {
- vconsensus = alignment.getAAFrequency();
- }
- else
- {
- Vector temp = alignment.getAAFrequency();
- vconsensus.clear();
-
- Enumeration e = temp.elements();
-
- while (e.hasMoreElements())
- {
- vconsensus.add(e.nextElement());
- }
- }
-
- Hashtable hash = null;
-
- for (int i = 0; i < alignment.getWidth(); i++)
- {
- hash = (Hashtable) vconsensus.elementAt(i);
-
- float value = 0;
- if (ignoreGapsInConsensusCalculation)
- value = ( (Float) hash.get("pid_nogaps")).floatValue();
- else
- value = ( (Float) hash.get("pid_gaps")).floatValue();
-
- String maxRes = hash.get("maxResidue").toString();
- String mouseOver = hash.get("maxResidue") + " ";
-
- if (maxRes.length() > 1)
- {
- mouseOver = "[" + maxRes + "] ";
- maxRes = "+";
- }
-
- mouseOver += ( (int) value + "%");
- annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
- }
-
- if (consensus == null)
- {
- consensus = new AlignmentAnnotation("Consensus", "PID",
- annotations, 0f, 100f,AlignmentAnnotation.BAR_GRAPH);
-
- if (showIdentity)
- {
- alignment.addAnnotation(consensus);
- }
- }
- else
- {
- consensus.annotations = annotations;
- }
-
- if (globalColourScheme != null)
- globalColourScheme.setConsensus(vconsensus);
-
- }catch(OutOfMemoryError error)
- {
- javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "Out of memory calculating consensus!!"
- +
- "\nSee help files for increasing Java Virtual Machine memory."
- , "Out of memory",
- javax.swing.JOptionPane.WARNING_MESSAGE);
- System.out.println("Consensus calculation: " + error);
- System.gc();
- }
-
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceGroup getSelectionGroup()
- {
- return selectionGroup;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param sg DOCUMENT ME!
- */
- public void setSelectionGroup(SequenceGroup sg)
- {
- selectionGroup = sg;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getConservationSelected()
- {
- return conservationColourSelected;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setConservationSelected(boolean b)
- {
- conservationColourSelected = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getAbovePIDThreshold()
- {
- return abovePIDThreshold;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setAbovePIDThreshold(boolean b)
- {
- abovePIDThreshold = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getStartRes()
- {
- return startRes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getEndRes()
- {
- return endRes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getStartSeq()
- {
- return startSeq;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param cs DOCUMENT ME!
- */
- public void setGlobalColourScheme(ColourSchemeI cs)
- {
- globalColourScheme = cs;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ColourSchemeI getGlobalColourScheme()
- {
- return globalColourScheme;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param res DOCUMENT ME!
- */
- public void setStartRes(int res)
- {
- this.startRes = res;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param seq DOCUMENT ME!
- */
- public void setStartSeq(int seq)
- {
- this.startSeq = seq;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param res DOCUMENT ME!
- */
- public void setEndRes(int res)
- {
- if (res > (alignment.getWidth() - 1))
- {
- // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
- res = alignment.getWidth() - 1;
- }
-
- if (res < 0)
- {
- res = 0;
- }
-
- this.endRes = res;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param seq DOCUMENT ME!
- */
- public void setEndSeq(int seq)
- {
- if (seq > alignment.getHeight())
- {
- seq = alignment.getHeight();
- }
-
- if (seq < 0)
- {
- seq = 0;
- }
-
- this.endSeq = seq;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getEndSeq()
- {
- return endSeq;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param f DOCUMENT ME!
- */
- public void setFont(Font f)
- {
- font = f;
-
- Container c = new Container();
-
- java.awt.FontMetrics fm = c.getFontMetrics(font);
- setCharHeight(fm.getHeight());
- setCharWidth(fm.charWidth('M'));
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Font getFont()
- {
- return font;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param w DOCUMENT ME!
- */
- public void setCharWidth(int w)
- {
- this.charWidth = w;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getCharWidth()
- {
- return charWidth;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param h DOCUMENT ME!
- */
- public void setCharHeight(int h)
- {
- this.charHeight = h;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getCharHeight()
- {
- return charHeight;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param w DOCUMENT ME!
- */
- public void setWrappedWidth(int w)
- {
- this.wrappedWidth = w;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getWrappedWidth()
- {
- return wrappedWidth;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public AlignmentI getAlignment()
- {
- return alignment;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param align DOCUMENT ME!
- */
- public void setAlignment(AlignmentI align)
- {
- this.alignment = align;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setWrapAlignment(boolean state)
- {
- wrapAlignment = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setShowText(boolean state)
- {
- showText = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setRenderGaps(boolean state)
- {
- renderGaps = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getColourText()
- {
- return showColourText;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setColourText(boolean state)
- {
- showColourText = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param state DOCUMENT ME!
- */
- public void setShowBoxes(boolean state)
- {
- showBoxes = state;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getWrapAlignment()
- {
- return wrapAlignment;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowText()
- {
- return showText;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowBoxes()
- {
- return showBoxes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public char getGapCharacter()
- {
- return getAlignment().getGapCharacter();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param gap DOCUMENT ME!
- */
- public void setGapCharacter(char gap)
- {
- if (getAlignment() != null)
- {
- getAlignment().setGapCharacter(gap);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param thresh DOCUMENT ME!
- */
- public void setThreshold(int thresh)
- {
- threshold = thresh;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getThreshold()
- {
- return threshold;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param inc DOCUMENT ME!
- */
- public void setIncrement(int inc)
- {
- increment = inc;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getIncrement()
- {
- return increment;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param y DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getIndex(int y)
- {
- int y1 = 0;
- int starty = getStartSeq();
- int endy = getEndSeq();
-
- for (int i = starty; i <= endy; i++)
- {
- if ((i < alignment.getHeight()) &&
- (alignment.getSequenceAt(i) != null))
- {
- int y2 = y1 + getCharHeight();
-
- if ((y >= y1) && (y <= y2))
- {
- return i;
- }
-
- y1 = y2;
- }
- else
- {
- return -1;
- }
- }
-
- return -1;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ColumnSelection getColumnSelection()
- {
- return colSel;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param tree DOCUMENT ME!
- */
- public void setCurrentTree(NJTree tree)
- {
- currentTree = tree;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public NJTree getCurrentTree()
- {
- return currentTree;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setColourAppliesToAllGroups(boolean b)
- {
- colourAppliesToAllGroups = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getColourAppliesToAllGroups()
- {
- return colourAppliesToAllGroups;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowJVSuffix()
- {
- return showJVSuffix;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setShowJVSuffix(boolean b)
- {
- showJVSuffix = b;
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getShowAnnotation()
- {
- return showAnnotation;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setShowAnnotation(boolean b)
- {
- showAnnotation = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getScaleAboveWrapped()
- {
- return scaleAboveWrapped;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getScaleLeftWrapped()
- {
- return scaleLeftWrapped;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean getScaleRightWrapped()
- {
- return scaleRightWrapped;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setScaleAboveWrapped(boolean b)
- {
- scaleAboveWrapped = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setScaleLeftWrapped(boolean b)
- {
- scaleLeftWrapped = b;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setScaleRightWrapped(boolean b)
- {
- scaleRightWrapped = b;
- }
-
- /**
- * Property change listener for changes in alignment
- *
- * @param listener DOCUMENT ME!
- */
- public void addPropertyChangeListener(
- java.beans.PropertyChangeListener listener)
- {
- changeSupport.addPropertyChangeListener(listener);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param listener DOCUMENT ME!
- */
- public void removePropertyChangeListener(
- java.beans.PropertyChangeListener listener)
- {
- changeSupport.removePropertyChangeListener(listener);
- }
-
- /**
- * Property change listener for changes in alignment
- *
- * @param prop DOCUMENT ME!
- * @param oldvalue DOCUMENT ME!
- * @param newvalue DOCUMENT ME!
- */
- public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
- {
- changeSupport.firePropertyChange(prop, oldvalue, newvalue);
- }
-
- public void setIgnoreGapsConsensus(boolean b)
- {
- ignoreGapsInConsensusCalculation = b;
- updateConsensus();
- if(globalColourScheme!=null)
- {
- globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
- }
- }
-
- public boolean getIgnoreGapsConsensus()
- {
- return ignoreGapsInConsensusCalculation;
- }
-
- public void setDataset(boolean b)
- {
- isDataset = b;
- }
-
- public boolean isDataset()
- {
- return isDataset;
- }
-
- public void hideSequence(SequenceI seq)
- {
- alignment.getHiddenSequences().hideSequence(seq);
- hasHiddenRows = true;
- }
-
- public void showSequence(int index)
- {
- alignment.getHiddenSequences().showSequence(index);
-
- if(alignment.getHiddenSequences().getSize()<1)
- hasHiddenRows = false;
- }
-
- public int adjustForHiddenSeqs(int alignmentIndex)
- {
- return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
- }
-}
+ /*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.gui;
+
+import jalview.analysis.*;
+
+import jalview.bin.*;
+
+import jalview.datamodel.*;
+
+import jalview.schemes.*;
+
+import java.awt.*;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AlignViewport
+{
+ int startRes;
+ int endRes;
+ int startSeq;
+ int endSeq;
+ boolean showJVSuffix = true;
+ boolean showText = true;
+ boolean showColourText = false;
+ boolean showBoxes = true;
+ boolean wrapAlignment = false;
+ boolean renderGaps = true;
+ boolean showSequenceFeatures = false;
+ boolean showAnnotation = true;
+ boolean showConservation = true;
+ boolean showQuality = true;
+ boolean showIdentity = true;
+ boolean colourAppliesToAllGroups = true;
+ ColourSchemeI globalColourScheme = null;
+ boolean conservationColourSelected = false;
+ boolean abovePIDThreshold = false;
+ SequenceGroup selectionGroup;
+ int charHeight;
+ int charWidth;
+ boolean validCharWidth;
+ int wrappedWidth;
+ Font font;
+ AlignmentI alignment;
+ ColumnSelection colSel = new ColumnSelection();
+ int threshold;
+ int increment;
+ NJTree currentTree = null;
+ boolean scaleAboveWrapped = false;
+ boolean scaleLeftWrapped = true;
+ boolean scaleRightWrapped = true;
+ boolean hasHiddenColumns = false;
+ boolean hasHiddenRows = false;
+ boolean showHiddenMarkers = true;
+
+ boolean cursorMode = false;
+
+ // The following vector holds the features which are
+ // currently visible, in the correct order or rendering
+ Hashtable featuresDisplayed = null;
+
+
+ /** DOCUMENT ME!! */
+ public Vector vconsensus;
+ AlignmentAnnotation consensus;
+ AlignmentAnnotation conservation;
+ AlignmentAnnotation quality;
+ boolean autoCalculateConsensus = true;
+
+ /** DOCUMENT ME!! */
+ public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
+
+ // JBPNote Prolly only need this in the applet version.
+ private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
+
+ boolean ignoreGapsInConsensusCalculation = false;
+
+ boolean isDataset = false;
+
+ boolean antiAlias = false;
+
+ boolean padGaps = false;
+
+
+ public AlignViewport(AlignmentI al, boolean dataset)
+ {
+ isDataset = dataset;
+ setAlignment(al);
+ init();
+ }
+ /**
+ * Creates a new AlignViewport object.
+ *
+ * @param al DOCUMENT ME!
+ */
+ public AlignViewport(AlignmentI al)
+ {
+ setAlignment(al);
+ init();
+ }
+ /**
+ * Create a new AlignViewport with hidden regions
+ * @param al AlignmentI
+ * @param hiddenColumns ColumnSelection
+ */
+ public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {
+ setAlignment(al);
+ if (hiddenColumns!=null) {
+ this.colSel = hiddenColumns;
+ if (hiddenColumns.getHiddenColumns() != null)
+ hasHiddenColumns = true;
+ }
+ init();
+ }
+
+ void init()
+ {
+ this.startRes = 0;
+ this.endRes = alignment.getWidth() - 1;
+ this.startSeq = 0;
+ this.endSeq = alignment.getHeight() - 1;
+
+ antiAlias = Cache.getDefault("ANTI_ALIAS", false);
+
+ showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
+ showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
+ showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
+
+ showQuality = Cache.getDefault("SHOW_QUALITY", true);
+ showIdentity = Cache.getDefault("SHOW_IDENTITY", true);
+
+ autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
+
+ padGaps = Cache.getDefault("PAD_GAPS", false);
+
+ String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
+ String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
+ String fontSize = Cache.getDefault("FONT_SIZE", "10");
+
+ int style = 0;
+
+ if (fontStyle.equals("bold"))
+ {
+ style = 1;
+ }
+ else if (fontStyle.equals("italic"))
+ {
+ style = 2;
+ }
+
+ setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
+
+
+ alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
+
+
+ // We must set conservation and consensus before setting colour,
+ // as Blosum and Clustal require this to be done
+ if(vconsensus==null && !isDataset)
+ {
+ updateConservation();
+ updateConsensus();
+ }
+
+ if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
+ {
+ globalColourScheme = ColourSchemeProperty.getColour(alignment,
+ jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
+
+ if (globalColourScheme instanceof UserColourScheme)
+ {
+ globalColourScheme = UserDefinedColours.loadDefaultColours();
+ ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
+ }
+
+ if (globalColourScheme != null)
+ {
+ globalColourScheme.setConsensus(vconsensus);
+ }
+ }
+ }
+
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setShowSequenceFeatures(boolean b)
+ {
+ showSequenceFeatures = b;
+ }
+
+ public boolean getShowSequenceFeatures()
+ {
+ return showSequenceFeatures;
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void updateConservation()
+ {
+ if(alignment.isNucleotide())
+ return;
+
+ try{
+ Conservation cons = new jalview.analysis.Conservation("All",
+ jalview.schemes.ResidueProperties.propHash, 3,
+ alignment.getSequences(), 0, alignment.getWidth() - 1);
+ cons.calculate();
+ cons.verdict(false, ConsPercGaps);
+ cons.findQuality();
+
+ int alWidth = alignment.getWidth();
+ Annotation[] annotations = new Annotation[alWidth];
+ Annotation[] qannotations = new Annotation[alWidth];
+ String sequence = cons.getConsSequence().getSequence();
+ float minR;
+ float minG;
+ float minB;
+ float maxR;
+ float maxG;
+ float maxB;
+ minR = 0.3f;
+ minG = 0.0f;
+ minB = 0f;
+ maxR = 1.0f - minR;
+ maxG = 0.9f - minG;
+ maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
+
+ float min = 0f;
+ float max = 11f;
+ float qmin = cons.qualityRange[0].floatValue();
+ float qmax = cons.qualityRange[1].floatValue();
+
+ for (int i = 0; i < alWidth; i++)
+ {
+ float value = 0;
+
+ try
+ {
+ value = Integer.parseInt(sequence.charAt(i) + "");
+ }
+ catch (Exception ex)
+ {
+ if (sequence.charAt(i) == '*')
+ {
+ value = 11;
+ }
+
+ if (sequence.charAt(i) == '+')
+ {
+ value = 10;
+ }
+ }
+
+ float vprop = value - min;
+ vprop /= max;
+ annotations[i] = new Annotation(sequence.charAt(i) + "",
+ String.valueOf(value), ' ', value,
+ new Color(minR + (maxR * vprop),
+ minG + (maxG * vprop),
+ minB + (maxB * vprop)));
+
+ // Quality calc
+ value = ( (Double) cons.quality.get(i)).floatValue();
+ vprop = value - qmin;
+ vprop /= qmax;
+ qannotations[i] = new Annotation(" ", String.valueOf(value), ' ',
+ value,
+ new Color(minR + (maxR * vprop),
+ minG + (maxG * vprop),
+ minB + (maxB * vprop)));
+ }
+
+ if (conservation == null)
+ {
+ conservation = new AlignmentAnnotation("Conservation",
+ "Conservation of total alignment less than " +
+ ConsPercGaps + "% gaps",
+ annotations, 0f, // cons.qualityRange[0].floatValue(),
+ 11f, // cons.qualityRange[1].floatValue()
+ AlignmentAnnotation.BAR_GRAPH);
+
+ if (showConservation)
+ {
+ alignment.addAnnotation(conservation);
+ }
+
+ quality = new AlignmentAnnotation("Quality",
+ "Alignment Quality based on Blosum62 scores",
+ qannotations,
+ cons.qualityRange[0].floatValue(),
+ cons.qualityRange[1].floatValue(),
+ AlignmentAnnotation.BAR_GRAPH);
+
+ if (showQuality)
+ {
+ alignment.addAnnotation(quality);
+ }
+ }
+ else
+ {
+ conservation.annotations = annotations;
+ quality.annotations = qannotations;
+ quality.graphMax = cons.qualityRange[1].floatValue();
+ }
+ }
+ catch (OutOfMemoryError error)
+ {
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Out of memory calculating conservation!!"
+ +
+ "\nSee help files for increasing Java Virtual Machine memory."
+ , "Out of memory",
+ javax.swing.JOptionPane.WARNING_MESSAGE);
+ }
+ });
+
+ System.out.println("Conservation calculation: " + error);
+ System.gc();
+
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void updateConsensus()
+ {
+ try{
+ Annotation[] annotations = new Annotation[alignment.getWidth()];
+
+ // this routine prevents vconsensus becoming a new object each time
+ // consenus is calculated. Important for speed of Blosum62
+ // and PID colouring of alignment
+ if (vconsensus == null)
+ {
+ vconsensus = alignment.getAAFrequency();
+ }
+ else
+ {
+ Vector temp = alignment.getAAFrequency();
+ vconsensus.clear();
+
+ Enumeration e = temp.elements();
+
+ while (e.hasMoreElements())
+ {
+ vconsensus.add(e.nextElement());
+ }
+ }
+
+ Hashtable hash = null;
+
+ for (int i = 0; i < alignment.getWidth(); i++)
+ {
+ hash = (Hashtable) vconsensus.elementAt(i);
+
+ float value = 0;
+ if (ignoreGapsInConsensusCalculation)
+ value = ( (Float) hash.get("pid_nogaps")).floatValue();
+ else
+ value = ( (Float) hash.get("pid_gaps")).floatValue();
+
+ String maxRes = hash.get("maxResidue").toString();
+ String mouseOver = hash.get("maxResidue") + " ";
+
+ if (maxRes.length() > 1)
+ {
+ mouseOver = "[" + maxRes + "] ";
+ maxRes = "+";
+ }
+
+ mouseOver += ( (int) value + "%");
+ annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
+ }
+
+ if (consensus == null)
+ {
+ consensus = new AlignmentAnnotation("Consensus", "PID",
+ annotations, 0f, 100f,AlignmentAnnotation.BAR_GRAPH);
+
+ if (showIdentity)
+ {
+ alignment.addAnnotation(consensus);
+ }
+ }
+ else
+ {
+ consensus.annotations = annotations;
+ }
+
+ if (globalColourScheme != null)
+ globalColourScheme.setConsensus(vconsensus);
+
+ }catch(OutOfMemoryError error)
+ {
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Out of memory calculating consensus!!"
+ +
+ "\nSee help files for increasing Java Virtual Machine memory."
+ , "Out of memory",
+ javax.swing.JOptionPane.WARNING_MESSAGE);
+ }
+ });
+
+
+ System.out.println("Consensus calculation: " + error);
+ System.gc();
+ }
+
+ }
+ /**
+ * get the consensus sequence as displayed under the PID consensus annotation row.
+ * @return consensus sequence as a new sequence object
+ */
+ public SequenceI getConsensusSeq() {
+ if (consensus==null)
+ updateConsensus();
+ if (consensus==null)
+ return null;
+ StringBuffer seqs=new StringBuffer();
+ for (int i=0; i (alignment.getWidth() - 1))
+ {
+ // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
+ res = alignment.getWidth() - 1;
+ }
+
+ if (res < 0)
+ {
+ res = 0;
+ }
+
+ this.endRes = res;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param seq DOCUMENT ME!
+ */
+ public void setEndSeq(int seq)
+ {
+ if (seq > alignment.getHeight())
+ {
+ seq = alignment.getHeight();
+ }
+
+ if (seq < 0)
+ {
+ seq = 0;
+ }
+
+ this.endSeq = seq;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getEndSeq()
+ {
+ return endSeq;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param f DOCUMENT ME!
+ */
+ public void setFont(Font f)
+ {
+ font = f;
+
+ Container c = new Container();
+
+ java.awt.FontMetrics fm = c.getFontMetrics(font);
+ setCharHeight(fm.getHeight());
+ setCharWidth(fm.charWidth('M'));
+ validCharWidth = true;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Font getFont()
+ {
+ return font;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param w DOCUMENT ME!
+ */
+ public void setCharWidth(int w)
+ {
+ this.charWidth = w;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getCharWidth()
+ {
+ return charWidth;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param h DOCUMENT ME!
+ */
+ public void setCharHeight(int h)
+ {
+ this.charHeight = h;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getCharHeight()
+ {
+ return charHeight;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param w DOCUMENT ME!
+ */
+ public void setWrappedWidth(int w)
+ {
+ this.wrappedWidth = w;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getWrappedWidth()
+ {
+ return wrappedWidth;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AlignmentI getAlignment()
+ {
+ return alignment;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param align DOCUMENT ME!
+ */
+ public void setAlignment(AlignmentI align)
+ {
+ this.alignment = align;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setWrapAlignment(boolean state)
+ {
+ wrapAlignment = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setShowText(boolean state)
+ {
+ showText = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setRenderGaps(boolean state)
+ {
+ renderGaps = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getColourText()
+ {
+ return showColourText;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setColourText(boolean state)
+ {
+ showColourText = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setShowBoxes(boolean state)
+ {
+ showBoxes = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getWrapAlignment()
+ {
+ return wrapAlignment;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowText()
+ {
+ return showText;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowBoxes()
+ {
+ return showBoxes;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public char getGapCharacter()
+ {
+ return getAlignment().getGapCharacter();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param gap DOCUMENT ME!
+ */
+ public void setGapCharacter(char gap)
+ {
+ if (getAlignment() != null)
+ {
+ getAlignment().setGapCharacter(gap);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param thresh DOCUMENT ME!
+ */
+ public void setThreshold(int thresh)
+ {
+ threshold = thresh;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getThreshold()
+ {
+ return threshold;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param inc DOCUMENT ME!
+ */
+ public void setIncrement(int inc)
+ {
+ increment = inc;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getIncrement()
+ {
+ return increment;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ColumnSelection getColumnSelection()
+ {
+ return colSel;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param tree DOCUMENT ME!
+ */
+ public void setCurrentTree(NJTree tree)
+ {
+ currentTree = tree;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public NJTree getCurrentTree()
+ {
+ return currentTree;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setColourAppliesToAllGroups(boolean b)
+ {
+ colourAppliesToAllGroups = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getColourAppliesToAllGroups()
+ {
+ return colourAppliesToAllGroups;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowJVSuffix()
+ {
+ return showJVSuffix;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setShowJVSuffix(boolean b)
+ {
+ showJVSuffix = b;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowAnnotation()
+ {
+ return showAnnotation;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setShowAnnotation(boolean b)
+ {
+ showAnnotation = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getScaleAboveWrapped()
+ {
+ return scaleAboveWrapped;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getScaleLeftWrapped()
+ {
+ return scaleLeftWrapped;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getScaleRightWrapped()
+ {
+ return scaleRightWrapped;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setScaleAboveWrapped(boolean b)
+ {
+ scaleAboveWrapped = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setScaleLeftWrapped(boolean b)
+ {
+ scaleLeftWrapped = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setScaleRightWrapped(boolean b)
+ {
+ scaleRightWrapped = b;
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void addPropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void removePropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param prop DOCUMENT ME!
+ * @param oldvalue DOCUMENT ME!
+ * @param newvalue DOCUMENT ME!
+ */
+ public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
+ {
+ changeSupport.firePropertyChange(prop, oldvalue, newvalue);
+ }
+
+ public void setIgnoreGapsConsensus(boolean b)
+ {
+ ignoreGapsInConsensusCalculation = b;
+ updateConsensus();
+ if(globalColourScheme!=null)
+ {
+ globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
+ }
+ }
+
+ public boolean getIgnoreGapsConsensus()
+ {
+ return ignoreGapsInConsensusCalculation;
+ }
+
+ public void setDataset(boolean b)
+ {
+ isDataset = b;
+ }
+
+ public boolean isDataset()
+ {
+ return isDataset;
+ }
+
+
+ public void hideSelectedColumns()
+ {
+ if (colSel.size() < 1)
+ return;
+
+ colSel.hideSelectedColumns();
+ setSelectionGroup(null);
+
+ hasHiddenColumns = true;
+ }
+
+
+ public void hideColumns(int start, int end)
+ {
+ if(start==end)
+ colSel.hideColumns(start);
+ else
+ colSel.hideColumns(start, end);
+
+ hasHiddenColumns = true;
+ }
+
+ public void hideAllSelectedSeqs()
+ {
+ if (selectionGroup == null)
+ return;
+
+ SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
+
+ for (int i = 0; i < seqs.length; i++)
+ {
+ alignment.getHiddenSequences().hideSequence(seqs[i]);
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ hasHiddenRows = true;
+ setSelectionGroup(null);
+ }
+
+ public void hideSequence(SequenceI seq)
+ {
+ if(seq!=null)
+ {
+ alignment.getHiddenSequences().hideSequence(seq);
+ hasHiddenRows = true;
+ firePropertyChange("alignment", null, alignment.getSequences());
+ }
+ }
+
+ public void showSequence(int index)
+ {
+ Vector tmp = alignment.getHiddenSequences().showSequence(index);
+ if(tmp.size()>0)
+ {
+ if(selectionGroup==null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth()-1);
+ }
+
+ for (int t = 0; t < tmp.size(); t++)
+ {
+ selectionGroup.addSequence(
+ (SequenceI) tmp.elementAt(t), false
+ );
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ }
+
+ if(alignment.getHiddenSequences().getSize()<1)
+ hasHiddenRows = false;
+ }
+
+ public void showColumn(int col)
+ {
+ colSel.revealHiddenColumns(col);
+ if(colSel.getHiddenColumns()==null)
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenColumns()
+ {
+ colSel.revealAllHiddenColumns();
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenSeqs()
+ {
+ if(alignment.getHiddenSequences().getSize()>0)
+ {
+ if(selectionGroup==null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth()-1);
+ }
+ Vector tmp = alignment.getHiddenSequences().showAll();
+ for(int t=0; t last)
+ {
+ hideStart = last;
+ } else
+ continue;
+ }
+
+ if (hideStart>end)
+ break;
+
+ if (hideEnd>end)
+ hideEnd=end;
+
+ if (hideStart>hideEnd)
+ break;
+ /**
+ * form operations...
+ */
+ if (last=KeyEvent.VK_0
- && evt.getKeyCode()<=KeyEvent.VK_9)
- {
- seqPanel.numberPressed(evt.getKeyChar());
- }
-
- switch (evt.getKeyCode())
- {
- case 27: // escape key
- av.setSelectionGroup(null);
- repaint();
-
- break;
-
- case KeyEvent.VK_DOWN:
- if(av.cursorMode)
- {
- seqPanel.moveCursor(0,1);
- }
- else
- alignFrame.moveSelectedSequences(false);
- break;
-
- case KeyEvent.VK_UP:
- if (av.cursorMode)
- {
- seqPanel.moveCursor(0,-1);
- }
- else
- alignFrame.moveSelectedSequences(true);
- break;
-
- case KeyEvent.VK_LEFT:
- if(av.cursorMode)
- {
- seqPanel.moveCursor(-1,0);
- }
- break;
-
- case KeyEvent.VK_RIGHT:
- if (av.cursorMode)
- {
- seqPanel.moveCursor(1,0);
- }
- break;
-
- case KeyEvent.VK_SPACE:
- if(av.cursorMode)
- {
- seqPanel.insertGapAtCursor(evt.isControlDown());
- }
- break;
-
- case KeyEvent.VK_DELETE:
- if(av.cursorMode)
- {
- seqPanel.deleteGapAtCursor(evt.isControlDown());
- break;
- }
-
- case KeyEvent.VK_BACK_SPACE:
- if(!av.cursorMode)
- {
- alignFrame.cut_actionPerformed(null);
- seqPanel.seqCanvas.repaint();
- }
- break;
-
- case KeyEvent.VK_Q:
- if(av.cursorMode)
- {
- seqPanel.setSelectionAreaAtCursor(true);
- }
- break;
- case KeyEvent.VK_M:
- if(av.cursorMode)
- {
- seqPanel.setSelectionAreaAtCursor(false);
- }
- break;
-
- case KeyEvent.VK_F2:
- av.cursorMode = ! av.cursorMode;
- alignFrame.statusBar.setText("Keyboard editing mode is "+
- (av.cursorMode ? "on" : "off"));
- if(av.cursorMode)
- {
- seqPanel.seqCanvas.cursorX = av.startRes;
- seqPanel.seqCanvas.cursorY = av.startSeq;
- }
- seqPanel.seqCanvas.repaint();
- break;
-
- case KeyEvent.VK_F1:
- try
- {
- ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
- java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
- javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
-
- javax.help.HelpBroker hb = hs.createHelpBroker();
- hb.setCurrentID("home");
- hb.setDisplayed(true);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- break;
-
- }
- }
- });
- }
-
- /**
- * DOCUMENT ME!
- */
- public void fontChanged()
- {
- // set idCanvas bufferedImage to null
- // to prevent drawing old image
- FontMetrics fm = getFontMetrics(av.getFont());
-
- scalePanelHolder.setPreferredSize(new Dimension(10,
- av.charHeight + fm.getDescent()));
- idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
- av.charHeight + fm.getDescent()));
-
- idPanel.idCanvas.gg = null;
- seqPanel.seqCanvas.img = null;
- annotationPanel.adjustPanelHeight();
-
- Dimension d = calculateIdWidth();
- d.setSize(d.width + 4, d.height);
- idPanel.idCanvas.setPreferredSize(d);
- hscrollFillerPanel.setPreferredSize(d);
-
- if (av.getWrapAlignment())
- {
- int max = av.alignment.getWidth() /
- seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
- vscroll.setMaximum(max);
- vscroll.setUnitIncrement(1);
- vscroll.setVisibleAmount(1);
- }
- else
- {
- setScrollValues(av.getStartRes(), av.getStartSeq());
- }
-
- if (overviewPanel != null)
- overviewPanel.setBoxPosition();
-
- repaint();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Dimension calculateIdWidth()
- {
- Container c = new Container();
-
- FontMetrics fm = c.getFontMetrics(av.font);
- AlignmentI al = av.getAlignment();
-
- int i = 0;
- int idWidth = 0;
- String id;
-
- while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))
- {
- SequenceI s = al.getSequenceAt(i);
-
- id = s.getDisplayId(av.getShowJVSuffix());
-
- if (fm.stringWidth(id) > idWidth)
- {
- idWidth = fm.stringWidth(id);
- }
-
- i++;
- }
-
- // Also check annotation label widths
- i = 0;
-
- if (al.getAlignmentAnnotation() != null)
- {
- fm = c.getFontMetrics(alabels.getFont());
-
- while (i < al.getAlignmentAnnotation().length)
- {
- String label = al.getAlignmentAnnotation()[i].label;
-
- if (fm.stringWidth(label) > idWidth)
- {
- idWidth = fm.stringWidth(label);
- }
-
- i++;
- }
- }
-
- return new Dimension(idWidth, 12);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param results DOCUMENT ME!
- */
- public void highlightSearchResults(SearchResults results)
- {
- seqPanel.seqCanvas.highlightSearchResults(results);
-
- // do we need to scroll the panel?
- if (results != null)
- {
- SequenceI seq = results.getResultSequence(0);
- int seqIndex = av.alignment.findIndex(seq);
- int start = seq.findIndex(results.getResultStart(0)) - 1;
- int end = seq.findIndex(results.getResultEnd(0)) - 1;
-
- if(!av.wrapAlignment)
- {
- if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
- ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
- {
- setScrollValues(start, seqIndex);
- }
- }
- else
- {
- int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
- if( start(av.getStartRes()+cwidth) )
- {
- vscroll.setValue(start / cwidth);
- av.startRes = vscroll.getValue() * cwidth;
- }
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public OverviewPanel getOverviewPanel()
- {
- return overviewPanel;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param op DOCUMENT ME!
- */
- public void setOverviewPanel(OverviewPanel op)
- {
- overviewPanel = op;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setAnnotationVisible(boolean b)
- {
- if (!av.wrapAlignment)
- {
- annotationSpaceFillerHolder.setVisible(b);
- annotationScroller.setVisible(b);
- }
- repaint();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param wrap DOCUMENT ME!
- */
- public void setWrapAlignment(boolean wrap)
- {
- av.startSeq = 0;
- scalePanelHolder.setVisible(!wrap);
- hscroll.setVisible(!wrap);
- idwidthAdjuster.setVisible(!wrap);
-
- if (wrap)
- {
- annotationScroller.setVisible(false);
- annotationSpaceFillerHolder.setVisible(false);
- }
- else if (av.showAnnotation)
- {
- annotationScroller.setVisible(true);
- annotationSpaceFillerHolder.setVisible(true);
- }
-
- idSpaceFillerPanel1.setVisible(!wrap);
-
- repaint();
- }
-
- // return value is true if the scroll is valid
- public boolean scrollUp(boolean up)
- {
- if (up)
- {
- if (vscroll.getValue() < 1)
- {
- return false;
- }
-
- fastPaint = false;
- vscroll.setValue(vscroll.getValue() - 1);
- }
- else
- {
- if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
- {
- return false;
- }
-
- fastPaint = false;
- vscroll.setValue(vscroll.getValue() + 1);
- }
-
- fastPaint = true;
-
- return true;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param right DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean scrollRight(boolean right)
- {
- if (!right)
- {
- if (hscroll.getValue() < 1)
- {
- return false;
- }
-
- fastPaint = false;
- hscroll.setValue(hscroll.getValue() - 1);
- }
- else
- {
- if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
- {
- return false;
- }
-
- fastPaint = false;
- hscroll.setValue(hscroll.getValue() + 1);
- }
-
- fastPaint = true;
-
- return true;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
- */
- public void setScrollValues(int x, int y)
- {
-
- int width = av.alignment.getWidth();
- int height = av.alignment.getHeight();
-
- if(av.hasHiddenColumns)
- width = av.getColumnSelection().findColumnPosition(width);
-
- av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1);
-
- hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
- vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
-
- if (hextent > width)
- {
- hextent = width;
- }
-
- if (vextent > height)
- {
- vextent = height;
- }
-
- if ( (hextent + x) > width)
- {
- x = width - hextent;
- }
-
- if ( (vextent + y) > height)
- {
- y = height - vextent;
- }
-
- if (y < 0)
- {
- y = 0;
- }
-
- if (x < 0)
- {
- x = 0;
- }
-
- hscroll.setValues(x, hextent, 0, width);
- vscroll.setValues(y, vextent, 0, height);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param evt DOCUMENT ME!
- */
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- int oldX = av.getStartRes();
- int oldY = av.getStartSeq();
-
- if (evt.getSource() == hscroll)
- {
- int x = hscroll.getValue();
- av.setStartRes(x);
- av.setEndRes( (x +
- (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
- }
-
- if (evt.getSource() == vscroll)
- {
- int offy = vscroll.getValue();
-
- if (av.getWrapAlignment())
- {
- int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
- seqCanvas.getWidth());
- av.setStartRes(vscroll.getValue() * rowSize);
- av.setEndRes( (vscroll.getValue() + 1) * rowSize);
- }
- else
- {
- av.setStartSeq(offy);
- av.setEndSeq(offy +
- (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
- }
- }
-
- if (overviewPanel != null)
- {
- overviewPanel.setBoxPosition();
- }
-
- int scrollX = av.startRes - oldX;
- int scrollY = av.startSeq - oldY;
-
- if (av.getWrapAlignment() || !fastPaint)
- {
- repaint();
- }
- else
- {
- // Make sure we're not trying to draw a panel
- // larger than the visible window
- if(scrollX>av.endRes-av.startRes)
- scrollX = av.endRes-av.startRes;
- else if(scrollX (av.getAlignment().getWidth() - 1))
- {
- endRes = av.getAlignment().getWidth() - 1;
- }
-
- startSeq = (pi / pagesWide) * totalSeq;
- endSeq = startSeq + totalSeq;
-
- if (endSeq > av.getAlignment().getHeight())
- {
- endSeq = av.getAlignment().getHeight();
- }
-
- int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
-
- if (av.showAnnotation)
- {
- pagesHigh += annotationPanel.adjustPanelHeight() + 3;
- }
-
- pagesHigh /= pheight;
-
- if (pi >= (pagesWide * pagesHigh))
- {
- return Printable.NO_SUCH_PAGE;
- }
-
- //draw Scale
- pg.translate(idWidth, 0);
- scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
- pg.translate( -idWidth, scaleHeight);
-
- ////////////////
- // Draw the ids
- Color currentColor = null;
- Color currentTextColor = null;
-
- pg.setFont(new Font(av.getFont().getName(),
- Font.ITALIC,
- av.getFont().getSize()));
- for (int i = startSeq; i < endSeq; i++)
- {
- if ( (av.getSelectionGroup() != null) &&
- av.getSelectionGroup().sequences.contains(
- av.getAlignment().getSequenceAt(i)))
- {
- currentColor = Color.gray;
- currentTextColor = Color.black;
- }
- else
- {
- currentColor = av.getAlignment().getSequenceAt(i).getColor();
- currentTextColor = Color.black;
- }
-
- pg.setColor(currentColor);
- pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
- av.getCharHeight());
-
- pg.setColor(currentTextColor);
-
- String string = av.getAlignment().getSequenceAt(i).getDisplayId
- ( av.getShowJVSuffix());
-
- pg.drawString(string, 0,
- ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
- (av.getCharHeight() / 5));
- }
-
- pg.setFont(av.getFont());
-
- // draw main sequence panel
- pg.translate(idWidth, 0);
- seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
-
- if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
- {
- pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3);
- alabels.drawComponent( (Graphics2D) pg, idWidth);
- pg.translate(idWidth+3, 0);
- annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
- 1);
- }
-
- return Printable.PAGE_EXISTS;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param pg DOCUMENT ME!
- * @param pwidth DOCUMENT ME!
- * @param pheight DOCUMENT ME!
- * @param pi DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws PrinterException DOCUMENT ME!
- */
- public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
- int pi)
- throws PrinterException
- {
-
- int annotationHeight = 0;
- AnnotationLabels labels = null;
- if (av.showAnnotation)
- {
- annotationHeight = annotationPanel.adjustPanelHeight();
- labels = new AnnotationLabels(av);
- }
-
- int hgap = av.charHeight;
- if (av.scaleAboveWrapped)
- hgap += av.charHeight;
-
- int cHeight = av.getAlignment().getHeight() * av.charHeight
- + hgap
- + annotationHeight;
-
- int idWidth = calculateIdWidth().width + 4;
-
- int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
- idWidth);
-
- int totalHeight = cHeight * (av.alignment.getWidth() / resWidth + 1);
-
- pg.setColor(Color.white);
- pg.fillRect(0, 0, pwidth, pheight);
- pg.setFont(av.getFont());
-
- ////////////////
- // Draw the ids
- pg.setColor(Color.black);
-
- pg.translate(0, -pi * pheight);
-
- pg.setClip(0, pi * pheight, pwidth, pheight);
-
- int ypos = hgap;
- Font italic = new Font(av.getFont().getName(), Font.ITALIC,
- av.getFont().getSize());
- pg.setFont(italic);
-
- do
- {
- for (int i = 0; i < av.alignment.getHeight(); i++)
- {
- SequenceI s = av.alignment.getSequenceAt(i);
- String string = s.getDisplayId( av.getShowJVSuffix());
-
- pg.drawString(string, 0,
- ( (i * av.charHeight) + ypos + av.charHeight) -
- (av.charHeight / 5));
- }
- if (labels != null)
- {
- pg.translate(-3,
- ypos +
- (av.getAlignment().getHeight() * av.charHeight));
-
- pg.setFont(av.getFont());
- labels.drawComponent(pg, idWidth);
- pg.setFont(italic);
- pg.translate(+3,
- -ypos -
- (av.getAlignment().getHeight() * av.charHeight));
- }
-
- ypos += cHeight;
- }
- while (ypos < totalHeight);
-
- pg.translate(idWidth, 0);
-
- seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
-
- if ( (pi * pheight) < totalHeight)
- {
- return Printable.PAGE_EXISTS;
-
- }
- else
- {
- return Printable.NO_SUCH_PAGE;
- }
- }
-
- void makeAlignmentImage(int type, File file)
- {
- int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
- int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);
-
- if (idPanel.getWidth() == 0)
- {
- width += calculateIdWidth().getWidth() + 4;
- }
-
- if (av.getWrapAlignment())
- {
- height = getWrappedHeight();
- width = seqPanel.getWidth() + idPanel.getWidth();
- }
- else if (av.getShowAnnotation())
- {
- height += annotationPanel.adjustPanelHeight() + 3;
- }
-
- jalview.util.ImageMaker im;
- if(type==jalview.util.ImageMaker.PNG)
- im = new jalview.util.ImageMaker(this,
- jalview.util.ImageMaker.PNG,
- "Create PNG image from alignment",
- width, height, file, null);
- else
- im = new jalview.util.ImageMaker(this,
- jalview.util.ImageMaker.EPS,
- "Create EPS file from alignment",
- width, height, file, alignFrame.getTitle() );
-
- try
- {
- if (av.getWrapAlignment())
- {
- if(im.getGraphics()!=null)
- {
- printWrappedAlignment(im.getGraphics(), width, height, 0);
- im.writeImage();
- }
- }
- else
- {
- if(im.getGraphics()!=null)
- {
- printUnwrapped(im.getGraphics(), width, height, 0);
- im.writeImage();
- }
- }
- }
- catch (OutOfMemoryError err)
- {
- System.out.println("########################\n"
- + "OUT OF MEMORY " + file + "\n"
- + "########################");
-
- JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "Out of Memory Creating Image!!"
- +
- "\nSee help files for increasing Java Virtual Machine memory."
- , "Out of memory",
- JOptionPane.WARNING_MESSAGE);
- System.out.println("Create IMAGE: " + err);
- System.gc();
-
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- /**
- * DOCUMENT ME!
- */
- public void makeEPS(File epsFile)
- {
- makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
- }
-
- /**
- * DOCUMENT ME!
- */
- public void makePNG(File pngFile)
- {
- makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
- }
-
- public void makePNGImageMap(File imgMapFile, String imageName)
- {
- ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
- //////////////////////////////////////////////
- int idWidth = calculateIdWidth().width + 4;
- FontMetrics fm = getFontMetrics(av.getFont());
- int scaleHeight = av.charHeight + fm.getDescent();
-
- // Gen image map
- //////////////////////////////////
- if (imgMapFile != null)
- {
- try
- {
- int s, sSize = av.alignment.getHeight(),
- res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
- StringBuffer text = new StringBuffer();
- PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
- out.println(jalview.io.HTMLOutput.getImageMapHTML());
- out.println(""
- + "