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 System.out.println("this is a PDB format and RNA sequence");
186 Annotate3D an3d = new Annotate3D(id);
187 System.out.println(id);
188 //BufferedWriter r = an3d.getReader();
190 BufferedReader in = new BufferedReader(new FileReader("temp.rnaml"));
193 while ((str = in.readLine()) != null) {
194 System.out.println(str);
195 System.out.println("toto");
198 String type = "File";
199 RnamlFile rnaml =new RnamlFile("temp.rnaml",type);
200 System.out.println("Create rnamfile object");
201 //rnaml.parse("temp");
202 this.annotations =rnaml.getAnnot();
206 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
208 if (chainannot != null)
210 for (int ai = 0; ai < chainannot.length; ai++)
213 chainannot[ai].visible = VisibleChainAnnotation;
214 annotations.addElement(chainannot[ai]);
218 } catch (OutOfMemoryError er)
220 System.out.println("OUT OF MEMORY LOADING PDB FILE");
221 throw new IOException("Out of memory loading PDB File");
223 catch (NumberFormatException ex)
226 System.err.println("Couldn't read number from line:");
227 System.err.println(line);
233 * make a friendly ID string.
236 * @return truncated dataName to after last '/'
238 private String safeName(String dataName)
241 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
243 dataName = dataName.substring(p + 1);
248 public void makeResidueList()
250 for (int i = 0; i < chains.size(); i++)
252 ((PDBChain) chains.elementAt(i)).makeResidueList();
256 public void makeCaBondList()
258 for (int i = 0; i < chains.size(); i++)
260 ((PDBChain) chains.elementAt(i)).makeCaBondList();
264 public PDBChain findChain(String id)
266 for (int i = 0; i < chains.size(); i++)
268 if (((PDBChain) chains.elementAt(i)).id.equals(id))
270 return (PDBChain) chains.elementAt(i);
277 public void setChargeColours()
279 for (int i = 0; i < chains.size(); i++)
281 ((PDBChain) chains.elementAt(i)).setChargeColours();
285 public void setColours(jalview.schemes.ColourSchemeI cs)
287 for (int i = 0; i < chains.size(); i++)
289 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
293 public void setChainColours()
295 for (int i = 0; i < chains.size(); i++)
297 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
298 1.0f / (float) i, .4f, 1.0f));
301 public boolean isRNA(SequenceI seqs)
303 for (int i=0;i<seqs.getLength();i++){
304 if((seqs.getCharAt(i)!='A') &&(seqs.getCharAt(i)!='C')&&(seqs.getCharAt(i)!='G')&&(seqs.getCharAt(i)!='U'))