2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
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";
36 private static final String IEASTATUS = "IEA:jalview";
38 public Vector bonds = new Vector();
39 public Vector atoms = new Vector();
40 public Vector residues = new Vector();
42 public Sequence sequence;
43 public boolean isVisible = true;
44 public int pdbstart = 0;
45 public int pdbend = 0;
46 public int seqstart = 0;
47 public int seqend = 0;
48 public String pdbid = "";
49 public PDBChain(String pdbid, String id)
51 this.pdbid = pdbid.toLowerCase();
59 for (int i = 0; i < bonds.size(); i++)
61 tmp = tmp + ( (Bond) bonds.elementAt(i)).at1.resName + " " +
62 ( (Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
69 public void makeExactMapping(AlignSeq as, SequenceI s1)
71 int pdbpos = as.getSeq2Start() - 2;
72 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
74 for (int i = 0; i < as.astr1.length(); i++)
76 if (as.astr1.charAt(i) != '-')
81 if (as.astr2.charAt(i) != '-')
86 if (as.astr1.charAt(i) == as.astr2.charAt(i))
88 Residue res = (Residue) residues.elementAt(pdbpos);
89 Enumeration en = res.atoms.elements();
90 while (en.hasMoreElements())
92 Atom atom = (Atom) en.nextElement();
93 atom.alignmentMapping = alignpos;
99 * copy over the RESNUM seqfeatures from the internal chain sequence to the mapped sequence
101 * @param status The Status of the transferred annotation
102 * @return the features added to sq (or its dataset)
104 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq, String status)
107 while (sq!=null && sq.getDatasetSequence()!=null)
109 sq = sq.getDatasetSequence();
116 * Remove any existing features for this chain if they exist ?
117 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures();
118 int totfeat=seqsfeatures.length;
119 // Remove any features for this exact chain ?
120 for (int i=0; i<seqsfeatures.length; i++) {
124 status = PDBChain.IEASTATUS;
126 SequenceFeature[] features = sequence.getSequenceFeatures();
127 for (int i = 0; i < features.length; i++)
129 if (features[i].getFeatureGroup().equals(pdbid))
131 SequenceFeature tx = new SequenceFeature(features[i]);
133 ( (Atom) ( (Residue) residues.elementAt(tx.getBegin() - offset)).
134 atoms.elementAt(0)).alignmentMapping);
136 ( (Atom) ( (Residue) residues.elementAt(tx.getEnd() - offset)).
137 atoms.elementAt(0)).alignmentMapping);
138 tx.setStatus(status +
139 ( (tx.getStatus() == null || tx.getStatus().length() == 0) ?
140 "" : ":" + tx.getStatus()));
141 if (tx.begin!=0 && tx.end!=0)
142 sq.addSequenceFeature(tx);
148 public void makeCaBondList()
150 for (int i = 0; i < (residues.size() - 1); i++)
152 Residue tmpres = (Residue) residues.elementAt(i);
153 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
154 Atom at1 = tmpres.findAtom("CA");
155 Atom at2 = tmpres2.findAtom("CA");
157 if ( (at1 != null) && (at2 != null))
159 if (at1.chain.equals(at2.chain))
166 System.out.println("not found " + i);
171 public void makeBond(Atom at1, Atom at2)
173 float[] start = new float[3];
174 float[] end = new float[3];
184 bonds.addElement(new Bond(start, end, at1, at2));
187 public void makeResidueList()
190 StringBuffer seq = new StringBuffer();
191 Vector resFeatures = new Vector();
192 Vector resAnnotation = new Vector();
193 int i, iSize = atoms.size() - 1;
195 for (i = 0; i <= iSize; i++)
197 Atom tmp = (Atom) atoms.elementAt(i);
198 resNumber = tmp.resNumber;
206 Vector resAtoms = new Vector();
207 //Add atoms to a vector while the residue number
208 //remains the same as the first atom's resNumber (res)
209 while ( (resNumber == res) && (i < atoms.size()))
211 resAtoms.addElement( (Atom) atoms.elementAt(i));
214 if (i < atoms.size())
216 resNumber = ( (Atom) atoms.elementAt(i)).resNumber;
224 //We need this to keep in step with the outer for i = loop
227 //Make a new Residue object with the new atoms vector
228 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
230 Residue tmpres = (Residue) residues.lastElement();
231 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
232 // Make A new SequenceFeature for the current residue numbering
234 new SequenceFeature("RESNUM",
235 tmpat.resName + ":" + tmpat.resNumIns + " " +
237 "", offset + count, offset + count,
240 //MCview.PDBChain.PDBFILEFEATURE);
241 resFeatures.addElement(sf);
242 resAnnotation.addElement(new Annotation(tmpat.tfactor));
243 // Keep totting up the sequence
244 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
247 // System.err.println("PDBReader:Null aa3Hash for " +
253 seq.append(ResidueProperties.aa[ ( (Integer) ResidueProperties.
255 .get(tmpat.resName)).intValue()]);
265 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note: resNumber-offset ~= seq.size()
266 // System.out.println("PDB Sequence is :\nSequence = " + seq);
267 // System.out.println("No of residues = " + residues.size());
268 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
270 sequence.addSequenceFeature( (SequenceFeature) resFeatures.elementAt(i));
271 resFeatures.setElementAt(null, i);
273 Annotation[] annots = new Annotation[resAnnotation.size()];
275 for (i=0,iSize=annots.length; i<iSize; i++)
277 annots[i] = (Annotation) resAnnotation.elementAt(i);
278 if (annots[i].value>max)
279 max = annots[i].value;
280 resAnnotation.setElementAt(null, i);
282 AlignmentAnnotation tfactorann = new AlignmentAnnotation("PDB.CATempFactor","CA Temperature Factor for "+sequence.getName(),
283 annots, 0, max, AlignmentAnnotation.LINE_GRAPH);
284 tfactorann.setSequenceRef(sequence);
285 sequence.addAlignmentAnnotation(tfactorann);
288 public void setChargeColours()
290 for (int i = 0; i < bonds.size(); i++)
294 Bond b = (Bond) bonds.elementAt(i);
296 if (b.at1.resName.equalsIgnoreCase("ASP") ||
297 b.at1.resName.equalsIgnoreCase("GLU"))
299 b.startCol = Color.red;
301 else if (b.at1.resName.equalsIgnoreCase("LYS") ||
302 b.at1.resName.equalsIgnoreCase("ARG"))
304 b.startCol = Color.blue;
306 else if (b.at1.resName.equalsIgnoreCase("CYS"))
308 b.startCol = Color.yellow;
312 b.startCol = Color.lightGray;
315 if (b.at2.resName.equalsIgnoreCase("ASP") ||
316 b.at2.resName.equalsIgnoreCase("GLU"))
318 b.endCol = Color.red;
320 else if (b.at2.resName.equalsIgnoreCase("LYS") ||
321 b.at2.resName.equalsIgnoreCase("ARG"))
323 b.endCol = Color.blue;
325 else if (b.at2.resName.equalsIgnoreCase("CYS"))
327 b.endCol = Color.yellow;
331 b.endCol = Color.lightGray;
336 Bond b = (Bond) bonds.elementAt(i);
337 b.startCol = Color.gray;
338 b.endCol = Color.gray;
343 public void setChainColours(jalview.schemes.ColourSchemeI cs)
347 for (int i = 0; i < bonds.size(); i++)
351 b = (Bond) bonds.elementAt(i);
353 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at1.
354 resName)).intValue();
355 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
357 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at2.resName)).
359 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
364 b = (Bond) bonds.elementAt(i);
365 b.startCol = Color.gray;
366 b.endCol = Color.gray;
371 public void setChainColours(Color col)
373 for (int i = 0; i < bonds.size(); i++)
375 Bond tmp = (Bond) bonds.elementAt(i);
381 public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq, String status)
383 AlignmentAnnotation[] transferred = null;
390 * copy any sequence annotation onto the sequence mapped using the provided StructureMapping
393 public void transferResidueAnnotation(StructureMapping mapping)
395 SequenceI sq = mapping.getSequence();
398 if (sequence!=null && sequence.getAnnotation()!=null)
403 Annotation[] an=new Annotation[sq.getEnd()-sq.getStart()+1];
404 for (int i=sq.getStart(),j=sq.getEnd(),k=0; i<=j; i++,k++)
406 int prn = mapping.getPDBResNum(k+1);
408 an[k] = new Annotation((float)prn);
424 sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM", "PDB Residue Numbering for "+this.pdbid+":"+this.id, an, (float)min,(float)max, AlignmentAnnotation.LINE_GRAPH));