Search in sources :

Example 21 with Association

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

the class MappingService method validateAndMapAllAssociations.

/**
     * Perform validation and mapping of all database associations
     *
     * @param associations Collection of associations to map
     * @param performer    name of curator/job carrying out the mapping
     */
public void validateAndMapAllAssociations(Collection<Association> associations, String performer) throws EnsemblMappingException {
    // Default mapping user
    SecureUser user = secureUserRepository.findByEmail("automatic_mapping_process");
    String eRelease = this.getEnsemblRelease();
    int totalAssociationDone = 1;
    List<Long> associationsFailed = new ArrayList<Long>();
    for (Association association : associations) {
        try {
            getLog().debug("Start doMapping Association nr:" + String.valueOf(totalAssociationDone));
            doMapping(association, eRelease);
            // Update mapping event
            trackingOperationService.update(association, user, "ASSOCIATION_MAPPING");
            // Once mapping is complete, update mapping record
            getLog().debug("Update mapping record");
            mappingRecordService.updateAssociationMappingRecord(association, new Date(), performer);
            totalAssociationDone = totalAssociationDone + 1;
        } catch (EnsemblMappingException e) {
            //throw new EnsemblMappingException("Attempt to map all associations failed", e);
            associationsFailed.add(association.getId());
        }
    }
    getLog().debug("Number of associations FAILED");
    getLog().debug(String.valueOf(associationsFailed.size()));
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser)

Example 22 with Association

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

the class DefaultGWASOWLConverter method convertStudy.

protected void convertStudy(Study study, OWLOntology ontology) {
    // get the study class
    OWLClass studyCls = getDataFactory().getOWLClass(IRI.create(OntologyConstants.STUDY_CLASS_IRI));
    // create a new study instance
    OWLNamedIndividual studyIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, study));
    // assert class membership
    OWLClassAssertionAxiom classAssertion = getDataFactory().getOWLClassAssertionAxiom(studyCls, studyIndiv);
    getManager().addAxiom(ontology, classAssertion);
    // add datatype properties...
    // get datatype relations
    OWLDataProperty has_author = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_AUTHOR_PROPERTY_IRI));
    OWLDataProperty has_publication_date = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_PUBLICATION_DATE_PROPERTY_IRI));
    OWLDataProperty has_pubmed_id = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_PUBMED_ID_PROPERTY_IRI));
    // get annotation relations
    OWLAnnotationProperty rdfsLabel = getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
    // assert author relation
    OWLLiteral author = getDataFactory().getOWLLiteral(study.getAuthor());
    OWLDataPropertyAssertionAxiom author_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_author, studyIndiv, author);
    AddAxiom add_author = new AddAxiom(ontology, author_relation);
    getManager().applyChange(add_author);
    // assert publication_date relation
    if (study.getPublicationDate() != null) {
        String rfcTimezone = new SimpleDateFormat("Z").format(study.getPublicationDate());
        String xsdTimezone = rfcTimezone.substring(0, 3).concat(":").concat(rfcTimezone.substring(3, rfcTimezone.length()));
        String xmlDatetimeStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(study.getPublicationDate()) + xsdTimezone;
        OWLLiteral publication_date = getDataFactory().getOWLLiteral(xmlDatetimeStr, OWL2Datatype.XSD_DATE_TIME);
        OWLDataPropertyAssertionAxiom publication_date_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_publication_date, studyIndiv, publication_date);
        AddAxiom add_publication_date = new AddAxiom(ontology, publication_date_relation);
        getManager().applyChange(add_publication_date);
    }
    // assert pubmed_id relation
    OWLLiteral pubmed_id = getDataFactory().getOWLLiteral(study.getPubmedId());
    OWLDataPropertyAssertionAxiom pubmed_id_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_pubmed_id, studyIndiv, pubmed_id);
    AddAxiom add_pubmed_id = new AddAxiom(ontology, pubmed_id_relation);
    getManager().applyChange(add_pubmed_id);
    // assert label
    OWLLiteral study_label = getDataFactory().getOWLLiteral(pubmed_id.toString());
    OWLAnnotationAssertionAxiom label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, studyIndiv.getIRI(), study_label);
    AddAxiom add_label = new AddAxiom(ontology, label_annotation);
    getManager().applyChange(add_label);
    // add object properties...
    // get the has_part relation
    OWLObjectProperty has_part = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.HAS_PART_PROPERTY_IRI));
    OWLObjectProperty part_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.PART_OF_PROPERTY_IRI));
    // for this study, get all trait associations 
    Collection<Association> associations = study.getAssociations();
    // and create an study has_part association assertion for each one
    for (Association association : associations) {
        // get the trait association instance for this association
        IRI traitIRI = getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, association);
        OWLNamedIndividual taIndiv = getDataFactory().getOWLNamedIndividual(traitIRI);
        // assert relation
        OWLObjectPropertyAssertionAxiom has_part_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(has_part, studyIndiv, taIndiv);
        AddAxiom addAxiomChange = new AddAxiom(ontology, has_part_relation);
        getManager().applyChange(addAxiomChange);
        OWLObjectPropertyAssertionAxiom is_part_of_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(part_of, taIndiv, studyIndiv);
        AddAxiom addAxiomChangeRev = new AddAxiom(ontology, is_part_of_relation);
        getManager().applyChange(addAxiomChangeRev);
    }
}
Also used : OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) IRI(org.semanticweb.owlapi.model.IRI) AddAxiom(org.semanticweb.owlapi.model.AddAxiom) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLDataPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) Association(uk.ac.ebi.spot.goci.model.Association) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLObjectPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) SimpleDateFormat(java.text.SimpleDateFormat)

Example 23 with Association

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

the class DefaultGWASOWLPublisher method publishGWASData.

public OWLOntology publishGWASData() throws OWLConversionException {
    // create new ontology
    OWLOntology conversion = getConverter().createConversionOntology();
    // grab all studies from the DAO
    getLog().debug("Fetching studies that require conversion to OWL using StudyRepository...");
    Collection<Study> studies = getStudyService().deepFindPublishedStudies();
    //TODO : check with Tony probably better to do it at the Repository/Service level
    //Discard studies which are not associated with a disease trait and those which haven't been published yet
    //by the GWAS catalog.
    Iterator<Study> iterator = studies.iterator();
    while (iterator.hasNext()) {
        Study study = iterator.next();
        //Remove study which have no diseaseTrait.
        if (study.getDiseaseTrait() == null) {
            iterator.remove();
            getLog().error("Study '" + study.getId() + "' has no disease trait");
        } else if (study.getHousekeeping().getCatalogPublishDate() == null) {
            iterator.remove();
            getLog().error("Study '" + study.getId() + "' has not yet been published");
        } else //Remove studies that have been unpublished
        if (study.getHousekeeping().getCatalogUnpublishDate() != null) {
            iterator.remove();
            getLog().error("Study '" + study.getId() + "' has been unpublished");
        }
    //            }else {
    //
    //                //Remove study which have no associations where pvalue is not null.
    //                Collection<Association> associations = study.getAssociations();
    //                Iterator<Association> associationIterator = associations.iterator();
    //                int associationCount = 0;
    //                while (associationIterator.hasNext()) {
    //                    Association association = associationIterator.next();
    //
    //                    if (association.getPvalueExponent() != null && association.getPvalueMantissa() != null) {
    //                        associationCount++;
    //                    }
    //                }
    //                if (associationCount == 0) {
    //                    iterator.remove();
    //                }
    //            }
    }
    getLog().debug("Query complete, got " + studies.size() + " studies");
    // if studies limit is not set, convert all data, else filter to first n studies and associated data
    if (getStudiesLimit() == -1 && FilterProperties.getDateFilter() == null && FilterProperties.getPvalueFilter() == null) {
        System.out.println("Converting all available data");
        // grab all other data from the DAO
        getLog().debug("Fetching traits that require conversion to OWL using AssociationRepository...");
        Collection<Association> traitAssociations = getAssociationService().findReallyAll();
        //TODO check with Tony how to do that in a better way from service or repository (how to not get associations linked to study with no trait.
        //Discard all the associations which are linked to study which are not linked to a disease trait or haven't
        //been published yet in the GWAS catalog.
        Iterator<Association> associationIterator = traitAssociations.iterator();
        while (associationIterator.hasNext()) {
            Association association = associationIterator.next();
            if (association.getStudy().getDiseaseTrait() == null) {
                associationIterator.remove();
            } else if (association.getStudy().getHousekeeping().getCatalogPublishDate() == null) {
                associationIterator.remove();
            } else if (association.getStudy().getHousekeeping().getCatalogUnpublishDate() != null) {
                associationIterator.remove();
            }
        }
        getLog().debug("Fetching SNPs that require conversion to OWL using SingleNucleotidePolymorphismRepository...");
        Collection<SingleNucleotidePolymorphism> snps = getSingleNucleotidePolymorphismService().findAll();
        getLog().debug("All data fetched");
        // convert this data, starting with SNPs (no dependencies) and working up to studies
        getLog().debug("Starting conversion to OWL...");
        getLog().debug("Converting SNPs...");
        getConverter().addSNPsToOntology(snps, conversion);
        getLog().debug("Converting Trait Associations...");
        getConverter().addAssociationsToOntology(traitAssociations, conversion);
        getLog().debug("Converting Studies...");
        getConverter().addStudiesToOntology(studies, conversion);
        getLog().debug("All conversion done!");
        return conversion;
    } else {
        System.out.println("Data conforming to the filter only");
        return filterAndPublishGWASData(conversion, studies);
    }
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Association(uk.ac.ebi.spot.goci.model.Association) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)

Example 24 with Association

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

the class AssociationRowProcessorTest method testCreateAssociationFromUploadRow.

@Test
public void testCreateAssociationFromUploadRow() throws Exception {
    // Stubbing mock object behaviour
    when(associationAttributeService.createLocusGenes(STANDARD_ROW.getAuthorReportedGene(), ",")).thenReturn(Arrays.asList(GENE_01, GENE_02));
    when(associationAttributeService.createSnp(STANDARD_ROW.getSnp())).thenReturn(SNP_01);
    when(associationAttributeService.createRiskAllele(STANDARD_ROW.getStrongestAllele(), SNP_01)).thenReturn(RA_01);
    when(associationAttributeService.createSnp(STANDARD_ROW.getProxy())).thenReturn(PROXY);
    Association association = associationRowProcessor.createAssociationFromUploadRow(STANDARD_ROW);
    verify(associationCalculationService, never()).reverseCI(STANDARD_ROW.getRange());
    verify(associationCalculationService, never()).setRange(STANDARD_ROW.getStandardError(), STANDARD_ROW.getOrPerCopyNum());
    verify(associationAttributeService, never()).getEfoTraitsFromRepository(Collections.EMPTY_LIST);
    verify(associationAttributeService, times(1)).createLocusGenes(STANDARD_ROW.getAuthorReportedGene(), ",");
    verify(associationAttributeService, times(1)).createSnp(STANDARD_ROW.getSnp());
    verify(associationAttributeService, times(1)).createSnp(STANDARD_ROW.getProxy());
    verify(associationAttributeService, times(1)).createRiskAllele(STANDARD_ROW.getStrongestAllele(), SNP_01);
    assertThat(association).extracting("id", "riskFrequency", "pvalueDescription", "pvalueMantissa", "pvalueExponent", "multiSnpHaplotype", "snpInteraction", "snpApproved", "snpType", "standardError", "range", "description", "orPerCopyNum", "orPerCopyRecip", "orPerCopyRecipRange", "betaNum", "betaUnit", "betaDirection", "study", "associationReport", "lastMappingDate", "lastMappingPerformedBy", "lastUpdateDate").containsExactly(null, "0.52", "(some pvalue description)", 2, -7, false, false, false, null, (float) 0.6, "[0.82-0.92]", null, (float) 1.22, null, null, null, null, null, null, null, null, null, null);
    assertThat(association.getEfoTraits()).isEmpty();
    assertThat(association.getEvents()).isEmpty();
    assertThat(association.getStudy()).isNull();
    assertThat(association.getLoci()).hasSize(1);
    // Check locus attributes
    Collection<Gene> locusGenes = new ArrayList<>();
    association.getLoci().stream().forEach(locus -> {
        locusGenes.addAll(locus.getAuthorReportedGenes());
    });
    Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
    association.getLoci().stream().forEach(locus -> {
        locusRiskAlleles.addAll(locus.getStrongestRiskAlleles());
    });
    Collection<SingleNucleotidePolymorphism> proxies = new ArrayList<>();
    locusRiskAlleles.stream().forEach(riskAllele -> {
        proxies.addAll(riskAllele.getProxySnps());
    });
    assertThat(association.getLoci()).extracting(Locus::getDescription).containsOnly("Single variant");
    assertThat(locusGenes).hasSize(2).contains(GENE_01, GENE_02);
    assertThat(locusRiskAlleles).hasSize(1).contains(RA_01);
    assertThat(locusRiskAlleles).extracting("riskAlleleName", "riskFrequency", "snp.rsId").contains(tuple("rs123-?", "0.52", "rs123"));
    assertThat(locusRiskAlleles).extracting(RiskAllele::getSnp).contains(SNP_01);
    assertThat(proxies).contains(PROXY);
    assertThat(proxies).extracting(SingleNucleotidePolymorphism::getRsId).containsExactly("rs99");
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) Gene(uk.ac.ebi.spot.goci.model.Gene) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Test(org.junit.Test)

Example 25 with Association

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

the class AssociationRowProcessor method createAssociationFromUploadRow.

public Association createAssociationFromUploadRow(AssociationUploadRow row) {
    Association newAssociation = new Association();
    // Set EFO traits
    if (row.getEfoTrait() != null) {
        String[] uris = row.getEfoTrait().split(",");
        Collection<String> efoUris = new ArrayList<>();
        for (String uri : uris) {
            String trimmedUri = uri.trim();
            efoUris.add(trimmedUri);
        }
        Collection<EfoTrait> efoTraits = associationAttributeService.getEfoTraitsFromRepository(efoUris);
        newAssociation.setEfoTraits(efoTraits);
    }
    /// Set OR
    newAssociation.setOrPerCopyRecip(row.getOrPerCopyRecip());
    newAssociation.setOrPerCopyRecipRange(row.getOrPerCopyRecipRange());
    // Set beta
    newAssociation.setBetaNum(row.getBetaNum());
    newAssociation.setBetaUnit(row.getBetaUnit());
    newAssociation.setBetaDirection(row.getBetaDirection());
    // Calculate OR num if OR recip is present , otherwise set to whatever is in upload
    boolean recipReverse = false;
    if ((row.getOrPerCopyRecip() != null) && (row.getOrPerCopyNum() == null)) {
        getLog().info("Calculating OR from OR recip value");
        newAssociation.setOrPerCopyNum(((100 / row.getOrPerCopyRecip()) / 100));
        recipReverse = true;
    } else {
        newAssociation.setOrPerCopyNum(row.getOrPerCopyNum());
    }
    // Calculate range , this logic is retained from Dani's original code
    if ((row.getOrPerCopyRecipRange() != null) && recipReverse) {
        newAssociation.setRange(associationCalculationService.reverseCI(row.getOrPerCopyRecipRange()));
    } else if ((row.getRange() == null) && (row.getStandardError() != null)) {
        if (row.getOrPerCopyNum() != null) {
            newAssociation.setRange(associationCalculationService.setRange(row.getStandardError(), row.getOrPerCopyNum()));
        } else {
            if (row.getBetaNum() != null) {
                newAssociation.setRange(associationCalculationService.setRange(row.getStandardError(), row.getBetaNum()));
            }
        }
    } else {
        newAssociation.setRange(row.getRange());
    }
    // Add brackets to the p-value description
    if (row.getPvalueDescription() != null && !row.getPvalueDescription().isEmpty()) {
        if (!row.getPvalueDescription().startsWith("(") && !row.getPvalueDescription().endsWith(")")) {
            StringJoiner newPvalueDescription = new StringJoiner("", "(", ")");
            newPvalueDescription.add(row.getPvalueDescription());
            newAssociation.setPvalueDescription(newPvalueDescription.toString());
        } else {
            newAssociation.setPvalueDescription(row.getPvalueDescription());
        }
    } else {
        newAssociation.setPvalueDescription(row.getPvalueDescription());
    }
    // Set values common to all association types
    newAssociation.setRiskFrequency(row.getAssociationRiskFrequency());
    newAssociation.setPvalueMantissa(row.getPvalueMantissa());
    newAssociation.setPvalueExponent(row.getPvalueExponent());
    newAssociation.setSnpType(row.getSnpType());
    newAssociation.setStandardError(row.getStandardError());
    newAssociation.setDescription(row.getDescription());
    if (row.getMultiSnpHaplotype() != null) {
        if (row.getMultiSnpHaplotype().equalsIgnoreCase("Y")) {
            newAssociation.setMultiSnpHaplotype(true);
        }
    } else {
        newAssociation.setMultiSnpHaplotype(false);
    }
    if (row.getSnpInteraction() != null) {
        if (row.getSnpInteraction().equalsIgnoreCase("Y")) {
            newAssociation.setSnpInteraction(true);
        }
    } else {
        newAssociation.setSnpInteraction(false);
    }
    // If there is a risk allele proceed to create loci
    if (row.getStrongestAllele() != null) {
        newAssociation.setLoci(createLoci(row, newAssociation.getSnpInteraction(), newAssociation.getMultiSnpHaplotype()));
    }
    return newAssociation;
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) ArrayList(java.util.ArrayList) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) StringJoiner(java.util.StringJoiner)

Aggregations

Association (uk.ac.ebi.spot.goci.model.Association)38 ArrayList (java.util.ArrayList)14 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)10 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)9 Study (uk.ac.ebi.spot.goci.model.Study)7 Test (org.junit.Test)6 Gene (uk.ac.ebi.spot.goci.model.Gene)6 SimpleDateFormat (java.text.SimpleDateFormat)5 EnsemblMappingException (uk.ac.ebi.spot.goci.exception.EnsemblMappingException)5 Locus (uk.ac.ebi.spot.goci.model.Locus)5 EfoTrait (uk.ac.ebi.spot.goci.model.EfoTrait)4 Filter (uk.ac.ebi.spot.goci.pussycat.lang.Filter)4 Collection (java.util.Collection)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 IOException (java.io.IOException)2 URI (java.net.URI)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2