Skip to content

Commit

Permalink
add qcFailed field to shesmu detailed cases
Browse files Browse the repository at this point in the history
add changelog
  • Loading branch information
grapigeau committed Nov 14, 2024
1 parent 4e9ebb2 commit 7252bdc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import java.util.Set;

import static java.util.Collections.unmodifiableSet;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -16,11 +13,13 @@ public class ShesmuSample {

private final String id;
private final boolean supplemental;
private final boolean qcFailed;


private ShesmuSample(Builder builder) {
this.id = requireNonNull(builder.id);
this.supplemental = requireNonNull(builder.supplemental);
this.qcFailed = requireNonNull(builder.qcFailed);
}


Expand All @@ -32,13 +31,18 @@ public Boolean isSupplemental() {
return supplemental;
}

public Boolean qcFailed() {
return qcFailed;
}



@JsonPOJOBuilder(withPrefix = "")
public static class Builder {

private String id;
private boolean supplemental;
private boolean qcFailed;

public ShesmuSample build() {
return new ShesmuSample(this);
Expand All @@ -55,5 +59,11 @@ public Builder supplemental(boolean supplemental) {
return this;
}

public Builder qcFailed(boolean qcFailed) {
this.qcFailed = qcFailed;
return this;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,66 +127,78 @@ public Set<ShesmuCase> getShesmuCases() {

public Set<ShesmuDetailedCase> getShesmuDetailedCases() {
return caseData.getCases().stream()
.filter(kase -> kase.getTests().stream()
.anyMatch(test -> !test.getFullDepthSequencings().isEmpty()
|| test.getLibraryQualifications().stream()
.anyMatch(sample -> sample.getRun() != null)))
.map(kase -> convertCaseToShesmuDetailedCase(kase))
.collect(Collectors.toSet());
.filter(kase -> kase.getTests().stream()
.anyMatch(test -> !test.getFullDepthSequencings().isEmpty()
|| test.getLibraryQualifications().stream()
.anyMatch(sample -> sample.getRun() != null)))
.map(kase -> convertCaseToShesmuDetailedCase(kase))
.collect(Collectors.toSet());
}

private Set<ShesmuSequencing> getSequencingForShesmuCase(Case kase){
private Set<ShesmuSequencing> getSequencingForShesmuCase(Case kase) {

Set<ShesmuSequencing> sequencings = new HashSet<>();
final long reqId = kase.getRequisition().getId();

for (Test test : kase.getTests()) {

ShesmuSequencing fullDepthSeq = makeShesmuSequencing(test.getFullDepthSequencings(), MetricCategory.FULL_DEPTH_SEQUENCING, reqId, test.getName());
ShesmuSequencing fullDepthSeq = makeShesmuSequencing(test.getFullDepthSequencings(),
MetricCategory.FULL_DEPTH_SEQUENCING, reqId, test.getName());
if (fullDepthSeq != null) {
sequencings.add(fullDepthSeq);
}

ShesmuSequencing libraryQual = makeShesmuSequencing(test.getLibraryQualifications(), MetricCategory.LIBRARY_QUALIFICATION, reqId, test.getName());
ShesmuSequencing libraryQual = makeShesmuSequencing(test.getLibraryQualifications(),
MetricCategory.LIBRARY_QUALIFICATION, reqId, test.getName());
if (libraryQual != null) {
sequencings.add(libraryQual);
}
};
} ;

return sequencings;
}

private ShesmuSequencing makeShesmuSequencing(List<Sample> samples, MetricCategory type, long reqId, String name){
private ShesmuSequencing makeShesmuSequencing(List<Sample> samples, MetricCategory type,
long reqId, String name) {

Set<ShesmuSample> shesmuSamples = new HashSet<>();

boolean hasPassed = false;
boolean hasWaiting = false;
for (Sample sample : samples){
for (Sample sample : samples) {

if (sample.getDataReviewPassed() == null || sample.getQcPassed() == null){
if (sample.getDataReviewPassed() == null || sample.getQcPassed() == null) {
hasWaiting = true;
} else if (sample.getDataReviewPassed() && sample.getQcPassed()) {
hasPassed = true;
}

if (!(sample.getRun() == null && type.equals(MetricCategory.LIBRARY_QUALIFICATION))) {
shesmuSamples.add(new ShesmuSample.Builder()
.id(sample.getId())
.supplemental(!Objects.equals(sample.getRequisitionId(), reqId))
.build());
.id(sample.getId())
.supplemental(!Objects.equals(sample.getRequisitionId(), reqId))
.qcFailed(getQcFailed(sample))
.build());
}
}

if (shesmuSamples.isEmpty()) {
return null;
}
return new ShesmuSequencing.Builder()
.test(name)
.limsIds(shesmuSamples)
.complete((hasPassed && !hasWaiting))
.type(type)
.build();
.test(name)
.limsIds(shesmuSamples)
.complete((hasPassed && !hasWaiting))
.type(type)
.build();
}

private boolean getQcFailed(Sample sample) {
Run run = sample.getRun();
return (!(sample.getDataReviewPassed() == null || sample.getDataReviewPassed())
&& !(sample.getQcPassed() == null || sample.getQcPassed())
&& !(run.getDataReviewPassed() == null || run.getDataReviewPassed())
&& !(run.getQcPassed() == null || run.getQcPassed()));
}

private Set<String> getLimsIusIdsForShesmu(Case kase) {
Expand Down Expand Up @@ -242,17 +254,17 @@ private ShesmuCase convertCaseToShesmuCase(Case kase) {

private ShesmuDetailedCase convertCaseToShesmuDetailedCase(Case kase) {
return new ShesmuDetailedCase.Builder()
.assayName(caseData.getAssaysById().get(kase.getAssayId()).getName())
.assayVersion(caseData.getAssaysById().get(kase.getAssayId()).getVersion())
.caseIdentifier(kase.getId())
.caseStatus(getCaseStatus(kase))
.paused(kase.getRequisition().isPaused())
.stopped(kase.getRequisition().isStopped())
.completedDateLocal(getCompletedDate(kase))
.requisitionId(kase.getRequisition().getId())
.requisitionName(kase.getRequisition().getName())
.sequencing(getSequencingForShesmuCase(kase))
.build();
.assayName(caseData.getAssaysById().get(kase.getAssayId()).getName())
.assayVersion(caseData.getAssaysById().get(kase.getAssayId()).getVersion())
.caseIdentifier(kase.getId())
.caseStatus(getCaseStatus(kase))
.paused(kase.getRequisition().isPaused())
.stopped(kase.getRequisition().isStopped())
.completedDateLocal(getCompletedDate(kase))
.requisitionId(kase.getRequisition().getId())
.requisitionName(kase.getRequisition().getName())
.sequencing(getSequencingForShesmuCase(kase))
.build();
}

@Scheduled(fixedDelay = 1L, timeUnit = TimeUnit.MINUTES)
Expand Down
1 change: 1 addition & 0 deletions changes/add_qc_failed_field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Field qcFailed on shesmu detailed cases

0 comments on commit 7252bdc

Please sign in to comment.