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.Mapping;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.schemes.ResidueProperties;
31 import jalview.structure.StructureMapping;
33 import java.awt.Color;
34 import java.util.Enumeration;
35 import java.util.List;
36 import java.util.Vector;
41 * SequenceFeature group for PDB File features added to sequences
43 private static final String PDBFILEFEATURE = "PDBFile";
45 private static final String IEASTATUS = "IEA:jalview";
49 public Vector bonds = new Vector();
51 public Vector atoms = new Vector();
53 public Vector residues = new Vector();
58 * sequence is the sequence extracted by the chain parsing code
60 public SequenceI sequence;
63 * shadow is the sequence created by any other parsing processes (e.g. Jmol,
66 public SequenceI shadow = null;
68 public boolean isNa = false;
70 public boolean isVisible = true;
72 public int pdbstart = 0;
74 public int pdbend = 0;
76 public int seqstart = 0;
78 public int seqend = 0;
80 public String pdbid = "";
82 public PDBChain(String pdbid, String id)
84 this.pdbid = pdbid.toLowerCase();
89 * character used to write newlines
91 protected String newline = System.getProperty("line.separator");
93 public Mapping shadowMap;
95 public void setNewlineString(String nl)
100 public String getNewlineString()
105 public String print()
109 for (int i = 0; i < bonds.size(); i++)
111 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
112 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
120 * Annotate the residues with their corresponding positions in s1 using the
121 * alignment in as NOTE: This clears all atom.alignmentMapping values on the
127 public void makeExactMapping(AlignSeq as, SequenceI s1)
129 int pdbpos = as.getSeq2Start() - 2;
130 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
131 // first clear out any old alignmentMapping values:
132 for (Atom atom : (Vector<Atom>) atoms)
134 atom.alignmentMapping = -1;
136 // and now trace the alignment onto the atom set.
137 for (int i = 0; i < as.astr1.length(); i++)
139 if (as.astr1.charAt(i) != '-')
144 if (as.astr2.charAt(i) != '-')
149 if (as.astr1.charAt(i) == as.astr2.charAt(i))
151 Residue res = (Residue) residues.elementAt(pdbpos);
152 Enumeration en = res.atoms.elements();
153 while (en.hasMoreElements())
155 Atom atom = (Atom) en.nextElement();
156 atom.alignmentMapping = alignpos;
163 * copy over the RESNUM seqfeatures from the internal chain sequence to the
168 * The Status of the transferred annotation
169 * @return the features added to sq (or its dataset)
171 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
175 while (sq != null && sq.getDatasetSequence() != null)
177 sq = sq.getDatasetSequence();
184 * Remove any existing features for this chain if they exist ?
185 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
186 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
187 * ? for (int i=0; i<seqsfeatures.length; i++) { }
191 status = PDBChain.IEASTATUS;
193 SequenceFeature[] features = sequence.getSequenceFeatures();
194 for (int i = 0; i < features.length; i++)
196 if (features[i].getFeatureGroup().equals(pdbid))
198 SequenceFeature tx = new SequenceFeature(features[i]);
199 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
200 - offset)).atoms.elementAt(0)).alignmentMapping);
201 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
202 - offset)).atoms.elementAt(0)).alignmentMapping);
204 + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? ""
205 : ":" + tx.getStatus()));
206 if (tx.begin != 0 && tx.end != 0)
208 sq.addSequenceFeature(tx);
215 public void makeCaBondList()
219 for (int i = 0; i < (residues.size() - 1); i++)
221 Residue tmpres = (Residue) residues.elementAt(i);
222 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
223 Atom at1 = tmpres.findAtom("CA");
224 Atom at2 = tmpres2.findAtom("CA");
226 if ((at1 == null) && (at2 == null))
229 at1 = tmpres.findAtom("P");
230 at2 = tmpres2.findAtom("P");
232 if ((at1 != null) && (at2 != null))
234 if (at1.chain.equals(at2.chain))
245 System.out.println("not found " + i);
248 if (numNa > 0 && ((numNa / residues.size()) > 0.99))
254 public void makeBond(Atom at1, Atom at2)
256 float[] start = new float[3];
257 float[] end = new float[3];
267 bonds.addElement(new Bond(start, end, at1, at2));
270 public void makeResidueList(boolean visibleChainAnnotation)
274 boolean deoxyn = false;
275 boolean nucleotide = false;
276 StringBuffer seq = new StringBuffer();
277 Vector resFeatures = new Vector();
278 Vector resAnnotation = new Vector();
279 int i, iSize = atoms.size() - 1;
281 for (i = 0; i <= iSize; i++)
283 Atom tmp = (Atom) atoms.elementAt(i);
284 resNumber = tmp.resNumber;
292 Vector resAtoms = new Vector();
293 // Add atoms to a vector while the residue number
294 // remains the same as the first atom's resNumber (res)
295 while ((resNumber == res) && (i < atoms.size()))
297 resAtoms.addElement(atoms.elementAt(i));
300 if (i < atoms.size())
302 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
310 // We need this to keep in step with the outer for i = loop
313 // Make a new Residue object with the new atoms vector
314 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
316 Residue tmpres = (Residue) residues.lastElement();
317 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
318 // Make A new SequenceFeature for the current residue numbering
319 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
320 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
321 + count, offset + count, pdbid);
322 // MCview.PDBChain.PDBFILEFEATURE);
323 resFeatures.addElement(sf);
324 resAnnotation.addElement(new Annotation(tmpat.tfactor));
325 // Keep totting up the sequence
326 if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
328 String nucname = tmpat.resName.trim();
329 // use the aaIndex rather than call 'toLower' - which would take a bit
331 deoxyn = nucname.length() == 2
332 && ResidueProperties.aaIndex[nucname.charAt(0)] == ResidueProperties.aaIndex['D'];
333 if (tmpat.name.equalsIgnoreCase("CA")
334 || ResidueProperties.nucleotideIndex[nucname
335 .charAt((deoxyn ? 1 : 0))] == -1)
338 // System.err.println("PDBReader:Null aa3Hash for " +
345 seq.append(nucname.charAt((deoxyn ? 1 : 0)));
353 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
355 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
365 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
369 // Add normalised feature scores to RESNUM indicating start/end of sequence
370 // sf.setScore(offset+count);
372 // System.out.println("PDB Sequence is :\nSequence = " + seq);
373 // System.out.println("No of residues = " + residues.size());
374 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
376 sequence.addSequenceFeature((SequenceFeature) resFeatures
378 resFeatures.setElementAt(null, i);
380 if (visibleChainAnnotation)
382 Annotation[] annots = new Annotation[resAnnotation.size()];
384 for (i = 0, iSize = annots.length; i < iSize; i++)
386 annots[i] = (Annotation) resAnnotation.elementAt(i);
387 if (annots[i].value > max)
389 max = annots[i].value;
391 resAnnotation.setElementAt(null, i);
394 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
395 "Temperature Factor", "Temperature Factor for " + pdbid + id,
397 AlignmentAnnotation.LINE_GRAPH);
398 tfactorann.setSequenceRef(sequence);
399 sequence.addAlignmentAnnotation(tfactorann);
403 public void setChargeColours()
405 for (int i = 0; i < bonds.size(); i++)
409 Bond b = (Bond) bonds.elementAt(i);
411 if (b.at1.resName.equalsIgnoreCase("ASP")
412 || b.at1.resName.equalsIgnoreCase("GLU"))
414 b.startCol = Color.red;
416 else if (b.at1.resName.equalsIgnoreCase("LYS")
417 || b.at1.resName.equalsIgnoreCase("ARG"))
419 b.startCol = Color.blue;
421 else if (b.at1.resName.equalsIgnoreCase("CYS"))
423 b.startCol = Color.yellow;
427 b.startCol = Color.lightGray;
430 if (b.at2.resName.equalsIgnoreCase("ASP")
431 || b.at2.resName.equalsIgnoreCase("GLU"))
433 b.endCol = Color.red;
435 else if (b.at2.resName.equalsIgnoreCase("LYS")
436 || b.at2.resName.equalsIgnoreCase("ARG"))
438 b.endCol = Color.blue;
440 else if (b.at2.resName.equalsIgnoreCase("CYS"))
442 b.endCol = Color.yellow;
446 b.endCol = Color.lightGray;
448 } catch (Exception e)
450 Bond b = (Bond) bonds.elementAt(i);
451 b.startCol = Color.gray;
452 b.endCol = Color.gray;
457 public void setChainColours(jalview.schemes.ColourSchemeI cs)
461 for (int i = 0; i < bonds.size(); i++)
465 b = (Bond) bonds.elementAt(i);
467 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
469 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
471 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
473 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
475 } catch (Exception e)
477 b = (Bond) bonds.elementAt(i);
478 b.startCol = Color.gray;
479 b.endCol = Color.gray;
484 public void setChainColours(Color col)
486 for (int i = 0; i < bonds.size(); i++)
488 Bond tmp = (Bond) bonds.elementAt(i);
495 * copy any sequence annotation onto the sequence mapped using the provided
499 * - positional mapping between destination sequence and pdb resnum
501 * - mapping between destination sequence and local chain
503 public void transferResidueAnnotation(
504 StructureMapping mapping, jalview.datamodel.Mapping sqmpping)
506 SequenceI sq = mapping.getSequence();
510 while (dsq.getDatasetSequence() != null)
512 dsq = dsq.getDatasetSequence();
514 // any annotation will be transferred onto the dataset sequence
516 if (shadow != null && shadow.getAnnotation() != null)
519 for (AlignmentAnnotation ana : shadow.getAnnotation())
521 List<AlignmentAnnotation> transfer = sq.getAlignmentAnnotations(
522 ana.getCalcId(), ana.label);
523 if (transfer == null || transfer.size() == 0)
525 ana = new AlignmentAnnotation(ana);
526 ana.liftOver(sequence, shadowMap);
527 ana.liftOver(dsq, sqmpping);
528 dsq.addAlignmentAnnotation(ana);
538 if (sequence != null && sequence.getAnnotation() != null)
540 for (AlignmentAnnotation ana : sequence.getAnnotation())
542 List<AlignmentAnnotation> transfer = sq
543 .getAlignmentAnnotations(ana.getCalcId(), ana.label);
544 if (transfer == null || transfer.size() == 0)
546 ana = new AlignmentAnnotation(ana);
547 ana.liftOver(dsq, sqmpping);
548 // mapping.transfer(ana);
559 // Useful for debugging mappings - adds annotation for mapped position
560 float min = -1, max = 0;
561 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
562 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
564 int prn = mapping.getPDBResNum(k + 1);
566 an[k] = new Annotation(prn);
584 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
585 "PDB Residue Numbering for " + this.pdbid + ":" + this.id,
586 an, min, max, AlignmentAnnotation.LINE_GRAPH));