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.*;
32 * SequenceFeature group for PDB File features added to sequences
34 private static final String PDBFILEFEATURE = "PDBFile";
35 private static final String IEASTATUS = "IEA:jalview";
37 public Vector bonds = new Vector();
38 public Vector atoms = new Vector();
39 public Vector residues = new Vector();
41 public Sequence sequence;
42 public boolean isVisible = true;
43 public int pdbstart = 0;
44 public int pdbend = 0;
45 public int seqstart = 0;
46 public int seqend = 0;
47 public String pdbid = "";
48 public PDBChain(String pdbid, String id)
50 this.pdbid = pdbid.toLowerCase();
58 for (int i = 0; i < bonds.size(); i++)
60 tmp = tmp + ( (Bond) bonds.elementAt(i)).at1.resName + " " +
61 ( (Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
68 public void makeExactMapping(AlignSeq as, SequenceI s1)
70 int pdbpos = as.getSeq2Start() - 2;
71 int alignpos = s1.getStart() + as.getSeq1Start() - 3;
73 for (int i = 0; i < as.astr1.length(); i++)
75 if (as.astr1.charAt(i) != '-')
80 if (as.astr2.charAt(i) != '-')
85 if (as.astr1.charAt(i) == as.astr2.charAt(i))
87 Residue res = (Residue) residues.elementAt(pdbpos);
88 Enumeration en = res.atoms.elements();
89 while (en.hasMoreElements())
91 Atom atom = (Atom) en.nextElement();
92 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(PDBChain.PDBFILEFEATURE))
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 int i, iSize = atoms.size() - 1;
194 for (i = 0; i <= iSize; i++)
196 Atom tmp = (Atom) atoms.elementAt(i);
197 resNumber = tmp.resNumber;
205 Vector resAtoms = new Vector();
206 //Add atoms to a vector while the residue number
207 //remains the same as the first atom's resNumber (res)
208 while ( (resNumber == res) && (i < atoms.size()))
210 resAtoms.addElement( (Atom) atoms.elementAt(i));
213 if (i < atoms.size())
215 resNumber = ( (Atom) atoms.elementAt(i)).resNumber;
223 //We need this to keep in step with the outer for i = loop
226 //Make a new Residue object with the new atoms vector
227 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
229 Residue tmpres = (Residue) residues.lastElement();
230 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
231 // Make A new SequenceFeature for the current residue numbering
233 new SequenceFeature("RESNUM",
234 tmpat.resName + ":" + tmpat.resNumIns + " " +
236 "", offset + count, offset + count,
237 MCview.PDBChain.PDBFILEFEATURE);
238 resFeatures.addElement(sf);
239 // Keep totting up the sequence
240 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
243 // System.err.println("PDBReader:Null aa3Hash for " +
249 seq.append(ResidueProperties.aa[ ( (Integer) ResidueProperties.
251 .get(tmpat.resName)).intValue()]);
261 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note: resNumber-offset ~= seq.size()
262 // System.out.println("PDB Sequence is :\nSequence = " + seq);
263 // System.out.println("No of residues = " + residues.size());
264 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
266 sequence.addSequenceFeature( (SequenceFeature) resFeatures.elementAt(i));
267 resFeatures.setElementAt(null, i);
271 public void setChargeColours()
273 for (int i = 0; i < bonds.size(); i++)
277 Bond b = (Bond) bonds.elementAt(i);
279 if (b.at1.resName.equalsIgnoreCase("ASP") ||
280 b.at1.resName.equalsIgnoreCase("GLU"))
282 b.startCol = Color.red;
284 else if (b.at1.resName.equalsIgnoreCase("LYS") ||
285 b.at1.resName.equalsIgnoreCase("ARG"))
287 b.startCol = Color.blue;
289 else if (b.at1.resName.equalsIgnoreCase("CYS"))
291 b.startCol = Color.yellow;
295 b.startCol = Color.lightGray;
298 if (b.at2.resName.equalsIgnoreCase("ASP") ||
299 b.at2.resName.equalsIgnoreCase("GLU"))
301 b.endCol = Color.red;
303 else if (b.at2.resName.equalsIgnoreCase("LYS") ||
304 b.at2.resName.equalsIgnoreCase("ARG"))
306 b.endCol = Color.blue;
308 else if (b.at2.resName.equalsIgnoreCase("CYS"))
310 b.endCol = Color.yellow;
314 b.endCol = Color.lightGray;
319 Bond b = (Bond) bonds.elementAt(i);
320 b.startCol = Color.gray;
321 b.endCol = Color.gray;
326 public void setChainColours(jalview.schemes.ColourSchemeI cs)
330 for (int i = 0; i < bonds.size(); i++)
334 b = (Bond) bonds.elementAt(i);
336 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at1.
337 resName)).intValue();
338 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
340 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at2.resName)).
342 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
347 b = (Bond) bonds.elementAt(i);
348 b.startCol = Color.gray;
349 b.endCol = Color.gray;
354 public void setChainColours(Color col)
356 for (int i = 0; i < bonds.size(); i++)
358 Bond tmp = (Bond) bonds.elementAt(i);