2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
23 import jalview.schemes.ResidueProperties;
28 import jalview.analysis.AlignSeq;
31 public class PDBChain {
33 * SequenceFeature group for PDB File features added to sequences
35 private static final String PDBFILEFEATURE = "PDBFile";
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;
48 public PDBChain(String id) {
52 public String print() {
55 for (int i = 0; i < bonds.size(); i++) {
56 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " " +
57 ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
64 void makeExactMapping(AlignSeq as, Sequence s1)
66 int pdbpos = as.getSeq2Start()-2;
67 int alignpos = s1.getStart() + as.getSeq1Start()-3;
69 for(int i=0; i<as.astr1.length(); i++)
71 if (as.astr1.charAt(i) != '-')
76 if (as.astr2.charAt(i) != '-')
81 if (as.astr1.charAt(i) == as.astr2.charAt(i))
83 Residue res = (Residue) residues.elementAt(pdbpos);
84 Enumeration en = res.atoms.elements();
85 while (en.hasMoreElements())
87 Atom atom = (Atom) en.nextElement();
88 atom.alignmentMapping = alignpos;
94 * copy over the RESNUM seqfeatures from the internal chain sequence to the mapped sequence
97 public void transferRESNUMFeatures(SequenceI seq, String status) {
98 if (seq != sequence) {
99 /** SequenceFeature[] seqsfeatures=seq.getSequenceFeatures();
100 int totfeat=seqsfeatures.length;
101 // Remove any features for this exact chain ?
102 for (int i=0; i<seqsfeatures.length; i++) {
106 status = "IEA:jalview";
107 SequenceFeature[] features = sequence.getSequenceFeatures();
108 for (int i=0; i<features.length; i++) {
109 if (features[i].getFeatureGroup().equals(PDBChain.PDBFILEFEATURE)) {
110 SequenceFeature tx = new SequenceFeature(features[i]);
111 tx.setBegin(1+((Atom)((Residue)residues.elementAt(tx.getBegin()-offset)).atoms.elementAt(0)).alignmentMapping);
112 tx.setEnd(1+((Atom)((Residue)residues.elementAt(tx.getEnd()-offset)).atoms.elementAt(0)).alignmentMapping);
113 tx.setStatus(status+((tx.getStatus()==null || tx.getStatus().length()==0) ? "" : ":"+tx.getStatus()));
114 seq.getDatasetSequence().addSequenceFeature(tx);
121 public void makeCaBondList()
123 for (int i = 0; i < (residues.size() - 1); i++)
125 Residue tmpres = (Residue) residues.elementAt(i);
126 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
127 Atom at1 = tmpres.findAtom("CA");
128 Atom at2 = tmpres2.findAtom("CA");
130 if ((at1 != null) && (at2 != null))
132 if (at1.chain.equals(at2.chain))
138 System.out.println("not found "+i);
142 public void makeBond(Atom at1, Atom at2) {
143 float[] start = new float[3];
144 float[] end = new float[3];
154 bonds.addElement(new Bond(start, end, at1, at2));
157 public void makeResidueList() {
159 StringBuffer seq = new StringBuffer();
160 Vector resFeatures=new Vector();
161 int i, iSize = atoms.size()-1;
163 for (i = 0; i <= iSize; i++)
165 Atom tmp = (Atom) atoms.elementAt(i);
166 resNumber = tmp.resNumber;
173 Vector resAtoms = new Vector();
174 //Add atoms to a vector while the residue number
175 //remains the same as the first atom's resNumber (res)
176 while ((resNumber == res) && (i < atoms.size())) {
177 resAtoms.addElement((Atom) atoms.elementAt(i));
180 if (i < atoms.size()) {
181 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
187 //We need this to keep in step with the outer for i = loop
190 //Make a new Residue object with the new atoms vector
191 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
193 Residue tmpres = (Residue) residues.lastElement();
194 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
195 // Make A new SequenceFeature for the current residue numbering
197 new SequenceFeature("RESNUM",tmpat.resName+":"+tmpat.resNumIns,
198 "",offset+count,offset+count,MCview.PDBChain.PDBFILEFEATURE);
199 resFeatures.addElement(sf);
200 // Keep totting up the sequence
201 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
204 // System.err.println("PDBReader:Null aa3Hash for " +
208 seq.append(ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()
209 .get(tmpat.resName)).intValue()]);
214 if(id.length()<1 || id.equals(" "))
217 sequence = new Sequence(id, seq.toString(), offset, resNumber); // resNumber-offset ~= seq.size()
218 // System.out.println("PDB Sequence is :\nSequence = " + seq);
219 // System.out.println("No of residues = " + residues.size());
220 for (i=0,iSize=resFeatures.size(); i<iSize; i++) {
221 sequence.addSequenceFeature((SequenceFeature) resFeatures.elementAt(i));
222 resFeatures.setElementAt(null, i);
226 public void setChargeColours() {
227 for (int i = 0; i < bonds.size(); i++) {
229 Bond b = (Bond) bonds.elementAt(i);
231 if (b.at1.resName.equalsIgnoreCase("ASP") ||
232 b.at1.resName.equalsIgnoreCase("GLU")) {
233 b.startCol = Color.red;
234 } else if (b.at1.resName.equalsIgnoreCase("LYS") ||
235 b.at1.resName.equalsIgnoreCase("ARG")) {
236 b.startCol = Color.blue;
237 } else if (b.at1.resName.equalsIgnoreCase("CYS")) {
238 b.startCol = Color.yellow;
240 //int atno = ((Integer) ResidueProperties.getAA3Hash().get(b.at1.resName.toUpperCase())).intValue();
241 b.startCol = Color.lightGray;
244 if (b.at2.resName.equalsIgnoreCase("ASP") ||
245 b.at2.resName.equalsIgnoreCase("GLU")) {
246 b.endCol = Color.red;
247 } else if (b.at2.resName.equalsIgnoreCase("LYS") ||
248 b.at2.resName.equalsIgnoreCase("ARG")) {
249 b.endCol = Color.blue;
250 } else if (b.at2.resName.equalsIgnoreCase("CYS")) {
251 b.endCol = Color.yellow;
253 //int atno = ((Integer) ResidueProperties.getAA3Hash().get(b.at2.resName.toUpperCase())).intValue();
254 b.endCol = Color.lightGray;
256 } catch (Exception e) {
257 Bond b = (Bond) bonds.elementAt(i);
258 b.startCol = Color.gray;
259 b.endCol = Color.gray;
265 public void setChainColours(jalview.schemes.ColourSchemeI cs)
268 for (int i = 0; i < bonds.size(); i++) {
270 b = (Bond) bonds.elementAt(i);
272 /* ( (Bond) bonds.elementAt(i)).startCol = cs.findColour(
273 ResidueProperties.codonTranslate(
274 ResidueProperties.aa3Hash.get(b.at1.resName).toString().charAt(0)
277 b.endCol = cs.findColour(
278 ResidueProperties.aa[ ( (Integer) ResidueProperties.aa3Hash.
279 get(b.at2.resName)).intValue()]
282 } catch (Exception e)
284 b = (Bond) bonds.elementAt(i);
285 b.startCol = Color.gray;
286 b.endCol = Color.gray;
293 public void setChainColours(Color col)
295 for (int i = 0; i < bonds.size(); i++)
297 Bond tmp = (Bond) bonds.elementAt(i);