3 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
4 * Copyright (C) $$Year-Rel$$ The Jalview Authors
6 * This file is part of Jalview.
8 * Jalview is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation, either version 3
11 * of the License, or (at your option) any later version.
13 * Jalview is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 package jalview.ws.dbsources;
24 import jalview.api.FeatureSettingsModelI;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.DBRefEntry;
28 import jalview.datamodel.DBRefSource;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.PDBEntry.Type;
31 import jalview.datamodel.SequenceI;
32 import jalview.io.DataSourceType;
33 import jalview.io.FileFormat;
34 import jalview.io.FileFormatI;
35 import jalview.io.FormatAdapter;
36 import jalview.io.PDBFeatureSettings;
37 import jalview.structure.StructureImportSettings;
38 import jalview.util.MessageManager;
39 import jalview.ws.ebi.EBIFetchClient;
42 import java.util.ArrayList;
43 import java.util.List;
45 import com.stevesoft.pat.Regex;
51 public class Pdb extends EbiFileRetrievedProxy
53 private static final String SEPARATOR = "|";
55 private static final String COLON = ":";
57 private static final int PDB_ID_LENGTH = 4;
67 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
70 public String getAccessionSeparator()
78 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
81 public Regex getAccessionValidator()
83 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
89 * @see jalview.ws.DbSourceProxy#getDbSource()
92 public String getDbSource()
94 return DBRefSource.PDB;
100 * @see jalview.ws.DbSourceProxy#getDbVersion()
103 public String getDbVersion()
111 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
114 public AlignmentI getSequenceRecords(String queries) throws Exception
116 AlignmentI pdbAlignment = null;
119 if (queries.indexOf(COLON) > -1)
121 chain = queries.substring(queries.indexOf(COLON) + 1);
122 id = queries.substring(0, queries.indexOf(COLON));
130 * extract chain code if it is appended to the id and we
131 * don't already have one
133 if (queries.length() > PDB_ID_LENGTH && chain == null)
135 chain = queries.substring(PDB_ID_LENGTH, PDB_ID_LENGTH + 1);
136 id = queries.substring(0, PDB_ID_LENGTH);
139 if (!isValidReference(id))
141 System.err.println("Ignoring invalid pdb query: '" + id + "'");
147 * ensure that an mmCIF format structure file is saved with extension.cif,
148 * because the Chimera "open" command recognises this extension
150 Type pdbFileFormat = StructureImportSettings
151 .getDefaultStructureFileFormat();
152 String ext = pdbFileFormat.getExtension();
153 String fetchFormat = pdbFileFormat.getFormat();
155 EBIFetchClient ebi = new EBIFetchClient();
156 File tmpFile = ebi.fetchDataAsFile("pdb:" + id, fetchFormat, ext);
157 file = tmpFile.getAbsolutePath();
165 // todo get rid of Type and use FileFormatI instead?
166 FileFormatI fileFormat = (pdbFileFormat == Type.PDB) ? FileFormat.PDB
168 pdbAlignment = new FormatAdapter().readFile(file, DataSourceType.FILE,
170 if (pdbAlignment != null)
172 List<SequenceI> toremove = new ArrayList<SequenceI>();
173 for (SequenceI pdbcs : pdbAlignment.getSequences())
177 for (PDBEntry pid : pdbcs.getAllPDBEntries())
179 if (pid.getFile() == file)
181 chid = pid.getChainCode();
185 if (chain == null || (chid != null && (chid.equals(chain)
186 || chid.trim().equals(chain.trim())
187 || (chain.trim().length() == 0 && chid.equals("_")))))
189 // FIXME seems to result in 'PDB|1QIP|1qip|A' - 1QIP is redundant.
190 // TODO: suggest simplify naming to 1qip|A as default name defined
191 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + SEPARATOR + id
192 + SEPARATOR + pdbcs.getName());
193 // Might need to add more metadata to the PDBEntry object
196 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
197 * entry.setId(id); if (entry.getProperty() == null)
198 * entry.setProperty(new Hashtable());
199 * entry.getProperty().put("chains", pdbchain.id + "=" +
200 * sq.getStart() + "-" + sq.getEnd());
201 * sq.getDatasetSequence().addPDBId(entry);
204 // We make a DBRefEtntry because we have obtained the PDB file from
207 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
209 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
210 getDbVersion(), (chid == null ? id : id + chid));
212 pdbcs.addDBRef(dbentry);
216 // mark this sequence to be removed from the alignment
217 // - since it's not from the right chain
221 // now remove marked sequences
222 for (SequenceI pdbcs : toremove)
224 pdbAlignment.deleteSequence(pdbcs);
225 if (pdbcs.getAnnotation() != null)
227 for (AlignmentAnnotation aa : pdbcs.getAnnotation())
229 pdbAlignment.deleteAnnotation(aa);
235 if (pdbAlignment == null || pdbAlignment.getHeight() < 1)
237 throw new Exception(MessageManager.formatMessage(
238 "exception.no_pdb_records_for_chain", new String[]
239 { id, ((chain == null) ? "' '" : chain) }));
242 } catch (Exception ex) // Problem parsing PDB file
253 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
256 public boolean isValidReference(String accession)
258 Regex r = getAccessionValidator();
259 return r.search(accession.trim());
266 public String getTestQuery()
272 public String getDbName()
274 return "PDB"; // getDbSource();
284 * Returns a descriptor for suitable feature display settings with
286 * <li>ResNums or insertions features visible</li>
287 * <li>insertions features coloured red</li>
288 * <li>ResNum features coloured by label</li>
289 * <li>Insertions displayed above (on top of) ResNums</li>
293 public FeatureSettingsModelI getFeatureColourScheme()
295 return new PDBFeatureSettings();