2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2)
\r
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.ws.dbsources;
\r
21 import jalview.datamodel.Alignment;
\r
22 import jalview.datamodel.DBRefEntry;
\r
23 import jalview.datamodel.DBRefSource;
\r
24 import jalview.datamodel.SequenceI;
\r
26 import java.io.BufferedInputStream;
\r
27 import java.io.InputStream;
\r
28 import java.io.InputStreamReader;
\r
29 import java.util.Hashtable;
\r
30 import java.util.Vector;
\r
32 import MCview.PDBChain;
\r
33 import MCview.PDBfile;
\r
35 import com.stevesoft.pat.Regex;
\r
37 import jalview.datamodel.AlignmentI;
\r
38 import jalview.io.FileParse;
\r
39 import jalview.ws.ebi.EBIFetchClient;
\r
40 import jalview.ws.seqfetcher.DbSourceProxy;
\r
41 import jalview.ws.seqfetcher.DbSourceProxyImpl;
\r
47 public class Pdb extends EbiFileRetrievedProxy implements DbSourceProxy
\r
52 addDbSourceProperty(DBRefSource.PROTSEQDB);
\r
58 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
\r
60 public String getAccessionSeparator()
\r
62 // TODO Auto-generated method stub
\r
69 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
\r
71 public Regex getAccessionValidator()
\r
73 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
\r
79 * @see jalview.ws.DbSourceProxy#getDbSource()
\r
81 public String getDbSource()
\r
83 return DBRefSource.PDB;
\r
89 * @see jalview.ws.DbSourceProxy#getDbVersion()
\r
91 public String getDbVersion()
\r
99 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
\r
101 public AlignmentI getSequenceRecords(String queries) throws Exception
\r
104 Vector result = new Vector();
\r
105 String chain = null;
\r
107 if (queries.indexOf(":") > -1)
\r
109 chain = queries.substring(queries.indexOf(":") + 1);
\r
110 id = queries.substring(0, queries.indexOf(":"));
\r
116 if (queries.length() > 4 && chain == null)
\r
118 chain = queries.substring(4, 5);
\r
119 id = queries.substring(0, 4);
\r
121 if (!isValidReference(id))
\r
123 System.err.println("Ignoring invalid pdb query: '" + id + "'");
\r
127 EBIFetchClient ebi = new EBIFetchClient();
\r
128 file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();
\r
137 PDBfile pdbfile = new PDBfile(file,
\r
138 jalview.io.AppletFormatAdapter.FILE);
\r
139 for (int i = 0; i < pdbfile.chains.size(); i++)
\r
142 || ((PDBChain) pdbfile.chains.elementAt(i)).id
\r
143 .toUpperCase().equals(chain))
\r
145 PDBChain pdbchain = (PDBChain) pdbfile.chains.elementAt(i);
\r
146 // Get the Chain's Sequence - who's dataset includes any special
\r
147 // features added from the PDB file
\r
148 SequenceI sq = pdbchain.sequence;
\r
149 // Specially formatted name for the PDB chain sequences retrieved from
\r
151 sq.setName(jalview.datamodel.DBRefSource.PDB + "|" + id + "|"
\r
153 // Might need to add more metadata to the PDBEntry object
\r
156 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
\r
157 * entry.setId(id); if (entry.getProperty() == null)
\r
158 * entry.setProperty(new Hashtable());
\r
159 * entry.getProperty().put("chains", pdbchain.id + "=" + sq.getStart() +
\r
160 * "-" + sq.getEnd()); sq.getDatasetSequence().addPDBId(entry);
\r
163 // We make a DBRefEtntry because we have obtained the PDB file from a
\r
164 // verifiable source
\r
165 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
\r
167 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
\r
168 getDbVersion(), id + pdbchain.id);
\r
169 sq.addDBRef(dbentry);
\r
170 // and add seuqence to the retrieved set
\r
171 result.addElement(sq.deriveSequence());
\r
175 if (result.size() < 1)
\r
177 throw new Exception("No PDB Records for " + id + " chain "
\r
178 + ((chain == null) ? "' '" : chain));
\r
180 } catch (Exception ex) // Problem parsing PDB file
\r
186 SequenceI[] results = new SequenceI[result.size()];
\r
187 for (int i = 0, j = result.size(); i < j; i++)
\r
189 results[i] = (SequenceI) result.elementAt(i);
\r
190 result.setElementAt(null, i);
\r
192 return new Alignment(results);
\r
198 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
\r
200 public boolean isValidReference(String accession)
\r
202 Regex r = getAccessionValidator();
\r
203 return r.search(accession.trim());
\r
207 * obtain human glyoxalase chain A sequence
\r
209 public String getTestQuery()
\r
214 public String getDbName()
\r
216 return "PDB"; // getDbSource();
\r