2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Hashtable;
26 import java.util.List;
27 import java.util.Vector;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.DBRefSource;
31 import jalview.datamodel.SequenceI;
32 import jalview.io.DataSourceType;
33 import jalview.io.FileParse;
34 import jalview.io.StructureFile;
35 import jalview.util.MessageManager;
37 public class PDBfile extends StructureFile
39 private static String CALC_ID_PREFIX = "JalviewPDB";
41 public PDBfile(boolean addAlignmentAnnotations,
42 boolean predictSecondaryStructure, boolean externalSecStr)
45 addSettings(addAlignmentAnnotations, predictSecondaryStructure,
49 public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr,
50 boolean externalSecStr, String dataObject,
51 DataSourceType sourceType) throws IOException
53 super(false, dataObject, sourceType);
54 addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
58 public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr,
59 boolean externalSecStr, FileParse source) throws IOException
62 addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
67 public String print(SequenceI[] seqs, boolean jvSuffix)
73 public void parse() throws IOException
75 setDbRefType(DBRefSource.PDB);
76 // TODO set the filename sensibly - try using data source name.
77 setId(safeName(getDataName()));
79 setChains(new Vector<PDBChain>());
80 List<SequenceI> rna = new ArrayList<SequenceI>();
81 List<SequenceI> prot = new ArrayList<SequenceI>();
84 boolean modelFlag = false;
85 boolean terFlag = false;
89 String atomnam = null;
92 while ((line = nextLine()) != null)
94 if (line.indexOf("HEADER") == 0)
96 if (line.length() > 62)
99 if (line.length() > 67)
101 tid = line.substring(62, 67).trim();
105 tid = line.substring(62).trim();
107 if (tid.length() > 0)
114 // Were we to do anything with SEQRES - we start it here
115 if (line.indexOf("SEQRES") == 0)
119 if (line.indexOf("MODEL") == 0)
124 if (line.indexOf("TER") == 0)
129 if (modelFlag && line.indexOf("ENDMDL") == 0)
133 if (line.indexOf("ATOM") == 0
134 || (line.indexOf("HETATM") == 0 && !terFlag))
138 // Jalview is only interested in CA bonds????
139 atomnam = line.substring(12, 15).trim();
140 if (!atomnam.equals("CA") && !atomnam.equals("P"))
145 Atom tmpatom = new Atom(line);
146 if (tmpatom.resNumIns.trim().equals(lastID))
148 // phosphorylated protein - seen both CA and P..
151 tmpchain = findChain(tmpatom.chain);
152 if (tmpchain != null)
154 tmpchain.atoms.addElement(tmpatom);
158 // PDBfile never handles alphafold models
159 tmpchain = new PDBChain(getId(), tmpatom.chain);
160 getChains().add(tmpchain);
161 tmpchain.atoms.addElement(tmpatom);
163 lastID = tmpatom.resNumIns.trim();
173 setId(inFile.getName());
175 for (PDBChain chain : getChains())
177 SequenceI chainseq = postProcessChain(chain);
187 if (predictSecondaryStructure)
189 addSecondaryStructure(rna, prot);
191 } catch (OutOfMemoryError er)
193 System.out.println("OUT OF MEMORY LOADING PDB FILE");
194 throw new IOException(MessageManager
195 .getString("exception.outofmemory_loading_pdb_file"));
196 } catch (NumberFormatException ex)
200 System.err.println("Couldn't read number from line:");
201 System.err.println(line);
208 * Process a parsed chain to construct and return a Sequence, and add it to
209 * the list of sequences parsed.
215 public static boolean isCalcIdHandled(String calcId)
217 return calcId != null && (CALC_ID_PREFIX.equals(calcId));
220 public static boolean isCalcIdForFile(AlignmentAnnotation alan,
223 return alan.getCalcId() != null
224 && CALC_ID_PREFIX.equals(alan.getCalcId())
225 && pdbFile.equals(alan.getProperty("PDBID"));
228 public static String relocateCalcId(String calcId,
229 Hashtable<String, String> alreadyLoadedPDB) throws Exception
231 int s = CALC_ID_PREFIX.length(),
232 end = calcId.indexOf(CALC_ID_PREFIX, s);
233 String between = calcId.substring(s, end - 1);
234 return CALC_ID_PREFIX + alreadyLoadedPDB.get(between) + ":"
235 + calcId.substring(end);
238 private void markCalcIds()
240 for (SequenceI sq : seqs)
242 if (sq.getAnnotation() != null)
244 for (AlignmentAnnotation aa : sq.getAnnotation())
246 String oldId = aa.getCalcId();
251 aa.setCalcId(CALC_ID_PREFIX);
252 aa.setProperty("PDBID", getId());
253 aa.setProperty("oldCalcId", oldId);