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