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();
71 * character used to write newlines
73 protected String newline = System.getProperty("line.separator");
75 public void setNewlineString(String nl)
80 public String getNewlineString()
89 for (int i = 0; i < bonds.size(); i++)
91 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
92 + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
100 * Annotate the residues with their corresponding positions in s1 using the
106 public void makeExactMapping(AlignSeq as, SequenceI s1)
108 int pdbpos = as.getSeq2Start() - 2;
109 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
111 for (int i = 0; i < as.astr1.length(); i++)
113 if (as.astr1.charAt(i) != '-')
118 if (as.astr2.charAt(i) != '-')
123 if (as.astr1.charAt(i) == as.astr2.charAt(i))
125 Residue res = (Residue) residues.elementAt(pdbpos);
126 Enumeration en = res.atoms.elements();
127 while (en.hasMoreElements())
129 Atom atom = (Atom) en.nextElement();
130 atom.alignmentMapping = alignpos;
137 * copy over the RESNUM seqfeatures from the internal chain sequence to the
142 * The Status of the transferred annotation
143 * @return the features added to sq (or its dataset)
145 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
149 while (sq != null && sq.getDatasetSequence() != null)
151 sq = sq.getDatasetSequence();
158 * Remove any existing features for this chain if they exist ?
159 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
160 * totfeat=seqsfeatures.length; // Remove any features for this exact chain
161 * ? for (int i=0; i<seqsfeatures.length; i++) { }
165 status = PDBChain.IEASTATUS;
167 SequenceFeature[] features = sequence.getSequenceFeatures();
168 for (int i = 0; i < features.length; i++)
170 if (features[i].getFeatureGroup().equals(pdbid))
172 SequenceFeature tx = new SequenceFeature(features[i]);
173 tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
174 - offset)).atoms.elementAt(0)).alignmentMapping);
175 tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
176 - offset)).atoms.elementAt(0)).alignmentMapping);
178 + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? ""
179 : ":" + tx.getStatus()));
180 if (tx.begin != 0 && tx.end != 0)
181 sq.addSequenceFeature(tx);
187 public void makeCaBondList()
191 for (int i = 0; i < (residues.size() - 1); i++)
193 Residue tmpres = (Residue) residues.elementAt(i);
194 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
195 Atom at1 = tmpres.findAtom("CA");
196 Atom at2 = tmpres2.findAtom("CA");
198 if ((at1 == null) && (at2 == null))
201 at1 = tmpres.findAtom("P");
202 at2 = tmpres2.findAtom("P");
204 if ((at1 != null) && (at2 != null))
206 if (at1.chain.equals(at2.chain))
217 System.out.println("not found " + i);
220 if (numNa > 0 && ((numNa / residues.size()) > 0.99))
226 public void makeBond(Atom at1, Atom at2)
228 float[] start = new float[3];
229 float[] end = new float[3];
239 bonds.addElement(new Bond(start, end, at1, at2));
242 public void makeResidueList()
246 boolean deoxyn=false;
247 boolean nucleotide = false;
248 StringBuffer seq = new StringBuffer();
249 Vector resFeatures = new Vector();
250 Vector resAnnotation = new Vector();
251 int i, iSize = atoms.size() - 1;
253 for (i = 0; i <= iSize; i++)
255 Atom tmp = (Atom) atoms.elementAt(i);
256 resNumber = tmp.resNumber;
264 Vector resAtoms = new Vector();
265 // Add atoms to a vector while the residue number
266 // remains the same as the first atom's resNumber (res)
267 while ((resNumber == res) && (i < atoms.size()))
269 resAtoms.addElement((Atom) atoms.elementAt(i));
272 if (i < atoms.size())
274 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
282 // We need this to keep in step with the outer for i = loop
285 // Make a new Residue object with the new atoms vector
286 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
288 Residue tmpres = (Residue) residues.lastElement();
289 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
290 // Make A new SequenceFeature for the current residue numbering
291 SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
292 + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
293 + count, offset + count, pdbid);
294 // MCview.PDBChain.PDBFILEFEATURE);
295 resFeatures.addElement(sf);
296 resAnnotation.addElement(new Annotation(tmpat.tfactor));
297 // Keep totting up the sequence
298 if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null)
300 String nucname = tmpat.resName.trim();
301 // use the aaIndex rather than call 'toLower' - which would take a bit more time.
302 deoxyn=nucname.length()==2 && ResidueProperties.aaIndex[nucname.charAt(0)]==ResidueProperties.aaIndex['D'];
303 if (tmpat.name.equalsIgnoreCase("CA")
304 || ResidueProperties.nucleotideIndex[nucname.charAt((deoxyn ? 1 : 0))] == -1)
307 // System.err.println("PDBReader:Null aa3Hash for " +
314 seq.append(nucname.charAt((deoxyn ? 1 : 0)));
322 .println("Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
324 seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
334 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
338 // Add normalised feature scores to RESNUM indicating start/end of sequence
339 // sf.setScore(offset+count);
341 // System.out.println("PDB Sequence is :\nSequence = " + seq);
342 // System.out.println("No of residues = " + residues.size());
343 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
345 sequence.addSequenceFeature((SequenceFeature) resFeatures
347 resFeatures.setElementAt(null, i);
349 Annotation[] annots = new Annotation[resAnnotation.size()];
351 for (i = 0, iSize = annots.length; i < iSize; i++)
353 annots[i] = (Annotation) resAnnotation.elementAt(i);
354 if (annots[i].value > max)
355 max = annots[i].value;
356 resAnnotation.setElementAt(null, i);
358 AlignmentAnnotation tfactorann = new AlignmentAnnotation(
359 "PDB.TempFactor", "Temperature Factor for "
360 + sequence.getName(), annots, 0, max,
361 AlignmentAnnotation.LINE_GRAPH);
362 tfactorann.setSequenceRef(sequence);
363 sequence.addAlignmentAnnotation(tfactorann);
366 public void setChargeColours()
368 for (int i = 0; i < bonds.size(); i++)
372 Bond b = (Bond) bonds.elementAt(i);
374 if (b.at1.resName.equalsIgnoreCase("ASP")
375 || b.at1.resName.equalsIgnoreCase("GLU"))
377 b.startCol = Color.red;
379 else if (b.at1.resName.equalsIgnoreCase("LYS")
380 || b.at1.resName.equalsIgnoreCase("ARG"))
382 b.startCol = Color.blue;
384 else if (b.at1.resName.equalsIgnoreCase("CYS"))
386 b.startCol = Color.yellow;
390 b.startCol = Color.lightGray;
393 if (b.at2.resName.equalsIgnoreCase("ASP")
394 || b.at2.resName.equalsIgnoreCase("GLU"))
396 b.endCol = Color.red;
398 else if (b.at2.resName.equalsIgnoreCase("LYS")
399 || b.at2.resName.equalsIgnoreCase("ARG"))
401 b.endCol = Color.blue;
403 else if (b.at2.resName.equalsIgnoreCase("CYS"))
405 b.endCol = Color.yellow;
409 b.endCol = Color.lightGray;
411 } catch (Exception e)
413 Bond b = (Bond) bonds.elementAt(i);
414 b.startCol = Color.gray;
415 b.endCol = Color.gray;
420 public void setChainColours(jalview.schemes.ColourSchemeI cs)
424 for (int i = 0; i < bonds.size(); i++)
428 b = (Bond) bonds.elementAt(i);
430 index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
432 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
434 index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
436 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
438 } catch (Exception e)
440 b = (Bond) bonds.elementAt(i);
441 b.startCol = Color.gray;
442 b.endCol = Color.gray;
447 public void setChainColours(Color col)
449 for (int i = 0; i < bonds.size(); i++)
451 Bond tmp = (Bond) bonds.elementAt(i);
457 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
460 AlignmentAnnotation[] transferred = null;
467 * copy any sequence annotation onto the sequence mapped using the provided
472 public void transferResidueAnnotation(StructureMapping mapping)
474 SequenceI sq = mapping.getSequence();
477 if (sequence != null && sequence.getAnnotation() != null)
481 float min = -1, max = 0;
482 Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
483 for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
485 int prn = mapping.getPDBResNum(k + 1);
487 an[k] = new Annotation((float) prn);
505 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
506 "PDB Residue Numbering for " + this.pdbid + ":" + this.id,
507 an, (float) min, (float) max, AlignmentAnnotation.LINE_GRAPH));