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