Search in sources :

Example 1 with SampleSet

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;
}
Also used : Run(com.hartwig.api.model.Run) Logger(org.slf4j.Logger) Status(com.hartwig.api.model.Status) LoggerFactory(org.slf4j.LoggerFactory) RunApi(com.hartwig.api.RunApi) OnlyOne(com.hartwig.api.helpers.OnlyOne) SampleSet(com.hartwig.api.model.SampleSet) SampleType(com.hartwig.api.model.SampleType) List(java.util.List) ApiException(com.hartwig.ApiException) SetApi(com.hartwig.api.SetApi) CreateRun(com.hartwig.api.model.CreateRun) Optional(java.util.Optional) SampleApi(com.hartwig.api.SampleApi) Sample(com.hartwig.api.model.Sample) Ini(com.hartwig.api.model.Ini) SampleSet(com.hartwig.api.model.SampleSet) CreateRun(com.hartwig.api.model.CreateRun) Sample(com.hartwig.api.model.Sample) Run(com.hartwig.api.model.Run) CreateRun(com.hartwig.api.model.CreateRun) ApiException(com.hartwig.ApiException)

Example 2 with SampleSet

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());
    }
}
Also used : StageOutput(com.hartwig.pipeline.StageOutput) Analysis(com.hartwig.events.Analysis) ImmutableAnalysisOutputBlob(com.hartwig.events.ImmutableAnalysisOutputBlob) Arrays(java.util.Arrays) ImmutableAnalysis(com.hartwig.events.ImmutableAnalysis) MD5s(com.hartwig.pipeline.metadata.MD5s) SageConfiguration(com.hartwig.pipeline.calling.sage.SageConfiguration) Aligner(com.hartwig.pipeline.alignment.Aligner) SnpGenotype(com.hartwig.pipeline.snpgenotype.SnpGenotype) Versions(com.hartwig.pipeline.tools.Versions) OutputIterator(com.hartwig.pipeline.transfer.OutputIterator) BamMetrics(com.hartwig.pipeline.metrics.BamMetrics) Blob(com.google.cloud.storage.Blob) Type(com.hartwig.events.Analysis.Type) Publisher(com.google.cloud.pubsub.v1.Publisher) PipelineStatus(com.hartwig.pipeline.execution.PipelineStatus) Molecule(com.hartwig.events.Analysis.Molecule) Bucket(com.google.cloud.storage.Bucket) Run(com.hartwig.api.model.Run) Pipeline(com.hartwig.events.Pipeline) PipelineState(com.hartwig.pipeline.PipelineState) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PipelineComplete(com.hartwig.events.PipelineComplete) StageOutput(com.hartwig.pipeline.StageOutput) Collectors(java.util.stream.Collectors) SampleSet(com.hartwig.api.model.SampleSet) Flagstat(com.hartwig.pipeline.flagstat.Flagstat) List(java.util.List) AddDatatype(com.hartwig.pipeline.metadata.AddDatatype) AnalysisOutputBlob(com.hartwig.events.AnalysisOutputBlob) SomaticRunMetadata(com.hartwig.pipeline.metadata.SomaticRunMetadata) CramConversion(com.hartwig.pipeline.cram.CramConversion) SingleSampleRunMetadata(com.hartwig.pipeline.metadata.SingleSampleRunMetadata) GermlineCaller(com.hartwig.pipeline.calling.germline.GermlineCaller) Optional(java.util.Optional) ImmutablePipeline(com.hartwig.events.ImmutablePipeline) Predicate.not(java.util.function.Predicate.not) NotNull(org.jetbrains.annotations.NotNull) SampleSet(com.hartwig.api.model.SampleSet) ImmutableAnalysisOutputBlob(com.hartwig.events.ImmutableAnalysisOutputBlob) Blob(com.google.cloud.storage.Blob) AnalysisOutputBlob(com.hartwig.events.AnalysisOutputBlob) Optional(java.util.Optional) SingleSampleRunMetadata(com.hartwig.pipeline.metadata.SingleSampleRunMetadata) ImmutableAnalysis(com.hartwig.events.ImmutableAnalysis) AddDatatype(com.hartwig.pipeline.metadata.AddDatatype)

Example 3 with SampleSet

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();
}
Also used : SampleSet(com.hartwig.api.model.SampleSet) Sample(com.hartwig.api.model.Sample)

Example 4 with SampleSet

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;
}
Also used : PipelineState(com.hartwig.pipeline.PipelineState) SampleSet(com.hartwig.api.model.SampleSet) ApiFuture(com.google.api.core.ApiFuture) Blob(com.google.cloud.storage.Blob) AnalysisOutputBlob(com.hartwig.events.AnalysisOutputBlob) PubsubMessage(com.google.pubsub.v1.PubsubMessage) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SampleSet (com.hartwig.api.model.SampleSet)4 Blob (com.google.cloud.storage.Blob)2 Run (com.hartwig.api.model.Run)2 Sample (com.hartwig.api.model.Sample)2 AnalysisOutputBlob (com.hartwig.events.AnalysisOutputBlob)2 PipelineState (com.hartwig.pipeline.PipelineState)2 List (java.util.List)2 Optional (java.util.Optional)2 NotNull (org.jetbrains.annotations.NotNull)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiFuture (com.google.api.core.ApiFuture)1 Publisher (com.google.cloud.pubsub.v1.Publisher)1 Bucket (com.google.cloud.storage.Bucket)1 PubsubMessage (com.google.pubsub.v1.PubsubMessage)1 ApiException (com.hartwig.ApiException)1 RunApi (com.hartwig.api.RunApi)1 SampleApi (com.hartwig.api.SampleApi)1 SetApi (com.hartwig.api.SetApi)1 OnlyOne (com.hartwig.api.helpers.OnlyOne)1 CreateRun (com.hartwig.api.model.CreateRun)1