1 package jalview.ext.ensembl;
3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.AlignmentI;
5 import jalview.io.FeaturesFile;
6 import jalview.io.FileParse;
8 import java.io.IOException;
9 import java.net.MalformedURLException;
11 import java.util.ArrayList;
12 import java.util.List;
15 * A client for fetching and processing Ensembl feature data in GFF format by
16 * calling the overlap REST service
19 * @see http://rest.ensembl.org/documentation/info/overlap_id
21 class EnsemblFeatures extends EnsemblRestClient
24 * The default features to retrieve from Ensembl
25 * can override in getSequenceRecords parameter
27 private EnsemblFeatureType[] featuresWanted = { EnsemblFeatureType.cds,
28 EnsemblFeatureType.exon, EnsemblFeatureType.variation };
31 * Default constructor (to use rest.ensembl.org)
33 public EnsemblFeatures()
39 * Constructor given the target domain to fetch data from
43 public EnsemblFeatures(String d)
49 public String getDbName()
51 return "ENSEMBL (features)";
55 * Makes a query to the REST overlap endpoint for the given sequence
56 * identifier. This returns an 'alignment' consisting of one 'dummy sequence'
57 * (the genomic sequence for which overlap features are returned by the
58 * service). This sequence will have on it sequence features which are the
59 * real information of interest, such as CDS regions or sequence variations.
62 public AlignmentI getSequenceRecords(String query) throws IOException
64 // TODO: use a vararg String... for getSequenceRecords instead?
65 List<String> queries = new ArrayList<String>();
67 FileParse fp = getSequenceReader(queries);
68 FeaturesFile fr = new FeaturesFile(fp);
69 return new Alignment(fr.getSeqsAsArray());
73 * Returns a URL for the REST overlap endpoint
79 protected URL getUrl(List<String> ids) throws MalformedURLException
81 StringBuffer urlstring = new StringBuffer(128);
82 urlstring.append(getDomain()).append("/overlap/id/")
85 // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
86 urlstring.append("?content-type=text/x-gff3");
89 * specify features to retrieve
90 * @see http://rest.ensembl.org/documentation/info/overlap_id
91 * could make the list a configurable entry in jalview.properties
93 for (EnsemblFeatureType feature : featuresWanted)
95 urlstring.append("&feature=").append(feature.name());
98 return new URL(urlstring.toString());
102 protected boolean useGetRequest()
108 * Returns the MIME type for GFF3. For GET requests the Content-type header
109 * describes the required encoding of the response.
112 protected String getRequestMimeType(boolean multipleIds)
114 return "text/x-gff3";
118 * Returns the MIME type for GFF3.
121 protected String getResponseMimeType()
123 return "text/x-gff3";
127 * Overloaded method that allows a list of features to retrieve to be
133 * @throws IOException
135 protected AlignmentI getSequenceRecords(String accId,
136 EnsemblFeatureType[] features) throws IOException
138 featuresWanted = features;
139 return getSequenceRecords(accId);