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.FormatAdapter;
33 import jalview.io.PDBFeatureSettings;
34 import jalview.structure.StructureImportSettings;
35 import jalview.util.MessageManager;
36 import jalview.ws.ebi.EBIFetchClient;
38 import java.util.ArrayList;
39 import java.util.List;
40 import java.util.Vector;
42 import com.stevesoft.pat.Regex;
48 public class Pdb extends EbiFileRetrievedProxy
55 public static final String FEATURE_INSERTION = "INSERTION";
57 public static final String FEATURE_RES_NUM = "RESNUM";
62 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
65 public String getAccessionSeparator()
67 // TODO Auto-generated method stub
74 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
77 public Regex getAccessionValidator()
79 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
85 * @see jalview.ws.DbSourceProxy#getDbSource()
88 public String getDbSource()
90 return DBRefSource.PDB;
96 * @see jalview.ws.DbSourceProxy#getDbVersion()
99 public String getDbVersion()
107 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
110 public AlignmentI getSequenceRecords(String queries) throws Exception
112 AlignmentI pdbAlignment = null;
113 Vector result = new Vector();
116 if (queries.indexOf(":") > -1)
118 chain = queries.substring(queries.indexOf(":") + 1);
119 id = queries.substring(0, queries.indexOf(":"));
125 if (queries.length() > 4 && chain == null)
127 chain = queries.substring(4, 5);
128 id = queries.substring(0, 4);
130 if (!isValidReference(id))
132 System.err.println("Ignoring invalid pdb query: '" + id + "'");
136 String ext = StructureImportSettings.getDefaultStructureFileFormat()
137 .equalsIgnoreCase(Type.MMCIF.toString()) ? ".cif" : ".xml";
138 EBIFetchClient ebi = new EBIFetchClient();
139 file = ebi.fetchDataAsFile("pdb:" + id,
140 StructureImportSettings.getDefaultStructureFileFormat().toLowerCase(),
151 pdbAlignment = new FormatAdapter().readFile(file,
152 jalview.io.AppletFormatAdapter.FILE,
153 StructureImportSettings.getDefaultStructureFileFormat());
154 if (pdbAlignment != null)
156 List<SequenceI> toremove = new ArrayList<SequenceI>();
157 for (SequenceI pdbcs : pdbAlignment.getSequences())
161 for (PDBEntry pid : pdbcs.getAllPDBEntries())
163 if (pid.getFile() == file)
165 chid = pid.getChainCode();
172 || (chid != null && (chid.equals(chain)
173 || chid.trim().equals(chain.trim()) || (chain
174 .trim().length() == 0 && chid.equals("_")))))
176 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id
177 + "|" + pdbcs.getName());
178 // Might need to add more metadata to the PDBEntry object
181 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
182 * entry.setId(id); if (entry.getProperty() == null)
183 * entry.setProperty(new Hashtable());
184 * entry.getProperty().put("chains", pdbchain.id + "=" +
185 * sq.getStart() + "-" + sq.getEnd());
186 * sq.getDatasetSequence().addPDBId(entry);
189 // We make a DBRefEtntry because we have obtained the PDB file from
192 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
194 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
195 getDbVersion(), (chid == null ? id : id + chid));
197 pdbcs.addDBRef(dbentry);
201 // mark this sequence to be removed from the alignment
202 // - since it's not from the right chain
206 // now remove marked sequences
207 for (SequenceI pdbcs : toremove)
209 pdbAlignment.deleteSequence(pdbcs);
210 if (pdbcs.getAnnotation() != null)
212 for (AlignmentAnnotation aa : pdbcs.getAnnotation())
214 pdbAlignment.deleteAnnotation(aa);
220 if (pdbAlignment == null || pdbAlignment.getHeight() < 1)
222 throw new Exception(MessageManager.formatMessage(
223 "exception.no_pdb_records_for_chain", new String[] { id,
224 ((chain == null) ? "' '" : chain) }));
227 } catch (Exception ex) // Problem parsing PDB file
238 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
241 public boolean isValidReference(String accession)
243 Regex r = getAccessionValidator();
244 return r.search(accession.trim());
251 public String getTestQuery()
257 public String getDbName()
259 return "PDB"; // getDbSource();
270 * Returns a descriptor for suitable feature display settings with
272 * <li>ResNums or insertions features visible</li>
273 * <li>insertions features coloured red</li>
274 * <li>ResNum features coloured by label</li>
275 * <li>Insertions displayed above (on top of) ResNums</li>
279 public FeatureSettingsModelI getFeatureColourScheme()
281 return new PDBFeatureSettings();