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