2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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()
208 boolean nucleotide=false;
209 StringBuffer seq = new StringBuffer();
210 Vector resFeatures = new Vector();
211 Vector resAnnotation = new Vector();
212 int i, iSize = atoms.size() - 1;
214 for (i = 0; i <= iSize; i++)
216 Atom tmp = (Atom) atoms.elementAt(i);
217 resNumber = tmp.resNumber;
225 Vector resAtoms = new Vector();
226 // Add atoms to a vector while the residue number
227 // remains the same as the first atom's resNumber (res)
228 while ((resNumber == res) && (i < atoms.size()))
230 resAtoms.addElement((Atom) atoms.elementAt(i));
233 if (i < atoms.size())
235 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
243 // We need this to keep in step with the outer for i = loop
246 // Make a new Residue object with the new atoms vector
247 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
249 Residue tmpres = (Residue) residues.lastElement();
250 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
251 // Make A new SequenceFeature for the current residue numbering
252 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
253 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
254 + count, offset + count, pdbid);
255 // MCview.PDBChain.PDBFILEFEATURE);
256 resFeatures.addElement(sf);
257 resAnnotation.addElement(new Annotation(tmpat.tfactor));
258 // Keep totting up the sequence
259 if ((symbol=ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
261 if (ResidueProperties.nucleotideIndex[tmpat.resName.charAt(0)]==-1)
264 // System.err.println("PDBReader:Null aa3Hash for " +
269 seq.append(tmpat.resName.charAt(0));
276 System.err.println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
278 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
288 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
292 // Add normalised feature scores to RESNUM indicating start/end of sequence
293 // sf.setScore(offset+count);
296 // System.out.println("PDB Sequence is :\nSequence = " + seq);
297 // System.out.println("No of residues = " + residues.size());
298 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
300 sequence.addSequenceFeature((SequenceFeature) resFeatures
302 resFeatures.setElementAt(null, i);
304 Annotation[] annots = new Annotation[resAnnotation.size()];
306 for (i = 0, iSize = annots.length; i < iSize; i++)
308 annots[i] = (Annotation) resAnnotation.elementAt(i);
309 if (annots[i].value > max)
310 max = annots[i].value;
311 resAnnotation.setElementAt(null, i);
313 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
314 "PDB.TempFactor", "Temperature Factor for "
315 + sequence.getName(), annots, 0, max,
316 AlignmentAnnotation.LINE_GRAPH);
317 tfactorann.setSequenceRef(sequence);
318 sequence.addAlignmentAnnotation(tfactorann);
321 public void setChargeColours()
323 for (int i = 0; i < bonds.size(); i++)
327 Bond b = (Bond) bonds.elementAt(i);
329 if (b.at1.resName.equalsIgnoreCase("ASP")
330 || b.at1.resName.equalsIgnoreCase("GLU"))
332 b.startCol = Color.red;
334 else if (b.at1.resName.equalsIgnoreCase("LYS")
335 || b.at1.resName.equalsIgnoreCase("ARG"))
337 b.startCol = Color.blue;
339 else if (b.at1.resName.equalsIgnoreCase("CYS"))
341 b.startCol = Color.yellow;
345 b.startCol = Color.lightGray;
348 if (b.at2.resName.equalsIgnoreCase("ASP")
349 || b.at2.resName.equalsIgnoreCase("GLU"))
351 b.endCol = Color.red;
353 else if (b.at2.resName.equalsIgnoreCase("LYS")
354 || b.at2.resName.equalsIgnoreCase("ARG"))
356 b.endCol = Color.blue;
358 else if (b.at2.resName.equalsIgnoreCase("CYS"))
360 b.endCol = Color.yellow;
364 b.endCol = Color.lightGray;
366 } catch (Exception e)
368 Bond b = (Bond) bonds.elementAt(i);
369 b.startCol = Color.gray;
370 b.endCol = Color.gray;
375 public void setChainColours(jalview.schemes.ColourSchemeI cs)
379 for (int i = 0; i < bonds.size(); i++)
383 b = (Bond) bonds.elementAt(i);
385 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
387 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
389 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
391 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
393 } catch (Exception e)
395 b = (Bond) bonds.elementAt(i);
396 b.startCol = Color.gray;
397 b.endCol = Color.gray;
402 public void setChainColours(Color col)
404 for (int i = 0; i < bonds.size(); i++)
406 Bond tmp = (Bond) bonds.elementAt(i);
412 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
415 AlignmentAnnotation[] transferred = null;
422 * copy any sequence annotation onto the sequence mapped using the provided
427 public void transferResidueAnnotation(StructureMapping mapping)
429 SequenceI sq = mapping.getSequence();
432 if (sequence != null && sequence.getAnnotation() != null)
436 float min = -1, max = 0;
437 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
438 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
440 int prn = mapping.getPDBResNum(k + 1);
442 an[k] = new Annotation((float) prn);
461 .addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
462 "PDB Residue Numbering for " + this.pdbid + ":"
463 + this.id, an, (float) min, (float) max,
464 AlignmentAnnotation.LINE_GRAPH));