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.
27 import jalview.analysis.*;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.structure.StructureMapping;
35 * SequenceFeature group for PDB File features added to sequences
37 private static final String PDBFILEFEATURE = "PDBFile";
39 private static final String IEASTATUS = "IEA:jalview";
43 public Vector bonds = new Vector();
45 public Vector atoms = new Vector();
47 public Vector residues = new Vector();
51 public Sequence sequence;
53 public boolean isNa = false;
55 public boolean isVisible = true;
57 public int pdbstart = 0;
59 public int pdbend = 0;
61 public int seqstart = 0;
63 public int seqend = 0;
65 public String pdbid = "";
67 public PDBChain(String pdbid, String id)
69 this.pdbid = pdbid.toLowerCase();
74 * character used to write newlines
76 protected String newline = System.getProperty("line.separator");
78 public void setNewlineString(String nl)
83 public String getNewlineString()
92 for (int i = 0; i < bonds.size(); i++)
94 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
95 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
103 * Annotate the residues with their corresponding positions in s1 using the
104 * alignment in as NOTE: This clears all atom.alignmentMapping values on the
110 public void makeExactMapping(AlignSeq as, SequenceI s1)
112 int pdbpos = as.getSeq2Start() - 2;
113 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
114 // first clear out any old alignmentMapping values:
115 for (Atom atom : (Vector<Atom>) atoms)
117 atom.alignmentMapping = -1;
119 // and now trace the alignment onto the atom set.
120 for (int i = 0; i < as.astr1.length(); i++)
122 if (as.astr1.charAt(i) != '-')
127 if (as.astr2.charAt(i) != '-')
132 if (as.astr1.charAt(i) == as.astr2.charAt(i))
134 Residue res = (Residue) residues.elementAt(pdbpos);
135 Enumeration en = res.atoms.elements();
136 while (en.hasMoreElements())
138 Atom atom = (Atom) en.nextElement();
139 atom.alignmentMapping = alignpos;
146 * copy over the RESNUM seqfeatures from the internal chain sequence to the
151 * The Status of the transferred annotation
152 * @return the features added to sq (or its dataset)
154 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
158 while (sq != null && sq.getDatasetSequence() != null)
160 sq = sq.getDatasetSequence();
167 * Remove any existing features for this chain if they exist ?
168 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
169 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
170 * ? for (int i=0; i<seqsfeatures.length; i++) { }
174 status = PDBChain.IEASTATUS;
176 SequenceFeature[] features = sequence.getSequenceFeatures();
177 for (int i = 0; i < features.length; i++)
179 if (features[i].getFeatureGroup().equals(pdbid))
181 SequenceFeature tx = new SequenceFeature(features[i]);
182 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
183 - offset)).atoms.elementAt(0)).alignmentMapping);
184 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
185 - offset)).atoms.elementAt(0)).alignmentMapping);
187 + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? ""
188 : ":" + tx.getStatus()));
189 if (tx.begin != 0 && tx.end != 0)
190 sq.addSequenceFeature(tx);
196 public void makeCaBondList()
200 for (int i = 0; i < (residues.size() - 1); i++)
202 Residue tmpres = (Residue) residues.elementAt(i);
203 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
204 Atom at1 = tmpres.findAtom("CA");
205 Atom at2 = tmpres2.findAtom("CA");
207 if ((at1 == null) && (at2 == null))
210 at1 = tmpres.findAtom("P");
211 at2 = tmpres2.findAtom("P");
213 if ((at1 != null) && (at2 != null))
215 if (at1.chain.equals(at2.chain))
226 System.out.println("not found " + i);
229 if (numNa > 0 && ((numNa / residues.size()) > 0.99))
235 public void makeBond(Atom at1, Atom at2)
237 float[] start = new float[3];
238 float[] end = new float[3];
248 bonds.addElement(new Bond(start, end, at1, at2));
251 public void makeResidueList()
255 boolean deoxyn = false;
256 boolean nucleotide = false;
257 StringBuffer seq = new StringBuffer();
258 Vector resFeatures = new Vector();
259 Vector resAnnotation = new Vector();
260 int i, iSize = atoms.size() - 1;
262 for (i = 0; i <= iSize; i++)
264 Atom tmp = (Atom) atoms.elementAt(i);
265 resNumber = tmp.resNumber;
273 Vector resAtoms = new Vector();
274 // Add atoms to a vector while the residue number
275 // remains the same as the first atom's resNumber (res)
276 while ((resNumber == res) && (i < atoms.size()))
278 resAtoms.addElement((Atom) atoms.elementAt(i));
281 if (i < atoms.size())
283 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
291 // We need this to keep in step with the outer for i = loop
294 // Make a new Residue object with the new atoms vector
295 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
297 Residue tmpres = (Residue) residues.lastElement();
298 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
299 // Make A new SequenceFeature for the current residue numbering
300 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
301 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
302 + count, offset + count, pdbid);
303 // MCview.PDBChain.PDBFILEFEATURE);
304 resFeatures.addElement(sf);
305 resAnnotation.addElement(new Annotation(tmpat.tfactor));
306 // Keep totting up the sequence
307 if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
309 String nucname = tmpat.resName.trim();
310 // use the aaIndex rather than call 'toLower' - which would take a bit
312 deoxyn = nucname.length() == 2
313 && ResidueProperties.aaIndex[nucname.charAt(0)] == ResidueProperties.aaIndex['D'];
314 if (tmpat.name.equalsIgnoreCase("CA")
315 || ResidueProperties.nucleotideIndex[nucname
316 .charAt((deoxyn ? 1 : 0))] == -1)
319 // System.err.println("PDBReader:Null aa3Hash for " +
326 seq.append(nucname.charAt((deoxyn ? 1 : 0)));
334 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
336 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
346 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
350 // Add normalised feature scores to RESNUM indicating start/end of sequence
351 // sf.setScore(offset+count);
353 // System.out.println("PDB Sequence is :\nSequence = " + seq);
354 // System.out.println("No of residues = " + residues.size());
355 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
357 sequence.addSequenceFeature((SequenceFeature) resFeatures
359 resFeatures.setElementAt(null, i);
361 Annotation[] annots = new Annotation[resAnnotation.size()];
363 for (i = 0, iSize = annots.length; i < iSize; i++)
365 annots[i] = (Annotation) resAnnotation.elementAt(i);
366 if (annots[i].value > max)
367 max = annots[i].value;
368 resAnnotation.setElementAt(null, i);
370 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
371 "PDB.TempFactor", "Temperature Factor for "
372 + sequence.getName(), annots, 0, max,
373 AlignmentAnnotation.LINE_GRAPH);
374 tfactorann.setSequenceRef(sequence);
375 sequence.addAlignmentAnnotation(tfactorann);
378 public void setChargeColours()
380 for (int i = 0; i < bonds.size(); i++)
384 Bond b = (Bond) bonds.elementAt(i);
386 if (b.at1.resName.equalsIgnoreCase("ASP")
387 || b.at1.resName.equalsIgnoreCase("GLU"))
389 b.startCol = Color.red;
391 else if (b.at1.resName.equalsIgnoreCase("LYS")
392 || b.at1.resName.equalsIgnoreCase("ARG"))
394 b.startCol = Color.blue;
396 else if (b.at1.resName.equalsIgnoreCase("CYS"))
398 b.startCol = Color.yellow;
402 b.startCol = Color.lightGray;
405 if (b.at2.resName.equalsIgnoreCase("ASP")
406 || b.at2.resName.equalsIgnoreCase("GLU"))
408 b.endCol = Color.red;
410 else if (b.at2.resName.equalsIgnoreCase("LYS")
411 || b.at2.resName.equalsIgnoreCase("ARG"))
413 b.endCol = Color.blue;
415 else if (b.at2.resName.equalsIgnoreCase("CYS"))
417 b.endCol = Color.yellow;
421 b.endCol = Color.lightGray;
423 } catch (Exception e)
425 Bond b = (Bond) bonds.elementAt(i);
426 b.startCol = Color.gray;
427 b.endCol = Color.gray;
432 public void setChainColours(jalview.schemes.ColourSchemeI cs)
436 for (int i = 0; i < bonds.size(); i++)
440 b = (Bond) bonds.elementAt(i);
442 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
444 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
446 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
448 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
450 } catch (Exception e)
452 b = (Bond) bonds.elementAt(i);
453 b.startCol = Color.gray;
454 b.endCol = Color.gray;
459 public void setChainColours(Color col)
461 for (int i = 0; i < bonds.size(); i++)
463 Bond tmp = (Bond) bonds.elementAt(i);
469 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
472 AlignmentAnnotation[] transferred = null;
479 * copy any sequence annotation onto the sequence mapped using the provided
484 public void transferResidueAnnotation(StructureMapping mapping)
486 SequenceI sq = mapping.getSequence();
489 if (sequence != null && sequence.getAnnotation() != null)
493 float min = -1, max = 0;
494 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
495 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
497 int prn = mapping.getPDBResNum(k + 1);
499 an[k] = new Annotation((float) prn);
517 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
518 "PDB Residue Numbering for " + this.pdbid + ":" + this.id,
519 an, (float) min, (float) max, AlignmentAnnotation.LINE_GRAPH));