2086eba7ad667f1a2cb0557a7ddaaa0bab43e65d
[jalview.git] / src / jalview / ext / ensembl / EnsemblCds.java
1 package jalview.ext.ensembl;
2
3 import jalview.datamodel.SequenceFeature;
4 import jalview.datamodel.SequenceI;
5 import jalview.io.gff.SequenceOntologyFactory;
6 import jalview.io.gff.SequenceOntologyI;
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 /**
12  * A client for direct fetching of CDS sequences from Ensembl (i.e. that part of
13  * the genomic sequence that is translated to protein)
14  * 
15  * TODO: not currently used as CDS sequences are computed from CDS features on
16  * transcripts - delete this class?
17  * 
18  * @author gmcarstairs
19  *
20  */
21 public class EnsemblCds extends EnsemblSeqProxy
22 {
23   /*
24    * fetch cds features on genomic sequence (to identify the CDS regions)
25    * and exon and variation features (to retain for display)
26    */
27   private static final EnsemblFeatureType[] FEATURES_TO_FETCH = {
28       EnsemblFeatureType.cds, EnsemblFeatureType.exon,
29       EnsemblFeatureType.variation };
30
31   /**
32    * Default constructor (to use rest.ensembl.org)
33    */
34   public EnsemblCds()
35   {
36     super();
37   }
38
39   /**
40    * Constructor given the target domain to fetch data from
41    * 
42    * @param d
43    */
44   public EnsemblCds(String d)
45   {
46     super(d);
47   }
48
49   @Override
50   public String getDbName()
51   {
52     return "ENSEMBL (CDS)";
53   }
54
55   @Override
56   protected EnsemblSeqType getSourceEnsemblType()
57   {
58     return EnsemblSeqType.CDS;
59   }
60
61   @Override
62   protected EnsemblFeatureType[] getFeaturesToFetch()
63   {
64     return FEATURES_TO_FETCH;
65   }
66
67   /**
68    * Answers true unless the feature type is 'CDS' (or a sub-type of CDS in the
69    * Sequence Ontology). CDS features are only retrieved in order to identify
70    * the cds sequence range, and are redundant information on the cds sequence
71    * itself.
72    */
73   @Override
74   protected boolean retainFeature(SequenceFeature sf, String accessionId)
75   {
76     if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
77             SequenceOntologyI.CDS))
78     {
79       return false;
80     }
81     return featureMayBelong(sf, accessionId);
82   }
83
84   /**
85    * Answers true if the sequence feature type is 'CDS' (or a subtype of CDS in
86    * the Sequence Ontology), and the Parent of the feature is the transcript we
87    * are retrieving
88    */
89   @Override
90   protected boolean identifiesSequence(SequenceFeature sf, String accId)
91   {
92     if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
93             SequenceOntologyI.CDS))
94     {
95       String parentFeature = (String) sf.getValue(PARENT);
96       if (("transcript:" + accId).equals(parentFeature))
97       {
98         return true;
99       }
100     }
101     return false;
102   }
103
104   /**
105    * Overrides this method to trivially return a range which is the whole of the
106    * nucleotide sequence. This is both faster than scanning for CDS features,
107    * and also means we don't need to keep CDS features on CDS sequence (where
108    * they are redundant information).
109    */
110   protected List<int[]> getCdsRanges(SequenceI dnaSeq)
111   {
112     int len = dnaSeq.getLength();
113     List<int[]> ranges = new ArrayList<int[]>();
114     ranges.add(new int[] { 1, len });
115     return ranges;
116   }
117
118 }