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;
35 import jalview.io.RnamlFile;
36 import jalview.ws.jws1.Annotate3D;
38 public class PDBfile extends jalview.io.AlignFile
45 * set to true to add chain alignment annotation as visible annotation.
47 boolean VisibleChainAnnotation = false;
49 public PDBfile(String inFile, String inType) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
51 super(inFile, inType);
54 public PDBfile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
64 public void parse() throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
66 // TODO set the filename sensibly - try using data source name.
67 id = safeName(getDataName());
69 chains = new Vector();
73 boolean modelFlag = false;
74 boolean terFlag = false;
78 String atomnam = null;
81 while ((line = nextLine()) != null)
83 if (line.indexOf("HEADER") == 0)
85 if (line.length() > 62)
88 if (line.length() > 67)
90 tid = line.substring(62, 67).trim();
94 tid = line.substring(62).trim();
103 // Were we to do anything with SEQRES - we start it here
104 if (line.indexOf("SEQRES") == 0)
108 if (line.indexOf("MODEL") == 0)
113 if (line.indexOf("TER") == 0)
118 if (modelFlag && line.indexOf("ENDMDL") == 0)
122 if (line.indexOf("ATOM") == 0
123 || (line.indexOf("HETATM") == 0 && !terFlag))
127 // Jalview is only interested in CA bonds????
128 atomnam = line.substring(12, 15).trim();
129 if (!atomnam.equals("CA") && !atomnam.equals("P"))
134 Atom tmpatom = new Atom(line);
135 tmpchain = findChain(tmpatom.chain);
136 if (tmpchain != null)
138 if (tmpatom.resNumIns.trim().equals(lastID))
140 // phosphorylated protein - seen both CA and P..
143 tmpchain.atoms.addElement(tmpatom);
147 tmpchain = new PDBChain(id, tmpatom.chain);
148 chains.addElement(tmpchain);
149 tmpchain.atoms.addElement(tmpatom);
151 lastID = tmpatom.resNumIns.trim();
161 id = inFile.getName();
163 for (int i = 0; i < chains.size(); i++)
165 SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
166 dataset.setName(id + "|" + dataset.getName());
167 PDBEntry entry = new PDBEntry();
171 entry.setFile(inFile.getAbsolutePath());
175 // TODO: decide if we should dump the datasource to disk
176 entry.setFile(getDataName());
178 dataset.addPDBId(entry);
179 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects
180 // maintain reference to
182 seqs.addElement(chainseq);
183 if(isRNA(chainseq)==true)
185 String path =inFile.getPath();
186 System.out.println("this is a PDB format and RNA sequence");
187 Annotate3D an3d = new Annotate3D(path);
188 System.out.println(id);
189 //BufferedWriter r = an3d.getReader();
191 // BufferedReader in = new BufferedReader(new FileReader("temp.rnaml"));
194 // while ((str = in.readLine()) != null) {
195 // System.out.println(str);
196 // System.out.println("toto");
199 //String type = "File";
200 //RnamlFile rnaml =new RnamlFile("temp.rnaml",type);
201 System.out.println("Create rnamfile object");
202 //rnaml.parse("temp");
203 //this.annotations =rnaml.getAnnot();
207 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
209 if (chainannot != null)
211 for (int ai = 0; ai < chainannot.length; ai++)
214 chainannot[ai].visible = VisibleChainAnnotation;
215 annotations.addElement(chainannot[ai]);
219 } catch (OutOfMemoryError er)
221 System.out.println("OUT OF MEMORY LOADING PDB FILE");
222 throw new IOException("Out of memory loading PDB File");
224 catch (NumberFormatException ex)
227 System.err.println("Couldn't read number from line:");
228 System.err.println(line);
234 * make a friendly ID string.
237 * @return truncated dataName to after last '/'
239 private String safeName(String dataName)
242 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
244 dataName = dataName.substring(p + 1);
249 public void makeResidueList()
251 for (int i = 0; i < chains.size(); i++)
253 ((PDBChain) chains.elementAt(i)).makeResidueList();
257 public void makeCaBondList()
259 for (int i = 0; i < chains.size(); i++)
261 ((PDBChain) chains.elementAt(i)).makeCaBondList();
265 public PDBChain findChain(String id)
267 for (int i = 0; i < chains.size(); i++)
269 if (((PDBChain) chains.elementAt(i)).id.equals(id))
271 return (PDBChain) chains.elementAt(i);
278 public void setChargeColours()
280 for (int i = 0; i < chains.size(); i++)
282 ((PDBChain) chains.elementAt(i)).setChargeColours();
286 public void setColours(jalview.schemes.ColourSchemeI cs)
288 for (int i = 0; i < chains.size(); i++)
290 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
294 public void setChainColours()
296 for (int i = 0; i < chains.size(); i++)
298 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
299 1.0f / (float) i, .4f, 1.0f));
302 public boolean isRNA(SequenceI seqs)
304 for (int i=0;i<seqs.getLength();i++){
305 if((seqs.getCharAt(i)!='A') &&(seqs.getCharAt(i)!='C')&&(seqs.getCharAt(i)!='G')&&(seqs.getCharAt(i)!='U'))