From: amwaterhouse Date: Mon, 28 Nov 2005 17:13:54 +0000 (+0000) Subject: Mapping for alignment added to residue X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=59349f26c3a53e4fb5da3ad1a506560124d62700;p=jalview.git Mapping for alignment added to residue --- diff --git a/src/MCview/Atom.java b/src/MCview/Atom.java index 6ae2baa..51c4f01 100755 --- a/src/MCview/Atom.java +++ b/src/MCview/Atom.java @@ -32,6 +32,7 @@ public class Atom { int type; Color color; String chain; + int alignmentMapping=-1; public boolean isSelected = false; diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index b3eb23f..4672271 100755 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -88,7 +88,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe int pdbend = 0; int seqstart = 0; int seqend = 0; - int [] mapping = null; + AlignSeq maxAlignseq = null;; for (int i = 0; i < pdb.chains.size(); i++) { @@ -126,7 +126,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe pdbend = as.seq2end; seqstart = as.seq1start + sequence.getStart()-1; seqend = as.seq1end + sequence.getEnd()-1; - mapping = as.getExactMapping(); + maxAlignseq = as; } mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); @@ -140,7 +140,8 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe mainchain.seqstart = seqstart; mainchain.seqend = seqend; mainchain.isVisible = true; - mainchain.seqMapping = mapping; + mainchain.makeExactMapping(maxAlignseq, sequence); + // mainchain.sequence = sequence; this.pdb = pdb; @@ -182,15 +183,6 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe } }); - /* - SequenceGroup sg = new SequenceGroup("PDB", - null, true,true,false, - sequence.findIndex(seqstart-1), - sequence.findIndex(seqend-1)); - sg.addSequence(sequence, false); - sg.setOutlineColour(Color.black); - seqcanvas.getViewport().getAlignment().addGroup(sg); - */ findCentre(); findWidth(); @@ -206,6 +198,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe ToolTipManager.sharedInstance().setDismissDelay(10000); } + Vector visiblebonds; void setupBonds() { @@ -463,6 +456,35 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe 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) @@ -477,34 +499,30 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1))) { - - int pos = // chain.seqstart + Don't include seqstart here, start from 0 - (tmp.at1.resNumber - chain.pdbstart - chain.offset)+1; - - int index = chain.seqMapping[pos]; + int index = findTrueIndex(tmp.at1.alignmentMapping); + //sequence.findIndex(tmp.at1.alignmentMapping); if (index != -1) { - tmp.startCol = seqcanvas.getSequenceRenderer().findSequenceColour( - Color.lightGray, sequence, index); + tmp.startCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour( sequence, index); - tmp.startCol = seqcanvas.getFeatureRenderer().findFeatureColour(tmp. - startCol, sequence, index); + tmp.startCol = seqcanvas.getFeatureRenderer(). + findFeatureColour(tmp.startCol, sequence, index); } } if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1))) { - int pos = // chain.seqstart + Don't include seqstart here, start from 0 - (tmp.at2.resNumber - chain.pdbstart - chain.offset)+1; - int index = chain.seqMapping[pos]; + int index = findTrueIndex(tmp.at2.alignmentMapping); + //sequence.findIndex( tmp.at2.alignmentMapping ); if (index != -1) { - tmp.endCol = seqcanvas.getSequenceRenderer().findSequenceColour( - tmp.endCol, sequence, index); - tmp.endCol = seqcanvas.getFeatureRenderer().findFeatureColour(tmp. - endCol, sequence, index); + tmp.endCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour( sequence, index); + tmp.endCol = seqcanvas.getFeatureRenderer(). + findFeatureColour(tmp.endCol, sequence, index); } } } @@ -652,18 +670,15 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); if (chain == mainchain) { - int pos = // chain.seqstart + Don't include seqstart here, start from 0 - (fatom.resNumber - chain.pdbstart - chain.offset) +1 ; - - if (chain.seqMapping[pos] != -1) + if (fatom.alignmentMapping != -1) { if (highlightRes == null) highlightRes = new Vector(); - if (highlightRes.contains((chain.seqMapping[pos]) + "")) - highlightRes.remove((chain.seqMapping[pos]) + ""); + if (highlightRes.contains(fatom.alignmentMapping+"" + "")) + highlightRes.remove(fatom.alignmentMapping + ""); else - highlightRes.add((chain.seqMapping[pos]) + ""); + highlightRes.add(fatom.alignmentMapping + ""); } } } @@ -695,10 +710,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe chain = (PDBChain) pdb.chains.elementAt(foundchain); if(chain == mainchain) { - int pos = // chain.seqstart + Don't include seqstart here, start from 0 - (fatom.resNumber - chain.pdbstart - chain.offset) +1 ; - - highlightSeqcanvas( chain.seqMapping[pos] ); + highlightSeqcanvas( fatom.alignmentMapping ); } } @@ -928,42 +940,41 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe public void highlightRes(int ii) { - int index = ii - mainchain.seqstart; - - if (highlightRes!=null - && highlightRes.contains( mainchain.seqMapping[index]+ "")) + if (highlightRes != null + && highlightRes.contains((ii-1) + "")) { - return; + return; } - if(highlightBond1!=null) - highlightBond1.at2.isSelected = false; - - if(highlightBond2!=null) - highlightBond2.at1.isSelected = false; - - highlightBond1 = null; - highlightBond2 = null; + 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()) - { - if(index>0) - { - highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); - highlightBond1.at2.isSelected = true; - // highlightBond1.at2.isSelected = true; - } + if (index != mainchain.bonds.size()) + { + highlightBond2 = (Bond) mainchain.bonds.elementAt(index); + highlightBond2.at1.isSelected = true; + } - if(index!=mainchain.bonds.size()) - { - highlightBond2 = (Bond) mainchain.bonds.elementAt(index); - highlightBond2.at1.isSelected = true; - // highlightBond2.at2.isSelected = true; + break; } } diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java index 3cf73d1..276525b 100755 --- a/src/MCview/PDBChain.java +++ b/src/MCview/PDBChain.java @@ -25,6 +25,7 @@ import jalview.schemes.ResidueProperties; import java.awt.*; import java.util.*; +import jalview.analysis.AlignSeq; public class PDBChain { @@ -39,7 +40,6 @@ public class PDBChain { public int pdbend = 0; public int seqstart = 0; public int seqend = 0; - public int [] seqMapping; //public DrawableSequence ds; public PDBChain(String id) { @@ -58,6 +58,38 @@ public class PDBChain { 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