2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
21 import jalview.datamodel.*;
\r
23 import jalview.gui.*;
\r
29 import org.exolab.castor.mapping.Mapping;
\r
31 import org.exolab.castor.xml.*;
\r
32 import jalview.analysis.AlignSeq;
\r
40 * @version $Revision$
\r
42 public class SequenceFeatureFetcher implements Runnable
\r
47 ArrayList unknownSequences;
\r
48 CutAndPasteTransfer output = new CutAndPasteTransfer();
\r
49 StringBuffer sbuffer = new StringBuffer();
\r
51 Vector localCache = new Vector();
\r
53 Vector getUniprotEntries(File file)
\r
56 UniprotFile uni = new UniprotFile();
\r
59 // 1. Load the mapping information from the file
\r
60 Mapping map = new Mapping(uni.getClass().getClassLoader());
\r
61 java.net.URL url = uni.getClass().getResource("/uniprot_mapping.xml");
\r
62 map.loadMapping(url);
\r
64 // 2. Unmarshal the data
\r
65 Unmarshaller unmar = new Unmarshaller();
\r
66 unmar.setIgnoreExtraElements(true);
\r
67 unmar.setMapping(map);
\r
68 uni = (UniprotFile) unmar.unmarshal(new FileReader(file));
\r
69 localCache.addAll( uni.getUniprotEntries() );
\r
71 // 3. marshal the data with the total price back and print the XML in the console
\r
72 // Marshaller marshaller = new Marshaller(
\r
73 // new FileWriter(jalview.bin.Cache.getProperty("UNIPROT_CACHE"))
\r
75 // marshaller.setMapping(map);
\r
76 // marshaller.marshal(uni);
\r
81 System.out.println("Error getUniprotEntries() "+e);
\r
82 // e.printStackTrace();
\r
83 // if(!updateLocalCache)
\r
87 return uni.getUniprotEntries();
\r
91 * Creates a new SequenceFeatureFetcher object.
\r
93 * @param align DOCUMENT ME!
\r
94 * @param ap DOCUMENT ME!
\r
96 public SequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap)
\r
98 unknownSequences = new ArrayList();
\r
102 Thread thread = new Thread(this);
\r
114 Vector sequences = align.getSequences();
\r
116 while (seqIndex < sequences.size())
\r
118 Vector ids = new Vector();
\r
120 for (int i = 0; (seqIndex < sequences.size()) && (i < 50);
\r
123 SequenceI sequence = (SequenceI) sequences.get(seqIndex);
\r
124 ids.add(sequence.getName());
\r
125 unknownSequences.add(sequence.getName());
\r
128 ///////////////////////////////////
\r
130 if (ids.size() > 0)
\r
132 StringBuffer remainingIds = new StringBuffer("uniprot:");
\r
133 for (int i = 0; i < ids.size(); i++)
\r
135 remainingIds.append(ids.get(i) + ";");
\r
137 EBIFetchClient ebi = new EBIFetchClient();
\r
138 File file = ebi.fetchDataAsFile(remainingIds.toString(),
\r
144 ReadUniprotFile(file, align, ids);
\r
149 catch (Exception ex)
\r
151 ex.printStackTrace();
\r
154 if (sbuffer.length() > 0)
\r
157 "Your sequences have been matched to Uniprot. Some of the ids have been\n" +
\r
158 "altered, most likely the start/end residue will have been updated.\n" +
\r
159 "Save your alignment to maintain the updated id.\n\n" +
\r
160 sbuffer.toString());
\r
161 Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300);
\r
164 if (unknownSequences.size() > 0)
\r
166 new WSWUBlastClient(ap, align, unknownSequences);
\r
169 ((Alignment)align).featuresAdded = true;
\r
178 * @param result DOCUMENT ME!
\r
179 * @param out DOCUMENT ME!
\r
180 * @param align DOCUMENT ME!
\r
182 void ReadUniprotFile(File file, AlignmentI align, Vector ids)
\r
187 SequenceI sequence = null;
\r
188 // String pdb = null;
\r
190 Vector entries = getUniprotEntries(file);
\r
192 int i, iSize = entries==null?0:entries.size();
\r
193 UniprotEntry entry;
\r
194 for (i = 0; i < iSize; i++)
\r
196 entry = (UniprotEntry) entries.elementAt(i);
\r
197 String idmatch = entry.getAccession();
\r
198 sequence = align.findName(idmatch);
\r
200 if (sequence == null)
\r
202 //Sequence maybe Name, not Accession
\r
203 idmatch = entry.getName();
\r
204 sequence = align.findName(idmatch);
\r
207 if (sequence == null)
\r
212 ids.remove(sequence.getName());
\r
213 unknownSequences.remove(sequence.getName());
\r
215 String nonGapped = AlignSeq.extractGaps("-. ", sequence.getSequence());
\r
217 int absStart = entry.getUniprotSequence().getContent().indexOf(
\r
218 nonGapped.toString());
\r
220 if (absStart == -1)
\r
222 unknownSequences.add(sequence.getName());
\r
223 sbuffer.append(sequence.getName() +
\r
224 " SEQUENCE NOT %100 MATCH \n");
\r
229 int absEnd = absStart + nonGapped.toString().length();
\r
232 if ( (absStart != sequence.getStart()) ||
\r
233 (absEnd != sequence.getEnd()))
\r
235 sbuffer.append("Updated: " + sequence.getName() + " " +
\r
236 sequence.getStart() + "/" + sequence.getEnd() +
\r
237 " to " + absStart + "/" + absEnd + "\n");
\r
240 sequence.setSequenceFeatures(entry.getFeatures());
\r
241 sequence.setStart(absStart);
\r
242 sequence.setEnd(absEnd);
\r