JAL-2679 use object_type=Transcript for lookup of Parent for Protein
[jalview.git] / src / jalview / ext / ensembl / EnsemblGenome.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.SequenceFeature;
24
25 /**
26  * A client to fetch genomic sequence from Ensembl
27  * 
28  * TODO: not currently used - delete?
29  * 
30  * @author gmcarstairs
31  *
32  */
33 public class EnsemblGenome extends EnsemblSeqProxy
34 {
35   /*
36    * fetch transcript features on genomic sequence (to identify the transcript 
37    * regions) and cds, exon and variation features (to retain)
38    */
39   private static final EnsemblFeatureType[] FEATURES_TO_FETCH = {
40       EnsemblFeatureType.transcript, EnsemblFeatureType.exon,
41       EnsemblFeatureType.cds, EnsemblFeatureType.variation };
42
43   /**
44    * Default constructor (to use rest.ensembl.org)
45    */
46   public EnsemblGenome()
47   {
48     super();
49   }
50
51   /**
52    * Constructor given the target domain to fetch data from
53    * 
54    * @param d
55    */
56   public EnsemblGenome(String d)
57   {
58     super(d);
59   }
60
61   @Override
62   public String getDbName()
63   {
64     return "ENSEMBL (Genomic)";
65   }
66
67   @Override
68   protected EnsemblSeqType getSourceEnsemblType()
69   {
70     return EnsemblSeqType.GENOMIC;
71   }
72
73   @Override
74   protected EnsemblFeatureType[] getFeaturesToFetch()
75   {
76     return FEATURES_TO_FETCH;
77   }
78
79   /**
80    * Answers true unless the feature type is 'transcript' (or a sub-type of
81    * transcript in the Sequence Ontology), or has a parent other than the given
82    * accession id. Transcript features are only retrieved in order to identify
83    * the transcript sequence range, and are redundant information on the
84    * transcript sequence itself.
85    */
86   @Override
87   protected boolean retainFeature(SequenceFeature sf, String accessionId)
88   {
89     if (isTranscript(sf.getType()))
90     {
91       return false;
92     }
93     return featureMayBelong(sf, accessionId);
94   }
95
96   /**
97    * Answers true if the sequence feature type is 'transcript' (or a subtype of
98    * transcript in the Sequence Ontology), and the ID of the feature is the
99    * transcript we are retrieving
100    */
101   @Override
102   protected boolean identifiesSequence(SequenceFeature sf, String accId)
103   {
104     if (isTranscript(sf.getType()))
105     {
106       String id = (String) sf.getValue("ID");
107       if (("transcript:" + accId).equals(id))
108       {
109         return true;
110       }
111     }
112     return false;
113   }
114
115 }