Search in sources :

Example 11 with Study

use of uk.ac.ebi.spot.goci.model.Study 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)

Example 12 with Study

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

the class PussycatGOCIController method setDateFilter.

private Filter setDateFilter(String dateMin, String dateMax) {
    Filter dateFilter;
    DateFormat df_input = new SimpleDateFormat("yyyy-MM-dd");
    Date to, from;
    try {
        if (dateMax != null) {
            int endYearVar = Integer.parseInt(dateMax.split("-")[0]);
            int endMonthVar = Integer.parseInt(dateMax.split("-")[1]);
            String end_month, end_year;
            //API call provides date for "up to and including the end of" - must increment month for query
            if (endMonthVar == 12) {
                end_month = "01";
                endYearVar++;
                end_year = Integer.toString(endYearVar);
            } else {
                endMonthVar++;
                if (endMonthVar > 9) {
                    end_month = Integer.toString(endMonthVar);
                } else {
                    end_month = "0".concat(Integer.toString(endMonthVar));
                }
                end_year = Integer.toString(endYearVar);
            }
            to = df_input.parse(end_year + "-" + end_month + "-01");
        } else {
            //change to use today's date
            to = df_input.parse(df_input.format(new Date()));
        }
        if (dateMin != null) {
            from = df_input.parse(dateMin + "-01");
        } else {
            from = df_input.parse("2005-01-01");
        }
        Calendar fromValue = Calendar.getInstance();
        fromValue.setTime(from);
        Calendar toValue = Calendar.getInstance();
        toValue.setTime(to);
        Study study = template(Study.class);
        dateFilter = refine(study).on(study.getPublicationDate()).hasRange(fromValue, toValue);
    } catch (ParseException e) {
        getLog().error("Bad date in URL for date range '" + dateMin + "' to '" + dateMax, e);
        throw new RuntimeException("Bad date in URL for date range '" + dateMin + "' to '" + dateMax, e);
    }
    return dateFilter;
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Filter(uk.ac.ebi.spot.goci.pussycat.lang.Filter) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 13 with Study

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

the class AssociationService method loadAssociatedData.

public void loadAssociatedData(Association association) {
    int traitCount = association.getEfoTraits().size();
    Study study = studyService.fetchOne(association.getStudy());
    AtomicInteger reportedGeneCount = new AtomicInteger();
    Collection<SingleNucleotidePolymorphism> snps = new HashSet<>();
    Collection<Region> regions = new HashSet<>();
    Collection<Gene> mappedGenes = new HashSet<>();
    Map<String, Set<String>> mappedGeneEntrezIds = new HashMap<>();
    Map<String, Set<String>> mappedGeneEnsemblIds = new HashMap<>();
    association.getLoci().forEach(locus -> {
        locus.getStrongestRiskAlleles().stream().map(RiskAllele::getSnp).forEach(snp -> {
            Collection<Location> snpLocations = snp.getLocations();
            for (Location location : snpLocations) {
                regions.add(location.getRegion());
            }
            snp.getGenomicContexts().forEach(context -> {
                mappedGenes.add(context.getGene());
                String geneName = context.getGene().getGeneName();
                Collection<EntrezGene> geneEntrezGeneIds = context.getGene().getEntrezGeneIds();
                Collection<EnsemblGene> geneEnsemblGeneIds = context.getGene().getEnsemblGeneIds();
                if (mappedGeneEntrezIds.containsKey(geneName)) {
                    for (EntrezGene entrezGene : geneEntrezGeneIds) {
                        mappedGeneEntrezIds.get(geneName).add(entrezGene.getEntrezGeneId());
                    }
                } else {
                    Set<String> entrezIds = new HashSet<>();
                    for (EntrezGene entrezGene : geneEntrezGeneIds) {
                        entrezIds.add(entrezGene.getEntrezGeneId());
                    }
                    mappedGeneEntrezIds.put(geneName, entrezIds);
                }
                if (mappedGeneEnsemblIds.containsKey(geneName)) {
                    for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
                        mappedGeneEnsemblIds.get(geneName).add(ensemblGene.getEnsemblGeneId());
                    }
                } else {
                    Set<String> ensemblIds = new HashSet<>();
                    for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
                        ensemblIds.add(ensemblGene.getEnsemblGeneId());
                    }
                    mappedGeneEntrezIds.put(geneName, ensemblIds);
                }
            });
            snps.add(snp);
        });
        snps.addAll(locus.getStrongestRiskAlleles().stream().map(RiskAllele::getSnp).collect(Collectors.toList()));
        reportedGeneCount.addAndGet(locus.getAuthorReportedGenes().size());
        locus.getAuthorReportedGenes().forEach(authorReportedGene -> {
            authorReportedGene.getEnsemblGeneIds().size();
            authorReportedGene.getEntrezGeneIds().size();
        });
    });
    getLog().trace("Association '" + association.getId() + "' is mapped to " + "" + traitCount + " EFO traits where study id = " + study.getId() + " " + "(author reported " + reportedGeneCount + " gene(s)); " + "this reports on " + snps.size() + " SNPs in " + regions.size() + " regions, " + "mapped to " + mappedGenes.size() + " genes.");
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene) EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene) Gene(uk.ac.ebi.spot.goci.model.Gene) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Region(uk.ac.ebi.spot.goci.model.Region) HashSet(java.util.HashSet) Location(uk.ac.ebi.spot.goci.model.Location)

Example 14 with Study

use of uk.ac.ebi.spot.goci.model.Study 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)

Example 15 with Study

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

the class StudyOperationsService method unpublishStudy.

/**
     * Unpublish a study entry in the database
     *
     * @param studyId         ID of study to unpublish
     * @param unpublishReason Reason the study is being unpublished
     * @param user            User performing request
     */
public void unpublishStudy(Long studyId, UnpublishReason unpublishReason, SecureUser user) {
    Study study = studyRepository.findOne(studyId);
    // Before we unpublish the study get its associated housekeeping
    Long housekeepingId = study.getHousekeeping().getId();
    Housekeeping housekeepingAttachedToStudy = housekeepingRepository.findOne(housekeepingId);
    //Set the unpublishDate and a new lastUpdateDate in houskeeping
    java.util.Date unpublishDate = new java.util.Date();
    housekeepingAttachedToStudy.setCatalogUnpublishDate(unpublishDate);
    housekeepingAttachedToStudy.setLastUpdateDate(unpublishDate);
    //Set the reason for unpublishing
    housekeepingAttachedToStudy.setUnpublishReason(unpublishReason);
    housekeepingAttachedToStudy.setIsPublished(false);
    //Set the unpublised status in housekeeping
    CurationStatus status = curationStatusRepository.findByStatus("Unpublished from catalog");
    housekeepingAttachedToStudy.setCurationStatus(status);
    updateStatus(study, housekeepingAttachedToStudy, user);
}
Also used : Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) Study(uk.ac.ebi.spot.goci.model.Study) Date(java.util.Date) CurationStatus(uk.ac.ebi.spot.goci.model.CurationStatus) Date(java.util.Date)

Aggregations

Study (uk.ac.ebi.spot.goci.model.Study)44 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 ArrayList (java.util.ArrayList)7 Association (uk.ac.ebi.spot.goci.model.Association)7 Housekeeping (uk.ac.ebi.spot.goci.model.Housekeeping)6 MultiStudyNoteForm (uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm)5 Date (java.util.Date)4 Test (org.junit.Test)4 Ancestry (uk.ac.ebi.spot.goci.model.Ancestry)4 NoteSubject (uk.ac.ebi.spot.goci.model.NoteSubject)4 SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)4 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)4 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 StudyNoteForm (uk.ac.ebi.spot.goci.curation.model.StudyNoteForm)3 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)3 StudyNote (uk.ac.ebi.spot.goci.model.StudyNote)3 IOException (java.io.IOException)2