2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignSeq;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.Annotation;
26 import jalview.datamodel.Sequence;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.SequenceI;
29 import jalview.schemes.ResidueProperties;
30 import jalview.structure.StructureMapping;
32 import java.awt.Color;
33 import java.util.Enumeration;
34 import java.util.List;
35 import java.util.Vector;
40 * SequenceFeature group for PDB File features added to sequences
42 private static final String PDBFILEFEATURE = "PDBFile";
44 private static final String IEASTATUS = "IEA:jalview";
48 public Vector bonds = new Vector();
50 public Vector atoms = new Vector();
52 public Vector residues = new Vector();
56 public Sequence sequence;
58 public boolean isNa = false;
60 public boolean isVisible = true;
62 public int pdbstart = 0;
64 public int pdbend = 0;
66 public int seqstart = 0;
68 public int seqend = 0;
70 public String pdbid = "";
72 public PDBChain(String pdbid, String id)
74 this.pdbid = pdbid.toLowerCase();
79 * character used to write newlines
81 protected String newline = System.getProperty("line.separator");
83 public void setNewlineString(String nl)
88 public String getNewlineString()
97 for (int i = 0; i < bonds.size(); i++)
99 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
100 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
108 * Annotate the residues with their corresponding positions in s1 using the
109 * alignment in as NOTE: This clears all atom.alignmentMapping values on the
115 public void makeExactMapping(AlignSeq as, SequenceI s1)
117 int pdbpos = as.getSeq2Start() - 2;
118 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
119 // first clear out any old alignmentMapping values:
120 for (Atom atom : (Vector<Atom>) atoms)
122 atom.alignmentMapping = -1;
124 // and now trace the alignment onto the atom set.
125 for (int i = 0; i < as.astr1.length(); i++)
127 if (as.astr1.charAt(i) != '-')
132 if (as.astr2.charAt(i) != '-')
137 if (as.astr1.charAt(i) == as.astr2.charAt(i))
139 Residue res = (Residue) residues.elementAt(pdbpos);
140 Enumeration en = res.atoms.elements();
141 while (en.hasMoreElements())
143 Atom atom = (Atom) en.nextElement();
144 atom.alignmentMapping = alignpos;
151 * copy over the RESNUM seqfeatures from the internal chain sequence to the
156 * The Status of the transferred annotation
157 * @return the features added to sq (or its dataset)
159 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
163 while (sq != null && sq.getDatasetSequence() != null)
165 sq = sq.getDatasetSequence();
172 * Remove any existing features for this chain if they exist ?
173 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
174 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
175 * ? for (int i=0; i<seqsfeatures.length; i++) { }
179 status = PDBChain.IEASTATUS;
181 SequenceFeature[] features = sequence.getSequenceFeatures();
182 for (int i = 0; i < features.length; i++)
184 if (features[i].getFeatureGroup().equals(pdbid))
186 SequenceFeature tx = new SequenceFeature(features[i]);
187 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
188 - offset)).atoms.elementAt(0)).alignmentMapping);
189 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
190 - offset)).atoms.elementAt(0)).alignmentMapping);
192 + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? ""
193 : ":" + tx.getStatus()));
194 if (tx.begin != 0 && tx.end != 0)
196 sq.addSequenceFeature(tx);
203 public void makeCaBondList()
207 for (int i = 0; i < (residues.size() - 1); i++)
209 Residue tmpres = (Residue) residues.elementAt(i);
210 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
211 Atom at1 = tmpres.findAtom("CA");
212 Atom at2 = tmpres2.findAtom("CA");
214 if ((at1 == null) && (at2 == null))
217 at1 = tmpres.findAtom("P");
218 at2 = tmpres2.findAtom("P");
220 if ((at1 != null) && (at2 != null))
222 if (at1.chain.equals(at2.chain))
233 System.out.println("not found " + i);
236 if (numNa > 0 && ((numNa / residues.size()) > 0.99))
242 public void makeBond(Atom at1, Atom at2)
244 float[] start = new float[3];
245 float[] end = new float[3];
255 bonds.addElement(new Bond(start, end, at1, at2));
258 public void makeResidueList()
262 boolean deoxyn = false;
263 boolean nucleotide = false;
264 StringBuffer seq = new StringBuffer();
265 Vector resFeatures = new Vector();
266 Vector resAnnotation = new Vector();
267 int i, iSize = atoms.size() - 1;
269 for (i = 0; i <= iSize; i++)
271 Atom tmp = (Atom) atoms.elementAt(i);
272 resNumber = tmp.resNumber;
280 Vector resAtoms = new Vector();
281 // Add atoms to a vector while the residue number
282 // remains the same as the first atom's resNumber (res)
283 while ((resNumber == res) && (i < atoms.size()))
285 resAtoms.addElement(atoms.elementAt(i));
288 if (i < atoms.size())
290 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
298 // We need this to keep in step with the outer for i = loop
301 // Make a new Residue object with the new atoms vector
302 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
304 Residue tmpres = (Residue) residues.lastElement();
305 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
306 // Make A new SequenceFeature for the current residue numbering
307 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
308 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
309 + count, offset + count, pdbid);
310 // MCview.PDBChain.PDBFILEFEATURE);
311 resFeatures.addElement(sf);
312 resAnnotation.addElement(new Annotation(tmpat.tfactor));
313 // Keep totting up the sequence
314 if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
316 String nucname = tmpat.resName.trim();
317 // use the aaIndex rather than call 'toLower' - which would take a bit
319 deoxyn = nucname.length() == 2
320 && ResidueProperties.aaIndex[nucname.charAt(0)] == ResidueProperties.aaIndex['D'];
321 if (tmpat.name.equalsIgnoreCase("CA")
322 || ResidueProperties.nucleotideIndex[nucname
323 .charAt((deoxyn ? 1 : 0))] == -1)
326 // System.err.println("PDBReader:Null aa3Hash for " +
333 seq.append(nucname.charAt((deoxyn ? 1 : 0)));
341 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
343 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
353 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
357 // Add normalised feature scores to RESNUM indicating start/end of sequence
358 // sf.setScore(offset+count);
360 // System.out.println("PDB Sequence is :\nSequence = " + seq);
361 // System.out.println("No of residues = " + residues.size());
362 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
364 sequence.addSequenceFeature((SequenceFeature) resFeatures
366 resFeatures.setElementAt(null, i);
368 Annotation[] annots = new Annotation[resAnnotation.size()];
370 for (i = 0, iSize = annots.length; i < iSize; i++)
372 annots[i] = (Annotation) resAnnotation.elementAt(i);
373 if (annots[i].value > max)
375 max = annots[i].value;
377 resAnnotation.setElementAt(null, i);
379 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
380 "PDB.TempFactor", "Temperature Factor for "
381 + sequence.getName(), annots, 0, max,
382 AlignmentAnnotation.LINE_GRAPH);
383 tfactorann.setSequenceRef(sequence);
384 sequence.addAlignmentAnnotation(tfactorann);
387 public void setChargeColours()
389 for (int i = 0; i < bonds.size(); i++)
393 Bond b = (Bond) bonds.elementAt(i);
395 if (b.at1.resName.equalsIgnoreCase("ASP")
396 || b.at1.resName.equalsIgnoreCase("GLU"))
398 b.startCol = Color.red;
400 else if (b.at1.resName.equalsIgnoreCase("LYS")
401 || b.at1.resName.equalsIgnoreCase("ARG"))
403 b.startCol = Color.blue;
405 else if (b.at1.resName.equalsIgnoreCase("CYS"))
407 b.startCol = Color.yellow;
411 b.startCol = Color.lightGray;
414 if (b.at2.resName.equalsIgnoreCase("ASP")
415 || b.at2.resName.equalsIgnoreCase("GLU"))
417 b.endCol = Color.red;
419 else if (b.at2.resName.equalsIgnoreCase("LYS")
420 || b.at2.resName.equalsIgnoreCase("ARG"))
422 b.endCol = Color.blue;
424 else if (b.at2.resName.equalsIgnoreCase("CYS"))
426 b.endCol = Color.yellow;
430 b.endCol = Color.lightGray;
432 } catch (Exception e)
434 Bond b = (Bond) bonds.elementAt(i);
435 b.startCol = Color.gray;
436 b.endCol = Color.gray;
441 public void setChainColours(jalview.schemes.ColourSchemeI cs)
445 for (int i = 0; i < bonds.size(); i++)
449 b = (Bond) bonds.elementAt(i);
451 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
453 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
455 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
457 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
459 } catch (Exception e)
461 b = (Bond) bonds.elementAt(i);
462 b.startCol = Color.gray;
463 b.endCol = Color.gray;
468 public void setChainColours(Color col)
470 for (int i = 0; i < bonds.size(); i++)
472 Bond tmp = (Bond) bonds.elementAt(i);
478 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
481 AlignmentAnnotation[] transferred = null;
488 * copy any sequence annotation onto the sequence mapped using the provided
493 public void transferResidueAnnotation(StructureMapping mapping)
495 SequenceI sq = mapping.getSequence();
498 if (sequence != null && sequence.getAnnotation() != null)
502 float min = -1, max = 0;
503 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
504 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
506 int prn = mapping.getPDBResNum(k + 1);
508 an[k] = new Annotation(prn);
526 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
527 "PDB Residue Numbering for " + this.pdbid + ":" + this.id,
528 an, min, max, AlignmentAnnotation.LINE_GRAPH));