2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.ws.ebi.EBIFetchClient;
30 import java.util.Iterator;
32 public abstract class EmblXmlSource extends EbiFileRetrievedProxy
36 * Last properly parsed embl file.
38 public jalview.datamodel.xdb.embl.EmblFile efile = null;
40 public EmblXmlSource()
46 * retrieve and parse an emblxml file
49 * either EMBL or EMBLCDS strings are allowed - anything else will
50 * not retrieve emblxml
55 public AlignmentI getEmblSequenceRecords(String emprefx, String query)
59 EBIFetchClient dbFetch = new EBIFetchClient();
63 reply = dbFetch.fetchDataAsFile(
64 emprefx.toLowerCase() + ":" + query.trim(), "emblxml", null);
68 throw new Exception("EBI EMBL XML retrieval failed on "
69 + emprefx.toLowerCase() + ":" + query.trim(), e);
71 return getEmblSequenceRecords(emprefx, query, reply);
75 * parse an emblxml file stored locally
78 * either EMBL or EMBLCDS strings are allowed - anything else will
79 * not retrieve emblxml
82 * the EMBL XML file containing the results of a query
86 public AlignmentI getEmblSequenceRecords(String emprefx, String query,
87 File reply) throws Exception
89 SequenceI seqs[] = null;
90 StringBuffer result = new StringBuffer();
91 if (reply != null && reply.exists())
94 file = reply.getAbsolutePath();
95 if (reply.length() > 25)
97 efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply);
101 result.append("# No EMBL record retrieved for "
102 + emprefx.toLowerCase() + ":" + query.trim());
107 for (Iterator i = efile.getEntries().iterator(); i.hasNext();)
109 EmblEntry entry = (EmblEntry) i.next();
110 SequenceI[] seqparts = entry.getSequences(false, true, emprefx); // TODO:
112 // !fetchNa,!fetchPeptide
120 if (seqparts != null)
122 SequenceI[] newseqs = null;
126 newseqs = new SequenceI[seqparts.length];
130 newseqs = new SequenceI[seqs.length + seqparts.length];
132 for (; si < seqs.length; si++)
134 newseqs[si] = seqs[si];
138 for (int j = 0; j < seqparts.length; si++, j++)
140 newseqs[si] = seqparts[j].deriveSequence(); // place DBReferences on
152 AlignmentI al = null;
153 if (seqs != null && seqs.length > 0)
155 al = new Alignment(seqs);
156 result.append("# Successfully parsed the " + emprefx
157 + " queries into an Alignment");