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