2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.ws.dbsources;
21 import jalview.datamodel.Alignment;
22 import jalview.datamodel.DBRefEntry;
23 import jalview.datamodel.DBRefSource;
24 import jalview.datamodel.PDBEntry;
25 import jalview.datamodel.SequenceI;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Vector;
31 import MCview.PDBChain;
32 import MCview.PDBfile;
34 import com.stevesoft.pat.Regex;
36 import jalview.datamodel.AlignmentI;
37 import jalview.io.FormatAdapter;
38 import jalview.ws.ebi.EBIFetchClient;
39 import jalview.ws.seqfetcher.DbSourceProxy;
45 public class Pdb extends EbiFileRetrievedProxy implements DbSourceProxy
50 addDbSourceProperty(DBRefSource.PROTSEQDB);
56 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
58 public String getAccessionSeparator()
60 // TODO Auto-generated method stub
67 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
69 public Regex getAccessionValidator()
71 return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
77 * @see jalview.ws.DbSourceProxy#getDbSource()
79 public String getDbSource()
81 return DBRefSource.PDB;
87 * @see jalview.ws.DbSourceProxy#getDbVersion()
89 public String getDbVersion()
97 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
99 public AlignmentI getSequenceRecords(String queries) throws Exception
101 AlignmentI pdbfile = null;
102 Vector result = new Vector();
105 if (queries.indexOf(":") > -1)
107 chain = queries.substring(queries.indexOf(":") + 1);
108 id = queries.substring(0, queries.indexOf(":"));
114 if (queries.length() > 4 && chain == null)
116 chain = queries.substring(4, 5);
117 id = queries.substring(0, 4);
119 if (!isValidReference(id))
121 System.err.println("Ignoring invalid pdb query: '" + id + "'");
125 EBIFetchClient ebi = new EBIFetchClient();
126 file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();
135 pdbfile = new FormatAdapter().readFile(file,
136 jalview.io.AppletFormatAdapter.FILE, "PDB");
139 List<SequenceI> toremove=new ArrayList<SequenceI>();
140 for (SequenceI pdbcs : pdbfile.getSequences())
144 for (PDBEntry pid : (Vector<PDBEntry>) pdbcs.getPDBId())
146 if (pid.getFile() == file)
148 chid = (String) pid.getProperty().get("CHAIN");
155 || (chid != null && (chid.equals(chain)
156 || chid.trim().equals(chain.trim()) || (chain
157 .trim().length() == 0 && chid.equals("_")))))
159 pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id
160 + "|" + pdbcs.getName());
161 // Might need to add more metadata to the PDBEntry object
164 * PDBEntry entry = new PDBEntry(); // Construct the PDBEntry
165 * entry.setId(id); if (entry.getProperty() == null)
166 * entry.setProperty(new Hashtable());
167 * entry.getProperty().put("chains", pdbchain.id + "=" +
168 * sq.getStart() + "-" + sq.getEnd());
169 * sq.getDatasetSequence().addPDBId(entry);
172 // We make a DBRefEtntry because we have obtained the PDB file from
175 // JBPNote - PDB DBRefEntry should also carry the chain and mapping
177 DBRefEntry dbentry = new DBRefEntry(getDbSource(),
178 getDbVersion(), (chid == null ? id : id + chid));
180 pdbcs.addDBRef(dbentry);
184 // mark this sequence to be removed from the alignment
185 // - since it's not from the right chain
189 // now remove marked sequences
190 for (SequenceI pdbcs:toremove) {
191 pdbfile.deleteSequence(pdbcs);
195 if (pdbfile == null || pdbfile.getHeight() < 1)
197 throw new Exception("No PDB Records for " + id + " chain "
198 + ((chain == null) ? "' '" : chain));
201 } catch (Exception ex) // Problem parsing PDB file
212 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
214 public boolean isValidReference(String accession)
216 Regex r = getAccessionValidator();
217 return r.search(accession.trim());
221 * obtain human glyoxalase chain A sequence
223 public String getTestQuery()
228 public String getDbName()
230 return "PDB"; // getDbSource();