Search in sources :

Example 1 with DepositionStudyDto

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

the class DepositionUtil method getSubmissionType.

public static Submission.SubmissionType getSubmissionType(DepositionSubmission submission) {
    if (submission.getBodyOfWork() != null && submission.getPublication() == null) {
        return Submission.SubmissionType.PRE_PUBLISHED;
    } else if (submission.getBodyOfWork() == null && submission.getPublication() == null) {
        return Submission.SubmissionType.UNKNOWN;
    } else if (submission.getPublication() != null) {
        String publicationStatus = submission.getPublication().getStatus();
        boolean hasSumStats = false;
        boolean hasMetadata = false;
        boolean hasAssociations = false;
        if (publicationStatus.equals("UNDER_SUBMISSION")) {
            hasMetadata = true;
        } else if (publicationStatus.equals("UNDER_SUMMARY_STATS_SUBMISSION")) {
            hasSumStats = true;
        }
        if (submission.getStudies() != null) {
            for (DepositionStudyDto studyDto : submission.getStudies()) {
                if (studyDto.getSummaryStatisticsFile() != null && !studyDto.getSummaryStatisticsFile().equals("") && !studyDto.getSummaryStatisticsFile().equals("NR")) {
                    hasSumStats = true;
                }
            }
        }
        if (submission.getAssociations() != null) {
            for (DepositionAssociationDto associationDto : submission.getAssociations()) {
                if (associationDto.getStudyTag() != null) {
                    hasAssociations = true;
                }
            }
        }
        if (hasMetadata && hasSumStats && hasAssociations) {
            return Submission.SubmissionType.METADATA_AND_SUM_STATS_AND_TOP_ASSOCIATIONS;
        }
        if (hasMetadata && hasSumStats && !hasAssociations) {
            return Submission.SubmissionType.METADATA_AND_SUM_STATS;
        }
        if (hasMetadata && !hasSumStats && hasAssociations) {
            return Submission.SubmissionType.METADATA_AND_TOP_ASSOCIATIONS;
        }
        if (hasMetadata && !hasSumStats && !hasAssociations) {
            return Submission.SubmissionType.METADATA;
        }
        if (!hasMetadata && hasSumStats && !hasAssociations) {
            return Submission.SubmissionType.SUM_STATS;
        }
    }
    return Submission.SubmissionType.UNKNOWN;
}
Also used : DepositionAssociationDto(uk.ac.ebi.spot.goci.model.deposition.DepositionAssociationDto) DepositionStudyDto(uk.ac.ebi.spot.goci.model.deposition.DepositionStudyDto)

Example 2 with DepositionStudyDto

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

the class BeanMapperTest method testConvertStudy.

@Test
public void testConvertStudy() {
    String dtoString = "{\n" + "      \"study_tag\": \"t1\",\n" + "      \"study_accession\": \"GCST90000116\",\n" + "      \"genotyping_technology\": \"Genome-wide genotyping array\",\n" + "      \"imputation\": false,\n" + "      \"variant_count\": 4,\n" + "      \"trait\": \"bmi\",\n" + "      \"summary_statistics_file\": \"abc123.tsv\",\n" + "      \"checksum\": \"a1195761f082f8cbc2f5a560743077cc\",\n" + "      \"summary_statistics_assembly\": \"GRCh38\",\n" + "      \"readme_file\": \"some text\"\n" + "    }";
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JodaModule());
    DepositionStudyDto studyDto = null;
    try {
        studyDto = objectMapper.readValue(dtoString, DepositionStudyDto.class);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    UnpublishedStudy study = BeanMapper.MAPPER.convert(studyDto);
    assertNotNull(study);
    assertNotNull(study.getSummaryStatsFile());
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) DepositionStudyDto(uk.ac.ebi.spot.goci.model.deposition.DepositionStudyDto) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with DepositionStudyDto

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

the class DepositionStudyService method publishSummaryStats.

public Pair<Boolean, List<String>> publishSummaryStats(Collection<DepositionStudyDto> studyDtos, Collection<Study> dbStudies) {
    getLog().info("Publishing summary stats: {} | {}", studyDtos.size(), dbStudies.size());
    List<String> errors = new ArrayList<>();
    boolean outcome = true;
    List<Long> studyIds = new ArrayList<>();
    for (Study study : dbStudies) {
        studyIds.add(study.getId());
    }
    try {
        for (DepositionStudyDto studyDto : studyDtos) {
            String tag = studyDto.getStudyTag();
            boolean match = false;
            for (Long studyId : studyIds) {
                Study study = studyService.findOne(studyId);
                if (study.getAccessionId() != null && study.getAccessionId().equals(studyDto.getAccession())) {
                    publishSummaryStats(study, tag);
                    match = true;
                }
            }
            if (!match) {
                for (Long studyId : studyIds) {
                    getLog().warn(" - Study [{}] has no study tag.", studyId);
                    errors.add("Warning: Study [" + studyId + "] has no study tag.");
                    publishSummaryStats(studyService.findOne(studyId), null);
                }
            }
        }
        getLog().info("Publishing summary stats done.");
    } catch (Exception e) {
        getLog().error("Encountered error: {}", e.getMessage(), e);
        errors.add("Error: " + e.getMessage());
        outcome = false;
    }
    return Pair.of(outcome, errors);
}
Also used : ArrayList(java.util.ArrayList) DepositionStudyDto(uk.ac.ebi.spot.goci.model.deposition.DepositionStudyDto)

Example 4 with DepositionStudyDto

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

the class DepositionUtil method getSubmissionType.

public static Submission.SubmissionType getSubmissionType(DepositionSubmission submission) {
    if (submission.getBodyOfWork() != null && submission.getPublication() == null) {
        return Submission.SubmissionType.PRE_PUBLISHED;
    } else if (submission.getBodyOfWork() == null && submission.getPublication() == null) {
        return Submission.SubmissionType.UNKNOWN;
    } else if (submission.getPublication() != null) {
        String publicationStatus = submission.getPublication().getStatus();
        boolean hasSumStats = false;
        boolean hasMetadata = false;
        boolean hasAssociations = false;
        if (publicationStatus.equals("UNDER_SUBMISSION")) {
            hasMetadata = true;
        } else if (publicationStatus.equals("UNDER_SUMMARY_STATS_SUBMISSION")) {
            hasSumStats = true;
        }
        if (submission.getStudies() != null) {
            for (DepositionStudyDto studyDto : submission.getStudies()) {
                if (studyDto.getSummaryStatisticsFile() != null && !studyDto.getSummaryStatisticsFile().equals("") && !studyDto.getSummaryStatisticsFile().equals("NR")) {
                    hasSumStats = true;
                }
            }
        }
        if (submission.getAssociations() != null) {
            for (DepositionAssociationDto associationDto : submission.getAssociations()) {
                if (associationDto.getStudyTag() != null) {
                    hasAssociations = true;
                }
            }
        }
        if (hasMetadata && hasSumStats && hasAssociations) {
            return Submission.SubmissionType.METADATA_AND_SUM_STATS_AND_TOP_ASSOCIATIONS;
        }
        if (hasMetadata && hasSumStats && !hasAssociations) {
            return Submission.SubmissionType.METADATA_AND_SUM_STATS;
        }
        if (hasMetadata && !hasSumStats && hasAssociations) {
            return Submission.SubmissionType.METADATA_AND_TOP_ASSOCIATIONS;
        }
        if (hasMetadata && !hasSumStats && !hasAssociations) {
            return Submission.SubmissionType.METADATA;
        }
        if (!hasMetadata && hasSumStats && !hasAssociations) {
            return Submission.SubmissionType.SUM_STATS;
        }
    }
    return Submission.SubmissionType.UNKNOWN;
}
Also used : DepositionAssociationDto(uk.ac.ebi.spot.goci.model.deposition.DepositionAssociationDto) DepositionStudyDto(uk.ac.ebi.spot.goci.model.deposition.DepositionStudyDto)

Example 5 with DepositionStudyDto

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

the class DepositionSubmissionImportService method importSubmission.

@Async
@Transactional
public void importSubmission(DepositionSubmission depositionSubmission, SecureUser currentUser, Long submissionImportId) {
    ImportLog importLog = new ImportLog();
    getLog().info("Evaluating submission type for: {}", depositionSubmission.getSubmissionId());
    Submission.SubmissionType submissionType = DepositionUtil.getSubmissionType(depositionSubmission);
    getLog().info("Found submission type for: {}", submissionType.name());
    Curator curator = curatorRepository.findByEmail(currentUser.getEmail());
    String submissionID = depositionSubmission.getSubmissionId();
    getLog().info("[{}] Retrieving publication: {}", submissionID, depositionSubmission.getPublication().getPmid());
    Publication publication = publicationService.findByPumedId(depositionSubmission.getPublication().getPmid());
    getLog().info("[{}] Found publication: {}", submissionID, publication.getPubmedId());
    getLog().info("[{}] Looking for studies in the local DB ...", submissionID);
    Collection<Study> dbStudies = studyService.findByPublication(depositionSubmission.getPublication().getPmid());
    List<Long> dbStudyIds = dbStudies.stream().map(Study::getId).collect(Collectors.toList());
    getLog().info("[{}] Found {} studies: {}", submissionID, dbStudies.size(), dbStudyIds);
    List<DepositionStudyDto> studies = depositionSubmission.getStudies();
    List<String> gcsts = studies.stream().map(DepositionStudyDto::getAccession).collect(Collectors.toList());
    getLog().info("[{}] Found {} studies in the submission retrieved from the Deposition App: {}", submissionID, studies.size(), gcsts);
    boolean outcome = true;
    if (submissionType == Submission.SubmissionType.SUM_STATS) {
        // if submission type is SUM_STATS only
        getLog().info("[{}] Found SUM_STATS submission.", submissionID, studies.size());
        ImportLogStep importStep = importLog.addStep(new ImportLogStep("Publishing summary stats", submissionID));
        Pair<Boolean, List<String>> result = depositionStudyService.publishSummaryStats(studies, dbStudies);
        if (result.getLeft()) {
            importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
            importLog.addErrors(result.getRight(), "Publishing summary stats");
            importStep = importLog.addStep(new ImportLogStep("Updating submission status: CURATION_COMPLETE", submissionID));
            String stepOutcome = ingestService.updateSubmissionStatus(depositionSubmission, "CURATION_COMPLETE", "PUBLISHED_WITH_SS");
            if (stepOutcome != null) {
                importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS_WITH_WARNINGS);
                importLog.addWarning(stepOutcome, "Updating submission status: CURATION_COMPLETE");
            } else {
                importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
            }
        } else {
            importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
            importLog.addErrors(result.getRight(), "Publishing summary stats");
            outcome = false;
        }
    } else {
        ImportLogStep studiesStep = importLog.addStep(new ImportLogStep("Verifying studies", submissionID));
        if (studies != null) {
            // && dbStudies.size() == 1) { //only do this for un-curated publications
            importLog.updateStatus(studiesStep.getId(), ImportLog.SUCCESS);
            getLog().info("[{}] Validating associations ...", submissionID);
            ImportLogStep importStep = importLog.addStep(new ImportLogStep("Validating associations", submissionID));
            for (DepositionStudyDto studyDto : studies) {
                List<DepositionAssociationDto> associations = depositionSubmission.getAssociations();
                if (associations != null) {
                    List<String> errors = associationValidationService.validateAssociations(studyDto.getStudyTag(), studyDto.getAccession(), associations);
                    importLog.addWarnings(errors, "Validating associations");
                }
            }
            getLog().info("[{}] Associations validated. Found {} errors and {} warnings.", submissionID, importLog.getErrorList().size(), importLog.getWarnings().size());
            if (!importLog.getErrorList().isEmpty()) {
                importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
                outcome = false;
            } else {
                importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
                getLog().info("[{}] Deleting proxy studies created when the publication was initially imported.", submissionID);
                importStep = importLog.addStep(new ImportLogStep("Deleting proxy studies", submissionID));
                String result = depositionStudyService.deleteStudies(dbStudies, curator, currentUser);
                if (result != null) {
                    importLog.addError(result, "Deleting proxy studies");
                    importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
                    outcome = false;
                } else {
                    importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
                }
                if (outcome) {
                    outcome = studiesProcessingService.processStudies(depositionSubmission, currentUser, publication, curator, importLog);
                    if (outcome) {
                        getLog().info("[{}] Deleting unpublished studies and body of works.", submissionID);
                        importStep = importLog.addStep(new ImportLogStep("Deleting unpublished data", submissionID));
                        result = cleanupPrePublishedStudies(studies);
                        if (result != null) {
                            importLog.addWarning(result, "Deleting unpublished data");
                            importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS_WITH_WARNINGS);
                        } else {
                            importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
                        }
                        importStep = importLog.addStep(new ImportLogStep("Updating submission status: CURATION_COMPLETE", submissionID));
                        result = ingestService.updateSubmissionStatus(depositionSubmission, "CURATION_COMPLETE", "CURATION_STARTED");
                        if (result != null) {
                            importLog.addWarning(result, "Updating submission status: CURATION_COMPLETE");
                            importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS_WITH_WARNINGS);
                        } else {
                            importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
                        }
                    }
                }
            }
        } else {
            importLog.updateStatus(studiesStep.getId(), ImportLog.FAIL);
            importLog.addError("Submission [" + submissionID + "] has no studies", "Verifying studies");
            outcome = false;
        }
    }
    if (outcome) {
        if (depositionSubmission.getPublication().getCorrespondingAuthor() != null) {
            getLog().info("Creating Publication extensions for corresponding authors ...");
            PublicationExtension author = new PublicationExtension();
            author.setCorrespondingAuthorEmail(depositionSubmission.getPublication().getCorrespondingAuthor().getEmail());
            if (depositionSubmission.getPublication().getCorrespondingAuthor().getGroup() != null) {
                author.setCorrespondingAuthorName(depositionSubmission.getPublication().getCorrespondingAuthor().getGroup());
            } else {
                author.setCorrespondingAuthorName(depositionSubmission.getPublication().getCorrespondingAuthor().getFirstName() + ' ' + depositionSubmission.getPublication().getCorrespondingAuthor().getLastName());
            }
            publicationExtensionRepository.save(author);
            getLog().info("Publication extension created: {}", author.getId());
            List<PublicationExtension> authorList = new ArrayList<>();
            authorList.add(author);
            publication.setCorrespondingAuthors(authorList);
            publicationService.save(publication);
            getLog().info("Publication [{}] saved.", publication.getPubmedId());
        }
    } else {
        ImportLogStep importStep = importLog.addStep(new ImportLogStep("Updating submission status: IMPORT_FAILED", submissionID));
        String stepOutcome = ingestService.updateSubmissionStatus(depositionSubmission, "IMPORT_FAILED", "");
        if (stepOutcome != null) {
            importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
            importLog.addError(stepOutcome, "Updating submission status: IMPORT_FAILED");
        } else {
            importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
        }
    }
    mailService.sendSubmissionImportNotification(outcome, depositionSubmission.getPublication().getPmid(), submissionID, importLog, currentUser.getEmail());
    getLog().info("Import process finalized: {}", depositionSubmission.getSubmissionId());
    getLog().info(importLog.pretty(false));
    submissionImportProgressService.deleteImport(submissionImportId);
}
Also used : Submission(uk.ac.ebi.spot.goci.model.deposition.Submission) DepositionSubmission(uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission) DepositionAssociationDto(uk.ac.ebi.spot.goci.model.deposition.DepositionAssociationDto) DepositionStudyDto(uk.ac.ebi.spot.goci.model.deposition.DepositionStudyDto) Async(org.springframework.scheduling.annotation.Async) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DepositionStudyDto (uk.ac.ebi.spot.goci.model.deposition.DepositionStudyDto)5 DepositionAssociationDto (uk.ac.ebi.spot.goci.model.deposition.DepositionAssociationDto)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Async (org.springframework.scheduling.annotation.Async)1 Transactional (org.springframework.transaction.annotation.Transactional)1 DepositionSubmission (uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission)1 Submission (uk.ac.ebi.spot.goci.model.deposition.Submission)1