2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
\r
3 * Copyright (C) 2008 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
19 package jalview.ws.dbsources;
\r
21 import jalview.datamodel.Alignment;
\r
22 import jalview.datamodel.AlignmentI;
\r
23 import jalview.datamodel.SequenceI;
\r
24 import jalview.datamodel.xdb.embl.EmblEntry;
\r
25 import jalview.ws.ebi.EBIFetchClient;
\r
27 import java.io.File;
\r
28 import java.util.Iterator;
\r
29 import java.util.Vector;
\r
31 public abstract class EmblXmlSource extends EbiFileRetrievedProxy
\r
35 * Last properly parsed embl file.
\r
37 public jalview.datamodel.xdb.embl.EmblFile efile = null;
\r
39 public EmblXmlSource()
\r
44 * retrieve and parse an emblxml file
\r
45 * @param emprefx either EMBL or EMBLCDS strings are allowed - anything else will not retrieve emblxml
\r
50 public AlignmentI getEmblSequenceRecords(String emprefx, String query) throws Exception
\r
53 EBIFetchClient dbFetch = new EBIFetchClient();
\r
56 reply = dbFetch.fetchDataAsFile(
\r
57 emprefx.toLowerCase() + ":" + query.trim(),
\r
63 throw new Exception("EBI EMBL XML retrieval failed on "+emprefx.toLowerCase()+":"+query.trim(),e);
\r
65 return getEmblSequenceRecords(emprefx, query, reply);
\r
68 * parse an emblxml file stored locally
\r
69 * @param emprefx either EMBL or EMBLCDS strings are allowed - anything else will not retrieve emblxml
\r
71 * @param file the EMBL XML file containing the results of a query
\r
75 public AlignmentI getEmblSequenceRecords(String emprefx, String query, File reply) throws Exception
\r
77 SequenceI seqs[] = null;
\r
78 StringBuffer result = new StringBuffer();
\r
79 if (reply != null && reply.exists())
\r
82 file = reply.getAbsolutePath();
\r
83 if (reply.length()>25)
\r
85 efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply);
\r
87 result.append("# No EMBL record retrieved for "+emprefx.toLowerCase()+":"+query.trim());
\r
91 for (Iterator i=efile.getEntries().iterator(); i.hasNext(); ) {
\r
92 EmblEntry entry = (EmblEntry) i.next();
\r
93 SequenceI[] seqparts = entry.getSequences(false, true, emprefx); // TODO: use !fetchNa,!fetchPeptide here instead - see todo in emblEntry
\r
94 if (seqparts!=null) {
\r
95 SequenceI[] newseqs = null;
\r
98 newseqs = new SequenceI[seqparts.length];
\r
100 newseqs = new SequenceI[seqs.length+seqparts.length];
\r
102 for (;si<seqs.length; si++) {
\r
103 newseqs[si] = seqs[si];
\r
107 for (int j=0;j<seqparts.length; si++, j++) {
\r
108 newseqs[si] = seqparts[j].deriveSequence(); // place DBReferences on dataset and refer
\r
117 AlignmentI al =null;
\r
118 if (seqs!=null && seqs.length>0)
\r
120 al = new Alignment(seqs);
\r
121 result.append("# Successfully parsed the "+emprefx+" queries into an Alignment");
\r