From: jprocter Date: Thu, 7 Sep 2006 11:39:37 +0000 (+0000) Subject: This commit was manufactured by cvs2svn to create branch 'VamJalview'. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0f71bfca98457c30f1051f142c31b6aaa3e23ead;p=jalview.git This commit was manufactured by cvs2svn to create branch 'VamJalview'. Cherrypick from master 2006-09-07 11:39:36 UTC jimp 'added copy consensus sequence to consensus annotation popup menu': src/jalview/appletgui/Tooltip.java src/jalview/datamodel/.cvsignore src/jalview/datamodel/AlignmentView.java src/jalview/datamodel/CigarArray.java src/jalview/datamodel/CigarBase.java src/jalview/datamodel/CigarCigar.java src/jalview/datamodel/CigarSimple.java src/jalview/datamodel/ColumnSelection.java src/jalview/datamodel/DBRefSource.java src/jalview/datamodel/SeqCigar.java src/jalview/datamodel/UniprotProteinName.java src/jalview/gui/AnnotationExporter.java src/jalview/gui/DasSourceBrowser.java src/jalview/gui/Jalview2XML_V1.java src/jalview/io/AnnotationFile.java src/jalview/io/DBRefFetcher.java src/jalview/io/DasSequenceFeatureFetcher.java src/jalview/io/FeaturesFile.java src/jalview/io/JnetAnnotationMaker.java src/jalview/io/StockholmFile.java src/jalview/jbgui/GDasSourceBrowser.java src/jalview/schemabinding/version2/Alignment.java src/jalview/schemabinding/version2/AlignmentDescriptor.java src/jalview/schemabinding/version2/Annotation.java src/jalview/schemabinding/version2/AnnotationColours.java src/jalview/schemabinding/version2/AnnotationColoursDescriptor.java src/jalview/schemabinding/version2/AnnotationDescriptor.java src/jalview/schemabinding/version2/AnnotationElement.java src/jalview/schemabinding/version2/AnnotationElementDescriptor.java src/jalview/schemabinding/version2/Colour.java src/jalview/schemabinding/version2/ColourDescriptor.java src/jalview/schemabinding/version2/DBRef.java src/jalview/schemabinding/version2/DBRefDescriptor.java src/jalview/schemabinding/version2/Feature.java src/jalview/schemabinding/version2/FeatureDescriptor.java src/jalview/schemabinding/version2/FeatureSettings.java src/jalview/schemabinding/version2/FeatureSettingsDescriptor.java src/jalview/schemabinding/version2/Features.java src/jalview/schemabinding/version2/FeaturesDescriptor.java src/jalview/schemabinding/version2/HiddenColumns.java src/jalview/schemabinding/version2/HiddenColumnsDescriptor.java src/jalview/schemabinding/version2/JGroup.java src/jalview/schemabinding/version2/JGroupDescriptor.java src/jalview/schemabinding/version2/JSeq.java src/jalview/schemabinding/version2/JSeqDescriptor.java src/jalview/schemabinding/version2/JalviewModel.java src/jalview/schemabinding/version2/JalviewModelDescriptor.java src/jalview/schemabinding/version2/JalviewModelSequence.java src/jalview/schemabinding/version2/JalviewModelSequenceDescriptor.java src/jalview/schemabinding/version2/JalviewUserColours.java src/jalview/schemabinding/version2/JalviewUserColoursDescriptor.java src/jalview/schemabinding/version2/OtherData.java src/jalview/schemabinding/version2/OtherDataDescriptor.java src/jalview/schemabinding/version2/Pdbentry.java src/jalview/schemabinding/version2/PdbentryDescriptor.java src/jalview/schemabinding/version2/PdbentryItem.java src/jalview/schemabinding/version2/PdbentryItemDescriptor.java src/jalview/schemabinding/version2/Pdbids.java src/jalview/schemabinding/version2/PdbidsDescriptor.java src/jalview/schemabinding/version2/Property.java src/jalview/schemabinding/version2/PropertyDescriptor.java src/jalview/schemabinding/version2/Sequence.java src/jalview/schemabinding/version2/SequenceDescriptor.java src/jalview/schemabinding/version2/SequenceSet.java src/jalview/schemabinding/version2/SequenceSetDescriptor.java src/jalview/schemabinding/version2/SequenceType.java src/jalview/schemabinding/version2/SequenceTypeDescriptor.java src/jalview/schemabinding/version2/Setting.java src/jalview/schemabinding/version2/SettingDescriptor.java src/jalview/schemabinding/version2/ThresholdLine.java src/jalview/schemabinding/version2/ThresholdLineDescriptor.java src/jalview/schemabinding/version2/Tree.java src/jalview/schemabinding/version2/TreeDescriptor.java src/jalview/schemabinding/version2/UserColourScheme.java src/jalview/schemabinding/version2/UserColourSchemeDescriptor.java src/jalview/schemabinding/version2/UserColours.java src/jalview/schemabinding/version2/UserColoursDescriptor.java src/jalview/schemabinding/version2/VAMSAS.java src/jalview/schemabinding/version2/VAMSASDescriptor.java src/jalview/schemabinding/version2/VamsasModel.java src/jalview/schemabinding/version2/VamsasModelDescriptor.java src/jalview/schemabinding/version2/Viewport.java src/jalview/schemabinding/version2/ViewportDescriptor.java src/jalview/util/ShiftList.java src/jalview/util/TableSorter.java src/jalview/ws/MsaWSThread.java src/jalview/ws/WSThread.java src/org/biojava/dasobert/das/DAS_FeatureRetrieve.java src/org/biojava/dasobert/das/DAS_Feature_Handler.java src/org/biojava/dasobert/das/FeatureThread.java src/org/biojava/dasobert/das2/Das2Capability.java src/org/biojava/dasobert/das2/Das2CapabilityImpl.java src/org/biojava/dasobert/das2/Das2Source.java src/org/biojava/dasobert/das2/Das2SourceImpl.java src/org/biojava/dasobert/das2/DasSourceConverter.java src/org/biojava/dasobert/das2/io/DAS2SourceHandler.java src/org/biojava/dasobert/das2/io/DasSourceReader.java src/org/biojava/dasobert/das2/io/DasSourceReaderImpl.java src/org/biojava/dasobert/dasregistry/Das1Source.java src/org/biojava/dasobert/dasregistry/Das2Validator.java src/org/biojava/dasobert/dasregistry/DasCoordSysComparator.java src/org/biojava/dasobert/dasregistry/DasCoordinateSystem.java src/org/biojava/dasobert/dasregistry/DasSource.java src/org/biojava/dasobert/dasregistry/DasSourceComparator.java src/org/biojava/dasobert/eventmodel/FeatureEvent.java src/org/biojava/dasobert/eventmodel/FeatureListener.java src/org/biojava/dasobert/eventmodel/ObjectListener.java src/org/biojava/dasobert/eventmodel/SequenceEvent.java src/org/biojava/dasobert/eventmodel/SequenceListener.java --- diff --git a/src/jalview/appletgui/Tooltip.java b/src/jalview/appletgui/Tooltip.java new file mode 100755 index 0000000..389b012 --- /dev/null +++ b/src/jalview/appletgui/Tooltip.java @@ -0,0 +1,190 @@ +/* + * 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.applet.*; +import java.awt.event.*; +import java.util.*; + +public class Tooltip extends Canvas implements MouseListener, + MouseMotionListener +{ + + private String [] tip; + protected Component owner; + + private Container mainContainer; + private LayoutManager mainLayout; + + private boolean shown; + + private final int VERTICAL_OFFSET = 20; + private final int HORIZONTAL_ENLARGE = 10; + + int fontHeight = 0; + + Image linkImage; + + FontMetrics fm; + + + + public Tooltip(String tip, Component owner) + { + this.owner = owner; + owner.addMouseListener(this); + owner.addMouseMotionListener(this); + setBackground(new Color(255, 255, 220)); + setTip(tip); + java.net.URL url = getClass().getResource("/images/link.gif"); + if (url != null) + { + linkImage = java.awt.Toolkit.getDefaultToolkit().getImage(url); + } + } + + + public void paint(Graphics g) + { + g.drawRect(0,0,getSize().width -1, getSize().height -1); + int lindex, x; + for(int i=0; i0) + { + g.drawString(tip[i].substring(0, lindex), 3, (i+1)*fontHeight-3); + x+=fm.stringWidth(tip[i].substring(0, lindex)+3); + } + g.drawImage(linkImage, x, i * fontHeight+1, this); + } + else + g.drawString(tip[i], 3, (i+1)*fontHeight - 3); + } + } + + private void addToolTip() + { + mainContainer.setLayout(null); + mainContainer.add(this, 0); + mainContainer.validate(); + repaint(); + shown = true; + } + + void setTip(String tip) + { + fm = getFontMetrics(owner.getFont()); + fontHeight = fm.getHeight(); + + int longestLine = 0; + StringTokenizer st = new StringTokenizer(tip, "\n"); + this.tip = new String[st.countTokens()]; + int index = 0; + while(st.hasMoreElements()) + { + this.tip[index] = st.nextToken(); + if(fm.stringWidth(this.tip[index])>longestLine) + longestLine = fm.stringWidth(this.tip[index]); + index ++; + } + + setSize(longestLine + HORIZONTAL_ENLARGE, + fontHeight*this.tip.length); + } + + void setTipLocation(int x, int y) + { + + setLocation((owner.getLocationOnScreen().x - mainContainer.getLocationOnScreen().x) +x, + (owner.getLocationOnScreen().y - mainContainer.getLocationOnScreen().y + VERTICAL_OFFSET)+y); + + + + // correction, whole tool tip must be visible + if (mainContainer.getSize().width < (getLocation().x + getSize().width)) + { + setLocation(mainContainer.getSize().width - getSize().width, + getLocation().y); + } + + } + + + private void removeToolTip() { + if (shown) { + mainContainer.remove(0); + mainContainer.setLayout(mainLayout); + mainContainer.validate(); + } + shown = false; + } + + private void findMainContainer() { + Container parent = owner.getParent(); + while (true) { + if ((parent instanceof Applet) || (parent instanceof Frame)) { + mainContainer = parent; + break; + } else { + parent = parent.getParent(); + } + } + mainLayout = mainContainer.getLayout(); + } + + public void mouseEntered(MouseEvent me) + { } + + public void mouseExited(MouseEvent me) + { + removeToolTip(); + } + + public void mousePressed(MouseEvent me) + { + removeToolTip(); + } + + public void mouseReleased(MouseEvent me) + {} + + public void mouseClicked(MouseEvent me) + {} + + public void mouseMoved(MouseEvent me) + { + if (shown) + setTipLocation(me.getX(), me.getY()); + else + { + findMainContainer(); + addToolTip(); + setTipLocation(me.getX(), me.getY()); + } + } + + public void mouseDragged(MouseEvent me) + {} +} diff --git a/src/jalview/datamodel/.cvsignore b/src/jalview/datamodel/.cvsignore new file mode 100644 index 0000000..a4d99ef --- /dev/null +++ b/src/jalview/datamodel/.cvsignore @@ -0,0 +1,5 @@ +.#Alignment.java.1.41 +.#Alignment.java.1.42 +.#Alignment.java.1.43 +.#Alignment.java.1.44 +.#AlignmentI.java.1.21 diff --git a/src/jalview/datamodel/AlignmentView.java b/src/jalview/datamodel/AlignmentView.java new file mode 100644 index 0000000..a76e90e --- /dev/null +++ b/src/jalview/datamodel/AlignmentView.java @@ -0,0 +1,434 @@ +/* + * 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; + + + +/** + *

Title:

+ * + *

Description:

+ * + *

Copyright: Copyright (c) 2004

+ * + *

Company: Dundee University

+ * + * @author not attributable + * @version 1.0 + */ +public class AlignmentView +{ + /** + * Transient object compactly representing a 'view' of an alignment - with discontinuities marked. + */ + private SeqCigar[] sequences = null; + private int[] contigs = null; + private int width=0; + public AlignmentView(CigarArray seqcigararray) + { + if (!seqcigararray.isSeqCigarArray()) + throw new Error("Implementation Error - can only make an alignment view from a CigarArray of sequences."); + //contigs = seqcigararray.applyDeletions(); + contigs = seqcigararray.getDeletedRegions(); + sequences = seqcigararray.getSeqCigarArray(); + width = seqcigararray.getWidth(); // visible width + } + + public void setSequences(SeqCigar[] sequences) + { + this.sequences = sequences; + } + + public void setContigs(int[] contigs) + { + this.contigs = contigs; + } + + public SeqCigar[] getSequences() + { + return sequences; + } + /** + * @see CigarArray.getDeletedRegions + * @return int[] { vis_start, sym_start, length } + */ + public int[] getContigs() + { + return contigs; + } + /** + * get the full alignment and a columnselection object marking the hidden regions + * @param gapCharacter char + * @return Object[] { SequenceI[], ColumnSelection} + */ + public Object[] getAlignmentAndColumnSelection(char gapCharacter) { + ColumnSelection colsel = new ColumnSelection(); + + return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel, contigs), colsel}; + } + /** + * getSequenceStrings + * + * @param c char + * @return String[] + */ + public String[] getSequenceStrings(char c) + { + String[] seqs=new String[sequences.length]; + for (int n=0; n 0) + { + int start = 0; + njobs = 0; + int fwidth = width; + for (int contig = 0; contig < contigs.length; contig += 3) + { + if ( (contigs[contig + 1] - start) > 0) + { + njobs++; + } + fwidth += contigs[contig + 2]; // end up with full region width (including hidden regions) + start = contigs[contig + 1] + contigs[contig + 2]; + } + if (start < fwidth) + { + njobs++; + } + smsa = new SequenceI[njobs][]; + start = 0; + int j = 0; + for (int contig = 0; contig < contigs.length; contig += 3) + { + if (contigs[contig + 1] - start > 0) + { + SequenceI mseq[] = new SequenceI[sequences.length]; + for (int s = 0; s < mseq.length; s++) + { + mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(start, + contigs[contig + 1]); + } + smsa[j] = mseq; + j++; + } + start = contigs[contig + 1] + contigs[contig + 2]; + } + if (start < fwidth) + { + SequenceI mseq[] = new SequenceI[sequences.length]; + for (int s = 0; s < mseq.length; s++) + { + mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(start, + fwidth + 1); + } + smsa[j] = mseq; + j++; + } + } + else + { + smsa = new SequenceI[1][]; + smsa[0] = new SequenceI[sequences.length]; + for (int s = 0; s < sequences.length; s++) + { + smsa[0][s] = sequences[s].getSeq(gapCharacter); + } + } + return smsa; + } + /** + * return full msa and hidden regions with visible blocks replaced with new sub alignments + * @param nvismsa SequenceI[][] + * @param orders AlignmentOrder[] corresponding to each SequenceI[] block. + * @return Object[] + */ + public Object[] getUpdatedView(SequenceI[][] nvismsa, AlignmentOrder[] orders, char gapCharacter) { + if (sequences == null || width <= 0) + { + throw new Error("empty view cannot be updated."); + } + if (nvismsa == null) + throw new Error( + "nvismsa==null. use getAlignmentAndColumnSelection() instead."); + if (contigs != null && contigs.length > 0) + { + SequenceI[] alignment = new SequenceI[sequences.length]; + ColumnSelection columnselection = new ColumnSelection(); + if (contigs != null && contigs.length > 0) + { + int start = 0; + int nwidth = 0; + int owidth = width; + int j = 0; + for (int contig = 0; contig < contigs.length; contig += 3) + { + owidth += contigs[contig + 2]; // recover final column width + if (contigs[contig + 1] - start > 0) + { + int swidth = 0; // subalignment width + if (nvismsa[j] != null) + { + SequenceI mseq[] = nvismsa[j]; + AlignmentOrder order=(orders==null) ? null : orders[j]; + j++; + if (mseq.length!=sequences.length) + throw new Error("Mismatch between number of sequences in block "+j+" ("+mseq.length+") and the original view ("+sequences.length+")"); + swidth = mseq[0].getLength(); // JBPNote: could ensure padded here. + for (int s = 0; s < mseq.length; s++) + { + if (alignment[s] == null) + { + alignment[s] = mseq[s]; + } + else + { + alignment[s].setSequence(alignment[s].getSequence() + + mseq[s].getSequence()); + if (mseq[s].getStart() <= mseq[s].getEnd()) + { + alignment[s].setEnd(mseq[s].getEnd()); + } + if (order!=null) { + order.updateSequence(mseq[s], alignment[s]); + } + } + } + } + else + { + // recover original alignment block or place gaps + if (true) + { + // recover input data + for (int s = 0; s < sequences.length; s++) + { + SequenceI oseq = sequences[s].getSeq(gapCharacter).getSubSequence(start, + contigs[contig + 1]); + if (swidth < oseq.getLength()) + { + swidth = oseq.getLength(); + } + if (alignment[s] == null) + { + alignment[s] = oseq; + } + else + { + alignment[s].setSequence(alignment[s].getSequence() + + oseq.getSequence()); + if (oseq.getEnd() >= oseq.getStart()) + { + alignment[s].setEnd(oseq.getEnd()); + } + } + } + + } + j++; + } + nwidth += swidth; + } + // advance to begining of visible region + start = contigs[contig + 1] + contigs[contig + 2]; + // add hidden segment to right of next region + for (int s = 0; s < sequences.length; s++) + { + SequenceI hseq = sequences[s].getSeq(gapCharacter).getSubSequence(contigs[contig + + 1], start); + if (alignment[s] == null) + { + alignment[s] = hseq; + } + else + { + alignment[s].setSequence(alignment[s].getSequence() + + hseq.getSequence()); + if (hseq.getEnd() >= hseq.getStart()) + { + alignment[s].setEnd(hseq.getEnd()); + } + } + } + // mark hidden segment as hidden in the new alignment + columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2] - 1); + nwidth += contigs[contig + 2]; + } + // Do final segment - if it exists + if (j < nvismsa.length) + { + int swidth = 0; + if (nvismsa[j] != null) + { + SequenceI mseq[] = nvismsa[j]; + AlignmentOrder order = (orders!=null) ? orders[j] : null; + swidth = mseq[0].getLength(); + for (int s = 0; s < mseq.length; s++) + { + if (alignment[s] == null) + { + alignment[s] = mseq[s]; + } + else + { + alignment[s].setSequence(alignment[s].getSequence() + + mseq[s].getSequence()); + if (mseq[s].getEnd() >= mseq[s].getStart()) + { + alignment[s].setEnd(mseq[s].getEnd()); + } + if (order!=null) { + order.updateSequence(mseq[s], alignment[s]); + } + } + } + } + else + { + if (start < owidth) + { + // recover input data or place gaps + if (true) + { + // recover input data + for (int s = 0; s < sequences.length; s++) + { + SequenceI oseq = sequences[s].getSeq(gapCharacter).getSubSequence(start, + owidth + 1); + if (swidth < oseq.getLength()) + { + swidth = oseq.getLength(); + } + if (alignment[s] == null) + { + alignment[s] = oseq; + } + else + { + alignment[s].setSequence(alignment[s].getSequence() + + oseq.getSequence()); + if (oseq.getEnd() >= oseq.getStart()) + { + alignment[s].setEnd(oseq.getEnd()); + } + } + } + nwidth += swidth; + } + else + { + // place gaps. + throw new Error("Padding not yet implemented."); + } + } + } + } + } + return new Object[] { alignment, columnselection}; + } else { + if (nvismsa.length!=1) + throw new Error("Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks="+nvismsa.length); + if (nvismsa[0]!=null) + return new Object[] { nvismsa[0], new ColumnSelection()}; + else + return getAlignmentAndColumnSelection(gapCharacter); + } + } + /** + * returns simple array of start end positions of visible range on alignment. + * vis_start and vis_end are inclusive - use SequenceI.getSubSequence(vis_start, vis_end+1) to recover visible sequence from underlying alignment. + * @return int[] { start_i, end_i } for 1 0) + { + int start = 0; + int nvis = 0; + int fwidth = width; + for (int contig = 0; contig < contigs.length; contig += 3) + { + if ( (contigs[contig + 1] - start) > 0) + { + nvis++; + } + fwidth += contigs[contig + 2]; // end up with full region width (including hidden regions) + start = contigs[contig + 1] + contigs[contig + 2]; + } + if (start < fwidth) + { + nvis++; + } + int viscontigs[] = new int[nvis*2]; + nvis=0; + start=0; + for (int contig=0; contig 0) + { + viscontigs[nvis] = start; + viscontigs[nvis+1]=contigs[contig+1]-1; // end is inclusive + nvis+=2; + } + start = contigs[contig + 1] + contigs[contig + 2]; + } + if (start 0) + { + refCigars = new CigarSimple[cigars.length]; + for (int c = 0; c < cigars.length; c++) + { + refCigars[c] = cigars[c]; + if (! ( (cigars[c] instanceof SeqCigar) + || cigars[c] instanceof CigarCigar)) + { + seqcigararray = false; + } + } + } + } + /** + * @see Cigar.getSequenceAndDeletions + * @param GapChar char + * @return Object[][] + */ + protected Object[][] getArrayofSequenceAndDeletions(char GapChar) { + if (refCigars == null || refCigars.length == 0 || length == 0) { + return null; + } + Object[][] sqanddels = new Object[refCigars.length][]; + for (int c=0; c