JAL-1705 derive transcript sequences from gene sequence/GFF; handle CDS
[jalview.git] / src / jalview / ext / ensembl / EnsemblCds.java
1 package jalview.ext.ensembl;
2
3 import jalview.datamodel.SequenceFeature;
4 import jalview.io.gff.SequenceOntology;
5
6 public class EnsemblCds extends EnsemblSeqProxy
7 {
8   /*
9    * fetch cds features on genomic sequence (to identify the CDS regions)
10    * and variation features (to retain)
11    */
12   private static final EnsemblFeatureType[] FEATURES_TO_FETCH = {
13       EnsemblFeatureType.cds, EnsemblFeatureType.variation };
14
15   /**
16    * Constructor
17    */
18   public EnsemblCds()
19   {
20     super();
21   }
22
23   @Override
24   public String getDbName()
25   {
26     return "ENSEMBL (CDS)";
27   }
28
29   @Override
30   protected EnsemblSeqType getSourceEnsemblType()
31   {
32     return EnsemblSeqType.CDS;
33   }
34
35   @Override
36   protected EnsemblFeatureType[] getFeaturesToFetch()
37   {
38     return FEATURES_TO_FETCH;
39   }
40
41   /**
42    * Answers true unless the feature type is 'CDS' (or a sub-type of CDS in the
43    * Sequence Ontology). CDS features are only retrieved in order to identify
44    * the cds sequence range, and are redundant information on the cds sequence
45    * itself.
46    */
47   @Override
48   protected boolean retainFeature(SequenceFeature sf, String accessionId)
49   {
50     if (SequenceOntology.getInstance().isA(sf.getType(),
51             SequenceOntology.CDS))
52     {
53       return false;
54     }
55     return featureMayBelong(sf, accessionId);
56   }
57
58   /**
59    * Answers true if the sequence feature type is 'CDS' (or a subtype of CDS in
60    * the Sequence Ontology), and the Parent of the feature is the transcript we
61    * are retrieving
62    */
63   @Override
64   protected boolean identifiesSequence(SequenceFeature sf, String accId)
65   {
66     if (SequenceOntology.getInstance().isA(sf.getType(),
67             SequenceOntology.CDS))
68     {
69       String parentFeature = (String) sf.getValue(PARENT);
70       if (("transcript:" + accId).equals(parentFeature))
71       {
72         return true;
73       }
74     }
75     return false;
76   }
77
78 }