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;
22 import java.io.FileReader;
23 import java.util.Enumeration;
24 import java.util.Vector;
26 import org.exolab.castor.xml.Unmarshaller;
28 import com.stevesoft.pat.Regex;
30 import jalview.datamodel.Alignment;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.DBRefEntry;
33 import jalview.datamodel.DBRefSource;
34 import jalview.datamodel.PDBEntry;
35 import jalview.datamodel.SequenceFeature;
36 import jalview.datamodel.SequenceI;
37 import jalview.datamodel.UniprotEntry;
38 import jalview.datamodel.UniprotFile;
39 import jalview.ws.ebi.EBIFetchClient;
40 import jalview.ws.seqfetcher.DbSourceProxy;
41 import jalview.ws.seqfetcher.DbSourceProxyImpl;
47 public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
52 addDbSourceProperty(DBRefSource.SEQDB, DBRefSource.SEQDB);
53 addDbSourceProperty(DBRefSource.PROTSEQDB);
54 // addDbSourceProperty(DBRefSource.MULTIACC, new Integer(50));
60 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
62 public String getAccessionSeparator()
70 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
72 public Regex getAccessionValidator()
74 return new Regex("([A-Z]+[0-9]+[A-Z0-9]+|[A-Z0-9]+_[A-Z0-9]+)");
80 * @see jalview.ws.DbSourceProxy#getDbSource()
82 public String getDbSource()
84 return DBRefSource.UNIPROT;
90 * @see jalview.ws.DbSourceProxy#getDbVersion()
92 public String getDbVersion()
94 return "0"; // we really don't know what version we're on.
97 private EBIFetchClient ebi = null;
99 private static org.exolab.castor.mapping.Mapping map;
101 public Vector getUniprotEntries(File file)
103 UniprotFile uni = new UniprotFile();
108 // 1. Load the mapping information from the file
109 map = new org.exolab.castor.mapping.Mapping(uni.getClass()
111 java.net.URL url = getClass().getResource("/uniprot_mapping.xml");
112 map.loadMapping(url);
115 // 2. Unmarshal the data
116 Unmarshaller unmar = new Unmarshaller(uni);
117 unmar.setIgnoreExtraElements(true);
118 unmar.setMapping(map);
121 uni = (UniprotFile) unmar.unmarshal(new FileReader(file));
123 } catch (Exception e)
125 System.out.println("Error getUniprotEntries() " + e);
128 return uni.getUniprotEntries();
134 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
136 public AlignmentI getSequenceRecords(String queries) throws Exception
141 queries = queries.toUpperCase().replaceAll(
142 "(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
144 ebi = new EBIFetchClient();
145 StringBuffer result = new StringBuffer();
146 // uniprotxml parameter required since december 2007
147 // uniprotkb dbname changed introduced december 2008
148 File file = ebi.fetchDataAsFile("uniprotkb:" + queries, "uniprotxml",
150 Vector entries = getUniprotEntries(file);
154 // First, make the new sequences
155 Enumeration en = entries.elements();
156 while (en.hasMoreElements())
158 UniprotEntry entry = (UniprotEntry) en.nextElement();
160 StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot");
161 Enumeration en2 = entry.getAccession().elements();
162 while (en2.hasMoreElements())
165 name.append(en2.nextElement());
167 en2 = entry.getName().elements();
168 while (en2.hasMoreElements())
171 name.append(en2.nextElement());
174 if (entry.getProtein() != null
175 && entry.getProtein().getName() != null)
177 for (int nm = 0, nmSize = entry.getProtein().getName().size(); nm < nmSize; nm++)
179 name.append(" " + entry.getProtein().getName().elementAt(nm));
183 result.append(name + "\n"
184 + entry.getUniprotSequence().getContent() + "\n");
188 // Then read in the features and apply them to the dataset
189 al = parseResult(result.toString());
192 // Decorate the alignment with database entries.
193 addUniprotXrefs(al, entries);
202 } catch (Exception e)
210 * add an ordered set of UniprotEntry objects to an ordered set of seuqences.
213 * - a sequence of n sequences
215 * a seuqence of n uniprot entries to be analysed.
217 public void addUniprotXrefs(Alignment al, Vector entries)
219 for (int i = 0; i < entries.size(); i++)
221 UniprotEntry entry = (UniprotEntry) entries.elementAt(i);
222 Enumeration e = entry.getDbReference().elements();
223 Vector onlyPdbEntries = new Vector();
224 Vector dbxrefs = new Vector();
225 while (e.hasMoreElements())
227 PDBEntry pdb = (PDBEntry) e.nextElement();
228 DBRefEntry dbr = new DBRefEntry();
229 dbr.setSource(pdb.getType());
230 dbr.setAccessionId(pdb.getId());
231 dbr.setVersion(DBRefSource.UNIPROT + ":" + getDbVersion());
232 dbxrefs.addElement(dbr);
233 if (!pdb.getType().equals("PDB"))
238 onlyPdbEntries.addElement(pdb);
240 SequenceI sq = al.getSequenceAt(i);
241 while (sq.getDatasetSequence() != null)
243 sq = sq.getDatasetSequence();
246 Enumeration en2 = entry.getAccession().elements();
247 while (en2.hasMoreElements())
249 // we always add as uniprot if we retrieved from uniprot or uniprot name
250 sq.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, getDbVersion(), en2
251 .nextElement().toString()));
253 en2 = dbxrefs.elements();
254 while (en2.hasMoreElements())
256 // we always add as uniprot if we retrieved from uniprot or uniprot name
257 sq.addDBRef((DBRefEntry) en2.nextElement());
260 sq.setPDBId(onlyPdbEntries);
261 if (entry.getFeature() != null)
263 e = entry.getFeature().elements();
264 while (e.hasMoreElements())
266 SequenceFeature sf = (SequenceFeature) e.nextElement();
267 sf.setFeatureGroup("Uniprot");
268 sq.addSequenceFeature(sf);
277 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
279 public boolean isValidReference(String accession)
281 // TODO: make the following a standard validator
282 return (accession == null || accession.length() < 2) ? false
283 : getAccessionValidator().search(accession);
287 * return LDHA_CHICK uniprot entry
289 public String getTestQuery()
294 public String getDbName()
296 return "Uniprot"; // getDbSource();