2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 import jalview.analysis.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import jalview.structure.StructureMapping;
33 * SequenceFeature group for PDB File features added to sequences
35 private static final String PDBFILEFEATURE = "PDBFile";
37 private static final String IEASTATUS = "IEA:jalview";
41 public Vector bonds = new Vector();
43 public Vector atoms = new Vector();
45 public Vector residues = new Vector();
49 public Sequence sequence;
51 public boolean isVisible = true;
53 public int pdbstart = 0;
55 public int pdbend = 0;
57 public int seqstart = 0;
59 public int seqend = 0;
61 public String pdbid = "";
63 public PDBChain(String pdbid, String id)
65 this.pdbid = pdbid.toLowerCase();
73 for (int i = 0; i < bonds.size(); i++)
75 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
76 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
83 public void makeExactMapping(AlignSeq as, SequenceI s1)
85 int pdbpos = as.getSeq2Start() - 2;
86 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
88 for (int i = 0; i < as.astr1.length(); i++)
90 if (as.astr1.charAt(i) != '-')
95 if (as.astr2.charAt(i) != '-')
100 if (as.astr1.charAt(i) == as.astr2.charAt(i))
102 Residue res = (Residue) residues.elementAt(pdbpos);
103 Enumeration en = res.atoms.elements();
104 while (en.hasMoreElements())
106 Atom atom = (Atom) en.nextElement();
107 atom.alignmentMapping = alignpos;
114 * copy over the RESNUM seqfeatures from the internal chain sequence to the
119 * The Status of the transferred annotation
120 * @return the features added to sq (or its dataset)
122 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
126 while (sq != null && sq.getDatasetSequence() != null)
128 sq = sq.getDatasetSequence();
135 * Remove any existing features for this chain if they exist ?
136 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
137 * totfeat=seqsfeatures.length; // Remove any features for this exact chain ?
138 * for (int i=0; i<seqsfeatures.length; i++) { }
142 status = PDBChain.IEASTATUS;
144 SequenceFeature[] features = sequence.getSequenceFeatures();
145 for (int i = 0; i < features.length; i++)
147 if (features[i].getFeatureGroup().equals(pdbid))
149 SequenceFeature tx = new SequenceFeature(features[i]);
150 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
151 - offset)).atoms.elementAt(0)).alignmentMapping);
152 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
153 - offset)).atoms.elementAt(0)).alignmentMapping);
156 + ((tx.getStatus() == null || tx.getStatus()
157 .length() == 0) ? "" : ":" + tx.getStatus()));
158 if (tx.begin != 0 && tx.end != 0)
159 sq.addSequenceFeature(tx);
165 public void makeCaBondList()
167 for (int i = 0; i < (residues.size() - 1); i++)
169 Residue tmpres = (Residue) residues.elementAt(i);
170 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
171 Atom at1 = tmpres.findAtom("CA");
172 Atom at2 = tmpres2.findAtom("CA");
174 if ((at1 != null) && (at2 != null))
176 if (at1.chain.equals(at2.chain))
183 System.out.println("not found " + i);
188 public void makeBond(Atom at1, Atom at2)
190 float[] start = new float[3];
191 float[] end = new float[3];
201 bonds.addElement(new Bond(start, end, at1, at2));
204 public void makeResidueList()
207 StringBuffer seq = new StringBuffer();
208 Vector resFeatures = new Vector();
209 Vector resAnnotation = new Vector();
210 int i, iSize = atoms.size() - 1;
212 for (i = 0; i <= iSize; i++)
214 Atom tmp = (Atom) atoms.elementAt(i);
215 resNumber = tmp.resNumber;
223 Vector resAtoms = new Vector();
224 // Add atoms to a vector while the residue number
225 // remains the same as the first atom's resNumber (res)
226 while ((resNumber == res) && (i < atoms.size()))
228 resAtoms.addElement((Atom) atoms.elementAt(i));
231 if (i < atoms.size())
233 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
241 // We need this to keep in step with the outer for i = loop
244 // Make a new Residue object with the new atoms vector
245 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
247 Residue tmpres = (Residue) residues.lastElement();
248 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
249 // Make A new SequenceFeature for the current residue numbering
250 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
251 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
252 + count, offset + count, pdbid);
254 // MCview.PDBChain.PDBFILEFEATURE);
255 resFeatures.addElement(sf);
256 resAnnotation.addElement(new Annotation(tmpat.tfactor));
257 // Keep totting up the sequence
258 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
261 // System.err.println("PDBReader:Null aa3Hash for " +
267 seq.append(ResidueProperties.aa[((Integer) ResidueProperties
268 .getAA3Hash().get(tmpat.resName)).intValue()]);
278 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
282 // System.out.println("PDB Sequence is :\nSequence = " + seq);
283 // System.out.println("No of residues = " + residues.size());
284 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
286 sequence.addSequenceFeature((SequenceFeature) resFeatures
288 resFeatures.setElementAt(null, i);
290 Annotation[] annots = new Annotation[resAnnotation.size()];
292 for (i = 0, iSize = annots.length; i < iSize; i++)
294 annots[i] = (Annotation) resAnnotation.elementAt(i);
295 if (annots[i].value > max)
296 max = annots[i].value;
297 resAnnotation.setElementAt(null, i);
299 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
300 "PDB.CATempFactor", "CA Temperature Factor for "
301 + sequence.getName(), annots, 0, max,
302 AlignmentAnnotation.LINE_GRAPH);
303 tfactorann.setSequenceRef(sequence);
304 sequence.addAlignmentAnnotation(tfactorann);
307 public void setChargeColours()
309 for (int i = 0; i < bonds.size(); i++)
313 Bond b = (Bond) bonds.elementAt(i);
315 if (b.at1.resName.equalsIgnoreCase("ASP")
316 || b.at1.resName.equalsIgnoreCase("GLU"))
318 b.startCol = Color.red;
320 else if (b.at1.resName.equalsIgnoreCase("LYS")
321 || b.at1.resName.equalsIgnoreCase("ARG"))
323 b.startCol = Color.blue;
325 else if (b.at1.resName.equalsIgnoreCase("CYS"))
327 b.startCol = Color.yellow;
331 b.startCol = Color.lightGray;
334 if (b.at2.resName.equalsIgnoreCase("ASP")
335 || b.at2.resName.equalsIgnoreCase("GLU"))
337 b.endCol = Color.red;
339 else if (b.at2.resName.equalsIgnoreCase("LYS")
340 || b.at2.resName.equalsIgnoreCase("ARG"))
342 b.endCol = Color.blue;
344 else if (b.at2.resName.equalsIgnoreCase("CYS"))
346 b.endCol = Color.yellow;
350 b.endCol = Color.lightGray;
352 } catch (Exception e)
354 Bond b = (Bond) bonds.elementAt(i);
355 b.startCol = Color.gray;
356 b.endCol = Color.gray;
361 public void setChainColours(jalview.schemes.ColourSchemeI cs)
365 for (int i = 0; i < bonds.size(); i++)
369 b = (Bond) bonds.elementAt(i);
371 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
373 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
375 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
377 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
379 } catch (Exception e)
381 b = (Bond) bonds.elementAt(i);
382 b.startCol = Color.gray;
383 b.endCol = Color.gray;
388 public void setChainColours(Color col)
390 for (int i = 0; i < bonds.size(); i++)
392 Bond tmp = (Bond) bonds.elementAt(i);
398 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
401 AlignmentAnnotation[] transferred = null;
408 * copy any sequence annotation onto the sequence mapped using the provided
413 public void transferResidueAnnotation(StructureMapping mapping)
415 SequenceI sq = mapping.getSequence();
418 if (sequence != null && sequence.getAnnotation() != null)
422 float min = -1, max = 0;
423 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
424 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
426 int prn = mapping.getPDBResNum(k + 1);
428 an[k] = new Annotation((float) prn);
447 .addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
448 "PDB Residue Numbering for " + this.pdbid + ":"
449 + this.id, an, (float) min, (float) max,
450 AlignmentAnnotation.LINE_GRAPH));