Search in sources :

Example 11 with Association

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

the class PussycatGOCIController method setPvalueFilter.

private Filter setPvalueFilter(String pvalueMin, String pvalueMax) {
    double start_pvalue, end_pvalue;
    if (pvalueMin != null) {
        int startMantissaNum = Integer.parseInt(pvalueMin.split("e")[0]);
        int startExponentNum = Integer.parseInt(pvalueMin.split("e")[1]);
        start_pvalue = startMantissaNum * Math.pow(10, startExponentNum);
    } else {
        start_pvalue = 0.0;
    }
    if (pvalueMax != null) {
        int endMantissaNum = Integer.parseInt(pvalueMax.split("e")[0]);
        int endExponentNum = Integer.parseInt(pvalueMax.split("e")[1]);
        end_pvalue = endMantissaNum * Math.pow(10, endExponentNum);
    } else {
        end_pvalue = 1 * Math.pow(10, -5);
    }
    Association association = template(Association.class);
    Filter filter = refine(association).on(association.getPvalue()).hasValues(start_pvalue, end_pvalue);
    return filter;
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) Filter(uk.ac.ebi.spot.goci.pussycat.lang.Filter)

Example 12 with Association

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

the class TestFilenameGenerator method testGenerator.

@Test
public void testGenerator() {
    int e1 = -8;
    int m1 = 5;
    double p1 = m1 * Math.pow(10, e1);
    Association association = template(Association.class);
    Filter f1 = refine(association).on(association.getPvalue()).hasValues(0.0, p1);
    Filter f2 = refine(association).on(association.getPvalue()).hasValues(0.0, p1);
    TestSession session = new TestSession();
    String n1 = session.generateFilename(f1);
    System.out.println(n1);
    String n2 = session.generateFilename(f2);
    System.out.println(n2);
    String n3 = session.generateFilename();
    System.out.println(n3);
    assertEquals(n1, n2);
    assertNotNull(n3);
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) Filter(uk.ac.ebi.spot.goci.pussycat.lang.Filter) Test(org.junit.Test)

Example 13 with Association

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

the class QueryManager method getAssociationForTraitAndBand.

public List<URI> getAssociationForTraitAndBand(SparqlTemplate sparqlTemplate, URI trait, URI bandIndividual, List<Filter> filters) {
    List<URI> results = new ArrayList<URI>();
    if (filters.size() == 0) {
        Object retrieved = checkCache("getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual);
        if (retrieved != null) {
            return (List<URI>) retrieved;
        }
        List<URI> queryResults = sparqlTemplate.query(SparqlQueries.ASSOCIATIONS_FOR_TRAIT_AND_BAND, new URIMapper("association"), trait, bandIndividual);
        // de-duplicate results; should be handled by        List<URI> results = new ArrayList<URI>();
        for (URI queryResult : queryResults) {
            if (!results.contains(queryResult)) {
                results.add(queryResult);
            }
        }
        return cache(results, "getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual);
    } else if (filters.size() == 1) {
        for (Filter filter : filters) {
            if (filter.getFilteredType().equals(Association.class)) {
                Object retrieved = checkCache("getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual, filter.getFilteredValues().get(1), filter.getFilteredValues().get(0));
                if (retrieved != null) {
                    return (List<URI>) retrieved;
                }
                results.addAll(sparqlTemplate.query(SparqlQueries.ASSOCIATIONS_FOR_TRAIT_AND_BAND_PVALUE_FILTER, new URIMapper("association"), trait, bandIndividual, filter.getFilteredValues().get(1), filter.getFilteredValues().get(0)));
                return cache(results, "getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual, filter.getFilteredValues().get(1), filter.getFilteredValues().get(0));
            } else if (filter.getFilteredType().equals(Study.class)) {
                Object retrieved = checkCache("getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual, filter.getFilteredRange().to(), filter.getFilteredRange().from());
                if (retrieved != null) {
                    return (List<URI>) retrieved;
                }
                results.addAll(sparqlTemplate.query(SparqlQueries.ASSOCIATIONS_FOR_TRAIT_AND_BAND_DATE_FILTER, new URIMapper("association"), trait, bandIndividual, filter.getFilteredRange().to(), filter.getFilteredRange().from()));
                return cache(results, "getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual, 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();
            }
        }
        Object retrieved = checkCache("getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual, pval_max, pval_min, date_max, date_min);
        if (retrieved != null) {
            return (List<URI>) retrieved;
        }
        results.addAll(sparqlTemplate.query(SparqlQueries.ASSOCIATIONS_FOR_TRAIT_AND_BAND_PVALUE_DATE_FILTER, new URIMapper("association"), trait, bandIndividual, pval_max, pval_min, date_max, date_min));
        return cache(results, "getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual, pval_max, pval_min, date_max, date_min);
    }
    return cache(results, "getAssociationsForTraitInBand", sparqlTemplate, trait, bandIndividual);
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) Filter(uk.ac.ebi.spot.goci.pussycat.lang.Filter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI)

Example 14 with Association

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

the class SnpAssociationTableViewService method createSnpAssociationTableView.

/**
     * Create object, from Association, that will be returned to view
     *
     * @param association Association object
     */
public SnpAssociationTableView createSnpAssociationTableView(Association association) {
    SnpAssociationTableView snpAssociationTableView = new SnpAssociationTableView();
    // For SNP interaction studies snp, proxy snps, risk alleles etc
    // should be separated by an 'x'
    String delimiter = "; ";
    if (association.getSnpInteraction()) {
        delimiter = " x ";
    }
    snpAssociationTableView.setAssociationId(association.getId());
    // For each locus relevant attributes
    Collection<Locus> loci = association.getLoci();
    Collection<String> allLociGenes = new ArrayList<>();
    Collection<String> allLociRiskAlleles = new ArrayList<String>();
    Collection<String> allLociSnps = new ArrayList<String>();
    Collection<String> allLociProxySnps = new ArrayList<String>();
    Collection<String> allLociRiskAlleleFrequencies = new ArrayList<String>();
    Collection<String> allLociSnpStatuses = new ArrayList<String>();
    // By looking at each locus in turn we can keep order in view
    for (Locus locus : loci) {
        // Store gene names, a locus can have a number of genes attached.
        // Per locus create a comma separated list and add to an array.
        // Further processing will then delimit this list
        // either by ; or 'x' depending on association type
        Collection<String> currentlocusGenes = new ArrayList<>();
        String commaSeparatedGenes = "";
        for (Gene gene : locus.getAuthorReportedGenes()) {
            currentlocusGenes.add(gene.getGeneName());
        }
        if (!currentlocusGenes.isEmpty()) {
            commaSeparatedGenes = String.join(", ", currentlocusGenes);
            allLociGenes.add(commaSeparatedGenes);
        } else {
            allLociGenes.add("NR");
        }
        //This sort ensures that haplotype SNPs are displayed in the correct order
        Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
        for (RiskAllele riskAllele : ra) {
            allLociRiskAlleles.add(riskAllele.getRiskAlleleName());
            // Based on assumption we only have one locus with a single risk allele attached
            if (!association.getMultiSnpHaplotype() && !association.getSnpInteraction()) {
                if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
                    allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
                }
            }
            // SNPs attached to risk allele
            SingleNucleotidePolymorphism snp = riskAllele.getSnp();
            allLociSnps.add(snp.getRsId());
            // Set proxies if present
            Collection<String> currentLocusProxies = new ArrayList<>();
            String commaSeparatedProxies = "";
            if (riskAllele.getProxySnps() != null) {
                for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
                    currentLocusProxies.add(proxySnp.getRsId());
                }
            }
            // Comma separate proxies in view
            if (!currentLocusProxies.isEmpty()) {
                commaSeparatedProxies = String.join(", ", currentLocusProxies);
                allLociProxySnps.add(commaSeparatedProxies);
            } else {
                allLociProxySnps.add("NR");
            }
            // Only required for SNP interaction studies
            if (association.getSnpInteraction() != null) {
                if (association.getSnpInteraction()) {
                    // Genome wide Vs Limited List
                    Collection<String> snpStatus = new ArrayList<>();
                    String commaSeparatedSnpStatus = "";
                    if (riskAllele.getLimitedList() != null) {
                        if (riskAllele.getLimitedList()) {
                            snpStatus.add("LL");
                        }
                    }
                    if (riskAllele.getGenomeWide() != null) {
                        if (riskAllele.getGenomeWide()) {
                            snpStatus.add("GW");
                        }
                    }
                    if (!snpStatus.isEmpty()) {
                        commaSeparatedSnpStatus = String.join(", ", snpStatus);
                        allLociSnpStatuses.add(commaSeparatedSnpStatus);
                    } else {
                        allLociSnpStatuses.add("NR");
                    }
                    // Allele risk frequency
                    if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
                        allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
                    } else {
                        allLociRiskAlleleFrequencies.add("NR");
                    }
                }
            }
        }
    }
    // Create delimited strings for view
    String authorReportedGenes = null;
    if (allLociGenes.size() > 1) {
        authorReportedGenes = String.join(delimiter, allLociGenes);
    } else {
        authorReportedGenes = String.join("", allLociGenes);
    }
    snpAssociationTableView.setAuthorReportedGenes(authorReportedGenes);
    String strongestRiskAlleles = null;
    if (allLociRiskAlleles.size() > 1) {
        strongestRiskAlleles = String.join(delimiter, allLociRiskAlleles);
    } else {
        strongestRiskAlleles = String.join("", allLociRiskAlleles);
    }
    snpAssociationTableView.setStrongestRiskAlleles(strongestRiskAlleles);
    String associationSnps = null;
    if (allLociSnps.size() > 1) {
        associationSnps = String.join(delimiter, allLociSnps);
    } else {
        associationSnps = String.join("", allLociSnps);
    }
    snpAssociationTableView.setSnps(associationSnps);
    String associationProxies = null;
    if (allLociProxySnps.size() > 1) {
        associationProxies = String.join(delimiter, allLociProxySnps);
    } else {
        associationProxies = String.join("", allLociProxySnps);
    }
    snpAssociationTableView.setProxySnps(associationProxies);
    // Set both risk frequencies
    String associationRiskAlleleFrequencies = null;
    if (allLociRiskAlleleFrequencies.size() > 1) {
        associationRiskAlleleFrequencies = String.join(delimiter, allLociRiskAlleleFrequencies);
    } else {
        associationRiskAlleleFrequencies = String.join("", allLociRiskAlleleFrequencies);
    }
    snpAssociationTableView.setRiskAlleleFrequencies(associationRiskAlleleFrequencies);
    snpAssociationTableView.setAssociationRiskFrequency(association.getRiskFrequency());
    String associationSnpStatuses = null;
    if (allLociSnpStatuses.size() > 1) {
        associationSnpStatuses = String.join(delimiter, allLociSnpStatuses);
    } else {
        associationSnpStatuses = String.join("", allLociSnpStatuses);
    }
    snpAssociationTableView.setSnpStatuses(associationSnpStatuses);
    snpAssociationTableView.setPvalueMantissa(association.getPvalueMantissa());
    snpAssociationTableView.setPvalueExponent(association.getPvalueExponent());
    snpAssociationTableView.setPvalueDescription(association.getPvalueDescription());
    Collection<String> efoTraits = new ArrayList<>();
    for (EfoTrait efoTrait : association.getEfoTraits()) {
        efoTraits.add(efoTrait.getTrait());
    }
    String associationEfoTraits = null;
    associationEfoTraits = String.join(", ", efoTraits);
    snpAssociationTableView.setEfoTraits(associationEfoTraits);
    // Set OR values
    snpAssociationTableView.setOrPerCopyNum(association.getOrPerCopyNum());
    snpAssociationTableView.setOrPerCopyRecip(association.getOrPerCopyRecip());
    snpAssociationTableView.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
    // Set beta values
    snpAssociationTableView.setBetaNum(association.getBetaNum());
    snpAssociationTableView.setBetaDirection(association.getBetaDirection());
    snpAssociationTableView.setBetaUnit(association.getBetaUnit());
    snpAssociationTableView.setRange(association.getRange());
    snpAssociationTableView.setDescription(association.getDescription());
    snpAssociationTableView.setStandardError(association.getStandardError());
    snpAssociationTableView.setAssociationType(association.getSnpType());
    if (association.getMultiSnpHaplotype() != null) {
        if (association.getMultiSnpHaplotype()) {
            snpAssociationTableView.setMultiSnpHaplotype("Yes");
        }
        if (!association.getMultiSnpHaplotype()) {
            snpAssociationTableView.setMultiSnpHaplotype("No");
        }
    }
    if (association.getSnpInteraction() != null) {
        if (association.getSnpInteraction()) {
            snpAssociationTableView.setSnpInteraction("Yes");
        }
        if (!association.getSnpInteraction()) {
            snpAssociationTableView.setSnpInteraction("No");
        }
    }
    if (association.getSnpApproved() != null) {
        if (association.getSnpApproved()) {
            snpAssociationTableView.setSnpApproved("Yes");
        }
        if (!association.getSnpApproved()) {
            snpAssociationTableView.setSnpApproved("No");
        }
    }
    // Get validation warnings
    snpAssociationTableView.setValidationWarnings(associationValidationReportService.getWarningSet(association.getId()));
    // Get mapping details
    if (association.getLastMappingPerformedBy() != null) {
        snpAssociationTableView.setLastMappingPerformedBy(association.getLastMappingPerformedBy());
    }
    snpAssociationTableView.setMappingStatus("false");
    if (association.getLastMappingDate() != null) {
        snpAssociationTableView.setMappingStatus("true");
    }
    if (association.getLastMappingDate() != null) {
        DateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
        String dateOfLastMapping = df.format(association.getLastMappingDate());
        snpAssociationTableView.setLastMappingDate(dateOfLastMapping);
    }
    return snpAssociationTableView;
}
Also used : RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Locus(uk.ac.ebi.spot.goci.model.Locus) Gene(uk.ac.ebi.spot.goci.model.Gene) Service(org.springframework.stereotype.Service) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) Association(uk.ac.ebi.spot.goci.model.Association) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) DateFormat(java.text.DateFormat) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) Gene(uk.ac.ebi.spot.goci.model.Gene) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus) SimpleDateFormat(java.text.SimpleDateFormat) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView)

Example 15 with Association

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

the class AssociationUploadService method upload.

public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException {
    // File errors will contain any validation errors and be returned to controller if any are found
    List<AssociationUploadErrorView> fileErrors = new ArrayList<>();
    String originalFilename = file.getOriginalFilename();
    getLog().info("Uploading file: ".concat(originalFilename));
    // Upload file
    try {
        uploadFile(file, study.getId());
        // Send file, including path, to SNP batch loader process
        File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename);
        ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full");
        if (validationSummary != null) {
            // Check if we have any row errors
            long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream().filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()).count();
            // Errors found
            if (rowErrorCount > 0) {
                studyFileService.deleteFile(study.getId(), originalFilename);
                getLog().error("Row errors found in file: " + originalFilename);
                validationSummary.getRowValidationSummaries().forEach(rowValidationSummary -> fileErrors.addAll(processRowError(rowValidationSummary)));
            } else {
                // Determine if we have any errors rather than warnings
                // Errors prevent saving association
                List<ValidationError> allAssociationsErrors = new ArrayList<>();
                validationSummary.getAssociationSummaries().forEach(associationSummary -> allAssociationsErrors.addAll(associationSummary.getErrors()));
                long associationErrorCount = allAssociationsErrors.parallelStream().filter(validationError -> !validationError.getWarning()).count();
                if (associationErrorCount > 0) {
                    studyFileService.deleteFile(study.getId(), originalFilename);
                    getLog().error("Association errors found in file: " + originalFilename);
                    validationSummary.getAssociationSummaries().forEach(associationSummary -> fileErrors.addAll(processAssociationError(associationSummary)));
                } else {
                    Integer numberOfAssociations = validationSummary.getAssociationSummaries().size();
                    String description = numberOfAssociations.toString().concat(" associations created from upload of '").concat(originalFilename).concat("'");
                    createBatchUploadEvent(study, description, user);
                    saveAssociations(validationSummary.getAssociationSummaries(), study, user);
                }
            }
        }
        return fileErrors;
    } catch (IOException e) {
        throw new IOException(e);
    }
}
Also used : RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) IOException(java.io.IOException) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) File(java.io.File) TrackingOperationService(uk.ac.ebi.spot.goci.service.TrackingOperationService) ArrayList(java.util.ArrayList) List(java.util.List) Service(org.springframework.stereotype.Service) Association(uk.ac.ebi.spot.goci.model.Association) Qualifier(org.springframework.beans.factory.annotation.Qualifier) MultipartFile(org.springframework.web.multipart.MultipartFile) Study(uk.ac.ebi.spot.goci.model.Study) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) AssociationFileUploadService(uk.ac.ebi.spot.goci.service.AssociationFileUploadService) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) ArrayList(java.util.ArrayList) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

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