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)
113 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 seq.addSequenceFeature(tx);
147 public void makeCaBondList()
149 for (int i = 0; i < (residues.size() - 1); i++)
151 Residue tmpres = (Residue) residues.elementAt(i);
152 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
153 Atom at1 = tmpres.findAtom("CA");
154 Atom at2 = tmpres2.findAtom("CA");
156 if ( (at1 != null) && (at2 != null))
158 if (at1.chain.equals(at2.chain))
165 System.out.println("not found " + i);
170 public void makeBond(Atom at1, Atom at2)
172 float[] start = new float[3];
173 float[] end = new float[3];
183 bonds.addElement(new Bond(start, end, at1, at2));
186 public void makeResidueList()
189 StringBuffer seq = new StringBuffer();
190 Vector resFeatures = new Vector();
191 int i, iSize = atoms.size() - 1;
193 for (i = 0; i <= iSize; i++)
195 Atom tmp = (Atom) atoms.elementAt(i);
196 resNumber = tmp.resNumber;
204 Vector resAtoms = new Vector();
205 //Add atoms to a vector while the residue number
206 //remains the same as the first atom's resNumber (res)
207 while ( (resNumber == res) && (i < atoms.size()))
209 resAtoms.addElement( (Atom) atoms.elementAt(i));
212 if (i < atoms.size())
214 resNumber = ( (Atom) atoms.elementAt(i)).resNumber;
222 //We need this to keep in step with the outer for i = loop
225 //Make a new Residue object with the new atoms vector
226 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
228 Residue tmpres = (Residue) residues.lastElement();
229 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
230 // Make A new SequenceFeature for the current residue numbering
232 new SequenceFeature("RESNUM",
233 tmpat.resName + ":" + tmpat.resNumIns + " " +
235 "", offset + count, offset + count,
236 MCview.PDBChain.PDBFILEFEATURE);
237 resFeatures.addElement(sf);
238 // Keep totting up the sequence
239 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
242 // System.err.println("PDBReader:Null aa3Hash for " +
248 seq.append(ResidueProperties.aa[ ( (Integer) ResidueProperties.
250 .get(tmpat.resName)).intValue()]);
260 sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note: resNumber-offset ~= seq.size()
261 // System.out.println("PDB Sequence is :\nSequence = " + seq);
262 // System.out.println("No of residues = " + residues.size());
263 for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
265 sequence.addSequenceFeature( (SequenceFeature) resFeatures.elementAt(i));
266 resFeatures.setElementAt(null, i);
270 public void setChargeColours()
272 for (int i = 0; i < bonds.size(); i++)
276 Bond b = (Bond) bonds.elementAt(i);
278 if (b.at1.resName.equalsIgnoreCase("ASP") ||
279 b.at1.resName.equalsIgnoreCase("GLU"))
281 b.startCol = Color.red;
283 else if (b.at1.resName.equalsIgnoreCase("LYS") ||
284 b.at1.resName.equalsIgnoreCase("ARG"))
286 b.startCol = Color.blue;
288 else if (b.at1.resName.equalsIgnoreCase("CYS"))
290 b.startCol = Color.yellow;
294 b.startCol = Color.lightGray;
297 if (b.at2.resName.equalsIgnoreCase("ASP") ||
298 b.at2.resName.equalsIgnoreCase("GLU"))
300 b.endCol = Color.red;
302 else if (b.at2.resName.equalsIgnoreCase("LYS") ||
303 b.at2.resName.equalsIgnoreCase("ARG"))
305 b.endCol = Color.blue;
307 else if (b.at2.resName.equalsIgnoreCase("CYS"))
309 b.endCol = Color.yellow;
313 b.endCol = Color.lightGray;
318 Bond b = (Bond) bonds.elementAt(i);
319 b.startCol = Color.gray;
320 b.endCol = Color.gray;
325 public void setChainColours(jalview.schemes.ColourSchemeI cs)
329 for (int i = 0; i < bonds.size(); i++)
333 b = (Bond) bonds.elementAt(i);
335 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at1.
336 resName)).intValue();
337 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
339 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at2.resName)).
341 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
346 b = (Bond) bonds.elementAt(i);
347 b.startCol = Color.gray;
348 b.endCol = Color.gray;
353 public void setChainColours(Color col)
355 for (int i = 0; i < bonds.size(); i++)
357 Bond tmp = (Bond) bonds.elementAt(i);