JAL-1705 include stop codons in derived CDS; support ensemblgenomes
[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 /**
12  * A client to fetch CDNA sequence from Ensembl (i.e. that part of the genomic
13  * sequence that is transcribed to RNA, but not necessarily translated to
14  * protein)
15  * 
16  * @author gmcarstairs
17  *
18  */
19 public class EnsemblCdna extends EnsemblSeqProxy
20 {
21   /*
22    * accepts ENST or ENSTG with 11 digits
23    * or ENSMUST or similar for other species
24    * or CCDSnnnnn.nn with at least 3 digits
25    */
26   private static final Regex ACCESSION_REGEX = new Regex(
27           "(ENS([A-Z]{3}|)[TG][0-9]{11}$)" + "|" + "(CCDS[0-9.]{3,}$)");
28   
29   /*
30    * fetch exon features on genomic sequence (to identify the cdna regions)
31    * and cds and variation features (to retain)
32    */
33   private static final EnsemblFeatureType[] FEATURES_TO_FETCH = {
34       EnsemblFeatureType.exon, EnsemblFeatureType.cds,
35       EnsemblFeatureType.variation };
36
37   /**
38    * Default constructor (to use rest.ensembl.org)
39    */
40   public EnsemblCdna()
41   {
42     super();
43   }
44
45   /**
46    * Constructor given the target domain to fetch data from
47    * 
48    * @param d
49    */
50   public EnsemblCdna(String d)
51   {
52     super(d);
53   }
54
55   @Override
56   public String getDbName()
57   {
58     return "ENSEMBL (CDNA)";
59   }
60
61   @Override
62   protected EnsemblSeqType getSourceEnsemblType()
63   {
64     return EnsemblSeqType.CDNA;
65   }
66
67   @Override
68   public Regex getAccessionValidator()
69   {
70     return ACCESSION_REGEX;
71   }
72
73   @Override
74   protected EnsemblFeatureType[] getFeaturesToFetch()
75   {
76     return FEATURES_TO_FETCH;
77   }
78
79   /**
80    * Answers true unless the feature type is 'transcript' (or a sub-type in the
81    * Sequence Ontology).
82    */
83   @Override
84   protected boolean retainFeature(SequenceFeature sf, String accessionId)
85   {
86     if (isTranscript(sf.getType()))
87     {
88       return false;
89     }
90     return featureMayBelong(sf, accessionId);
91   }
92
93   /**
94    * Answers true if the sequence feature type is 'exon' (or a subtype of exon
95    * in the Sequence Ontology), and the Parent of the feature is the transcript
96    * we are retrieving
97    */
98   @Override
99   protected boolean identifiesSequence(SequenceFeature sf, String accId)
100   {
101     if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
102             SequenceOntologyI.EXON))
103     {
104       String parentFeature = (String) sf.getValue(PARENT);
105       if (("transcript:" + accId).equals(parentFeature))
106       {
107         return true;
108       }
109     }
110     return false;
111   }
112
113   @Override
114   protected List<String> getCrossReferenceDatabases()
115   {
116     return super.getCrossReferenceDatabases();
117     // 30/01/16 also found Vega_transcript, OTTT, ENS_LRG_transcript, UCSC,
118     // HGNC_trans_name, RefSeq_mRNA, RefSeq_mRNA_predicted
119   }
120
121 }