2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
24 import jalview.analysis.*;
25 import jalview.datamodel.*;
26 import jalview.schemes.*;
27 import jalview.structure.StructureMapping;
32 * SequenceFeature group for PDB File features added to sequences
34 private static final String PDBFILEFEATURE = "PDBFile";
36 private static final String IEASTATUS = "IEA:jalview";
40 public Vector bonds = new Vector();
42 public Vector atoms = new Vector();
44 public Vector residues = new Vector();
48 public Sequence sequence;
50 public boolean isNa = false;
52 public boolean isVisible = true;
54 public int pdbstart = 0;
56 public int pdbend = 0;
58 public int seqstart = 0;
60 public int seqend = 0;
62 public String pdbid = "";
64 public PDBChain(String pdbid, String id)
66 this.pdbid = pdbid.toLowerCase();
74 for (int i = 0; i < bonds.size(); i++)
76 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
77 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
84 public void makeExactMapping(AlignSeq as, SequenceI s1)
86 int pdbpos = as.getSeq2Start() - 2;
87 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
89 for (int i = 0; i < as.astr1.length(); i++)
91 if (as.astr1.charAt(i) != '-')
96 if (as.astr2.charAt(i) != '-')
101 if (as.astr1.charAt(i) == as.astr2.charAt(i))
103 Residue res = (Residue) residues.elementAt(pdbpos);
104 Enumeration en = res.atoms.elements();
105 while (en.hasMoreElements())
107 Atom atom = (Atom) en.nextElement();
108 atom.alignmentMapping = alignpos;
115 * copy over the RESNUM seqfeatures from the internal chain sequence to the
120 * The Status of the transferred annotation
121 * @return the features added to sq (or its dataset)
123 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
127 while (sq != null && sq.getDatasetSequence() != null)
129 sq = sq.getDatasetSequence();
136 * Remove any existing features for this chain if they exist ?
137 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
138 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
139 * ? for (int i=0; i<seqsfeatures.length; i++) { }
143 status = PDBChain.IEASTATUS;
145 SequenceFeature[] features = sequence.getSequenceFeatures();
146 for (int i = 0; i < features.length; i++)
148 if (features[i].getFeatureGroup().equals(pdbid))
150 SequenceFeature tx = new SequenceFeature(features[i]);
151 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
152 - offset)).atoms.elementAt(0)).alignmentMapping);
153 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
154 - offset)).atoms.elementAt(0)).alignmentMapping);
156 + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? ""
157 : ":" + tx.getStatus()));
158 if (tx.begin != 0 && tx.end != 0)
159 sq.addSequenceFeature(tx);
165 public void makeCaBondList()
169 for (int i = 0; i < (residues.size() - 1); i++)
171 Residue tmpres = (Residue) residues.elementAt(i);
172 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
173 Atom at1 = tmpres.findAtom("CA");
174 Atom at2 = tmpres2.findAtom("CA");
176 if ((at1 == null) && (at2 == null))
179 at1 = tmpres.findAtom("P");
180 at2 = tmpres2.findAtom("P");
182 if ((at1 != null) && (at2 != null))
184 if (at1.chain.equals(at2.chain))
195 System.out.println("not found " + i);
198 if (numNa > 0 && ((numNa / residues.size()) > 0.99))
204 public void makeBond(Atom at1, Atom at2)
206 float[] start = new float[3];
207 float[] end = new float[3];
217 bonds.addElement(new Bond(start, end, at1, at2));
220 public void makeResidueList()
224 boolean nucleotide = false;
225 StringBuffer seq = new StringBuffer();
226 Vector resFeatures = new Vector();
227 Vector resAnnotation = new Vector();
228 int i, iSize = atoms.size() - 1;
230 for (i = 0; i <= iSize; i++)
232 Atom tmp = (Atom) atoms.elementAt(i);
233 resNumber = tmp.resNumber;
241 Vector resAtoms = new Vector();
242 // Add atoms to a vector while the residue number
243 // remains the same as the first atom's resNumber (res)
244 while ((resNumber == res) && (i < atoms.size()))
246 resAtoms.addElement((Atom) atoms.elementAt(i));
249 if (i < atoms.size())
251 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
259 // We need this to keep in step with the outer for i = loop
262 // Make a new Residue object with the new atoms vector
263 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
265 Residue tmpres = (Residue) residues.lastElement();
266 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
267 // Make A new SequenceFeature for the current residue numbering
268 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
269 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
270 + count, offset + count, pdbid);
271 // MCview.PDBChain.PDBFILEFEATURE);
272 resFeatures.addElement(sf);
273 resAnnotation.addElement(new Annotation(tmpat.tfactor));
274 // Keep totting up the sequence
275 if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
277 String nucname = tmpat.resName.trim();
278 if (tmpat.name.equalsIgnoreCase("CA") || ResidueProperties.nucleotideIndex[nucname.charAt(0)] == -1)
281 // System.err.println("PDBReader:Null aa3Hash for " +
288 seq.append(nucname.charAt(0));
296 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
298 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
308 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
312 // Add normalised feature scores to RESNUM indicating start/end of sequence
313 // sf.setScore(offset+count);
315 // System.out.println("PDB Sequence is :\nSequence = " + seq);
316 // System.out.println("No of residues = " + residues.size());
317 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
319 sequence.addSequenceFeature((SequenceFeature) resFeatures
321 resFeatures.setElementAt(null, i);
323 Annotation[] annots = new Annotation[resAnnotation.size()];
325 for (i = 0, iSize = annots.length; i < iSize; i++)
327 annots[i] = (Annotation) resAnnotation.elementAt(i);
328 if (annots[i].value > max)
329 max = annots[i].value;
330 resAnnotation.setElementAt(null, i);
332 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
333 "PDB.TempFactor", "Temperature Factor for "
334 + sequence.getName(), annots, 0, max,
335 AlignmentAnnotation.LINE_GRAPH);
336 tfactorann.setSequenceRef(sequence);
337 sequence.addAlignmentAnnotation(tfactorann);
340 public void setChargeColours()
342 for (int i = 0; i < bonds.size(); i++)
346 Bond b = (Bond) bonds.elementAt(i);
348 if (b.at1.resName.equalsIgnoreCase("ASP")
349 || b.at1.resName.equalsIgnoreCase("GLU"))
351 b.startCol = Color.red;
353 else if (b.at1.resName.equalsIgnoreCase("LYS")
354 || b.at1.resName.equalsIgnoreCase("ARG"))
356 b.startCol = Color.blue;
358 else if (b.at1.resName.equalsIgnoreCase("CYS"))
360 b.startCol = Color.yellow;
364 b.startCol = Color.lightGray;
367 if (b.at2.resName.equalsIgnoreCase("ASP")
368 || b.at2.resName.equalsIgnoreCase("GLU"))
370 b.endCol = Color.red;
372 else if (b.at2.resName.equalsIgnoreCase("LYS")
373 || b.at2.resName.equalsIgnoreCase("ARG"))
375 b.endCol = Color.blue;
377 else if (b.at2.resName.equalsIgnoreCase("CYS"))
379 b.endCol = Color.yellow;
383 b.endCol = Color.lightGray;
385 } catch (Exception e)
387 Bond b = (Bond) bonds.elementAt(i);
388 b.startCol = Color.gray;
389 b.endCol = Color.gray;
394 public void setChainColours(jalview.schemes.ColourSchemeI cs)
398 for (int i = 0; i < bonds.size(); i++)
402 b = (Bond) bonds.elementAt(i);
404 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
406 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
408 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
410 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
412 } catch (Exception e)
414 b = (Bond) bonds.elementAt(i);
415 b.startCol = Color.gray;
416 b.endCol = Color.gray;
421 public void setChainColours(Color col)
423 for (int i = 0; i < bonds.size(); i++)
425 Bond tmp = (Bond) bonds.elementAt(i);
431 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
434 AlignmentAnnotation[] transferred = null;
441 * copy any sequence annotation onto the sequence mapped using the provided
446 public void transferResidueAnnotation(StructureMapping mapping)
448 SequenceI sq = mapping.getSequence();
451 if (sequence != null && sequence.getAnnotation() != null)
455 float min = -1, max = 0;
456 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
457 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
459 int prn = mapping.getPDBResNum(k + 1);
461 an[k] = new Annotation((float) prn);
479 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
480 "PDB Residue Numbering for " + this.pdbid + ":" + this.id,
481 an, (float) min, (float) max, AlignmentAnnotation.LINE_GRAPH));