Search in sources :

Example 6 with Association

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

the class AssociationRowProcessorTest method testCreateAssociationFromUploadRowHaplotype.

@Test
public void testCreateAssociationFromUploadRowHaplotype() throws Exception {
    // Stubbing mock object behaviour
    when(associationAttributeService.createSnp("rs456")).thenReturn(SNP_04);
    when(associationAttributeService.createSnp("rs678")).thenReturn(SNP_05);
    when(associationAttributeService.createRiskAllele("rs456-T", SNP_04)).thenReturn(RA_04);
    when(associationAttributeService.createRiskAllele("rs678-?", SNP_05)).thenReturn(RA_05);
    when(associationCalculationService.reverseCI("[0.87-0.94]")).thenReturn("[1.06-1.15]");
    Association association = associationRowProcessor.createAssociationFromUploadRow(HAPLOTYPE_ROW);
    verify(associationCalculationService, times(1)).reverseCI(Matchers.anyString());
    verify(associationCalculationService, never()).setRange(Matchers.anyDouble(), Matchers.anyDouble());
    verify(associationAttributeService, never()).getEfoTraitsFromRepository(Collections.EMPTY_LIST);
    verify(associationAttributeService, never()).createLocusGenes(Matchers.anyString(), Matchers.anyString());
    verify(associationAttributeService, times(1)).createSnp("rs456");
    verify(associationAttributeService, times(1)).createSnp("rs678");
    verify(associationAttributeService, times(1)).createRiskAllele("rs456-T", SNP_04);
    verify(associationAttributeService, times(1)).createRiskAllele("rs678-?", SNP_05);
    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, null, "(description)", 2, -7, true, false, false, null, null, "[1.06-1.15]", null, 1.2048193f, 0.83f, "[0.87-0.94]", 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);
    Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
    association.getLoci().stream().forEach(locus -> {
        locusRiskAlleles.addAll(locus.getStrongestRiskAlleles());
    });
    // Check locus attributes
    Collection<Gene> locusGenes = new ArrayList<>();
    association.getLoci().stream().forEach(locus -> {
        locusGenes.addAll(locus.getAuthorReportedGenes());
    });
    assertThat(association.getLoci()).extracting(Locus::getDescription).containsOnly("2-SNP haplotype");
    assertThat(locusGenes).isEmpty();
    assertThat(locusRiskAlleles).hasSize(2).contains(RA_04, RA_05);
    assertThat(locusRiskAlleles).extracting(RiskAllele::getRiskFrequency).containsNull();
    assertThat(locusRiskAlleles).extracting("riskAlleleName", "riskFrequency", "snp.rsId").contains(tuple("rs456-T", null, "rs456"), tuple("rs678-?", null, "rs678"));
    assertThat(locusRiskAlleles).extracting(RiskAllele::getSnp).containsExactly(SNP_04, SNP_05);
}
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) Test(org.junit.Test)

Example 7 with Association

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

the class AssociationFileUploadService method createAssociationSummary.

/**
     * Process uploaded file, create an association and return a list of its errors
     *
     * @param row             Row to validate and convert into an association
     * @param validationLevel level of validation to run
     */
private AssociationSummary createAssociationSummary(AssociationUploadRow row, String validationLevel, String eRelease) {
    getLog().info("Creating association summary for row " + row.getRowNumber());
    Association association = associationRowProcessor.createAssociationFromUploadRow(row);
    Collection<ValidationError> errors = validationService.runAssociationValidation(association, validationLevel, eRelease);
    AssociationSummary associationSummary = new AssociationSummary();
    associationSummary.setRowNumber(row.getRowNumber());
    associationSummary.setAssociation(association);
    associationSummary.setErrors(errors);
    return associationSummary;
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError)

Example 8 with Association

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

the class SparqlPussycatSession method loadAssociations.

private List<URI> loadAssociations(SparqlTemplate sparqlTemplate, String queryString, List<Filter> filters) {
    List<AssociationLocation> associationLocations = null;
    if (filters.size() == 0) {
        associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
                                                                                    and can't be rendered anyway*/
        new QuerySolutionMapper<AssociationLocation>() {

            @Override
            public AssociationLocation mapQuerySolution(QuerySolution qs) {
                URI association = URI.create(qs.getResource("association").getURI());
                String bandName = qs.getLiteral("band").getLexicalForm();
                return new AssociationLocation(association, bandName);
            }
        });
    } else if (filters.size() == 1) {
        for (Filter filter : filters) {
            if (filter.getFilteredType().equals(Association.class)) {
                associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
                                                                                    and can't be rendered anyway*/
                new QuerySolutionMapper<AssociationLocation>() {

                    @Override
                    public AssociationLocation mapQuerySolution(QuerySolution qs) {
                        URI association = URI.create(qs.getResource("association").getURI());
                        String bandName = qs.getLiteral("band").getLexicalForm();
                        return new AssociationLocation(association, bandName);
                    }
                }, filter.getFilteredValues().get(1), filter.getFilteredValues().get(0));
            } else if (filter.getFilteredType().equals(Study.class)) {
                associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
                                                                                    and can't be rendered anyway*/
                new QuerySolutionMapper<AssociationLocation>() {

                    @Override
                    public AssociationLocation mapQuerySolution(QuerySolution qs) {
                        URI association = URI.create(qs.getResource("association").getURI());
                        String bandName = qs.getLiteral("band").getLexicalForm();
                        return new AssociationLocation(association, bandName);
                    }
                }, filter.getFilteredRange().to(), filter.getFilteredRange().from());
            }
        }
    } else {
        Object pval_min = null, pval_max = null, date_min = null, date_max = null;
        for (Filter filter : filters) {
            if (filter.getFilteredType().equals(Association.class)) {
                pval_min = filter.getFilteredValues().get(0);
                pval_max = filter.getFilteredValues().get(1);
            } else if (filter.getFilteredType().equals(Study.class)) {
                date_min = filter.getFilteredRange().from();
                date_max = filter.getFilteredRange().to();
            }
        }
        associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
                                                                                    and can't be rendered anyway*/
        new QuerySolutionMapper<AssociationLocation>() {

            @Override
            public AssociationLocation mapQuerySolution(QuerySolution qs) {
                URI association = URI.create(qs.getResource("association").getURI());
                String bandName = qs.getLiteral("band").getLexicalForm();
                return new AssociationLocation(association, bandName);
            }
        }, pval_max, pval_min, date_max, date_min);
    }
    Collections.sort(associationLocations);
    List<URI> associations = new ArrayList<URI>();
    for (AssociationLocation al : associationLocations) {
        associations.add(al.getAssociation());
    }
    return associations;
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) QuerySolutionMapper(uk.ac.ebi.spot.goci.sparql.pussycat.query.QuerySolutionMapper) Association(uk.ac.ebi.spot.goci.model.Association) QuerySolution(com.hp.hpl.jena.query.QuerySolution) Filter(uk.ac.ebi.spot.goci.pussycat.lang.Filter)

Example 9 with Association

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

the class DefaultGWASOWLPublisher method validateGWASData.

/**
     * Validates the data obtained from the GWAS catalog (prior to converting to OWL)
     *
     * @param studies the set of studies to validate
     */
protected void validateGWASData(Collection<Study> studies) {
    // now check a random assortment of 5 studies for trait associations, abandoning broken ones
    int count = 0;
    int noAssocCount = 0;
    int termMismatches = 0;
    for (Study study : studies) {
        //            try {
        Collection<Association> associations = study.getAssociations();
        getLog().debug("Study (PubMed ID '" + study.getPubmedId() + "') had " + associations.size() + " associations");
        if (associations.size() > 0) {
            for (Association association : associations) {
                String efoTraitsDashSepList = "";
                for (EfoTrait efoTrait : association.getEfoTraits()) {
                    if ("".equals(efoTraitsDashSepList)) {
                        efoTraitsDashSepList.concat(efoTrait.getTrait());
                    } else {
                        efoTraitsDashSepList.concat(", " + efoTrait.getTrait());
                    }
                }
                for (Locus locus : association.getLoci()) {
                    for (RiskAllele riskAllele : locus.getStrongestRiskAlleles()) {
                        getLog().debug(//                                "    Association: SNP '" + association.getAssociatedSNP().getRSID() +
                        "    Association: SNP '" + riskAllele.getSnp().getRsId() + "' <-> Trait '" + efoTraitsDashSepList.toString() + "'");
                    }
                }
            }
            count++;
        } else {
            noAssocCount++;
        }
    }
    int eligCount = studies.size() - noAssocCount;
    int correctCount = count + termMismatches;
    getLog().info("\n\nREPORT:\n" + eligCount + "/" + studies.size() + " declared associations and therefore could usefully be mapped.\n" + (eligCount - count - termMismatches) + "/" + eligCount + " failed due to data integrity concerns.\n" + count + "/" + correctCount + " studies could be completely mapped after passing all checks.\n" + termMismatches + "/" + correctCount + " failed due to missing or duplicated terms in EFO");
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Association(uk.ac.ebi.spot.goci.model.Association) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) Locus(uk.ac.ebi.spot.goci.model.Locus)

Example 10 with Association

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

the class DefaultGWASOWLPublisher method filterAndPublishGWASData.

private OWLOntology filterAndPublishGWASData(OWLOntology conversion, Collection<Study> studies) throws OWLConversionException {
    //TODO : check with tony : Discard studies which are not yet associated with a trait.
    //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();
    //            if(study.getDiseaseTrait() == null) {
    //                iterator.remove();
    //            }
    //            else if( study.getHousekeeping().getCatalogPublishDate() == null) {
    //                iterator.remove();
    //            }
    //            else if(study.getHousekeeping().getCatalogUnpublishDate() != null){
    //                iterator.remove();
    //            }
    //        }
    Collection<Study> filteredStudies = new ArrayList<Study>();
    Collection<Association> filteredTraitAssociations = new ArrayList<Association>();
    Collection<SingleNucleotidePolymorphism> filteredSNPs = new ArrayList<SingleNucleotidePolymorphism>();
    int count = 0;
    int studyLimit = getStudiesLimit() == -1 ? Integer.MAX_VALUE : getStudiesLimit();
    Iterator<Study> studyIterator = studies.iterator();
    while (count < studyLimit && studyIterator.hasNext()) {
        Study nextStudy = studyIterator.next();
        //only process a study if no date filter has been provided or if the study's publication date is smaller than the filter date
        if (FilterProperties.getDateFilter() == null || nextStudy.getPublicationDate().before(FilterProperties.getDateFilter())) {
            System.out.println("Qualifying study");
            for (Association nextTA : nextStudy.getAssociations()) {
                float filter = 0;
                float pval = 0;
                if (FilterProperties.getPvalueFilter() != null) {
                    filter = (float) (FilterProperties.getPvalueMant() * Math.pow(10, FilterProperties.getPvalueExp()));
                    pval = (float) (nextTA.getPvalueMantissa() * Math.pow(10, nextTA.getPvalueExponent()));
                    System.out.println("Your comparators are " + filter + " and " + pval);
                }
                if (FilterProperties.getPvalueFilter() == null || pval < filter) {
                    System.out.println("Qualifying association");
                    filteredTraitAssociations.add(nextTA);
                    for (Locus locus : nextTA.getLoci()) {
                        for (RiskAllele riskAllele : locus.getStrongestRiskAlleles()) {
                            filteredSNPs.add(riskAllele.getSnp());
                        }
                    }
                }
            }
            filteredStudies.add(nextStudy);
            count++;
        }
    }
    // convert this data, starting with SNPs (no dependencies) and working up to studies
    getLog().debug("Starting conversion to OWL...");
    getLog().debug("Converting " + filteredSNPs.size() + " filtered SNPs...");
    getConverter().addSNPsToOntology(filteredSNPs, conversion);
    getLog().debug("Converting " + filteredTraitAssociations.size() + " filtered Trait Associations...");
    getConverter().addAssociationsToOntology(filteredTraitAssociations, conversion);
    getLog().debug("Converting " + filteredStudies.size() + " filtered Studies...");
    getConverter().addStudiesToOntology(filteredStudies, conversion);
    getLog().debug("All conversion done!");
    return conversion;
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Association(uk.ac.ebi.spot.goci.model.Association) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus)

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