2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
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 isNa = false;
53 public boolean isVisible = true;
55 public int pdbstart = 0;
57 public int pdbend = 0;
59 public int seqstart = 0;
61 public int seqend = 0;
63 public String pdbid = "";
65 public PDBChain(String pdbid, String id)
67 this.pdbid = pdbid.toLowerCase();
72 * character used to write newlines
74 protected String newline = System.getProperty("line.separator");
76 public void setNewlineString(String nl)
81 public String getNewlineString()
90 for (int i = 0; i < bonds.size(); i++)
92 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
93 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
101 * Annotate the residues with their corresponding positions in s1 using the
102 * alignment in as NOTE: This clears all atom.alignmentMapping values on the
108 public void makeExactMapping(AlignSeq as, SequenceI s1)
110 int pdbpos = as.getSeq2Start() - 2;
111 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
112 // first clear out any old alignmentMapping values:
113 for (Atom atom : (Vector<Atom>) atoms)
115 atom.alignmentMapping = -1;
117 // and now trace the alignment onto the atom set.
118 for (int i = 0; i < as.astr1.length(); i++)
120 if (as.astr1.charAt(i) != '-')
125 if (as.astr2.charAt(i) != '-')
130 if (as.astr1.charAt(i) == as.astr2.charAt(i))
132 Residue res = (Residue) residues.elementAt(pdbpos);
133 Enumeration en = res.atoms.elements();
134 while (en.hasMoreElements())
136 Atom atom = (Atom) en.nextElement();
137 atom.alignmentMapping = alignpos;
144 * copy over the RESNUM seqfeatures from the internal chain sequence to the
149 * The Status of the transferred annotation
150 * @return the features added to sq (or its dataset)
152 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
156 while (sq != null && sq.getDatasetSequence() != null)
158 sq = sq.getDatasetSequence();
165 * Remove any existing features for this chain if they exist ?
166 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
167 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
168 * ? for (int i=0; i<seqsfeatures.length; i++) { }
172 status = PDBChain.IEASTATUS;
174 SequenceFeature[] features = sequence.getSequenceFeatures();
175 for (int i = 0; i < features.length; i++)
177 if (features[i].getFeatureGroup().equals(pdbid))
179 SequenceFeature tx = new SequenceFeature(features[i]);
180 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
181 - offset)).atoms.elementAt(0)).alignmentMapping);
182 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
183 - offset)).atoms.elementAt(0)).alignmentMapping);
185 + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? ""
186 : ":" + tx.getStatus()));
187 if (tx.begin != 0 && tx.end != 0)
188 sq.addSequenceFeature(tx);
194 public void makeCaBondList()
198 for (int i = 0; i < (residues.size() - 1); i++)
200 Residue tmpres = (Residue) residues.elementAt(i);
201 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
202 Atom at1 = tmpres.findAtom("CA");
203 Atom at2 = tmpres2.findAtom("CA");
205 if ((at1 == null) && (at2 == null))
208 at1 = tmpres.findAtom("P");
209 at2 = tmpres2.findAtom("P");
211 if ((at1 != null) && (at2 != null))
213 if (at1.chain.equals(at2.chain))
224 System.out.println("not found " + i);
227 if (numNa > 0 && ((numNa / residues.size()) > 0.99))
233 public void makeBond(Atom at1, Atom at2)
235 float[] start = new float[3];
236 float[] end = new float[3];
246 bonds.addElement(new Bond(start, end, at1, at2));
249 public void makeResidueList()
253 boolean deoxyn = false;
254 boolean nucleotide = false;
255 StringBuffer seq = new StringBuffer();
256 Vector resFeatures = new Vector();
257 Vector resAnnotation = new Vector();
258 int i, iSize = atoms.size() - 1;
260 for (i = 0; i <= iSize; i++)
262 Atom tmp = (Atom) atoms.elementAt(i);
263 resNumber = tmp.resNumber;
271 Vector resAtoms = new Vector();
272 // Add atoms to a vector while the residue number
273 // remains the same as the first atom's resNumber (res)
274 while ((resNumber == res) && (i < atoms.size()))
276 resAtoms.addElement((Atom) atoms.elementAt(i));
279 if (i < atoms.size())
281 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
289 // We need this to keep in step with the outer for i = loop
292 // Make a new Residue object with the new atoms vector
293 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
295 Residue tmpres = (Residue) residues.lastElement();
296 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
297 // Make A new SequenceFeature for the current residue numbering
298 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
299 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
300 + count, offset + count, pdbid);
301 // MCview.PDBChain.PDBFILEFEATURE);
302 resFeatures.addElement(sf);
303 resAnnotation.addElement(new Annotation(tmpat.tfactor));
304 // Keep totting up the sequence
305 if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
307 String nucname = tmpat.resName.trim();
308 // use the aaIndex rather than call 'toLower' - which would take a bit
310 deoxyn = nucname.length() == 2
311 && ResidueProperties.aaIndex[nucname.charAt(0)] == ResidueProperties.aaIndex['D'];
312 if (tmpat.name.equalsIgnoreCase("CA")
313 || ResidueProperties.nucleotideIndex[nucname
314 .charAt((deoxyn ? 1 : 0))] == -1)
317 // System.err.println("PDBReader:Null aa3Hash for " +
324 seq.append(nucname.charAt((deoxyn ? 1 : 0)));
332 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
334 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
344 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
348 // Add normalised feature scores to RESNUM indicating start/end of sequence
349 // sf.setScore(offset+count);
351 // System.out.println("PDB Sequence is :\nSequence = " + seq);
352 // System.out.println("No of residues = " + residues.size());
353 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
355 sequence.addSequenceFeature((SequenceFeature) resFeatures
357 resFeatures.setElementAt(null, i);
359 Annotation[] annots = new Annotation[resAnnotation.size()];
361 for (i = 0, iSize = annots.length; i < iSize; i++)
363 annots[i] = (Annotation) resAnnotation.elementAt(i);
364 if (annots[i].value > max)
365 max = annots[i].value;
366 resAnnotation.setElementAt(null, i);
368 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
369 "PDB.TempFactor", "Temperature Factor for "
370 + sequence.getName(), annots, 0, max,
371 AlignmentAnnotation.LINE_GRAPH);
372 tfactorann.setSequenceRef(sequence);
373 sequence.addAlignmentAnnotation(tfactorann);
376 public void setChargeColours()
378 for (int i = 0; i < bonds.size(); i++)
382 Bond b = (Bond) bonds.elementAt(i);
384 if (b.at1.resName.equalsIgnoreCase("ASP")
385 || b.at1.resName.equalsIgnoreCase("GLU"))
387 b.startCol = Color.red;
389 else if (b.at1.resName.equalsIgnoreCase("LYS")
390 || b.at1.resName.equalsIgnoreCase("ARG"))
392 b.startCol = Color.blue;
394 else if (b.at1.resName.equalsIgnoreCase("CYS"))
396 b.startCol = Color.yellow;
400 b.startCol = Color.lightGray;
403 if (b.at2.resName.equalsIgnoreCase("ASP")
404 || b.at2.resName.equalsIgnoreCase("GLU"))
406 b.endCol = Color.red;
408 else if (b.at2.resName.equalsIgnoreCase("LYS")
409 || b.at2.resName.equalsIgnoreCase("ARG"))
411 b.endCol = Color.blue;
413 else if (b.at2.resName.equalsIgnoreCase("CYS"))
415 b.endCol = Color.yellow;
419 b.endCol = Color.lightGray;
421 } catch (Exception e)
423 Bond b = (Bond) bonds.elementAt(i);
424 b.startCol = Color.gray;
425 b.endCol = Color.gray;
430 public void setChainColours(jalview.schemes.ColourSchemeI cs)
434 for (int i = 0; i < bonds.size(); i++)
438 b = (Bond) bonds.elementAt(i);
440 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
442 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
444 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
446 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
448 } catch (Exception e)
450 b = (Bond) bonds.elementAt(i);
451 b.startCol = Color.gray;
452 b.endCol = Color.gray;
457 public void setChainColours(Color col)
459 for (int i = 0; i < bonds.size(); i++)
461 Bond tmp = (Bond) bonds.elementAt(i);
467 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
470 AlignmentAnnotation[] transferred = null;
477 * copy any sequence annotation onto the sequence mapped using the provided
482 public void transferResidueAnnotation(StructureMapping mapping)
484 SequenceI sq = mapping.getSequence();
487 if (sequence != null && sequence.getAnnotation() != null)
491 float min = -1, max = 0;
492 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
493 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
495 int prn = mapping.getPDBResNum(k + 1);
497 an[k] = new Annotation((float) prn);
515 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
516 "PDB Residue Numbering for " + this.pdbid + ":" + this.id,
517 an, (float) min, (float) max, AlignmentAnnotation.LINE_GRAPH));