2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2)
\r
3 * Copyright (C) 2009 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
45 * retrieve and parse an emblxml file
\r
48 * either EMBL or EMBLCDS strings are allowed - anything else
\r
49 * will not retrieve emblxml
\r
54 public AlignmentI getEmblSequenceRecords(String emprefx, String query)
\r
58 EBIFetchClient dbFetch = new EBIFetchClient();
\r
62 reply = dbFetch.fetchDataAsFile(emprefx.toLowerCase() + ":"
\r
63 + query.trim(), "emblxml", null);
\r
64 } catch (Exception e)
\r
67 throw new Exception("EBI EMBL XML retrieval failed on "
\r
68 + emprefx.toLowerCase() + ":" + query.trim(), e);
\r
70 return getEmblSequenceRecords(emprefx, query, reply);
\r
74 * parse an emblxml file stored locally
\r
77 * either EMBL or EMBLCDS strings are allowed - anything else
\r
78 * will not retrieve emblxml
\r
81 * the EMBL XML file containing the results of a query
\r
85 public AlignmentI getEmblSequenceRecords(String emprefx, String query,
\r
86 File reply) throws Exception
\r
88 SequenceI seqs[] = null;
\r
89 StringBuffer result = new StringBuffer();
\r
90 if (reply != null && reply.exists())
\r
93 file = reply.getAbsolutePath();
\r
94 if (reply.length() > 25)
\r
96 efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply);
\r
100 result.append("# No EMBL record retrieved for "
\r
101 + emprefx.toLowerCase() + ":" + query.trim());
\r
106 for (Iterator i = efile.getEntries().iterator(); i.hasNext();)
\r
108 EmblEntry entry = (EmblEntry) i.next();
\r
109 SequenceI[] seqparts = entry.getSequences(false, true, emprefx); // TODO:
\r
111 // !fetchNa,!fetchPeptide
\r
119 if (seqparts != null)
\r
121 SequenceI[] newseqs = null;
\r
125 newseqs = new SequenceI[seqparts.length];
\r
129 newseqs = new SequenceI[seqs.length + seqparts.length];
\r
131 for (; si < seqs.length; si++)
\r
133 newseqs[si] = seqs[si];
\r
137 for (int j = 0; j < seqparts.length; si++, j++)
\r
139 newseqs[si] = seqparts[j].deriveSequence(); // place DBReferences on
\r
140 // dataset and refer
\r
151 AlignmentI al = null;
\r
152 if (seqs != null && seqs.length > 0)
\r
154 al = new Alignment(seqs);
\r
155 result.append("# Successfully parsed the " + emprefx
\r
156 + " queries into an Alignment");
\r