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.ext.ensembl;
23 import jalview.analysis.AlignmentUtils;
24 import jalview.bin.Cache;
25 import jalview.datamodel.DBRefSource;
26 import jalview.ws.seqfetcher.DbSourceProxyImpl;
28 import com.stevesoft.pat.Regex;
31 * A base class for Ensembl sequence fetchers
35 abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
37 // domain properties lookup keys:
38 protected static final String ENSEMBL_BASEURL = "ENSEMBL_BASEURL";
40 protected static final String ENSEMBL_GENOMES_BASEURL = "ENSEMBL_GENOMES_BASEURL";
42 // domain properties default values:
43 protected static final String DEFAULT_ENSEMBL_BASEURL = "https://rest.ensembl.org";
45 protected static final String DEFAULT_ENSEMBL_GENOMES_BASEURL = "https://rest.ensemblgenomes.org";
48 * accepts ENSG/T/E/P with 11 digits
49 * or ENSMUSP or similar for other species
50 * or CCDSnnnnn.nn with at least 3 digits
52 private static final Regex ACCESSION_REGEX = new Regex(
53 "(ENS([A-Z]{3}|)[GTEP]{1}[0-9]{11}$)" + "|"
54 + "(CCDS[0-9.]{3,}$)");
56 protected final String ensemblGenomesDomain;
58 protected final String ensemblDomain;
60 protected static final String OBJECT_TYPE_TRANSLATION = "Translation";
62 protected static final String OBJECT_TYPE_TRANSCRIPT = "Transcript";
64 protected static final String OBJECT_TYPE_GENE = "Gene";
66 protected static final String PARENT = "Parent";
68 protected static final String JSON_ID = AlignmentUtils.VARIANT_ID; // "id";
70 protected static final String OBJECT_TYPE = "object_type";
73 * possible values for the 'feature' parameter of the /overlap REST service
74 * @see http://rest.ensembl.org/documentation/info/overlap_id
76 protected enum EnsemblFeatureType
78 gene, transcript, cds, exon, repeat, simple, misc, variation,
79 somatic_variation, structural_variation, somatic_structural_variation,
80 constrained, regulatory
83 private String domain;
88 public EnsemblSequenceFetcher()
91 * the default domain names may be overridden in .jalview_properties;
92 * this allows an easy change from http to https in future if needed
94 ensemblDomain = Cache.getDefault(ENSEMBL_BASEURL,
95 DEFAULT_ENSEMBL_BASEURL).trim();
96 ensemblGenomesDomain = Cache.getDefault(ENSEMBL_GENOMES_BASEURL,
97 DEFAULT_ENSEMBL_GENOMES_BASEURL).trim();
98 domain = ensemblDomain;
102 public String getDbSource()
104 // NB ensure Uniprot xrefs are canonicalised from "Ensembl" to "ENSEMBL"
105 if (ensemblGenomesDomain.equals(getDomain()))
107 return DBRefSource.ENSEMBLGENOMES;
109 return DBRefSource.ENSEMBL;
113 public String getAccessionSeparator()
119 * Ensembl accession are ENST + 11 digits for human transcript, ENSG for human
120 * gene. Other species insert 3 letters e.g. ENSMUST..., ENSMUSG...
122 * @see http://www.ensembl.org/Help/View?id=151
125 public Regex getAccessionValidator()
127 return ACCESSION_REGEX;
131 public boolean isValidReference(String accession)
133 return getAccessionValidator().search(accession);
143 * Default test query is a transcript
146 public String getTestQuery()
148 // has CDS on reverse strand:
149 return "ENST00000288602";
150 // ENST00000461457 // forward strand
154 public boolean isDnaCoding()
160 * Returns the domain name to query e.g. http://rest.ensembl.org or
161 * http://rest.ensemblgenomes.org
165 protected String getDomain()
170 protected void setDomain(String d)
172 domain = d == null ? null : d.trim();