JAL-1705 JAL-1191 SequenceOntologyLite added as hard-coded alternative
[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.List;
9
10 public class EnsemblCds extends EnsemblSeqProxy
11 {
12   /*
13    * fetch cds features on genomic sequence (to identify the CDS regions)
14    * and exon and variation features (to retain for display)
15    */
16   private static final EnsemblFeatureType[] FEATURES_TO_FETCH = {
17       EnsemblFeatureType.cds, EnsemblFeatureType.exon,
18       EnsemblFeatureType.variation };
19
20   /**
21    * Constructor
22    */
23   public EnsemblCds()
24   {
25     super();
26   }
27
28   @Override
29   public String getDbName()
30   {
31     return "ENSEMBL (CDS)";
32   }
33
34   @Override
35   protected EnsemblSeqType getSourceEnsemblType()
36   {
37     return EnsemblSeqType.CDS;
38   }
39
40   @Override
41   protected EnsemblFeatureType[] getFeaturesToFetch()
42   {
43     return FEATURES_TO_FETCH;
44   }
45
46   /**
47    * Answers true unless the feature type is 'CDS' (or a sub-type of CDS in the
48    * Sequence Ontology). CDS features are only retrieved in order to identify
49    * the cds sequence range, and are redundant information on the cds sequence
50    * itself.
51    */
52   @Override
53   protected boolean retainFeature(SequenceFeature sf, String accessionId)
54   {
55     if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
56             SequenceOntologyI.CDS))
57     {
58       return false;
59     }
60     return featureMayBelong(sf, accessionId);
61   }
62
63   /**
64    * Answers true if the sequence feature type is 'CDS' (or a subtype of CDS in
65    * the Sequence Ontology), and the Parent of the feature is the transcript we
66    * are retrieving
67    */
68   @Override
69   protected boolean identifiesSequence(SequenceFeature sf, String accId)
70   {
71     if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
72             SequenceOntologyI.CDS))
73     {
74       String parentFeature = (String) sf.getValue(PARENT);
75       if (("transcript:" + accId).equals(parentFeature))
76       {
77         return true;
78       }
79     }
80     return false;
81   }
82
83   /**
84    * Overrides this method to trivially return a range which is the whole of the
85    * nucleotide sequence. This is both faster than scanning for CDS features,
86    * and also means we don't need to keep CDS features on CDS sequence (where
87    * they are redundant information).
88    */
89   @Override
90   protected int getCdsRanges(SequenceI dnaSeq, List<int[]> ranges)
91   {
92     int len = dnaSeq.getLength();
93     ranges.add(new int[] { 1, len });
94     return len;
95   }
96
97 }