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;
21 import java.io.FileReader;
22 import java.util.Enumeration;
23 import java.util.Vector;
25 import org.exolab.castor.xml.Unmarshaller;
27 import com.stevesoft.pat.Regex;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.DBRefEntry;
32 import jalview.datamodel.DBRefSource;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceI;
36 import jalview.datamodel.UniprotEntry;
37 import jalview.datamodel.UniprotFile;
38 import jalview.ws.ebi.EBIFetchClient;
39 import jalview.ws.seqfetcher.DbSourceProxy;
40 import jalview.ws.seqfetcher.DbSourceProxyImpl;
46 public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
51 addDbSourceProperty(DBRefSource.SEQDB, DBRefSource.SEQDB);
52 addDbSourceProperty(DBRefSource.PROTSEQDB);
53 // addDbSourceProperty(DBRefSource.MULTIACC, new Integer(50));
59 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
61 public String getAccessionSeparator()
69 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
71 public Regex getAccessionValidator()
73 return new Regex("([A-Z]+[0-9]+[A-Z0-9]+|[A-Z0-9]+_[A-Z0-9]+)");
79 * @see jalview.ws.DbSourceProxy#getDbSource()
81 public String getDbSource()
83 return DBRefSource.UNIPROT;
89 * @see jalview.ws.DbSourceProxy#getDbVersion()
91 public String getDbVersion()
93 return "0"; // we really don't know what version we're on.
96 private EBIFetchClient ebi = null;
98 private static org.exolab.castor.mapping.Mapping map;
100 public Vector getUniprotEntries(File file)
102 UniprotFile uni = new UniprotFile();
107 // 1. Load the mapping information from the file
108 map = new org.exolab.castor.mapping.Mapping(uni.getClass()
110 java.net.URL url = getClass().getResource("/uniprot_mapping.xml");
111 map.loadMapping(url);
114 // 2. Unmarshal the data
115 Unmarshaller unmar = new Unmarshaller(uni);
116 unmar.setIgnoreExtraElements(true);
117 unmar.setMapping(map);
120 uni = (UniprotFile) unmar.unmarshal(new FileReader(file));
122 } catch (Exception e)
124 System.out.println("Error getUniprotEntries() " + e);
127 return uni.getUniprotEntries();
133 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
135 public AlignmentI getSequenceRecords(String queries) throws Exception
140 queries = queries.toUpperCase().replaceAll(
141 "(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
143 ebi = new EBIFetchClient();
144 StringBuffer result = new StringBuffer();
145 // uniprotxml parameter required since december 2007
146 // uniprotkb dbname changed introduced december 2008
147 File file = ebi.fetchDataAsFile("uniprotkb:" + queries, "uniprotxml",
149 Vector entries = getUniprotEntries(file);
153 // First, make the new sequences
154 Enumeration en = entries.elements();
155 while (en.hasMoreElements())
157 UniprotEntry entry = (UniprotEntry) en.nextElement();
159 StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot");
160 Enumeration en2 = entry.getAccession().elements();
161 while (en2.hasMoreElements())
164 name.append(en2.nextElement());
166 en2 = entry.getName().elements();
167 while (en2.hasMoreElements())
170 name.append(en2.nextElement());
173 if (entry.getProtein() != null
174 && entry.getProtein().getName() != null)
176 for (int nm = 0, nmSize = entry.getProtein().getName().size(); nm < nmSize; nm++)
178 name.append(" " + entry.getProtein().getName().elementAt(nm));
182 result.append(name + "\n"
183 + entry.getUniprotSequence().getContent() + "\n");
187 // Then read in the features and apply them to the dataset
188 al = parseResult(result.toString());
191 // Decorate the alignment with database entries.
192 addUniprotXrefs(al, entries);
201 } catch (Exception e)
209 * add an ordered set of UniprotEntry objects to an ordered set of seuqences.
212 * - a sequence of n sequences
214 * a seuqence of n uniprot entries to be analysed.
216 public void addUniprotXrefs(Alignment al, Vector entries)
218 for (int i = 0; i < entries.size(); i++)
220 UniprotEntry entry = (UniprotEntry) entries.elementAt(i);
221 Enumeration e = entry.getDbReference().elements();
222 Vector onlyPdbEntries = new Vector();
223 Vector dbxrefs = new Vector();
224 while (e.hasMoreElements())
226 PDBEntry pdb = (PDBEntry) e.nextElement();
227 DBRefEntry dbr = new DBRefEntry();
228 dbr.setSource(pdb.getType());
229 dbr.setAccessionId(pdb.getId());
230 dbr.setVersion(DBRefSource.UNIPROT + ":" + getDbVersion());
231 dbxrefs.addElement(dbr);
232 if (!pdb.getType().equals("PDB"))
237 onlyPdbEntries.addElement(pdb);
239 SequenceI sq = al.getSequenceAt(i);
240 while (sq.getDatasetSequence() != null)
242 sq = sq.getDatasetSequence();
245 Enumeration en2 = entry.getAccession().elements();
246 while (en2.hasMoreElements())
248 // we always add as uniprot if we retrieved from uniprot or uniprot name
249 sq.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, getDbVersion(), en2
250 .nextElement().toString()));
252 en2 = dbxrefs.elements();
253 while (en2.hasMoreElements())
255 // we always add as uniprot if we retrieved from uniprot or uniprot name
256 sq.addDBRef((DBRefEntry) en2.nextElement());
259 sq.setPDBId(onlyPdbEntries);
260 if (entry.getFeature() != null)
262 e = entry.getFeature().elements();
263 while (e.hasMoreElements())
265 SequenceFeature sf = (SequenceFeature) e.nextElement();
266 sf.setFeatureGroup("Uniprot");
267 sq.addSequenceFeature(sf);
276 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
278 public boolean isValidReference(String accession)
280 // TODO: make the following a standard validator
281 return (accession == null || accession.length() < 2) ? false
282 : getAccessionValidator().search(accession);
286 * return LDHA_CHICK uniprot entry
288 public String getTestQuery()
293 public String getDbName()
295 return "Uniprot"; // getDbSource();