2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
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 isVisible = true;
52 public int pdbstart = 0;
54 public int pdbend = 0;
56 public int seqstart = 0;
58 public int seqend = 0;
60 public String pdbid = "";
62 public PDBChain(String pdbid, String id)
64 this.pdbid = pdbid.toLowerCase();
72 for (int i = 0; i < bonds.size(); i++)
74 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
75 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
82 public void makeExactMapping(AlignSeq as, SequenceI s1)
84 int pdbpos = as.getSeq2Start() - 2;
85 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
87 for (int i = 0; i < as.astr1.length(); i++)
89 if (as.astr1.charAt(i) != '-')
94 if (as.astr2.charAt(i) != '-')
99 if (as.astr1.charAt(i) == as.astr2.charAt(i))
101 Residue res = (Residue) residues.elementAt(pdbpos);
102 Enumeration en = res.atoms.elements();
103 while (en.hasMoreElements())
105 Atom atom = (Atom) en.nextElement();
106 atom.alignmentMapping = alignpos;
113 * copy over the RESNUM seqfeatures from the internal chain sequence to the
118 * The Status of the transferred annotation
119 * @return the features added to sq (or its dataset)
121 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
125 while (sq != null && sq.getDatasetSequence() != null)
127 sq = sq.getDatasetSequence();
134 * Remove any existing features for this chain if they exist ?
135 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
136 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
137 * ? for (int i=0; i<seqsfeatures.length; i++) { }
141 status = PDBChain.IEASTATUS;
143 SequenceFeature[] features = sequence.getSequenceFeatures();
144 for (int i = 0; i < features.length; i++)
146 if (features[i].getFeatureGroup().equals(pdbid))
148 SequenceFeature tx = new SequenceFeature(features[i]);
149 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
150 - offset)).atoms.elementAt(0)).alignmentMapping);
151 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
152 - offset)).atoms.elementAt(0)).alignmentMapping);
155 + ((tx.getStatus() == null || tx.getStatus()
156 .length() == 0) ? "" : ":" + tx.getStatus()));
157 if (tx.begin != 0 && tx.end != 0)
158 sq.addSequenceFeature(tx);
164 public void makeCaBondList()
166 for (int i = 0; i < (residues.size() - 1); i++)
168 Residue tmpres = (Residue) residues.elementAt(i);
169 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
170 Atom at1 = tmpres.findAtom("CA");
171 Atom at2 = tmpres2.findAtom("CA");
173 if ((at1 != null) && (at2 != null))
175 if (at1.chain.equals(at2.chain))
182 System.out.println("not found " + i);
187 public void makeBond(Atom at1, Atom at2)
189 float[] start = new float[3];
190 float[] end = new float[3];
200 bonds.addElement(new Bond(start, end, at1, at2));
203 public void makeResidueList()
207 boolean nucleotide = false;
208 StringBuffer seq = new StringBuffer();
209 Vector resFeatures = new Vector();
210 Vector resAnnotation = new Vector();
211 int i, iSize = atoms.size() - 1;
213 for (i = 0; i <= iSize; i++)
215 Atom tmp = (Atom) atoms.elementAt(i);
216 resNumber = tmp.resNumber;
224 Vector resAtoms = new Vector();
225 // Add atoms to a vector while the residue number
226 // remains the same as the first atom's resNumber (res)
227 while ((resNumber == res) && (i < atoms.size()))
229 resAtoms.addElement((Atom) atoms.elementAt(i));
232 if (i < atoms.size())
234 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
242 // We need this to keep in step with the outer for i = loop
245 // Make a new Residue object with the new atoms vector
246 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
248 Residue tmpres = (Residue) residues.lastElement();
249 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
250 // Make A new SequenceFeature for the current residue numbering
251 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
252 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
253 + 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 ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
260 if (ResidueProperties.nucleotideIndex[tmpat.resName.charAt(0)] == -1)
263 // System.err.println("PDBReader:Null aa3Hash for " +
270 seq.append(tmpat.resName.charAt(0));
278 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
280 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
290 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
294 // Add normalised feature scores to RESNUM indicating start/end of sequence
295 // sf.setScore(offset+count);
297 // System.out.println("PDB Sequence is :\nSequence = " + seq);
298 // System.out.println("No of residues = " + residues.size());
299 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
301 sequence.addSequenceFeature((SequenceFeature) resFeatures
303 resFeatures.setElementAt(null, i);
305 Annotation[] annots = new Annotation[resAnnotation.size()];
307 for (i = 0, iSize = annots.length; i < iSize; i++)
309 annots[i] = (Annotation) resAnnotation.elementAt(i);
310 if (annots[i].value > max)
311 max = annots[i].value;
312 resAnnotation.setElementAt(null, i);
314 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
315 "PDB.TempFactor", "Temperature Factor for "
316 + sequence.getName(), annots, 0, max,
317 AlignmentAnnotation.LINE_GRAPH);
318 tfactorann.setSequenceRef(sequence);
319 sequence.addAlignmentAnnotation(tfactorann);
322 public void setChargeColours()
324 for (int i = 0; i < bonds.size(); i++)
328 Bond b = (Bond) bonds.elementAt(i);
330 if (b.at1.resName.equalsIgnoreCase("ASP")
331 || b.at1.resName.equalsIgnoreCase("GLU"))
333 b.startCol = Color.red;
335 else if (b.at1.resName.equalsIgnoreCase("LYS")
336 || b.at1.resName.equalsIgnoreCase("ARG"))
338 b.startCol = Color.blue;
340 else if (b.at1.resName.equalsIgnoreCase("CYS"))
342 b.startCol = Color.yellow;
346 b.startCol = Color.lightGray;
349 if (b.at2.resName.equalsIgnoreCase("ASP")
350 || b.at2.resName.equalsIgnoreCase("GLU"))
352 b.endCol = Color.red;
354 else if (b.at2.resName.equalsIgnoreCase("LYS")
355 || b.at2.resName.equalsIgnoreCase("ARG"))
357 b.endCol = Color.blue;
359 else if (b.at2.resName.equalsIgnoreCase("CYS"))
361 b.endCol = Color.yellow;
365 b.endCol = Color.lightGray;
367 } catch (Exception e)
369 Bond b = (Bond) bonds.elementAt(i);
370 b.startCol = Color.gray;
371 b.endCol = Color.gray;
376 public void setChainColours(jalview.schemes.ColourSchemeI cs)
380 for (int i = 0; i < bonds.size(); i++)
384 b = (Bond) bonds.elementAt(i);
386 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
388 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
390 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
392 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
394 } catch (Exception e)
396 b = (Bond) bonds.elementAt(i);
397 b.startCol = Color.gray;
398 b.endCol = Color.gray;
403 public void setChainColours(Color col)
405 for (int i = 0; i < bonds.size(); i++)
407 Bond tmp = (Bond) bonds.elementAt(i);
413 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
416 AlignmentAnnotation[] transferred = null;
423 * copy any sequence annotation onto the sequence mapped using the provided
428 public void transferResidueAnnotation(StructureMapping mapping)
430 SequenceI sq = mapping.getSequence();
433 if (sequence != null && sequence.getAnnotation() != null)
437 float min = -1, max = 0;
438 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
439 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
441 int prn = mapping.getPDBResNum(k + 1);
443 an[k] = new Annotation((float) prn);
462 .addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
463 "PDB Residue Numbering for " + this.pdbid + ":"
464 + this.id, an, (float) min, (float) max,
465 AlignmentAnnotation.LINE_GRAPH));