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