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