2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
\r
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.ws.dbsources;
\r
20 import jalview.datamodel.Alignment;
\r
21 import jalview.datamodel.AlignmentI;
\r
22 import jalview.datamodel.SequenceI;
\r
23 import jalview.datamodel.xdb.embl.EmblEntry;
\r
24 import jalview.ws.ebi.EBIFetchClient;
\r
26 import java.io.File;
\r
27 import java.util.Iterator;
\r
28 import java.util.Vector;
\r
30 public abstract class EmblXmlSource extends EbiFileRetrievedProxy
\r
34 * Last properly parsed embl file.
\r
36 public jalview.datamodel.xdb.embl.EmblFile efile = null;
\r
38 public EmblXmlSource()
\r
44 * retrieve and parse an emblxml file
\r
47 * either EMBL or EMBLCDS strings are allowed - anything else will
\r
48 * not retrieve emblxml
\r
53 public AlignmentI getEmblSequenceRecords(String emprefx, String query)
\r
57 EBIFetchClient dbFetch = new EBIFetchClient();
\r
61 reply = dbFetch.fetchDataAsFile(
\r
62 emprefx.toLowerCase() + ":" + query.trim(), "emblxml", null);
\r
63 } catch (Exception e)
\r
66 throw new Exception("EBI EMBL XML retrieval failed on "
\r
67 + emprefx.toLowerCase() + ":" + query.trim(), e);
\r
69 return getEmblSequenceRecords(emprefx, query, reply);
\r
73 * parse an emblxml file stored locally
\r
76 * either EMBL or EMBLCDS strings are allowed - anything else will
\r
77 * not retrieve emblxml
\r
80 * the EMBL XML file containing the results of a query
\r
84 public AlignmentI getEmblSequenceRecords(String emprefx, String query,
\r
85 File reply) throws Exception
\r
87 SequenceI seqs[] = null;
\r
88 StringBuffer result = new StringBuffer();
\r
89 if (reply != null && reply.exists())
\r
92 file = reply.getAbsolutePath();
\r
93 if (reply.length() > 25)
\r
95 efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply);
\r
99 result.append("# No EMBL record retrieved for "
\r
100 + emprefx.toLowerCase() + ":" + query.trim());
\r
105 for (Iterator i = efile.getEntries().iterator(); i.hasNext();)
\r
107 EmblEntry entry = (EmblEntry) i.next();
\r
108 SequenceI[] seqparts = entry.getSequences(false, true, emprefx); // TODO:
\r
110 // !fetchNa,!fetchPeptide
\r
118 if (seqparts != null)
\r
120 SequenceI[] newseqs = null;
\r
124 newseqs = new SequenceI[seqparts.length];
\r
128 newseqs = new SequenceI[seqs.length + seqparts.length];
\r
130 for (; si < seqs.length; si++)
\r
132 newseqs[si] = seqs[si];
\r
136 for (int j = 0; j < seqparts.length; si++, j++)
\r
138 newseqs[si] = seqparts[j].deriveSequence(); // place DBReferences on
\r
139 // dataset and refer
\r
150 AlignmentI al = null;
\r
151 if (seqs != null && seqs.length > 0)
\r
153 al = new Alignment(seqs);
\r
154 result.append("# Successfully parsed the " + emprefx
\r
155 + " queries into an Alignment");
\r