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";
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) {
50 this.pdbid=pdbid.toLowerCase();
54 public String print() {
57 for (int i = 0; i < bonds.size(); i++) {
58 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " " +
59 ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
66 void makeExactMapping(AlignSeq as, Sequence s1)
68 int pdbpos = as.getSeq2Start()-2;
69 int alignpos = s1.getStart() + as.getSeq1Start()-3;
71 for(int i=0; i<as.astr1.length(); i++)
73 if (as.astr1.charAt(i) != '-')
78 if (as.astr2.charAt(i) != '-')
83 if (as.astr1.charAt(i) == as.astr2.charAt(i))
85 Residue res = (Residue) residues.elementAt(pdbpos);
86 Enumeration en = res.atoms.elements();
87 while (en.hasMoreElements())
89 Atom atom = (Atom) en.nextElement();
90 atom.alignmentMapping = alignpos;
96 * copy over the RESNUM seqfeatures from the internal chain sequence to the mapped sequence
98 * @param status The Status of the transferred annotation
99 * @return the features added to sq (or its dataset)
101 public SequenceFeature[] transferRESNUMFeatures(SequenceI seq, String status) {
106 sq = sq.getDatasetSequence();
109 * Remove any existing features for this chain if they exist ?
110 * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures();
111 int totfeat=seqsfeatures.length;
112 // Remove any features for this exact chain ?
113 for (int i=0; i<seqsfeatures.length; i++) {
116 status = PDBChain.IEASTATUS;
117 SequenceFeature[] features = sequence.getSequenceFeatures();
118 for (int i=0; i<features.length; i++) {
119 if (features[i].getFeatureGroup().equals(PDBChain.PDBFILEFEATURE)) {
120 SequenceFeature tx = new SequenceFeature(features[i]);
121 tx.setBegin(1+((Atom)((Residue)residues.elementAt(tx.getBegin()-offset)).atoms.elementAt(0)).alignmentMapping);
122 tx.setEnd(1+((Atom)((Residue)residues.elementAt(tx.getEnd()-offset)).atoms.elementAt(0)).alignmentMapping);
123 tx.setStatus(status+((tx.getStatus()==null || tx.getStatus().length()==0) ? "" : ":"+tx.getStatus()));
124 seq.addSequenceFeature(tx);
130 public void makeCaBondList()
132 for (int i = 0; i < (residues.size() - 1); i++)
134 Residue tmpres = (Residue) residues.elementAt(i);
135 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
136 Atom at1 = tmpres.findAtom("CA");
137 Atom at2 = tmpres2.findAtom("CA");
139 if ((at1 != null) && (at2 != null))
141 if (at1.chain.equals(at2.chain))
147 System.out.println("not found "+i);
151 public void makeBond(Atom at1, Atom at2) {
152 float[] start = new float[3];
153 float[] end = new float[3];
163 bonds.addElement(new Bond(start, end, at1, at2));
166 public void makeResidueList() {
168 StringBuffer seq = new StringBuffer();
169 Vector resFeatures=new Vector();
170 int i, iSize = atoms.size()-1;
172 for (i = 0; i <= iSize; i++)
174 Atom tmp = (Atom) atoms.elementAt(i);
175 resNumber = tmp.resNumber;
182 Vector resAtoms = new Vector();
183 //Add atoms to a vector while the residue number
184 //remains the same as the first atom's resNumber (res)
185 while ((resNumber == res) && (i < atoms.size())) {
186 resAtoms.addElement((Atom) atoms.elementAt(i));
189 if (i < atoms.size()) {
190 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
196 //We need this to keep in step with the outer for i = loop
199 //Make a new Residue object with the new atoms vector
200 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
202 Residue tmpres = (Residue) residues.lastElement();
203 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
204 // Make A new SequenceFeature for the current residue numbering
206 new SequenceFeature("RESNUM",tmpat.resName+":"+tmpat.resNumIns+" "+pdbid+id,
207 "",offset+count,offset+count,MCview.PDBChain.PDBFILEFEATURE);
208 resFeatures.addElement(sf);
209 // Keep totting up the sequence
210 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
213 // System.err.println("PDBReader:Null aa3Hash for " +
217 seq.append(ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()
218 .get(tmpat.resName)).intValue()]);
223 if(id.length()<1 || id.equals(" "))
226 sequence = new Sequence(id, seq.toString(), offset, resNumber-1); // Note: resNumber-offset ~= seq.size()
227 // System.out.println("PDB Sequence is :\nSequence = " + seq);
228 // System.out.println("No of residues = " + residues.size());
229 for (i=0,iSize=resFeatures.size(); i<iSize; i++) {
230 sequence.addSequenceFeature((SequenceFeature) resFeatures.elementAt(i));
231 resFeatures.setElementAt(null, i);
235 public void setChargeColours() {
236 for (int i = 0; i < bonds.size(); i++) {
238 Bond b = (Bond) bonds.elementAt(i);
240 if (b.at1.resName.equalsIgnoreCase("ASP") ||
241 b.at1.resName.equalsIgnoreCase("GLU")) {
242 b.startCol = Color.red;
243 } else if (b.at1.resName.equalsIgnoreCase("LYS") ||
244 b.at1.resName.equalsIgnoreCase("ARG")) {
245 b.startCol = Color.blue;
246 } else if (b.at1.resName.equalsIgnoreCase("CYS")) {
247 b.startCol = Color.yellow;
249 b.startCol = Color.lightGray;
252 if (b.at2.resName.equalsIgnoreCase("ASP") ||
253 b.at2.resName.equalsIgnoreCase("GLU")) {
254 b.endCol = Color.red;
255 } else if (b.at2.resName.equalsIgnoreCase("LYS") ||
256 b.at2.resName.equalsIgnoreCase("ARG")) {
257 b.endCol = Color.blue;
258 } else if (b.at2.resName.equalsIgnoreCase("CYS")) {
259 b.endCol = Color.yellow;
261 b.endCol = Color.lightGray;
263 } catch (Exception e) {
264 Bond b = (Bond) bonds.elementAt(i);
265 b.startCol = Color.gray;
266 b.endCol = Color.gray;
272 public void setChainColours(jalview.schemes.ColourSchemeI cs)
276 for (int i = 0; i < bonds.size(); i++) {
278 b = (Bond) bonds.elementAt(i);
280 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at1.
281 resName)).intValue();
282 b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
284 index = ( (Integer) ResidueProperties.aa3Hash.get(b.at2.resName)).
286 b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
288 } catch (Exception e)
290 b = (Bond) bonds.elementAt(i);
291 b.startCol = Color.gray;
292 b.endCol = Color.gray;
299 public void setChainColours(Color col)
301 for (int i = 0; i < bonds.size(); i++)
303 Bond tmp = (Bond) bonds.elementAt(i);