package org.opencb.cellbase.client.rest;

import org.opencb.biodata.models.core.RegulatoryFeature;
import org.opencb.biodata.models.core.Xref;
import org.opencb.biodata.models.variant.Variant;
import org.opencb.biodata.models.variant.avro.VariantAnnotation;
import org.opencb.cellbase.client.config.ClientConfiguration;
import org.opencb.commons.datastore.core.Query;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.commons.datastore.core.QueryResponse;

import java.io.IOException;

/**
 * Created by swaathi on 23/05/16.
 */
public class VariationClient extends FeatureClient<Variant> {

    public VariationClient(ClientConfiguration configuration) {
        super(configuration);
        this.clazz = Variant.class;

        this.category = "feature";
        this.subcategory = "variation";
    }

    public QueryResponse<String> getAllConsequenceTypes(Query query) throws IOException {
        return execute("consequence_types", query, new QueryOptions(), String.class);
    }

    public QueryResponse<String> getConsequenceTypeById(String id, QueryOptions options) throws IOException {
        return execute(id, "consequence_type", options, String.class);
    }
//    check data model returned
    public QueryResponse<RegulatoryFeature> getRegulatory(String id, QueryOptions options) throws IOException {
        return execute(id, "regulatory", options, RegulatoryFeature.class);
    }

    public QueryResponse<String> getPhenotype(String id, QueryOptions options) throws IOException {
        return execute(id, "phenotype", options, String.class);
    }

    public QueryResponse<String> getSequence(String id, QueryOptions options) throws IOException {
        return execute(id, "sequence", options, String.class);
    }

    public QueryResponse<String> getPopulationFrequency(String id, QueryOptions options) throws IOException {
        return execute(id, "population_frequency", options, String.class);
    }

    public QueryResponse<Xref> getXref(String id, QueryOptions options) throws IOException {
        return execute(id, "xref", options, Xref.class);
    }

    public QueryResponse<VariantAnnotation> getAnnotations(String id, QueryOptions options) throws IOException {
        this.category = "genomic";
        this.subcategory = "variant";
        return execute(id, "annotation", options, VariantAnnotation.class);
    }
}

@@ -500,16 +500,70 @@
 ception;
+%0Aimport java.util.List;%0Aimport java.util.concurrent.*;
 %0A%0A/**%0A *
@@ -2428,11 +2428,1331 @@
 );%0A    %7D
+%0A%0A    public QueryResponse%3CVariantAnnotation%3E getAnnotations(List%3CString%3E ids, QueryOptions options) throws IOException %7B%0A        this.category = %22genomic%22;%0A        this.subcategory = %22variant%22;%0A%0A%0A        Future%3CQueryResponse%3CVariantAnnotation%3E%3E future = null;%0A        ExecutorService executorService = Executors.newFixedThreadPool(4);%0A        for (int i = 0; i %3C 4; i++) %7B%0A            future = executorService.submit(new AnnotatorRunnable(ids, options));%0A        %7D%0A%0A        QueryResponse%3CVariantAnnotation%3E response = null;%0A        try %7B%0A            response = future.get();%0A        %7D catch (InterruptedException %7C ExecutionException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A%0A        executorService.shutdown();%0A%0A        return response;%0A    %7D%0A%0A    class AnnotatorRunnable implements Callable%3CQueryResponse%3CVariantAnnotation%3E%3E %7B%0A%0A        private List%3CString%3E ids;%0A        private QueryOptions options;%0A%0A        public AnnotatorRunnable(List%3CString%3E ids, QueryOptions options) %7B%0A            this.ids = ids;%0A            this.options = options;%0A        %7D%0A%0A        @Override%0A        public QueryResponse%3CVariantAnnotation%3E call() throws Exception %7B%0A            QueryResponse%3CVariantAnnotation%3E annotation = execute(ids, %22annotation%22, options, VariantAnnotation.class);%0A            return annotation;%0A        %7D%0A    %7D
 %0A%7D%0A

make variant annotation so launch several threads to increase the performance