2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.ws.dbsources;
20 import jalview.datamodel.Alignment;
21 import jalview.datamodel.AlignmentI;
22 import jalview.datamodel.SequenceI;
23 import jalview.datamodel.xdb.embl.EmblEntry;
24 import jalview.ws.ebi.EBIFetchClient;
27 import java.util.Iterator;
29 public abstract class EmblXmlSource extends EbiFileRetrievedProxy
33 * Last properly parsed embl file.
35 public jalview.datamodel.xdb.embl.EmblFile efile = null;
37 public EmblXmlSource()
43 * retrieve and parse an emblxml file
46 * either EMBL or EMBLCDS strings are allowed - anything else will
47 * not retrieve emblxml
52 public AlignmentI getEmblSequenceRecords(String emprefx, String query)
56 EBIFetchClient dbFetch = new EBIFetchClient();
60 reply = dbFetch.fetchDataAsFile(
61 emprefx.toLowerCase() + ":" + query.trim(), "emblxml", null);
65 throw new Exception("EBI EMBL XML retrieval failed on "
66 + emprefx.toLowerCase() + ":" + query.trim(), e);
68 return getEmblSequenceRecords(emprefx, query, reply);
72 * parse an emblxml file stored locally
75 * either EMBL or EMBLCDS strings are allowed - anything else will
76 * not retrieve emblxml
79 * the EMBL XML file containing the results of a query
83 public AlignmentI getEmblSequenceRecords(String emprefx, String query,
84 File reply) throws Exception
86 SequenceI seqs[] = null;
87 StringBuffer result = new StringBuffer();
88 if (reply != null && reply.exists())
91 file = reply.getAbsolutePath();
92 if (reply.length() > 25)
94 efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply);
98 result.append("# No EMBL record retrieved for "
99 + emprefx.toLowerCase() + ":" + query.trim());
104 for (Iterator i = efile.getEntries().iterator(); i.hasNext();)
106 EmblEntry entry = (EmblEntry) i.next();
107 SequenceI[] seqparts = entry.getSequences(false, true, emprefx); // TODO:
109 // !fetchNa,!fetchPeptide
117 if (seqparts != null)
119 SequenceI[] newseqs = null;
123 newseqs = new SequenceI[seqparts.length];
127 newseqs = new SequenceI[seqs.length + seqparts.length];
129 for (; si < seqs.length; si++)
131 newseqs[si] = seqs[si];
135 for (int j = 0; j < seqparts.length; si++, j++)
137 newseqs[si] = seqparts[j].deriveSequence(); // place DBReferences on
149 AlignmentI al = null;
150 if (seqs != null && seqs.length > 0)
152 al = new Alignment(seqs);
153 result.append("# Successfully parsed the " + emprefx
154 + " queries into an Alignment");