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();
70 * character used to write newlines
72 protected String newline = System.getProperty("line.separator");
73 public void setNewlineString(String nl)
77 public String getNewlineString()
85 for (int i = 0; i < bonds.size(); i++)
87 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
88 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
95 public void makeExactMapping(AlignSeq as, SequenceI s1)
97 int pdbpos = as.getSeq2Start() - 2;
98 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
100 for (int i = 0; i < as.astr1.length(); i++)
102 if (as.astr1.charAt(i) != '-')
107 if (as.astr2.charAt(i) != '-')
112 if (as.astr1.charAt(i) == as.astr2.charAt(i))
114 Residue res = (Residue) residues.elementAt(pdbpos);
115 Enumeration en = res.atoms.elements();
116 while (en.hasMoreElements())
118 Atom atom = (Atom) en.nextElement();
119 atom.alignmentMapping = alignpos;
126 * copy over the RESNUM seqfeatures from the internal chain sequence to the
131 * The Status of the transferred annotation
132 * @return the features added to sq (or its dataset)
134 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
138 while (sq != null && sq.getDatasetSequence() != null)
140 sq = sq.getDatasetSequence();
147 * Remove any existing features for this chain if they exist ?
148 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
149 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
150 * ? for (int i=0; i<seqsfeatures.length; i++) { }
154 status = PDBChain.IEASTATUS;
156 SequenceFeature[] features = sequence.getSequenceFeatures();
157 for (int i = 0; i < features.length; i++)
159 if (features[i].getFeatureGroup().equals(pdbid))
161 SequenceFeature tx = new SequenceFeature(features[i]);
162 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
163 - offset)).atoms.elementAt(0)).alignmentMapping);
164 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
165 - offset)).atoms.elementAt(0)).alignmentMapping);
167 + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? ""
168 : ":" + tx.getStatus()));
169 if (tx.begin != 0 && tx.end != 0)
170 sq.addSequenceFeature(tx);
176 public void makeCaBondList()
180 for (int i = 0; i < (residues.size() - 1); i++)
182 Residue tmpres = (Residue) residues.elementAt(i);
183 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
184 Atom at1 = tmpres.findAtom("CA");
185 Atom at2 = tmpres2.findAtom("CA");
187 if ((at1 == null) && (at2 == null))
190 at1 = tmpres.findAtom("P");
191 at2 = tmpres2.findAtom("P");
193 if ((at1 != null) && (at2 != null))
195 if (at1.chain.equals(at2.chain))
206 System.out.println("not found " + i);
209 if (numNa > 0 && ((numNa / residues.size()) > 0.99))
215 public void makeBond(Atom at1, Atom at2)
217 float[] start = new float[3];
218 float[] end = new float[3];
228 bonds.addElement(new Bond(start, end, at1, at2));
231 public void makeResidueList()
235 boolean nucleotide = false;
236 StringBuffer seq = new StringBuffer();
237 Vector resFeatures = new Vector();
238 Vector resAnnotation = new Vector();
239 int i, iSize = atoms.size() - 1;
241 for (i = 0; i <= iSize; i++)
243 Atom tmp = (Atom) atoms.elementAt(i);
244 resNumber = tmp.resNumber;
252 Vector resAtoms = new Vector();
253 // Add atoms to a vector while the residue number
254 // remains the same as the first atom's resNumber (res)
255 while ((resNumber == res) && (i < atoms.size()))
257 resAtoms.addElement((Atom) atoms.elementAt(i));
260 if (i < atoms.size())
262 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
270 // We need this to keep in step with the outer for i = loop
273 // Make a new Residue object with the new atoms vector
274 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
276 Residue tmpres = (Residue) residues.lastElement();
277 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
278 // Make A new SequenceFeature for the current residue numbering
279 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
280 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
281 + count, offset + count, pdbid);
282 // MCview.PDBChain.PDBFILEFEATURE);
283 resFeatures.addElement(sf);
284 resAnnotation.addElement(new Annotation(tmpat.tfactor));
285 // Keep totting up the sequence
286 if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
288 String nucname = tmpat.resName.trim();
289 if (tmpat.name.equalsIgnoreCase("CA") || ResidueProperties.nucleotideIndex[nucname.charAt(0)] == -1)
292 // System.err.println("PDBReader:Null aa3Hash for " +
299 seq.append(nucname.charAt(0));
307 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
309 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
319 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
323 // Add normalised feature scores to RESNUM indicating start/end of sequence
324 // sf.setScore(offset+count);
326 // System.out.println("PDB Sequence is :\nSequence = " + seq);
327 // System.out.println("No of residues = " + residues.size());
328 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
330 sequence.addSequenceFeature((SequenceFeature) resFeatures
332 resFeatures.setElementAt(null, i);
334 Annotation[] annots = new Annotation[resAnnotation.size()];
336 for (i = 0, iSize = annots.length; i < iSize; i++)
338 annots[i] = (Annotation) resAnnotation.elementAt(i);
339 if (annots[i].value > max)
340 max = annots[i].value;
341 resAnnotation.setElementAt(null, i);
343 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
344 "PDB.TempFactor", "Temperature Factor for "
345 + sequence.getName(), annots, 0, max,
346 AlignmentAnnotation.LINE_GRAPH);
347 tfactorann.setSequenceRef(sequence);
348 sequence.addAlignmentAnnotation(tfactorann);
351 public void setChargeColours()
353 for (int i = 0; i < bonds.size(); i++)
357 Bond b = (Bond) bonds.elementAt(i);
359 if (b.at1.resName.equalsIgnoreCase("ASP")
360 || b.at1.resName.equalsIgnoreCase("GLU"))
362 b.startCol = Color.red;
364 else if (b.at1.resName.equalsIgnoreCase("LYS")
365 || b.at1.resName.equalsIgnoreCase("ARG"))
367 b.startCol = Color.blue;
369 else if (b.at1.resName.equalsIgnoreCase("CYS"))
371 b.startCol = Color.yellow;
375 b.startCol = Color.lightGray;
378 if (b.at2.resName.equalsIgnoreCase("ASP")
379 || b.at2.resName.equalsIgnoreCase("GLU"))
381 b.endCol = Color.red;
383 else if (b.at2.resName.equalsIgnoreCase("LYS")
384 || b.at2.resName.equalsIgnoreCase("ARG"))
386 b.endCol = Color.blue;
388 else if (b.at2.resName.equalsIgnoreCase("CYS"))
390 b.endCol = Color.yellow;
394 b.endCol = Color.lightGray;
396 } catch (Exception e)
398 Bond b = (Bond) bonds.elementAt(i);
399 b.startCol = Color.gray;
400 b.endCol = Color.gray;
405 public void setChainColours(jalview.schemes.ColourSchemeI cs)
409 for (int i = 0; i < bonds.size(); i++)
413 b = (Bond) bonds.elementAt(i);
415 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
417 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
419 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
421 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
423 } catch (Exception e)
425 b = (Bond) bonds.elementAt(i);
426 b.startCol = Color.gray;
427 b.endCol = Color.gray;
432 public void setChainColours(Color col)
434 for (int i = 0; i < bonds.size(); i++)
436 Bond tmp = (Bond) bonds.elementAt(i);
442 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
445 AlignmentAnnotation[] transferred = null;
452 * copy any sequence annotation onto the sequence mapped using the provided
457 public void transferResidueAnnotation(StructureMapping mapping)
459 SequenceI sq = mapping.getSequence();
462 if (sequence != null && sequence.getAnnotation() != null)
466 float min = -1, max = 0;
467 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
468 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
470 int prn = mapping.getPDBResNum(k + 1);
472 an[k] = new Annotation((float) prn);
490 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
491 "PDB Residue Numbering for " + this.pdbid + ":" + this.id,
492 an, (float) min, (float) max, AlignmentAnnotation.LINE_GRAPH));