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 overlap data in GFF feature
19 * @see http://rest.ensembl.org/documentation/info/overlap_id
21 public class EnsemblOverlap extends EnsemblRestClient
24 * The default features to retrieve from Ensembl; can override in getSequenceRecords
26 private EnsemblFeatureType[] featuresWanted = { EnsemblFeatureType.cds,
27 EnsemblFeatureType.exon, EnsemblFeatureType.variation };
30 public String getDbName()
32 return "ENSEMBL (overlap)";
36 * Makes a query to the REST overlap endpoint for the given sequence
37 * identifier. This returns an 'alignment' consisting of one 'dummy sequence'
38 * (the genomic sequence for which overlap features are returned by the
39 * service). This sequence will have on it sequence features which are the
40 * real information of interest, such as CDS regions or sequence variations.
43 public AlignmentI getSequenceRecords(String query) throws IOException
45 // TODO: use a vararg String... for getSequenceRecords instead?
46 List<String> queries = new ArrayList<String>();
48 FileParse fp = getSequenceReader(queries);
49 FeaturesFile fr = new FeaturesFile(fp);
50 return new Alignment(fr.getSeqsAsArray());
54 * Returns a URL for the REST overlap endpoint
60 protected URL getUrl(List<String> ids) throws MalformedURLException
62 StringBuffer urlstring = new StringBuffer(128);
63 urlstring.append(ENSEMBL_REST).append("/overlap/id/")
66 // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
67 urlstring.append("?content-type=text/x-gff3");
70 * specify features to retrieve
71 * @see http://rest.ensembl.org/documentation/info/overlap_id
72 * could make the list a configurable entry in jalview.properties
74 for (EnsemblFeatureType feature : featuresWanted)
76 urlstring.append("&feature=").append(feature.name());
79 return new URL(urlstring.toString());
83 protected boolean useGetRequest()
89 * Returns the MIME type for GFF3. For GET requests the Content-type header
90 * describes the required encoding of the response.
93 protected String getRequestMimeType(boolean multipleIds)
99 * Returns the MIME type for GFF3.
102 protected String getResponseMimeType()
104 return "text/x-gff3";
108 * Overloaded method that allows a list of features to retrieve to be
114 * @throws IOException
116 protected AlignmentI getSequenceRecords(String accId,
117 EnsemblFeatureType[] features) throws IOException
119 featuresWanted = features;
120 return getSequenceRecords(accId);