Skip to content

Commit

Permalink
Added compound quality flags as array/set and integrated it into Comp…
Browse files Browse the repository at this point in the history
…oundController
  • Loading branch information
me62did authored and mfleisch committed May 20, 2023
1 parent e51fbcd commit 98dce16
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<CompoundId> getCompounds(@PathVariable String projectId, @RequestParam(required = false, defaultValue = "false") boolean topAnnotation, @RequestParam(required = false, defaultValue = "false") boolean msData) {
public List<CompoundId> 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<CompoundId> 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;
Expand Down Expand Up @@ -175,10 +175,11 @@ public List<CompoundId> 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);
}

/**
Expand Down Expand Up @@ -240,14 +241,27 @@ 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<CompoundQuality.CompoundQualityFlag> 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);
if (includeSummary)
compoundId.setTopAnnotation(asCompoundSummary(instance));
if (includeMsData)
compoundId.setMsData(asCompoundMsData(instance));
if (includeMsQuality)
compoundId.setQualityFlags(asCompoundQualityData(instance));
}
return compoundId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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})
* <p>
* Each Compound has a Set of Quality assessment flags.
*/
protected EnumSet<CompoundQuality.CompoundQualityFlag> 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;

Expand Down

0 comments on commit 98dce16

Please sign in to comment.