From 98dce16c15ed7c9f01349a0c130d95dc5d384d0b Mon Sep 17 00:00:00 2001 From: me62did Date: Sat, 20 May 2023 00:07:59 +0200 Subject: [PATCH] Added compound quality flags as array/set and integrated it into CompoundController --- .../compounds/CompoundController.java | 26 ++++++++++++++----- .../compounds/model/CompoundAnnotation.java | 8 +++--- .../compounds/model/CompoundId.java | 14 ++++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/CompoundController.java b/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/CompoundController.java index 418fa7c942..ca1debdbb5 100644 --- a/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/CompoundController.java +++ b/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/CompoundController.java @@ -44,7 +44,6 @@ import de.unijena.bioinf.projectspace.ProjectSpaceManager; import de.unijena.bioinf.projectspace.fingerid.FBCandidateNumber; import io.swagger.v3.oas.annotations.tags.Tag; -import org.checkerframework.checker.units.qual.C; import org.jetbrains.annotations.NotNull; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -59,6 +58,7 @@ import java.io.StringReader; import java.nio.file.Path; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Optional; import java.util.function.Function; @@ -87,12 +87,12 @@ public CompoundController(ComputeContext context) { * @return CompoundIds with additional annotations and MS/MS data (if specified). */ @GetMapping(value = "/compounds", produces = MediaType.APPLICATION_JSON_VALUE) - public List getCompounds(@PathVariable String projectId, @RequestParam(required = false, defaultValue = "false") boolean topAnnotation, @RequestParam(required = false, defaultValue = "false") boolean msData) { + public List getCompounds(@PathVariable String projectId, @RequestParam(required = false, defaultValue = "false") boolean topAnnotation, @RequestParam(required = false, defaultValue = "false") boolean msData, @RequestParam(required = false,defaultValue = "false") boolean msQuality) { LoggerFactory.getLogger(CompoundController.class).info("Started collecting compounds..."); final ProjectSpaceManager space = projectSpace(projectId); final ArrayList compoundIds = new ArrayList<>(); - space.projectSpace().forEach(ccid -> compoundIds.add(asCompoundId(ccid, space, topAnnotation, msData))); + space.projectSpace().forEach(ccid -> compoundIds.add(asCompoundId(ccid, space, topAnnotation, msData,msQuality))); LoggerFactory.getLogger(CompoundController.class).info("Finished parsing compounds..."); return compoundIds; @@ -175,10 +175,11 @@ public List importCompoundsFromString(@PathVariable String projectId @GetMapping(value = "/compounds/{cid}", produces = MediaType.APPLICATION_JSON_VALUE) public CompoundId getCompound(@PathVariable String projectId, @PathVariable String cid, @RequestParam(required = false, defaultValue = "false") boolean topAnnotation, - @RequestParam(required = false, defaultValue = "false") boolean msData) { + @RequestParam(required = false, defaultValue = "false") boolean msData, + @RequestParam(required = false, defaultValue = "false") boolean msQuality) { final ProjectSpaceManager space = projectSpace(projectId); final CompoundContainerId ccid = parseCID(space, cid); - return asCompoundId(ccid, space, topAnnotation, msData); + return asCompoundId(ccid, space, topAnnotation, msData,msQuality); } /** @@ -240,7 +241,18 @@ private MsData asCompoundMsData(Instance instance) { "Compound with ID '" + instance + "' has no input Data!")); } - private CompoundId asCompoundId(CompoundContainerId cid, ProjectSpaceManager ps, boolean includeSummary, boolean includeMsData) { + private EnumSet asCompoundQualityData(Instance instance){ + return instance.loadCompoundContainer(Ms2Experiment.class) + .getAnnotation(Ms2Experiment.class) + .flatMap(exp -> exp.getAnnotation(CompoundQuality.class)) + .map(CompoundQuality::getFlags) + .orElseThrow(()-> new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, + "Compound with ID '" + instance+ "' has no Quality information!")); + } + + + + private CompoundId asCompoundId(CompoundContainerId cid, ProjectSpaceManager ps, boolean includeSummary, boolean includeMsData, boolean includeMsQuality) { final CompoundId compoundId = CompoundId.of(cid); if (includeSummary || includeMsData) { Instance instance = ps.getInstanceFromCompound(cid); @@ -248,6 +260,8 @@ private CompoundId asCompoundId(CompoundContainerId cid, ProjectSpaceManager compoundId.setTopAnnotation(asCompoundSummary(instance)); if (includeMsData) compoundId.setMsData(asCompoundMsData(instance)); + if (includeMsQuality) + compoundId.setQualityFlags(asCompoundQualityData(instance)); } return compoundId; } diff --git a/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundAnnotation.java b/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundAnnotation.java index 9083d8ccb0..6fee2e1899 100644 --- a/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundAnnotation.java +++ b/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundAnnotation.java @@ -47,10 +47,10 @@ /** * Summary of the results of a Compound. Can be added to a CompoundId. - * It is not null within a CompoundId if it was not requested und non null otherwise - * The different summary fields within this summary are null if the corresponding - * compound does not contain the represented results. The content of non NULL - * summary field id the result was computed but is empty. + * It is null within a CompoundId if it was not requested und non-null otherwise. + * The different summary fields within this summary object are null if the corresponding + * compound does not contain the represented results. If fields are non-null + * the corresponding result has been computed but might still be empty. * */ @Getter @Setter diff --git a/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundId.java b/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundId.java index bd44087499..e452a93f5f 100644 --- a/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundId.java +++ b/sirius_rest_service/src/main/java/de/unijena/bioinf/ms/middleware/compounds/model/CompoundId.java @@ -20,10 +20,13 @@ package de.unijena.bioinf.ms.middleware.compounds.model; import de.unijena.bioinf.ChemistryBase.chem.PrecursorIonType; +import de.unijena.bioinf.ChemistryBase.ms.CompoundQuality; import de.unijena.bioinf.projectspace.CompoundContainerId; import lombok.Getter; import lombok.Setter; +import java.util.EnumSet; + /** * The CompoundId contains the ID of a compound together with some read-only information that might be displayed in * some summary view. @@ -50,6 +53,17 @@ public class CompoundId { protected CompoundAnnotation topAnnotation; protected MsData msData; + // Data and Result quality + /** + * Contains all pre-computation quality information that belong to + * this compound, such as information about the quality of the peak shape, MS2 spectrum etc., + * see ({@link CompoundQuality.CompoundQualityFlag}) + *

+ * Each Compound has a Set of Quality assessment flags. + */ + protected EnumSet qualityFlags; + //todo we will add an additional MSQuality Object with many different quality checks produced by LCMS Compound// Summary. + //todo handle computing flag protected boolean computing = false;