2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
\r
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.ws.dbsources;
\r
20 import jalview.datamodel.Alignment;
\r
21 import jalview.datamodel.DBRefEntry;
\r
22 import jalview.datamodel.DBRefSource;
\r
23 import jalview.datamodel.SequenceI;
\r
25 import java.io.BufferedInputStream;
\r
26 import java.io.InputStream;
\r
27 import java.io.InputStreamReader;
\r
28 import java.util.Hashtable;
\r
29 import java.util.Vector;
\r
31 import MCview.PDBChain;
\r
32 import MCview.PDBfile;
\r
34 import com.stevesoft.pat.Regex;
\r
36 import jalview.datamodel.AlignmentI;
\r
37 import jalview.io.FileParse;
\r
38 import jalview.ws.ebi.EBIFetchClient;
\r
39 import jalview.ws.seqfetcher.DbSourceProxy;
\r
40 import jalview.ws.seqfetcher.DbSourceProxyImpl;
\r
46 public class Pdb extends EbiFileRetrievedProxy implements DbSourceProxy
\r
51 addDbSourceProperty(DBRefSource.PROTSEQDB);
\r
57 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
\r
59 public String getAccessionSeparator()
\r
61 // TODO Auto-generated method stub
\r
68 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
\r
70 public Regex getAccessionValidator()
\r
72 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
\r
78 * @see jalview.ws.DbSourceProxy#getDbSource()
\r
80 public String getDbSource()
\r
82 return DBRefSource.PDB;
\r
88 * @see jalview.ws.DbSourceProxy#getDbVersion()
\r
90 public String getDbVersion()
\r
98 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
\r
100 public AlignmentI getSequenceRecords(String queries) throws Exception
\r
103 Vector result = new Vector();
\r
104 String chain = null;
\r
106 if (queries.indexOf(":") > -1)
\r
108 chain = queries.substring(queries.indexOf(":") + 1);
\r
109 id = queries.substring(0, queries.indexOf(":"));
\r
115 if (queries.length() > 4 && chain == null)
\r
117 chain = queries.substring(4, 5);
\r
118 id = queries.substring(0, 4);
\r
120 if (!isValidReference(id))
\r
122 System.err.println("Ignoring invalid pdb query: '" + id + "'");
\r
126 EBIFetchClient ebi = new EBIFetchClient();
\r
127 file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();
\r
136 PDBfile pdbfile = new PDBfile(file,
\r
137 jalview.io.AppletFormatAdapter.FILE);
\r
138 for (int i = 0; i < pdbfile.chains.size(); i++)
\r
141 || ((PDBChain) pdbfile.chains.elementAt(i)).id
\r
142 .toUpperCase().equals(chain))
\r
144 PDBChain pdbchain = (PDBChain) pdbfile.chains.elementAt(i);
\r
145 // Get the Chain's Sequence - who's dataset includes any special
\r
146 // features added from the PDB file
\r
147 SequenceI sq = pdbchain.sequence;
\r
148 // Specially formatted name for the PDB chain sequences retrieved from
\r
150 sq.setName(jalview.datamodel.DBRefSource.PDB + "|" + id + "|"
\r
152 // Might need to add more metadata to the PDBEntry object
\r
155 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
\r
156 * entry.setId(id); if (entry.getProperty() == null)
\r
157 * entry.setProperty(new Hashtable());
\r
158 * entry.getProperty().put("chains", pdbchain.id + "=" + sq.getStart()
\r
159 * + "-" + sq.getEnd()); sq.getDatasetSequence().addPDBId(entry);
\r
162 // We make a DBRefEtntry because we have obtained the PDB file from a
\r
163 // verifiable source
\r
164 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
\r
166 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
\r
167 getDbVersion(), id + pdbchain.id);
\r
168 sq.addDBRef(dbentry);
\r
169 // and add seuqence to the retrieved set
\r
170 result.addElement(sq.deriveSequence());
\r
174 if (result.size() < 1)
\r
176 throw new Exception("No PDB Records for " + id + " chain "
\r
177 + ((chain == null) ? "' '" : chain));
\r
179 } catch (Exception ex) // Problem parsing PDB file
\r
185 SequenceI[] results = new SequenceI[result.size()];
\r
186 for (int i = 0, j = result.size(); i < j; i++)
\r
188 results[i] = (SequenceI) result.elementAt(i);
\r
189 result.setElementAt(null, i);
\r
191 return new Alignment(results);
\r
197 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
\r
199 public boolean isValidReference(String accession)
\r
201 Regex r = getAccessionValidator();
\r
202 return r.search(accession.trim());
\r
206 * obtain human glyoxalase chain A sequence
\r
208 public String getTestQuery()
\r
213 public String getDbName()
\r
215 return "PDB"; // getDbSource();
\r