d4d1c08ef7fbf6e5b71f6a661be1ca0f2dd4ddea
[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("((ENST|ENSG|CCDS)[0-9.]{3,})");
15   
16   /*
17    * fetch exon features on genomic sequence (to identify the cdna regions)
18    * and cds and variation features (to retain)
19    */
20   private static final EnsemblFeatureType[] FEATURES_TO_FETCH = {
21       EnsemblFeatureType.exon, EnsemblFeatureType.cds,
22       EnsemblFeatureType.variation };
23
24   public EnsemblCdna()
25   {
26     super();
27   }
28
29   @Override
30   public String getDbName()
31   {
32     return "ENSEMBL (CDNA)";
33   }
34
35   @Override
36   protected EnsemblSeqType getSourceEnsemblType()
37   {
38     return EnsemblSeqType.CDNA;
39   }
40
41   @Override
42   public Regex getAccessionValidator()
43   {
44     return ACCESSION_REGEX;
45   }
46
47   @Override
48   protected EnsemblFeatureType[] getFeaturesToFetch()
49   {
50     return FEATURES_TO_FETCH;
51   }
52
53   /**
54    * Answers true unless the feature type is 'transcript' (or a sub-type in the
55    * Sequence Ontology).
56    */
57   @Override
58   protected boolean retainFeature(SequenceFeature sf, String accessionId)
59   {
60     if (isTranscript(sf.getType()))
61     {
62       return false;
63     }
64     return featureMayBelong(sf, accessionId);
65   }
66
67   /**
68    * Answers true if the sequence feature type is 'exon' (or a subtype of exon
69    * in the Sequence Ontology), and the Parent of the feature is the transcript
70    * we are retrieving
71    */
72   @Override
73   protected boolean identifiesSequence(SequenceFeature sf, String accId)
74   {
75     if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
76             SequenceOntologyI.EXON))
77     {
78       String parentFeature = (String) sf.getValue(PARENT);
79       if (("transcript:" + accId).equals(parentFeature))
80       {
81         return true;
82       }
83     }
84     return false;
85   }
86
87   @Override
88   protected List<String> getCrossReferenceDatabases()
89   {
90     return super.getCrossReferenceDatabases();
91     // 30/01/16 also found Vega_transcript, OTTT, ENS_LRG_transcript, UCSC,
92     // HGNC_trans_name, RefSeq_mRNA, RefSeq_mRNA_predicted
93   }
94
95 }