2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
25 import javax.xml.parsers.ParserConfigurationException;
27 import org.xml.sax.SAXException;
29 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
30 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
31 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
33 import jalview.datamodel.*;
34 import jalview.io.FileParse;
36 public class PDBfile extends jalview.io.AlignFile
43 * set to true to add chain alignment annotation as visible annotation.
45 boolean VisibleChainAnnotation = false;
47 public PDBfile(String inFile, String inType) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
49 super(inFile, inType);
52 public PDBfile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
62 public void parse() throws IOException
64 // TODO set the filename sensibly - try using data source name.
65 id = safeName(getDataName());
67 chains = new Vector();
71 boolean modelFlag = false;
72 boolean terFlag = false;
76 String atomnam = null;
79 while ((line = nextLine()) != null)
81 if (line.indexOf("HEADER") == 0)
83 if (line.length() > 62)
86 if (line.length() > 67)
88 tid = line.substring(62, 67).trim();
92 tid = line.substring(62).trim();
101 // Were we to do anything with SEQRES - we start it here
102 if (line.indexOf("SEQRES") == 0)
106 if (line.indexOf("MODEL") == 0)
111 if (line.indexOf("TER") == 0)
116 if (modelFlag && line.indexOf("ENDMDL") == 0)
120 if (line.indexOf("ATOM") == 0
121 || (line.indexOf("HETATM") == 0 && !terFlag))
125 // Jalview is only interested in CA bonds????
126 atomnam = line.substring(12, 15).trim();
127 if (!atomnam.equals("CA") && !atomnam.equals("P"))
132 Atom tmpatom = new Atom(line);
133 tmpchain = findChain(tmpatom.chain);
134 if (tmpchain != null)
136 if (tmpatom.resNumIns.trim().equals(lastID))
138 // phosphorylated protein - seen both CA and P..
141 tmpchain.atoms.addElement(tmpatom);
145 tmpchain = new PDBChain(id, tmpatom.chain);
146 chains.addElement(tmpchain);
147 tmpchain.atoms.addElement(tmpatom);
149 lastID = tmpatom.resNumIns.trim();
159 id = inFile.getName();
161 for (int i = 0; i < chains.size(); i++)
163 SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
164 dataset.setName(id + "|" + dataset.getName());
165 PDBEntry entry = new PDBEntry();
169 entry.setFile(inFile.getAbsolutePath());
173 // TODO: decide if we should dump the datasource to disk
174 entry.setFile(getDataName());
176 dataset.addPDBId(entry);
177 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects
178 // maintain reference to
180 seqs.addElement(chainseq);
181 if(isRNA(chainseq)==true)
183 System.out.println("this is a PDB format and RNA sequence");
186 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
188 if (chainannot != null)
190 for (int ai = 0; ai < chainannot.length; ai++)
193 chainannot[ai].visible = VisibleChainAnnotation;
194 annotations.addElement(chainannot[ai]);
198 } catch (OutOfMemoryError er)
200 System.out.println("OUT OF MEMORY LOADING PDB FILE");
201 throw new IOException("Out of memory loading PDB File");
203 catch (NumberFormatException ex)
206 System.err.println("Couldn't read number from line:");
207 System.err.println(line);
213 * make a friendly ID string.
216 * @return truncated dataName to after last '/'
218 private String safeName(String dataName)
221 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
223 dataName = dataName.substring(p + 1);
228 public void makeResidueList()
230 for (int i = 0; i < chains.size(); i++)
232 ((PDBChain) chains.elementAt(i)).makeResidueList();
236 public void makeCaBondList()
238 for (int i = 0; i < chains.size(); i++)
240 ((PDBChain) chains.elementAt(i)).makeCaBondList();
244 public PDBChain findChain(String id)
246 for (int i = 0; i < chains.size(); i++)
248 if (((PDBChain) chains.elementAt(i)).id.equals(id))
250 return (PDBChain) chains.elementAt(i);
257 public void setChargeColours()
259 for (int i = 0; i < chains.size(); i++)
261 ((PDBChain) chains.elementAt(i)).setChargeColours();
265 public void setColours(jalview.schemes.ColourSchemeI cs)
267 for (int i = 0; i < chains.size(); i++)
269 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
273 public void setChainColours()
275 for (int i = 0; i < chains.size(); i++)
277 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
278 1.0f / (float) i, .4f, 1.0f));
281 public boolean isRNA(SequenceI seqs)
283 for (int i=0;i<seqs.getLength();i++){
284 if((seqs.getCharAt(i)!='A') &&(seqs.getCharAt(i)!='C')&&(seqs.getCharAt(i)!='G')&&(seqs.getCharAt(i)!='U'))