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.Vector;
28 import MCview.PDBChain;
29 import MCview.PDBfile;
31 import com.stevesoft.pat.Regex;
33 import jalview.datamodel.AlignmentI;
34 import jalview.io.FormatAdapter;
35 import jalview.ws.ebi.EBIFetchClient;
36 import jalview.ws.seqfetcher.DbSourceProxy;
42 public class Pdb extends EbiFileRetrievedProxy implements DbSourceProxy
47 addDbSourceProperty(DBRefSource.PROTSEQDB);
53 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
55 public String getAccessionSeparator()
57 // TODO Auto-generated method stub
64 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
66 public Regex getAccessionValidator()
68 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
74 * @see jalview.ws.DbSourceProxy#getDbSource()
76 public String getDbSource()
78 return DBRefSource.PDB;
84 * @see jalview.ws.DbSourceProxy#getDbVersion()
86 public String getDbVersion()
94 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
96 public AlignmentI getSequenceRecords(String queries) throws Exception
98 AlignmentI pdbfile = null;
99 Vector result = new Vector();
102 if (queries.indexOf(":") > -1)
104 chain = queries.substring(queries.indexOf(":") + 1);
105 id = queries.substring(0, queries.indexOf(":"));
111 if (queries.length() > 4 && chain == null)
113 chain = queries.substring(4, 5);
114 id = queries.substring(0, 4);
116 if (!isValidReference(id))
118 System.err.println("Ignoring invalid pdb query: '" + id + "'");
122 EBIFetchClient ebi = new EBIFetchClient();
123 file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();
132 pdbfile = new FormatAdapter().readFile(file,
133 jalview.io.AppletFormatAdapter.FILE, "PDB");
136 for (SequenceI pdbcs : pdbfile.getSequences())
140 for (PDBEntry pid : (Vector<PDBEntry>) pdbcs.getPDBId())
142 if (pid.getFile() == file)
144 chid = (String) pid.getProperty().get("CHAIN");
151 || (chid != null && (chid.equals(chain)
152 || chid.trim().equals(chain.trim()) || (chain
153 .trim().length() == 0 && chid.equals("_")))))
155 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id
156 + "|" + pdbcs.getName());
157 // Might need to add more metadata to the PDBEntry object
160 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
161 * entry.setId(id); if (entry.getProperty() == null)
162 * entry.setProperty(new Hashtable());
163 * entry.getProperty().put("chains", pdbchain.id + "=" +
164 * sq.getStart() + "-" + sq.getEnd());
165 * sq.getDatasetSequence().addPDBId(entry);
168 // We make a DBRefEtntry because we have obtained the PDB file from
171 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
173 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
174 getDbVersion(), (chid == null ? id : id + chid));
176 pdbcs.addDBRef(dbentry);
180 // remove this sequence from the alignment - since it's not from the
182 pdbfile.deleteSequence(pdbcs);
186 if (pdbfile == null || pdbfile.getHeight() < 1)
188 throw new Exception("No PDB Records for " + id + " chain "
189 + ((chain == null) ? "' '" : chain));
191 } catch (Exception ex) // Problem parsing PDB file
202 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
204 public boolean isValidReference(String accession)
206 Regex r = getAccessionValidator();
207 return r.search(accession.trim());
211 * obtain human glyoxalase chain A sequence
213 public String getTestQuery()
218 public String getDbName()
220 return "PDB"; // getDbSource();