use of com.hartwig.api.model.SampleSet in project platinum by hartwigmedical.
the class ApiRerun method create.
Long create(final String sampleId) {
try {
List<Sample> samples = sampleApi.list(null, null, null, null, SampleType.TUMOR, sampleId);
for (Sample sample : samples) {
Optional<SampleSet> maybeSampleSet = OnlyOne.ofNullable(setApi.list(null, sample.getId(), true), SampleSet.class);
if (maybeSampleSet.isPresent()) {
SampleSet sampleSet = maybeSampleSet.get();
if (runApi.list(null, null, sampleSet.getId(), null, null, null, null, null).stream().anyMatch(r1 -> r1.getStatus().equals(Status.VALIDATED))) {
return OnlyOne.ofNullable(runApi.list(null, Ini.RERUN_INI, sampleSet.getId(), version, version, null, null, null), Run.class).filter(r -> !r.getStatus().equals(Status.INVALIDATED)).map(r -> {
LOGGER.info("Using existing run for sample [{}] id [{}]", sampleId, r.getId());
return r.getId();
}).orElseGet(() -> {
final Long id = runApi.create(new CreateRun().bucket(bucket).cluster("gcp").context("RESEARCH").ini(Ini.RERUN_INI).version(version).status(Status.PENDING).setId(sampleSet.getId())).getId();
LOGGER.info("Created API run for sample [{}] id [{}]", sampleId, id);
return id;
});
}
}
}
} catch (Exception e) {
LOGGER.error("Unable to create run for [{}] reason [{}]", sampleId, e.getMessage());
return null;
}
return null;
}
use of com.hartwig.api.model.SampleSet in project pipeline5 by hartwigmedical.
the class StagedOutputPublisher method publish.
public void publish(final PipelineState state, final SomaticRunMetadata metadata) {
if (state.status() != PipelineStatus.FAILED && run.isPresent()) {
List<AddDatatype> addDatatypes = state.stageOutputs().stream().map(StageOutput::datatypes).flatMap(List::stream).collect(Collectors.toList());
SampleSet set = setResolver.resolve(metadata.set(), useOnlyDBSets);
Optional<String> tumorSampleName = metadata.maybeTumor().map(SingleSampleRunMetadata::sampleName);
Optional<String> refSampleName = metadata.maybeReference().map(SingleSampleRunMetadata::sampleName);
ImmutableAnalysis.Builder alignedReadsAnalysis = eventBuilder(Type.ALIGNMENT);
ImmutableAnalysis.Builder somaticAnalysis = eventBuilder(Type.SOMATIC);
ImmutableAnalysis.Builder germlineAnalysis = eventBuilder(Type.GERMLINE);
OutputIterator.from(blob -> {
Optional<AddDatatype> dataType = addDatatypes.stream().filter(d -> blob.getName().endsWith(d.path())).findFirst();
Blob blobWithMd5 = sourceBucket.get(blob.getName());
if (isSecondary(blobWithMd5)) {
alignedReadsAnalysis.addOutput(createBlob(tumorSampleName, refSampleName, dataType, blobWithMd5));
} else {
if (isGermline(blobWithMd5)) {
germlineAnalysis.addOutput(createBlob(tumorSampleName, refSampleName, dataType, blobWithMd5));
} else if (notSecondary(blobWithMd5)) {
somaticAnalysis.addOutput(createBlob(tumorSampleName, refSampleName, dataType, blobWithMd5));
}
}
}, sourceBucket).iterate(metadata);
publish(PipelineComplete.builder().pipeline(ImmutablePipeline.builder().sample(tumorSampleName.orElseGet(() -> refSampleName.orElseThrow())).bucket(sourceBucket.getName()).runId(run.get().getId()).setId(set.getId()).context(context).addAnalyses(alignedReadsAnalysis.build(), somaticAnalysis.build(), germlineAnalysis.build()).version(Versions.pipelineMajorMinorVersion()).build()).build());
}
}
use of com.hartwig.api.model.SampleSet in project pipeline5 by hartwigmedical.
the class ResearchMetadataApi method get.
@Override
public SomaticRunMetadata get() {
List<Sample> possibleTumors = sampleApi.list(null, null, null, null, SampleType.TUMOR, biopsyName);
SampleSet set = possibleTumors.stream().flatMap(sample -> setApi.list(null, sample.getId(), true).stream()).collect(Collectors.toList()).stream().max(Comparator.comparing(SampleSet::getName)).orElseThrow(() -> new IllegalStateException(String.format("No viable set found for biopsy [%s]", biopsyName)));
Sample ref = OnlyOne.of(sampleApi.list(null, null, null, set.getId(), SampleType.REF, null), Sample.class);
Sample tumor = OnlyOne.of(sampleApi.list(null, null, null, set.getId(), SampleType.TUMOR, null), Sample.class);
return SomaticRunMetadata.builder().bucket(arguments.outputBucket()).set(set.getName()).maybeTumor(singleSample(tumor, SingleSampleRunMetadata.SampleType.TUMOR, set.getName())).maybeReference(singleSample(ref, SingleSampleRunMetadata.SampleType.REFERENCE, set.getName())).build();
}
use of com.hartwig.api.model.SampleSet in project pipeline5 by hartwigmedical.
the class ResearchMetadataApiTest method pipelineCompleteWithFile.
@NotNull
public ArgumentCaptor<PubsubMessage> pipelineCompleteWithFile(final String s, final StageOutput stageOutput) {
PipelineState state = new PipelineState();
state.add(stageOutput);
ArgumentCaptor<PubsubMessage> pubsubMessageArgumentCaptor = ArgumentCaptor.forClass(PubsubMessage.class);
SomaticRunMetadata metadata = TestInputs.defaultSomaticRunMetadata();
when(setResolver.resolve(metadata.set(), true)).thenReturn(new SampleSet().id(SET_ID));
Blob outputBlob = mock(Blob.class);
when(outputBlob.getBucket()).thenReturn("bucket");
when(outputBlob.getName()).thenReturn(s);
when(outputBlob.getSize()).thenReturn(1L);
when(outputBlob.getMd5()).thenReturn("md5");
when(bucket.get(s)).thenReturn(outputBlob);
Page<Blob> page = TestBlobs.pageOf(outputBlob);
when(bucket.list(Storage.BlobListOption.prefix("set/"))).thenReturn(page);
// noinspection unchecked
when(publisher.publish(pubsubMessageArgumentCaptor.capture())).thenReturn(mock(ApiFuture.class));
victim.complete(state, metadata);
return pubsubMessageArgumentCaptor;
}
Aggregations