2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.ensembl;
23 import jalview.datamodel.Alignment;
24 import jalview.datamodel.AlignmentI;
25 import jalview.io.FeaturesFile;
26 import jalview.io.FileParse;
28 import java.io.IOException;
29 import java.net.MalformedURLException;
31 import java.util.ArrayList;
32 import java.util.List;
35 * A client for fetching and processing Ensembl feature data in GFF format by
36 * calling the overlap REST service
39 * @see http://rest.ensembl.org/documentation/info/overlap_id
41 class EnsemblFeatures extends EnsemblRestClient
44 * The default features to retrieve from Ensembl
45 * can override in getSequenceRecords parameter
47 private EnsemblFeatureType[] featuresWanted = { EnsemblFeatureType.cds,
48 EnsemblFeatureType.exon, EnsemblFeatureType.variation };
51 * Default constructor (to use rest.ensembl.org)
53 public EnsemblFeatures()
59 * Constructor given the target domain to fetch data from
63 public EnsemblFeatures(String d)
69 public String getDbName()
71 return "ENSEMBL (features)";
75 * Makes a query to the REST overlap endpoint for the given sequence
76 * identifier. This returns an 'alignment' consisting of one 'dummy sequence'
77 * (the genomic sequence for which overlap features are returned by the
78 * service). This sequence will have on it sequence features which are the
79 * real information of interest, such as CDS regions or sequence variations.
82 public AlignmentI getSequenceRecords(String query) throws IOException
84 // TODO: use a vararg String... for getSequenceRecords instead?
85 List<String> queries = new ArrayList<>();
87 FileParse fp = getSequenceReader(queries);
88 if (fp == null || !fp.isValid())
92 FeaturesFile fr = new FeaturesFile(fp);
93 return new Alignment(fr.getSeqsAsArray());
97 * Returns a URL for the REST overlap endpoint
103 protected URL getUrl(List<String> ids) throws MalformedURLException
105 StringBuffer urlstring = new StringBuffer(128);
106 urlstring.append(getDomain()).append("/overlap/id/").append(ids.get(0));
108 // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
109 urlstring.append("?content-type=text/x-gff3");
112 * specify object_type=gene in case is shared by transcript and/or protein;
113 * currently only fetching features for gene sequences;
114 * refactor in future if needed to fetch for transcripts
116 urlstring.append("&").append(OBJECT_TYPE).append("=")
117 .append(OBJECT_TYPE_GENE);
120 * specify features to retrieve
121 * @see http://rest.ensembl.org/documentation/info/overlap_id
122 * could make the list a configurable entry in .jalview_properties
124 for (EnsemblFeatureType feature : featuresWanted)
126 urlstring.append("&feature=").append(feature.name());
129 return new URL(urlstring.toString());
133 protected boolean useGetRequest()
139 * Returns the MIME type for GFF3. For GET requests the Content-type header
140 * describes the required encoding of the response.
143 protected String getRequestMimeType(boolean multipleIds)
145 return "text/x-gff3";
149 * Returns the MIME type for GFF3.
152 protected String getResponseMimeType()
154 return "text/x-gff3";
158 * Overloaded method that allows a list of features to retrieve to be
164 * @throws IOException
166 protected AlignmentI getSequenceRecords(String accId,
167 EnsemblFeatureType[] features) throws IOException
169 featuresWanted = features;
170 return getSequenceRecords(accId);