<commit_before>package uk.ac.ebi.variation.eva.server.ws;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.opencb.opencga.lib.auth.IllegalOpenCGACredentialsException;
import org.opencb.opencga.lib.auth.MongoCredentials;
import org.opencb.opencga.storage.variant.VariantDBAdaptor;
import org.opencb.opencga.storage.variant.mongodb.VariantMongoDBAdaptor;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
@Path("/{version}/genes/")
@Produces(MediaType.APPLICATION_JSON)
public class GeneWSServer extends EvaWSServer {

    private VariantDBAdaptor variantMongoQueryBuilder;
    private MongoCredentials credentials;

    public GeneWSServer() {

    }

    public GeneWSServer(@DefaultValue("") @PathParam("version")String version, @Context UriInfo uriInfo, @Context HttpServletRequest hsr) throws IOException {
        super(version, uriInfo, hsr);
        try {
            credentials = new MongoCredentials("mongos-hxvm-dev-001", 27017, "eva_hsapiens", "biouser", "biopass");
            variantMongoQueryBuilder = new VariantMongoDBAdaptor(credentials);
        } catch (IllegalOpenCGACredentialsException e) {
            e.printStackTrace();
        }
    }

    @GET
    @Path("{gene}/variants")
    public Response getVariantsByGene(@PathParam("gene") String geneId,
                                      @DefaultValue("") @QueryParam("type") String variantType) {
        if (!variantType.isEmpty()) {
            queryOptions.put("type", variantType);
        }
        
        return createOkResponse(variantMongoQueryBuilder.getAllVariantsByGene(geneId, queryOptions));
    }
    
    @GET
    @Path("/ranking")
    public Response genesRankingByVariantsNumber(@PathParam("gene") String geneId, 
                                                 @DefaultValue("10") @QueryParam("limit") int limit,
                                                 @DefaultValue("desc") @QueryParam("sort") String sort,
                                                 @DefaultValue("") @QueryParam("type") String variantType) {
        if (!variantType.isEmpty()) {
            queryOptions.put("type", variantType);
        }
        
        if (sort.equalsIgnoreCase("desc")) {
            return createOkResponse(variantMongoQueryBuilder.getMostAffectedGenes(limit, queryOptions));
        } else if (sort.equalsIgnoreCase("asc")) {
            return createOkResponse(variantMongoQueryBuilder.getLeastAffectedGenes(limit, queryOptions));
        } else {
            return createOkResponse("Sorting criteria must be 'desc' or 'asc'");
        }
    }
    
    
}<commit_msg>Added filter by reference and alternate in Gene web service<commit_after>package uk.ac.ebi.variation.eva.server.ws;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.opencb.opencga.lib.auth.IllegalOpenCGACredentialsException;
import org.opencb.opencga.lib.auth.MongoCredentials;
import org.opencb.opencga.storage.variant.VariantDBAdaptor;
import org.opencb.opencga.storage.variant.mongodb.VariantMongoDBAdaptor;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
@Path("/{version}/genes/")
@Produces(MediaType.APPLICATION_JSON)
public class GeneWSServer extends EvaWSServer {

    private VariantDBAdaptor variantMongoQueryBuilder;
    private MongoCredentials credentials;

    public GeneWSServer() {

    }

    public GeneWSServer(@DefaultValue("") @PathParam("version")String version, @Context UriInfo uriInfo, @Context HttpServletRequest hsr) throws IOException {
        super(version, uriInfo, hsr);
        try {
            credentials = new MongoCredentials("mongos-hxvm-dev-001", 27017, "eva_hsapiens", "biouser", "biopass");
            variantMongoQueryBuilder = new VariantMongoDBAdaptor(credentials);
        } catch (IllegalOpenCGACredentialsException e) {
            e.printStackTrace();
        }
    }

    @GET
    @Path("{gene}/variants")
    public Response getVariantsByGene(@PathParam("gene") String geneId,
                                      @QueryParam("ref") String reference,
                                      @QueryParam("alt") String alternate, 
                                      @DefaultValue("") @QueryParam("type") String variantType) {
        if (!variantType.isEmpty()) {
            queryOptions.put("type", variantType);
        }
        if (reference != null) {
            queryOptions.put("reference", reference);
        }
        if (alternate != null) {
            queryOptions.put("alternate", alternate);
        }
        
        return createOkResponse(variantMongoQueryBuilder.getAllVariantsByGene(geneId, queryOptions));
    }
    
    @GET
    @Path("/ranking")
    public Response genesRankingByVariantsNumber(@PathParam("gene") String geneId,
                                                 @DefaultValue("10") @QueryParam("limit") int limit,
                                                 @DefaultValue("desc") @QueryParam("sort") String sort,
                                                 @DefaultValue("") @QueryParam("type") String variantType) {
        if (!variantType.isEmpty()) {
            queryOptions.put("type", variantType);
        }
        
        if (sort.equalsIgnoreCase("desc")) {
            return createOkResponse(variantMongoQueryBuilder.getMostAffectedGenes(limit, queryOptions));
        } else if (sort.equalsIgnoreCase("asc")) {
            return createOkResponse(variantMongoQueryBuilder.getLeastAffectedGenes(limit, queryOptions));
        } else {
            return createOkResponse("Sorting criteria must be 'desc' or 'asc'");
        }
    }
    
    
}
{'fraction_non_alphanumeric': 0.11440541411537222, 'fraction_numerical': 0.003222687721559781, 'mean_word_length': 2.752720677146312, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5834184', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1740, 'n_words': 311}