Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.ext.ensembl

File EnsemblSequenceFetcher.java

 

Coverage histogram

../../../img/srcFileCovDistChart7.png
30% of files have more coverage

Code metrics

2
12
10
2
172
83
11
0.92
1.2
5
1.1

Classes

Class Line # Actions
EnsemblSequenceFetcher 36 12 11
0.708333370.8%
EnsemblSequenceFetcher.EnsemblFeatureType 78 0 0
-1.0 -
 

Contributing tests

This file is covered by 233 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ext.ensembl;
22   
23    import jalview.analysis.AlignmentUtils;
24    import jalview.bin.Cache;
25    import jalview.datamodel.DBRefSource;
26    import jalview.util.Platform;
27    import jalview.ws.seqfetcher.DbSourceProxyImpl;
28   
29    import com.stevesoft.pat.Regex;
30   
31    /**
32    * A base class for Ensembl sequence fetchers
33    *
34    * @author gmcarstairs
35    */
 
36    abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
37    {
38    // domain properties lookup keys:
39    protected static final String ENSEMBL_BASEURL = "ENSEMBL_BASEURL";
40   
41    protected static final String ENSEMBL_GENOMES_BASEURL = "ENSEMBL_GENOMES_BASEURL";
42   
43    // domain properties default values:
44    protected static final String DEFAULT_ENSEMBL_BASEURL = "https://rest.ensembl.org";
45   
46    // ensemblgenomes REST service merged to ensembl 9th April 2019
47    protected static final String DEFAULT_ENSEMBL_GENOMES_BASEURL = DEFAULT_ENSEMBL_BASEURL;
48   
49    /*
50    * accepts ENSG/T/E/P with 11 digits
51    * or ENSMUSP or similar for other species
52    * or CCDSnnnnn.nn with at least 3 digits
53    */
54    private static final Regex ACCESSION_REGEX = Platform.newRegex(
55    "(ENS([A-Z]{3}|)[GTEP]{1}[0-9]{11}$)" + "|"
56    + "(CCDS[0-9.]{3,}$)");
57   
58    protected final String ensemblGenomesDomain;
59   
60    protected final String ensemblDomain;
61   
62    protected static final String OBJECT_TYPE_TRANSLATION = "Translation";
63   
64    protected static final String OBJECT_TYPE_TRANSCRIPT = "Transcript";
65   
66    protected static final String OBJECT_TYPE_GENE = "Gene";
67   
68    protected static final String PARENT = "Parent";
69   
70    protected static final String JSON_ID = AlignmentUtils.VARIANT_ID; // "id";
71   
72    protected static final String OBJECT_TYPE = "object_type";
73   
74    /*
75    * possible values for the 'feature' parameter of the /overlap REST service
76    * @see http://rest.ensembl.org/documentation/info/overlap_id
77    */
 
78    protected enum EnsemblFeatureType
79    {
80    gene, transcript, cds, exon, repeat, simple, misc, variation,
81    somatic_variation, structural_variation, somatic_structural_variation,
82    constrained, regulatory
83    }
84   
85    private String domain;
86   
87    /**
88    * Constructor
89    */
 
90  51 toggle public EnsemblSequenceFetcher()
91    {
92    /*
93    * the default domain names may be overridden in .jalview_properties;
94    * this allows an easy change from http to https in future if needed
95    */
96  51 ensemblDomain = Cache
97    .getDefault(ENSEMBL_BASEURL, DEFAULT_ENSEMBL_BASEURL).trim();
98  51 ensemblGenomesDomain = Cache.getDefault(ENSEMBL_GENOMES_BASEURL,
99    DEFAULT_ENSEMBL_GENOMES_BASEURL).trim();
100  51 domain = ensemblDomain;
101    }
102   
 
103  8140 toggle @Override
104    public String getDbSource()
105    {
106    // NB ensure Uniprot xrefs are canonicalised from "Ensembl" to "ENSEMBL"
107  8140 return DBRefSource.ENSEMBL;
108    }
109   
 
110  6 toggle @Override
111    public String getAccessionSeparator()
112    {
113  6 return " ";
114    }
115   
116    /**
117    * Ensembl accession are ENST + 11 digits for human transcript, ENSG for human
118    * gene. Other species insert 3 letters e.g. ENSMUST..., ENSMUSG...
119    *
120    * @see http://www.ensembl.org/Help/View?id=151
121    */
 
122  6 toggle @Override
123    public Regex getAccessionValidator()
124    {
125  6 return ACCESSION_REGEX;
126    }
127   
 
128  17 toggle @Override
129    public boolean isValidReference(String accession)
130    {
131  17 return getAccessionValidator().search(accession);
132    }
133   
 
134  0 toggle @Override
135    public int getTier()
136    {
137  0 return 0;
138    }
139   
140    /**
141    * Default test query is a transcript
142    */
 
143  0 toggle @Override
144    public String getTestQuery()
145    {
146    // has CDS on reverse strand:
147  0 return "ENST00000288602";
148    // ENST00000461457 // forward strand
149    }
150   
 
151  0 toggle @Override
152    public boolean isDnaCoding()
153    {
154  0 return true;
155    }
156   
157    /**
158    * Returns the domain name to query e.g. http://rest.ensembl.org or
159    * http://rest.ensemblgenomes.org
160    *
161    * @return
162    */
 
163  1 toggle protected String getDomain()
164    {
165  1 return domain;
166    }
167   
 
168  1 toggle protected void setDomain(String d)
169    {
170  1 domain = d == null ? null : d.trim();
171    }
172    }