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;
33 public abstract class EmblXmlSource extends EbiFileRetrievedProxy
37 * Last properly parsed embl file.
39 public EmblFile efile = null;
41 public EmblXmlSource()
47 * retrieve and parse an emblxml file
50 * either EMBL or EMBLCDS strings are allowed - anything else will
51 * not retrieve emblxml
56 public AlignmentI getEmblSequenceRecords(String emprefx, String query)
60 EBIFetchClient dbFetch = new EBIFetchClient();
64 reply = dbFetch.fetchDataAsFile(
65 emprefx.toLowerCase() + ":" + query.trim(), "emblxml", null,
70 throw new Exception(MessageManager.formatMessage(
71 "exception.ebiembl_retrieval_failed_on", new String[] {
72 emprefx.toLowerCase(), query.trim() }), e);
74 return getEmblSequenceRecords(emprefx, query, reply);
78 * parse an emblxml file stored locally
81 * either EMBL or EMBLCDS strings are allowed - anything else will
82 * not retrieve emblxml
85 * the EMBL XML file containing the results of a query
89 public AlignmentI getEmblSequenceRecords(String emprefx, String query,
90 File reply) throws Exception
92 SequenceI seqs[] = null;
93 StringBuffer result = new StringBuffer();
94 if (reply != null && reply.exists())
97 file = reply.getAbsolutePath();
98 if (reply.length() > 25)
100 efile = EmblFile.getEmblFile(reply);
104 result.append(MessageManager.formatMessage(
105 "label.no_embl_record_found",
106 new String[] { emprefx.toLowerCase(), query.trim() }));
111 for (EmblEntry entry : efile.getEntries())
113 SequenceI[] seqparts = entry.getSequences(false, true, emprefx);
114 // TODO: use !fetchNa,!fetchPeptide here instead - see todo in EmblEntry
115 if (seqparts != null)
117 SequenceI[] newseqs = null;
121 newseqs = new SequenceI[seqparts.length];
125 newseqs = new SequenceI[seqs.length + seqparts.length];
127 for (; si < seqs.length; si++)
129 newseqs[si] = seqs[si];
133 for (int j = 0; j < seqparts.length; si++, j++)
135 newseqs[si] = seqparts[j].deriveSequence();
136 // place DBReferences on dataset and refer
147 AlignmentI al = null;
148 if (seqs != null && seqs.length > 0)
150 al = new Alignment(seqs);
151 result.append(MessageManager.formatMessage(
152 "label.embl_successfully_parsed", new String[] { emprefx }));
160 public boolean isDnaCoding()