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;
41 import java.util.ArrayList;
42 import java.util.List;
43 import java.util.Vector;
45 import com.stevesoft.pat.Regex;
51 public class Pdb extends EbiFileRetrievedProxy
58 public static final String FEATURE_INSERTION = "INSERTION";
60 public static final String FEATURE_RES_NUM = "RESNUM";
65 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
68 public String getAccessionSeparator()
70 // TODO Auto-generated method stub
77 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
80 public Regex getAccessionValidator()
82 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
88 * @see jalview.ws.DbSourceProxy#getDbSource()
91 public String getDbSource()
93 return DBRefSource.PDB;
99 * @see jalview.ws.DbSourceProxy#getDbVersion()
102 public String getDbVersion()
110 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
113 public AlignmentI getSequenceRecords(String queries) throws Exception
115 AlignmentI pdbAlignment = null;
116 Vector result = new Vector();
119 if (queries.indexOf(":") > -1)
121 chain = queries.substring(queries.indexOf(":") + 1);
122 id = queries.substring(0, queries.indexOf(":"));
128 if (queries.length() > 4 && chain == null)
130 chain = queries.substring(4, 5);
131 id = queries.substring(0, 4);
133 if (!isValidReference(id))
135 System.err.println("Ignoring invalid pdb query: '" + id + "'");
139 Type pdbFileFormat = StructureImportSettings
140 .getDefaultStructureFileFormat();
141 String ext = "." + pdbFileFormat.getExtension();
142 EBIFetchClient ebi = new EBIFetchClient();
143 file = ebi.fetchDataAsFile("pdb:" + id, pdbFileFormat.getFormat(), ext)
152 // convert Type.PDB/MMCIF to FileFormat.PDB/MMCIF
153 // todo get rid of Type?
154 FileFormatI fileFormat = FileFormat.valueOf(pdbFileFormat.toString());
155 pdbAlignment = new FormatAdapter().readFile(file,
156 DataSourceType.FILE, fileFormat);
157 if (pdbAlignment != null)
159 List<SequenceI> toremove = new ArrayList<SequenceI>();
160 for (SequenceI pdbcs : pdbAlignment.getSequences())
164 for (PDBEntry pid : pdbcs.getAllPDBEntries())
166 if (pid.getFile() == file)
168 chid = pid.getChainCode();
175 || (chid != null && (chid.equals(chain)
176 || chid.trim().equals(chain.trim()) || (chain
177 .trim().length() == 0 && chid.equals("_")))))
179 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id
180 + "|" + pdbcs.getName());
181 // Might need to add more metadata to the PDBEntry object
184 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
185 * entry.setId(id); if (entry.getProperty() == null)
186 * entry.setProperty(new Hashtable());
187 * entry.getProperty().put("chains", pdbchain.id + "=" +
188 * sq.getStart() + "-" + sq.getEnd());
189 * sq.getDatasetSequence().addPDBId(entry);
192 // We make a DBRefEtntry because we have obtained the PDB file from
195 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
197 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
198 getDbVersion(), (chid == null ? id : id + chid));
200 pdbcs.addDBRef(dbentry);
204 // mark this sequence to be removed from the alignment
205 // - since it's not from the right chain
209 // now remove marked sequences
210 for (SequenceI pdbcs : toremove)
212 pdbAlignment.deleteSequence(pdbcs);
213 if (pdbcs.getAnnotation() != null)
215 for (AlignmentAnnotation aa : pdbcs.getAnnotation())
217 pdbAlignment.deleteAnnotation(aa);
223 if (pdbAlignment == null || pdbAlignment.getHeight() < 1)
225 throw new Exception(MessageManager.formatMessage(
226 "exception.no_pdb_records_for_chain", new String[] { id,
227 ((chain == null) ? "' '" : chain) }));
230 } catch (Exception ex) // Problem parsing PDB file
241 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
244 public boolean isValidReference(String accession)
246 Regex r = getAccessionValidator();
247 return r.search(accession.trim());
254 public String getTestQuery()
260 public String getDbName()
262 return "PDB"; // getDbSource();
273 * Returns a descriptor for suitable feature display settings with
275 * <li>ResNums or insertions features visible</li>
276 * <li>insertions features coloured red</li>
277 * <li>ResNum features coloured by label</li>
278 * <li>Insertions displayed above (on top of) ResNums</li>
282 public FeatureSettingsModelI getFeatureColourScheme()
284 return new PDBFeatureSettings();