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.
21 package jalview.ws.dbsources;
23 import jalview.api.FeatureSettingsModelI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.DBRefSource;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SequenceI;
30 import jalview.io.FormatAdapter;
31 import jalview.io.PDBFeatureSettings;
32 import jalview.util.MessageManager;
33 import jalview.ws.ebi.EBIFetchClient;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Vector;
39 import com.stevesoft.pat.Regex;
45 public class Pdb extends EbiFileRetrievedProxy
52 public static final String FEATURE_INSERTION = "INSERTION";
54 public static final String FEATURE_RES_NUM = "RESNUM";
56 private static String currentDefaultFomart = DBRefSource.PDB;
61 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
64 public String getAccessionSeparator()
66 // TODO Auto-generated method stub
73 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
76 public Regex getAccessionValidator()
78 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
84 * @see jalview.ws.DbSourceProxy#getDbSource()
87 public String getDbSource()
89 return DBRefSource.PDB;
95 * @see jalview.ws.DbSourceProxy#getDbVersion()
98 public String getDbVersion()
106 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
109 public AlignmentI getSequenceRecords(String queries) throws Exception
111 AlignmentI pdbAlignment = null;
112 Vector result = new Vector();
115 if (queries.indexOf(":") > -1)
117 chain = queries.substring(queries.indexOf(":") + 1);
118 id = queries.substring(0, queries.indexOf(":"));
124 if (queries.length() > 4 && chain == null)
126 chain = queries.substring(4, 5);
127 id = queries.substring(0, 4);
129 if (!isValidReference(id))
131 System.err.println("Ignoring invalid pdb query: '" + id + "'");
135 String ext = getCurrentDefaultFomart().equalsIgnoreCase("mmcif") ? ".cif"
137 EBIFetchClient ebi = new EBIFetchClient();
138 file = ebi.fetchDataAsFile("pdb:" + id,
139 getCurrentDefaultFomart().toLowerCase(), "raw", ext)
149 pdbAlignment = new FormatAdapter().readFile(file,
150 jalview.io.AppletFormatAdapter.FILE,
151 getCurrentDefaultFomart());
152 if (pdbAlignment != null)
154 List<SequenceI> toremove = new ArrayList<SequenceI>();
155 for (SequenceI pdbcs : pdbAlignment.getSequences())
159 for (PDBEntry pid : pdbcs.getAllPDBEntries())
161 if (pid.getFile() == file)
163 chid = pid.getChainCode();
170 || (chid != null && (chid.equals(chain)
171 || chid.trim().equals(chain.trim()) || (chain
172 .trim().length() == 0 && chid.equals("_")))))
174 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id
175 + "|" + pdbcs.getName());
176 // Might need to add more metadata to the PDBEntry object
179 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
180 * entry.setId(id); if (entry.getProperty() == null)
181 * entry.setProperty(new Hashtable());
182 * entry.getProperty().put("chains", pdbchain.id + "=" +
183 * sq.getStart() + "-" + sq.getEnd());
184 * sq.getDatasetSequence().addPDBId(entry);
187 // We make a DBRefEtntry because we have obtained the PDB file from
190 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
192 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
193 getDbVersion(), (chid == null ? id : id + chid));
195 pdbcs.addDBRef(dbentry);
199 // mark this sequence to be removed from the alignment
200 // - since it's not from the right chain
204 // now remove marked sequences
205 for (SequenceI pdbcs : toremove)
207 pdbAlignment.deleteSequence(pdbcs);
208 if (pdbcs.getAnnotation() != null)
210 for (AlignmentAnnotation aa : pdbcs.getAnnotation())
212 pdbAlignment.deleteAnnotation(aa);
218 if (pdbAlignment == null || pdbAlignment.getHeight() < 1)
220 throw new Exception(MessageManager.formatMessage(
221 "exception.no_pdb_records_for_chain", new String[] { id,
222 ((chain == null) ? "' '" : chain) }));
225 } catch (Exception ex) // Problem parsing PDB file
236 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
239 public boolean isValidReference(String accession)
241 Regex r = getAccessionValidator();
242 return r.search(accession.trim());
246 * obtain human glyoxalase chain A sequence
249 public String getTestQuery()
255 public String getDbName()
257 return "PDB"; // getDbSource();
266 public static String getCurrentDefaultFomart()
268 return currentDefaultFomart;
271 public static void setCurrentDefaultFomart(String currentDefaultFomart)
273 Pdb.currentDefaultFomart = currentDefaultFomart;
277 * Returns a descriptor for suitable feature display settings with
279 * <li>ResNums or insertions features visible</li>
280 * <li>insertions features coloured red</li>
281 * <li>ResNum features coloured by label</li>
282 * <li>Insertions displayed above (on top of) ResNums</li>
286 public FeatureSettingsModelI getFeatureColourScheme()
288 return new PDBFeatureSettings();