2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.ws.dbsources;
22 import java.io.FileReader;
23 import java.io.IOException;
24 import java.util.Enumeration;
25 import java.util.Hashtable;
26 import java.util.Vector;
28 import org.exolab.castor.xml.Unmarshaller;
30 import com.stevesoft.pat.Regex;
32 import jalview.datamodel.Alignment;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.DBRefEntry;
35 import jalview.datamodel.DBRefSource;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.SequenceFeature;
38 import jalview.datamodel.SequenceI;
39 import jalview.datamodel.UniprotEntry;
40 import jalview.datamodel.UniprotFile;
41 import jalview.io.FormatAdapter;
42 import jalview.io.IdentifyFile;
43 import jalview.ws.DBRefFetcher;
44 import jalview.ws.ebi.EBIFetchClient;
45 import jalview.ws.seqfetcher.DbSourceProxy;
46 import jalview.ws.seqfetcher.DbSourceProxyImpl;
52 public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
56 addDbSourceProperty(DBRefSource.SEQDB, DBRefSource.SEQDB);
57 addDbSourceProperty(DBRefSource.PROTSEQDB);
58 // addDbSourceProperty(DBRefSource.MULTIACC, new Integer(50));
64 * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
66 public String getAccessionSeparator()
74 * @see jalview.ws.DbSourceProxy#getAccessionValidator()
76 public Regex getAccessionValidator()
84 * @see jalview.ws.DbSourceProxy#getDbSource()
86 public String getDbSource()
88 return DBRefSource.UNIPROT;
94 * @see jalview.ws.DbSourceProxy#getDbVersion()
96 public String getDbVersion()
98 return "0"; // we really don't know what version we're on.
101 private EBIFetchClient ebi = null;
103 public Vector getUniprotEntries(File file)
105 UniprotFile uni = new UniprotFile();
108 // 1. Load the mapping information from the file
109 org.exolab.castor.mapping.Mapping map = new org.exolab.castor.mapping.Mapping(uni.getClass().getClassLoader());
110 java.net.URL url = getClass().getResource("/uniprot_mapping.xml");
111 map.loadMapping(url);
113 // 2. Unmarshal the data
114 Unmarshaller unmar = new Unmarshaller(uni);
115 unmar.setIgnoreExtraElements(true);
116 unmar.setMapping(map);
118 uni = (UniprotFile) unmar.unmarshal(new FileReader(file));
122 System.out.println("Error getUniprotEntries() " + e);
125 return uni.getUniprotEntries();
131 * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
133 public AlignmentI getSequenceRecords(String queries) throws Exception
139 ebi = new EBIFetchClient();
140 StringBuffer result=new StringBuffer();
141 // uniprotxml parameter required since december 2007
142 File file = ebi.fetchDataAsFile("uniprot:" + queries, "uniprotxml", null);
143 Vector entries = getUniprotEntries(file);
147 // First, make the new sequences
148 Enumeration en = entries.elements();
149 while (en.hasMoreElements())
151 UniprotEntry entry = (UniprotEntry) en.nextElement();
153 StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot");
154 Enumeration en2 = entry.getAccession().elements();
155 while (en2.hasMoreElements())
158 name.append(en2.nextElement());
160 en2 = entry.getName().elements();
161 while (en2.hasMoreElements())
164 name.append(en2.nextElement());
167 if (entry.getProtein()!=null && entry.getProtein().getName()!=null)
169 for (int nm=0,nmSize=entry.getProtein().getName().size(); nm<nmSize;nm++)
171 name.append(" " + entry.getProtein().getName().elementAt(nm));
175 result.append(name + "\n"
176 + entry.getUniprotSequence().getContent() + "\n");
180 // Then read in the features and apply them to the dataset
181 al = parseResult(result.toString());
184 // Decorate the alignment with database entries.
185 addUniprotXrefs(al, entries);
192 } catch (Exception e)
200 * add an ordered set of UniprotEntry objects to an ordered set of seuqences.
203 * a sequence of n sequences
205 * a seuqence of n uniprot entries to be analysed.
207 public void addUniprotXrefs(Alignment al, Vector entries)
209 for (int i = 0; i < entries.size(); i++)
211 UniprotEntry entry = (UniprotEntry) entries.elementAt(i);
212 Enumeration e = entry.getDbReference().elements();
213 Vector onlyPdbEntries = new Vector();
214 Vector dbxrefs = new Vector();
215 while (e.hasMoreElements())
217 PDBEntry pdb = (PDBEntry) e.nextElement();
218 DBRefEntry dbr = new DBRefEntry();
219 dbr.setSource(pdb.getType());
220 dbr.setAccessionId(pdb.getId());
221 dbr.setVersion(DBRefSource.UNIPROT+":"+getDbVersion());
222 dbxrefs.addElement(dbr);
223 if (!pdb.getType().equals("PDB"))
228 onlyPdbEntries.addElement(pdb);
230 SequenceI sq = al.getSequenceAt(i);
231 while (sq.getDatasetSequence()!=null)
233 sq = sq.getDatasetSequence();
236 Enumeration en2 = entry.getAccession().elements();
237 while (en2.hasMoreElements())
239 // we always add as uniprot if we retrieved from uniprot or uniprot name
241 new DBRefEntry(DBRefSource.UNIPROT, getDbVersion(), en2.nextElement()
244 en2 = dbxrefs.elements();
245 while (en2.hasMoreElements())
247 // we always add as uniprot if we retrieved from uniprot or uniprot name
248 sq.addDBRef((DBRefEntry) en2.nextElement());
251 sq.setPDBId(onlyPdbEntries);
252 if (entry.getFeature() != null)
254 e = entry.getFeature().elements();
255 while (e.hasMoreElements())
257 SequenceFeature sf = (SequenceFeature) e.nextElement();
258 sf.setFeatureGroup("Uniprot");
259 sq.addSequenceFeature(sf);
268 * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
270 public boolean isValidReference(String accession)
275 * return LDHA_CHICK uniprot entry
277 public String getTestQuery()
281 public String getDbName()
283 return "Uniprot"; // getDbSource();