Merge branch 'develop' into features/JAL-653_JAL-1766_htslib_refseqsupport
[jalview.git] / src / jalview / ext / ensembl / EnsemblCdna.java
1 package jalview.ext.ensembl;
2
3 import jalview.datamodel.SequenceFeature;
4 import jalview.io.gff.SequenceOntologyFactory;
5 import jalview.io.gff.SequenceOntologyI;
6
7 import java.util.List;
8
9 import com.stevesoft.pat.Regex;
10
11 public class EnsemblCdna extends EnsemblSeqProxy
12 {
13   // TODO modify to accept other species e.g. ENSMUSPnnn
14   private static final Regex ACCESSION_REGEX = new Regex(
15           "(ENST|ENSG|CCDS)[0-9.]{3,}$");
16   
17   /*
18    * fetch exon features on genomic sequence (to identify the cdna regions)
19    * and cds and variation features (to retain)
20    */
21   private static final EnsemblFeatureType[] FEATURES_TO_FETCH = {
22       EnsemblFeatureType.exon, EnsemblFeatureType.cds,
23       EnsemblFeatureType.variation };
24
25   public EnsemblCdna()
26   {
27     super();
28   }
29
30   @Override
31   public String getDbName()
32   {
33     return "ENSEMBL (CDNA)";
34   }
35
36   @Override
37   protected EnsemblSeqType getSourceEnsemblType()
38   {
39     return EnsemblSeqType.CDNA;
40   }
41
42   @Override
43   public Regex getAccessionValidator()
44   {
45     return ACCESSION_REGEX;
46   }
47
48   @Override
49   protected EnsemblFeatureType[] getFeaturesToFetch()
50   {
51     return FEATURES_TO_FETCH;
52   }
53
54   /**
55    * Answers true unless the feature type is 'transcript' (or a sub-type in the
56    * Sequence Ontology).
57    */
58   @Override
59   protected boolean retainFeature(SequenceFeature sf, String accessionId)
60   {
61     if (isTranscript(sf.getType()))
62     {
63       return false;
64     }
65     return featureMayBelong(sf, accessionId);
66   }
67
68   /**
69    * Answers true if the sequence feature type is 'exon' (or a subtype of exon
70    * in the Sequence Ontology), and the Parent of the feature is the transcript
71    * we are retrieving
72    */
73   @Override
74   protected boolean identifiesSequence(SequenceFeature sf, String accId)
75   {
76     if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
77             SequenceOntologyI.EXON))
78     {
79       String parentFeature = (String) sf.getValue(PARENT);
80       if (("transcript:" + accId).equals(parentFeature))
81       {
82         return true;
83       }
84     }
85     return false;
86   }
87
88   @Override
89   protected List<String> getCrossReferenceDatabases()
90   {
91     return super.getCrossReferenceDatabases();
92     // 30/01/16 also found Vega_transcript, OTTT, ENS_LRG_transcript, UCSC,
93     // HGNC_trans_name, RefSeq_mRNA, RefSeq_mRNA_predicted
94   }
95
96 }