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 java.util.Locale;
26 import java.io.IOException;
28 import com.stevesoft.pat.Regex;
30 import jalview.bin.Console;
31 import jalview.datamodel.Alignment;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.SequenceI;
34 import jalview.io.DataSourceType;
35 import jalview.io.EmblFlatFile;
36 import jalview.io.FileParse;
37 import jalview.ws.ebi.EBIFetchClient;
40 * A class that does partial parsing of an EMBL flatfile.
45 public abstract class EmblFlatfileSource extends EbiFileRetrievedProxy
47 private static final Regex ACCESSION_REGEX = new Regex("^[A-Z]+[0-9]+");
50 public String getDbVersion()
56 public String getAccessionSeparator()
62 public Regex getAccessionValidator()
64 return ACCESSION_REGEX;
68 public boolean isValidReference(String accession)
70 if (accession == null || accession.length() < 2)
74 return getAccessionValidator().search(accession);
78 public AlignmentI getSequenceRecords(String queries) throws Exception
89 protected AlignmentI getEmblSequenceRecords(String dbName, String query)
93 EBIFetchClient dbFetch = new EBIFetchClient();
97 reply = dbFetch.fetchDataAsFile(
98 dbName.toLowerCase(Locale.ROOT) + ":" + query.trim(), null,
100 } catch (Exception e)
104 String.format("EBI EMBL retrieval failed for %s:%s",
105 dbName.toLowerCase(Locale.ROOT), query.trim()),
108 return getEmblSequenceRecords(dbName, query, reply);
111 private AlignmentI getEmblSequenceRecords(String dbName, String query,
112 File reply) throws IOException
114 AlignmentI al = null;
116 if (reply != null && reply.exists())
118 file = reply.getAbsolutePath();
119 FileParse fp = new FileParse(file, DataSourceType.FILE);
120 EmblFlatFile emblParser = new EmblFlatFile(fp, getDbSource());
121 SequenceI[] seqs = emblParser.getSeqsAsArray();
124 al = new Alignment(seqs);
129 Console.error("No record found for '" + dbName + ":" + query + "'");
138 public boolean isDnaCoding()