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.util.Platform;
38 import jalview.ws.ebi.EBIFetchClient;
41 * A class that does partial parsing of an EMBL flatfile.
46 public abstract class EmblFlatfileSource extends EbiFileRetrievedProxy
48 private static Regex ACCESSION_REGEX = null;
51 public String getDbVersion()
57 public String getAccessionSeparator()
63 public Regex getAccessionValidator()
65 if (ACCESSION_REGEX == null)
67 ACCESSION_REGEX = Platform.newRegex("^[A-Z]+[0-9]+");
69 return ACCESSION_REGEX;
73 public boolean isValidReference(String accession)
75 if (accession == null || accession.length() < 2)
79 return getAccessionValidator().search(accession);
83 public AlignmentI getSequenceRecords(String queries) throws Exception
94 protected AlignmentI getEmblSequenceRecords(String dbName, String query)
98 EBIFetchClient dbFetch = new EBIFetchClient();
102 reply = dbFetch.fetchDataAsFile(
103 dbName.toLowerCase(Locale.ROOT) + ":" + query.trim(), null,
105 } catch (Exception e)
109 String.format("EBI EMBL retrieval failed for %s:%s",
110 dbName.toLowerCase(Locale.ROOT), query.trim()),
113 return getEmblSequenceRecords(dbName, query, reply);
116 private AlignmentI getEmblSequenceRecords(String dbName, String query,
117 File reply) throws IOException
119 AlignmentI al = null;
121 if (reply != null && reply.exists())
123 file = reply.getAbsolutePath();
124 FileParse fp = new FileParse(file, DataSourceType.FILE);
125 EmblFlatFile emblParser = new EmblFlatFile(fp, getDbSource());
126 SequenceI[] seqs = emblParser.getSeqsAsArray();
129 al = new Alignment(seqs);
134 Console.error("No record found for '" + dbName + ":" + query + "'");
143 public boolean isDnaCoding()