<commit_before>package uk.ac.ebi.fgpt.goci.pussycat.renderlet;

import net.sourceforge.fluxion.spi.ServiceProvider;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import uk.ac.ebi.fgpt.goci.lang.OntologyConstants;
import uk.ac.ebi.fgpt.goci.pussycat.layout.BandInformation;
import uk.ac.ebi.fgpt.goci.pussycat.layout.ColourMapper;
import uk.ac.ebi.fgpt.goci.pussycat.layout.SVGArea;
import uk.ac.ebi.fgpt.goci.pussycat.layout.SVGBuilder;
import uk.ac.ebi.fgpt.goci.utils.OntologyUtils;

import java.util.Set;

/**
 * A renderlet that is capable of rendering visualisations of "traits".  A trait is an OWL class from the
 * experimental factor ontology (EFO)
 *
 * @author <NAME>
 * @date 06/03/12
 */
@ServiceProvider
public class TraitRenderlet implements Renderlet<OWLOntology, OWLIndividual> {

    /*
    * TraitRenderlet should retrieve the appropriate RGB colour for the trait being rendered from a hardcoded
    * resource file
    *
    *
    * */

//    private String traitName;

    private Logger log = LoggerFactory.getLogger(getClass());

    protected Logger getLog() {
        return log;
    }

    @Override
    public String getName() {
        return "GWAS trait renderlet";
    }

    @Override
    public String getDisplayName() {
        return getName();
    }

    @Override
    public String getDescription() {
        return ("This is a renderlet displaying " + getDisplayName());
    }

    @Override
    public boolean canRender(RenderletNexus nexus, Object renderingContext, Object renderingEntity) {
        boolean renderable = false;
        if (renderingContext instanceof OWLOntology) {
            if (renderingEntity instanceof OWLNamedIndividual) {
                OWLNamedIndividual individual = (OWLNamedIndividual) renderingEntity;

                if (nexus.getLocationOfEntity(individual) == null) {
                    Set<OWLClass> allTypes = nexus.getReasoner()
                                                  .getTypes(individual, false)
                                                  .getFlattened();

                    for (OWLClass typeClass : allTypes) {
                        if (typeClass.getIRI().equals(IRI.create(OntologyConstants.EXPERIMENTAL_FACTOR_CLASS_IRI))) {
                            renderable = true;
                            break;
                        }
                    }
                }
            }
        }
        return renderable;
    }

    @Override
    public Element render(RenderletNexus nexus,
                          OWLOntology renderingContext,
                          OWLIndividual renderingEntity,
                          SVGBuilder builder) {
        OWLNamedIndividual gwasTrait = (OWLNamedIndividual) renderingEntity;
        OWLNamedIndividual association = getAssociation(nexus, gwasTrait);

        Element trait = null;

        if (association != null) {
            SVGArea associationSVG = nexus.getLocationOfEntity(association);

            if (nexus.getRenderingEvent(association) != null) {
                Element assocG = nexus.getRenderingEvent(association).getRenderedSVG();

                String location = assocG.getAttribute("transform");
                String bandName = getSNPLocation(nexus, association, renderingContext);

                if (bandName != null) {
                    trait = builder.createElement("circle");
                    BandInformation band = nexus.getBandLocations().get(bandName);

                    trait.setAttribute("transform", location);

                    double alength = associationSVG.getWidth();
                    double radius = 0.2 * alength;
                    double ax = associationSVG.getX();
                    double ay = associationSVG.getY();
                    double displacement = associationSVG.getHeight();
                    double cx, cy;
                    int size = band.getRenderedTraits().size();

                    int horizontal = size % 6;
                    int vertical = size / 6;

                    if (size == 0) {
                        cx = ax + alength + radius;
                    }
                    else {
                        if (vertical % 2 == 0) {
                            cx = ax + alength + (((2 * horizontal) + 1) * radius);
                        }
                        else {
                            cx = ax + alength + (((2 * horizontal) + 2) * radius);
                        }
                    }
                    cy = ay + displacement + (vertical * radius);

                    trait.setAttribute("cx", Double.toString(cx));
                    trait.setAttribute("cy", Double.toString(cy));
                    trait.setAttribute("r", Double.toString(radius));

                    String colour = getColour(gwasTrait, nexus);

                    trait.setAttribute("fill", colour);
                    trait.setAttribute("stroke", "black");
                    trait.setAttribute("stroke-width", "0.5");

                    String traitName = getTraitName(gwasTrait, renderingContext, nexus, association);
                    String mo = "showTooltip('" + traitName + "')";
                    trait.setAttribute("onmouseover", mo);
                    trait.setAttribute("onmouseout", "hideTooltip()");
                    trait.setAttribute("id", traitName);

                    IRI iri = getTraitClass(gwasTrait, renderingContext);
                    String traitClass = OntologyUtils.getShortForm(iri, renderingContext);
                    getLog().trace("Setting CSS class for trait '" + gwasTrait + "' to " + traitClass);
                    trait.setAttribute("class", traitClass + " gwas-trait");

                    SVGArea currentArea = new SVGArea(cx, cy, 2 * radius, 2 * radius, 0);
                    RenderingEvent<OWLIndividual> event = new RenderingEvent<OWLIndividual>(
                            renderingEntity, trait, currentArea, this);
                    nexus.renderingEventOccurred(event);
                    band.setRenderedTrait(traitName);
                }
            }
        }
        return trait;
    }
<commit_msg>goci-renderlet: restoring apostrophe escaping which seems to have gone missing in a merge<commit_after>package uk.ac.ebi.fgpt.goci.pussycat.renderlet;

import net.sourceforge.fluxion.spi.ServiceProvider;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import uk.ac.ebi.fgpt.goci.lang.OntologyConstants;
import uk.ac.ebi.fgpt.goci.pussycat.layout.BandInformation;
import uk.ac.ebi.fgpt.goci.pussycat.layout.ColourMapper;
import uk.ac.ebi.fgpt.goci.pussycat.layout.SVGArea;
import uk.ac.ebi.fgpt.goci.pussycat.layout.SVGBuilder;
import uk.ac.ebi.fgpt.goci.utils.OntologyUtils;

import java.util.Set;

/**
 * A renderlet that is capable of rendering visualisations of "traits".  A trait is an OWL class from the
 * experimental factor ontology (EFO)
 *
 * @author <NAME>
 * @date 06/03/12
 */
@ServiceProvider
public class TraitRenderlet implements Renderlet<OWLOntology, OWLIndividual> {

    /*
    * TraitRenderlet should retrieve the appropriate RGB colour for the trait being rendered from a hardcoded
    * resource file
    *
    *
    * */

//    private String traitName;

    private Logger log = LoggerFactory.getLogger(getClass());

    protected Logger getLog() {
        return log;
    }

    @Override
    public String getName() {
        return "GWAS trait renderlet";
    }

    @Override
    public String getDisplayName() {
        return getName();
    }

    @Override
    public String getDescription() {
        return ("This is a renderlet displaying " + getDisplayName());
    }

    @Override
    public boolean canRender(RenderletNexus nexus, Object renderingContext, Object renderingEntity) {
        boolean renderable = false;
        if (renderingContext instanceof OWLOntology) {
            if (renderingEntity instanceof OWLNamedIndividual) {
                OWLNamedIndividual individual = (OWLNamedIndividual) renderingEntity;

                if (nexus.getLocationOfEntity(individual) == null) {
                    Set<OWLClass> allTypes = nexus.getReasoner()
                                                  .getTypes(individual, false)
                                                  .getFlattened();

                    for (OWLClass typeClass : allTypes) {
                        if (typeClass.getIRI().equals(IRI.create(OntologyConstants.EXPERIMENTAL_FACTOR_CLASS_IRI))) {
                            renderable = true;
                            break;
                        }
                    }
                }
            }
        }
        return renderable;
    }

    @Override
    public Element render(RenderletNexus nexus,
                          OWLOntology renderingContext,
                          OWLIndividual renderingEntity,
                          SVGBuilder builder) {
        OWLNamedIndividual gwasTrait = (OWLNamedIndividual) renderingEntity;
        OWLNamedIndividual association = getAssociation(nexus, gwasTrait);

        Element trait = null;

        if (association != null) {
            SVGArea associationSVG = nexus.getLocationOfEntity(association);

            if (nexus.getRenderingEvent(association) != null) {
                Element assocG = nexus.getRenderingEvent(association).getRenderedSVG();

                String location = assocG.getAttribute("transform");
                String bandName = getSNPLocation(nexus, association, renderingContext);

                if (bandName != null) {
                    trait = builder.createElement("circle");
                    BandInformation band = nexus.getBandLocations().get(bandName);

                    trait.setAttribute("transform", location);

                    double alength = associationSVG.getWidth();
                    double radius = 0.2 * alength;
                    double ax = associationSVG.getX();
                    double ay = associationSVG.getY();
                    double displacement = associationSVG.getHeight();
                    double cx, cy;
                    int size = band.getRenderedTraits().size();

                    int horizontal = size % 6;
                    int vertical = size / 6;

                    if (size == 0) {
                        cx = ax + alength + radius;
                    }
                    else {
                        if (vertical % 2 == 0) {
                            cx = ax + alength + (((2 * horizontal) + 1) * radius);
                        }
                        else {
                            cx = ax + alength + (((2 * horizontal) + 2) * radius);
                        }
                    }
                    cy = ay + displacement + (vertical * radius);

                    trait.setAttribute("cx", Double.toString(cx));
                    trait.setAttribute("cy", Double.toString(cy));
                    trait.setAttribute("r", Double.toString(radius));

                    String colour = getColour(gwasTrait, nexus);

                    trait.setAttribute("fill", colour);
                    trait.setAttribute("stroke", "black");
                    trait.setAttribute("stroke-width", "0.5");

                    String traitName = getTraitName(gwasTrait, renderingContext, nexus, association);
                    if(traitName.contains("'")){
                        traitName = traitName.replace("'", "\\'");
                    }
                    String mo = "showTooltip('" + traitName + "')";
                    trait.setAttribute("onmouseover", mo);
                    trait.setAttribute("onmouseout", "hideTooltip()");
                    trait.setAttribute("id", traitName);

                    IRI iri = getTraitClass(gwasTrait, renderingContext);
                    String traitClass = OntologyUtils.getShortForm(iri, renderingContext);
                    getLog().trace("Setting CSS class for trait '" + gwasTrait + "' to " + traitClass);
                    trait.setAttribute("class", traitClass + " gwas-trait");

                    SVGArea currentArea = new SVGArea(cx, cy, 2 * radius, 2 * radius, 0);
                    RenderingEvent<OWLIndividual> event = new RenderingEvent<OWLIndividual>(
                            renderingEntity, trait, currentArea, this);
                    nexus.renderingEventOccurred(event);
                    band.setRenderedTrait(traitName);
                }
            }
        }
        return trait;
    }

{'fraction_non_alphanumeric': 0.09406407035175879, 'fraction_numerical': 0.003925879396984924, 'mean_word_length': 1.6996608732513776, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '382639', 'n_tokens_mistral': 3427, 'n_tokens_neox': 3202, 'n_words': 707}