Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ext.ensembl

File EnsemblSequenceFetcher.java

 

Coverage histogram

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

Code metrics

2
14
10
2
173
85
11
0.79
1.4
5
1.1

Classes

Class Line # Actions
EnsemblSequenceFetcher 34 14 11 8
0.692307769.2%
EnsemblSequenceFetcher.EnsemblFeatureType 75 0 0 0
-1.0 -
 

Contributing tests

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