2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.dbsources;
23 import jalview.datamodel.Alignment;
24 import jalview.datamodel.DBRefEntry;
25 import jalview.datamodel.DBRefSource;
26 import jalview.datamodel.PDBEntry;
27 import jalview.datamodel.SequenceI;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Vector;
33 import MCview.PDBChain;
34 import MCview.PDBfile;
36 import com.stevesoft.pat.Regex;
38 import jalview.datamodel.AlignmentI;
39 import jalview.io.FormatAdapter;
40 import jalview.ws.ebi.EBIFetchClient;
41 import jalview.ws.seqfetcher.DbSourceProxy;
47 public class Pdb extends EbiFileRetrievedProxy implements DbSourceProxy
52 addDbSourceProperty(DBRefSource.PROTSEQDB);
58 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
60 public String getAccessionSeparator()
62 // TODO Auto-generated method stub
69 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
71 public Regex getAccessionValidator()
73 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
79 * @see jalview.ws.DbSourceProxy#getDbSource()
81 public String getDbSource()
83 return DBRefSource.PDB;
89 * @see jalview.ws.DbSourceProxy#getDbVersion()
91 public String getDbVersion()
99 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
101 public AlignmentI getSequenceRecords(String queries) throws Exception
103 AlignmentI pdbfile = null;
104 Vector result = new Vector();
107 if (queries.indexOf(":") > -1)
109 chain = queries.substring(queries.indexOf(":") + 1);
110 id = queries.substring(0, queries.indexOf(":"));
116 if (queries.length() > 4 && chain == null)
118 chain = queries.substring(4, 5);
119 id = queries.substring(0, 4);
121 if (!isValidReference(id))
123 System.err.println("Ignoring invalid pdb query: '" + id + "'");
127 EBIFetchClient ebi = new EBIFetchClient();
128 file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();
137 pdbfile = new FormatAdapter().readFile(file,
138 jalview.io.AppletFormatAdapter.FILE, "PDB");
141 List<SequenceI> toremove = new ArrayList<SequenceI>();
142 for (SequenceI pdbcs : pdbfile.getSequences())
146 for (PDBEntry pid : (Vector<PDBEntry>) pdbcs.getPDBId())
148 if (pid.getFile() == file)
150 chid = (String) pid.getProperty().get("CHAIN");
157 || (chid != null && (chid.equals(chain)
158 || chid.trim().equals(chain.trim()) || (chain
159 .trim().length() == 0 && chid.equals("_")))))
161 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id
162 + "|" + pdbcs.getName());
163 // Might need to add more metadata to the PDBEntry object
166 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
167 * entry.setId(id); if (entry.getProperty() == null)
168 * entry.setProperty(new Hashtable());
169 * entry.getProperty().put("chains", pdbchain.id + "=" +
170 * sq.getStart() + "-" + sq.getEnd());
171 * sq.getDatasetSequence().addPDBId(entry);
174 // We make a DBRefEtntry because we have obtained the PDB file from
177 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
179 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
180 getDbVersion(), (chid == null ? id : id + chid));
182 pdbcs.addDBRef(dbentry);
186 // mark this sequence to be removed from the alignment
187 // - since it's not from the right chain
191 // now remove marked sequences
192 for (SequenceI pdbcs : toremove)
194 pdbfile.deleteSequence(pdbcs);
198 if (pdbfile == null || pdbfile.getHeight() < 1)
200 throw new Exception("No PDB Records for " + id + " chain "
201 + ((chain == null) ? "' '" : chain));
204 } catch (Exception ex) // Problem parsing PDB file
215 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
217 public boolean isValidReference(String accession)
219 Regex r = getAccessionValidator();
220 return r.search(accession.trim());
224 * obtain human glyoxalase chain A sequence
226 public String getTestQuery()
231 public String getDbName()
233 return "PDB"; // getDbSource();