/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ext.ensembl;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.io.gff.SequenceOntologyI;
import jalview.util.JSONUtils;
import jalview.util.Platform;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.ParseException;
/**
* A client for fetching and processing Ensembl feature data in GFF format by
* calling the overlap REST service
*
* @author gmcarstairs
* @see http://rest.ensembl.org/documentation/info/overlap_id
*/
class EnsemblFeatures extends EnsemblRestClient
{
/*
* The default features to retrieve from Ensembl
* can override in getSequenceRecords parameter
*/
private EnsemblFeatureType[] featuresWanted = { EnsemblFeatureType.cds,
EnsemblFeatureType.exon, EnsemblFeatureType.variation };
/**
* Default constructor (to use rest.ensembl.org)
*/
public EnsemblFeatures()
{
super();
}
/**
* Constructor given the target domain to fetch data from
*
* @param d
*/
public EnsemblFeatures(String d)
{
super(d);
}
@Override
public String getDbName()
{
return "ENSEMBL (features)";
}
/**
* Makes a query to the REST overlap endpoint for the given sequence
* identifier. This returns an 'alignment' consisting of one 'dummy sequence'
* (the genomic sequence for which overlap features are returned by the
* service). This sequence will have on it sequence features which are the
* real information of interest, such as CDS regions or sequence variations.
*/
@Override
public AlignmentI getSequenceRecords(String query) throws IOException
{
// TODO: use a vararg String... for getSequenceRecords instead?
List queries = new ArrayList<>();
queries.add(query);
SequenceI seq = parseFeaturesJson(queries);
if (seq == null)
return null;
return new Alignment(new SequenceI[] { seq });
}
/**
* Parses the JSON response into Jalview sequence features and attaches them
* to a dummy sequence
*
* @param br
* @return
*/
@SuppressWarnings("unchecked")
private SequenceI parseFeaturesJson(List queries)
{
SequenceI seq = new Sequence("Dummy", "");
try
{
Iterator