2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.dbsources;
20 import jalview.datamodel.Alignment;
21 import jalview.datamodel.DBRefEntry;
22 import jalview.datamodel.DBRefSource;
23 import jalview.datamodel.PDBEntry;
24 import jalview.datamodel.SequenceI;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Vector;
30 import MCview.PDBChain;
31 import MCview.PDBfile;
33 import com.stevesoft.pat.Regex;
35 import jalview.datamodel.AlignmentI;
36 import jalview.io.FormatAdapter;
37 import jalview.ws.ebi.EBIFetchClient;
38 import jalview.ws.seqfetcher.DbSourceProxy;
44 public class Pdb extends EbiFileRetrievedProxy implements DbSourceProxy
49 addDbSourceProperty(DBRefSource.PROTSEQDB);
55 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
57 public String getAccessionSeparator()
59 // TODO Auto-generated method stub
66 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
68 public Regex getAccessionValidator()
70 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
76 * @see jalview.ws.DbSourceProxy#getDbSource()
78 public String getDbSource()
80 return DBRefSource.PDB;
86 * @see jalview.ws.DbSourceProxy#getDbVersion()
88 public String getDbVersion()
96 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
98 public AlignmentI getSequenceRecords(String queries) throws Exception
100 AlignmentI pdbfile = null;
101 Vector result = new Vector();
104 if (queries.indexOf(":") > -1)
106 chain = queries.substring(queries.indexOf(":") + 1);
107 id = queries.substring(0, queries.indexOf(":"));
113 if (queries.length() > 4 && chain == null)
115 chain = queries.substring(4, 5);
116 id = queries.substring(0, 4);
118 if (!isValidReference(id))
120 System.err.println("Ignoring invalid pdb query: '" + id + "'");
124 EBIFetchClient ebi = new EBIFetchClient();
125 file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();
134 pdbfile = new FormatAdapter().readFile(file,
135 jalview.io.AppletFormatAdapter.FILE, "PDB");
138 List<SequenceI> toremove=new ArrayList<SequenceI>();
139 for (SequenceI pdbcs : pdbfile.getSequences())
143 for (PDBEntry pid : (Vector<PDBEntry>) pdbcs.getPDBId())
145 if (pid.getFile() == file)
147 chid = (String) pid.getProperty().get("CHAIN");
154 || (chid != null && (chid.equals(chain)
155 || chid.trim().equals(chain.trim()) || (chain
156 .trim().length() == 0 && chid.equals("_")))))
158 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id
159 + "|" + pdbcs.getName());
160 // Might need to add more metadata to the PDBEntry object
163 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
164 * entry.setId(id); if (entry.getProperty() == null)
165 * entry.setProperty(new Hashtable());
166 * entry.getProperty().put("chains", pdbchain.id + "=" +
167 * sq.getStart() + "-" + sq.getEnd());
168 * sq.getDatasetSequence().addPDBId(entry);
171 // We make a DBRefEtntry because we have obtained the PDB file from
174 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
176 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
177 getDbVersion(), (chid == null ? id : id + chid));
179 pdbcs.addDBRef(dbentry);
183 // mark this sequence to be removed from the alignment
184 // - since it's not from the right chain
188 // now remove marked sequences
189 for (SequenceI pdbcs:toremove) {
190 pdbfile.deleteSequence(pdbcs);
194 if (pdbfile == null || pdbfile.getHeight() < 1)
196 throw new Exception("No PDB Records for " + id + " chain "
197 + ((chain == null) ? "' '" : chain));
200 } catch (Exception ex) // Problem parsing PDB file
211 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
213 public boolean isValidReference(String accession)
215 Regex r = getAccessionValidator();
216 return r.search(accession.trim());
220 * obtain human glyoxalase chain A sequence
222 public String getTestQuery()
227 public String getDbName()
229 return "PDB"; // getDbSource();