Search in sources :

Example 1 with SnpLookupJson

use of uk.ac.ebi.spot.goci.model.SnpLookupJson in project goci by EBISPOT.

the class SnpCheckingRestService method getSnpLocations.

/**
     * Get the chromosome a SNP resides on
     *
     * @param snp Snp identifier to check
     * @return Set of all SNP chromosome names
     */
public Set<String> getSnpLocations(String snp, String eRelease) {
    Set<String> snpChromosomeNames = new HashSet<>();
    SnpLookupJson snpLookupJson = new SnpLookupJson();
    try {
        RestResponseResult snpDataApiResult = ensemblRestcallHistoryService.getEnsemblRestCallByTypeAndParamAndVersion("snp", snp, eRelease);
        if (snpDataApiResult == null) {
            snpDataApiResult = ensemblRestTemplateService.getRestCall(getEndpoint(), snp, "");
            ensemblRestcallHistoryService.create(snpDataApiResult, "snp", snp, eRelease);
        }
        if (!(snpDataApiResult.hasErorr())) {
            JSONObject snpResult = snpDataApiResult.getRestResult().getObject();
            JSONArray mappings = snpResult.getJSONArray("mappings");
            for (int i = 0; i < mappings.length(); ++i) {
                JSONObject mapping = mappings.getJSONObject(i);
                if (!mapping.has("seq_region_name")) {
                    continue;
                }
                String chromosome = mapping.getString("seq_region_name");
                //Integer position = Integer.valueOf(mapping.getInt("start"));
                snpChromosomeNames.add(chromosome);
            //System.out.println("Snp chromosome: ".concat(chromosome));
            }
        }
    }// The query returns a 400 error if response returns an error
     catch (Exception e) {
        //error = "Imnpossible retrieve SNP Mapping info."
        getLog().error("Getting locations for SNP ".concat(snp).concat(" failed"), e);
    }
    return snpChromosomeNames;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) RestResponseResult(uk.ac.ebi.spot.goci.model.RestResponseResult) SnpLookupJson(uk.ac.ebi.spot.goci.model.SnpLookupJson) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 RestResponseResult (uk.ac.ebi.spot.goci.model.RestResponseResult)1 SnpLookupJson (uk.ac.ebi.spot.goci.model.SnpLookupJson)1