2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.dbsources;
23 import jalview.datamodel.Alignment;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.SequenceI;
26 import jalview.datamodel.xdb.embl.EmblEntry;
27 import jalview.datamodel.xdb.embl.EmblFile;
28 import jalview.util.MessageManager;
29 import jalview.ws.ebi.EBIFetchClient;
32 import java.util.ArrayList;
33 import java.util.List;
35 public abstract class EmblXmlSource extends EbiFileRetrievedProxy
38 * JAL-1856 Embl returns this text for query not found
40 private static final String EMBL_NOT_FOUND_REPLY = "ERROR 12 No entries found.";
42 public EmblXmlSource()
48 * retrieve and parse an emblxml file
51 * either EMBL or EMBLCDS strings are allowed - anything else will
52 * not retrieve emblxml
57 public AlignmentI getEmblSequenceRecords(String emprefx, String query)
61 EBIFetchClient dbFetch = new EBIFetchClient();
65 reply = dbFetch.fetchDataAsFile(
66 emprefx.toLowerCase() + ":" + query.trim(), "display=xml",
71 throw new Exception(MessageManager.formatMessage(
72 "exception.ebiembl_retrieval_failed_on", new String[] {
73 emprefx.toLowerCase(), query.trim() }), e);
75 return getEmblSequenceRecords(emprefx, query, reply);
79 * parse an emblxml file stored locally
82 * either EMBL or EMBLCDS strings are allowed - anything else will
83 * not retrieve emblxml
86 * the EMBL XML file containing the results of a query
90 public AlignmentI getEmblSequenceRecords(String emprefx, String query,
91 File reply) throws Exception
93 EmblFile efile = null;
94 List<SequenceI> seqs = new ArrayList<SequenceI>();
96 if (reply != null && reply.exists())
98 file = reply.getAbsolutePath();
99 if (reply.length() > EMBL_NOT_FOUND_REPLY.length())
101 efile = EmblFile.getEmblFile(reply);
106 * invalid accession gets a reply with no <entry> elements, text content of
107 * EmbFile reads something like (e.g.) this ungrammatical phrase
108 * Entry: <acc> display type is either not supported or entry is not found.
110 List<SequenceI> peptides = new ArrayList<SequenceI>();
111 if (efile != null && efile.getEntries() != null)
113 for (EmblEntry entry : efile.getEntries())
115 SequenceI seq = entry.getSequence(emprefx, peptides);
118 seqs.add(seq.deriveSequence());
119 // place DBReferences on dataset and refer
124 AlignmentI al = null;
127 al = new Alignment(seqs.toArray(new SequenceI[seqs.size()]));
134 public boolean isDnaCoding()