Search in sources :

Example 1 with PussycatSessionNotReadyException

use of uk.ac.ebi.spot.goci.pussycat.exception.PussycatSessionNotReadyException in project goci by EBISPOT.

the class SparqlPussycatSession method performRendering.

@Override
public String performRendering(RenderletNexus renderletNexus, Filter... filters) throws PussycatSessionNotReadyException, NoRenderableDataException {
    // render
    if (!isRendering()) {
        setRendering(true);
        String associationQueryString = associationQueryMain;
        String traitQueryString = traitQueryMain;
        getLog().debug("Rendering SVG from SPARQL endpoint (filters = '" + filters + "')...");
        String associationPvalueFilters = "";
        String traitPvalueFilters = "";
        String associationDateFilters = "";
        String traitDateFilters = "";
        for (Filter filter : filters) {
            if (filter.getFilteredType().equals(Association.class)) {
                List<Double> values = filter.getFilteredValues();
                associationQueryString = associationQueryString.concat("?association gt:has_p_value ?pvalue .");
                traitQueryString = traitQueryString.concat("?association gt:has_p_value ?pvalue .");
                associationPvalueFilters = associationPvalueFilters.concat("  FILTER ( ?pvalue < ?? )").concat("  FILTER ( ?pvalue >= ?? )");
                traitPvalueFilters = traitPvalueFilters.concat("  FILTER ( ?pvalue < ?? )").concat("  FILTER ( ?pvalue >= ?? )");
            }
            if (filter.getFilteredType().equals(Study.class)) {
                associationQueryString = associationQueryString.concat("?association ro:part_of ?study . ?study gt:has_publication_date ?date .");
                traitQueryString = traitQueryString.concat("?association ro:part_of ?study . ?study gt:has_publication_date ?date . ");
                associationDateFilters = associationDateFilters.concat("  FILTER ( ?date < ?? ) ").concat("  FILTER ( ?date >= ?? ) ");
                traitDateFilters = traitDateFilters.concat("  FILTER ( ?date < ?? ) ").concat("  FILTER ( ?date >= ?? ) ");
            }
        }
        associationQueryString = associationQueryString.concat(associationPvalueFilters).concat(associationDateFilters).concat(associationQueryBandFilter);
        traitQueryString = traitQueryString.concat(traitPvalueFilters).concat(traitDateFilters).concat(" }");
        System.out.println(associationQueryString);
        System.out.println(traitQueryString);
        try {
            getLog().debug("Querying SPARQL endpoint for GWAS data...");
            List<URI> chromosomes = loadChromosomes(getSparqlTemplate());
            getLog().debug("Acquired " + chromosomes.size() + " chromosomes to render");
            List<URI> individuals = new ArrayList<URI>();
            individuals.addAll(loadAssociations(getSparqlTemplate(), associationQueryString, renderletNexus.getRenderingContext()));
            individuals.addAll(loadTraits(getSparqlTemplate(), traitQueryString, renderletNexus.getRenderingContext()));
            getLog().debug("Acquired " + individuals.size() + " individuals to render");
            if (individuals.size() == 0) {
                throw new NoRenderableDataException("No individuals available for rendering");
            }
            getLog().debug("GWAS data acquired, starting rendering...");
            // render chromosomes first
            for (URI chromosome : chromosomes) {
                dispatchRenderlet(renderletNexus, chromosome);
            }
            // then render individuals
            for (URI individual : individuals) {
                dispatchRenderlet(renderletNexus, individual);
            }
            getLog().debug("SVG rendering complete!");
            return renderletNexus.getSVG();
        } catch (SparqlQueryException e) {
            throw new RuntimeException("Failed to load data - cannot render SVG", e);
        } finally {
            getLog().debug("About to reset the renderlet nexus");
            setRendering(false);
            renderletNexus.reset();
        }
    } else {
        getLog().debug("The GWAS diagram is already being rendered");
        throw new PussycatSessionNotReadyException("The GWAS diagram is currently being rendered");
    }
}
Also used : NoRenderableDataException(uk.ac.ebi.spot.goci.pussycat.exception.NoRenderableDataException) Filter(uk.ac.ebi.spot.goci.pussycat.lang.Filter) SparqlQueryException(uk.ac.ebi.spot.goci.sparql.exception.SparqlQueryException) ArrayList(java.util.ArrayList) PussycatSessionNotReadyException(uk.ac.ebi.spot.goci.pussycat.exception.PussycatSessionNotReadyException) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 NoRenderableDataException (uk.ac.ebi.spot.goci.pussycat.exception.NoRenderableDataException)1 PussycatSessionNotReadyException (uk.ac.ebi.spot.goci.pussycat.exception.PussycatSessionNotReadyException)1 Filter (uk.ac.ebi.spot.goci.pussycat.lang.Filter)1 SparqlQueryException (uk.ac.ebi.spot.goci.sparql.exception.SparqlQueryException)1