Search in sources :

Example 1 with StageOutput

use of com.hartwig.pipeline.StageOutput 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 2 with StageOutput

use of com.hartwig.pipeline.StageOutput in project pipeline5 by hartwigmedical.

the class StageRunnerTest method skipsStageWhenDisabled.

@Test
public void skipsStageWhenDisabled() {
    when(startingPoint.usePersisted(NAMESPACE)).thenReturn(false);
    final StageOutput skippedOutput = mock(StageOutput.class);
    when(stage.skippedOutput(METADATA)).thenReturn(skippedOutput);
    when(stage.shouldRun(ARGUMENTS)).thenReturn(false);
    assertThat(victim.run(METADATA, stage)).isEqualTo(skippedOutput);
}
Also used : StageOutput(com.hartwig.pipeline.StageOutput) Test(org.junit.Test)

Example 3 with StageOutput

use of com.hartwig.pipeline.StageOutput in project pipeline5 by hartwigmedical.

the class VmExecutionLogSummary method ofFailedStages.

public static void ofFailedStages(final Storage storage, final PipelineState state) {
    List<StageOutput> failures = state.stageOutputs().stream().filter(stageOutput -> stageOutput.status().equals(PipelineStatus.FAILED)).collect(Collectors.toList());
    if (!failures.isEmpty()) {
        LOGGER.error("Failures in pipeline stages. Printing each failures full run.log here");
        for (StageOutput failure : failures) {
            for (Blob log : failure.failedLogLocations().stream().map(GoogleStorageLocation::asBlobId).map(storage::get).collect(Collectors.toList())) {
                LOGGER.error("========================================== start {} ==========================================", log.getName());
                LOGGER.error(new String(log.getContent()));
                LOGGER.error("========================================== end {} ==========================================", log.getName());
            }
        }
    }
}
Also used : StageOutput(com.hartwig.pipeline.StageOutput) Blob(com.google.cloud.storage.Blob) List(java.util.List) GoogleStorageLocation(com.hartwig.pipeline.storage.GoogleStorageLocation) Logger(org.slf4j.Logger) PipelineState(com.hartwig.pipeline.PipelineState) LoggerFactory(org.slf4j.LoggerFactory) PipelineStatus(com.hartwig.pipeline.execution.PipelineStatus) Storage(com.google.cloud.storage.Storage) StageOutput(com.hartwig.pipeline.StageOutput) Collectors(java.util.stream.Collectors) Blob(com.google.cloud.storage.Blob) GoogleStorageLocation(com.hartwig.pipeline.storage.GoogleStorageLocation)

Example 4 with StageOutput

use of com.hartwig.pipeline.StageOutput in project pipeline5 by hartwigmedical.

the class StagedOutputPublisherTest method usesDatatypeAndBarcodeWhenFileMatched.

@Test
public void usesDatatypeAndBarcodeWhenFileMatched() throws Exception {
    when(state.status()).thenReturn(PipelineStatus.SUCCESS);
    String path = TestInputs.referenceSample() + "/germline_caller/reference.germline.vcf.gz";
    Blob vcf = withBucketAndMd5(blob(path));
    Page<Blob> page = pageOf(vcf);
    StageOutput stageOutput = mock(StageOutput.class);
    when(stageOutput.datatypes()).thenReturn(List.of(new AddDatatype(DataType.GERMLINE_VARIANTS, "barcode", new ArchivePath(Folder.from(TestInputs.referenceRunMetadata()), "germline_caller", "reference.germline.vcf.gz"))));
    when(state.stageOutputs()).thenReturn(List.of(stageOutput));
    ArgumentCaptor<PubsubMessage> published = publish(page, TestInputs.defaultSingleSampleRunMetadata());
    PipelineComplete result = OBJECT_MAPPER.readValue(new String(published.getValue().getData().toByteArray()), PipelineComplete.class);
    assertThat(result.pipeline().analyses().get(2).output().get(0).datatype()).hasValue("GERMLINE_VARIANTS");
    assertThat(result.pipeline().analyses().get(2).output().get(0).barcode()).hasValue("barcode");
}
Also used : StageOutput(com.hartwig.pipeline.StageOutput) ArchivePath(com.hartwig.pipeline.metadata.ArchivePath) PipelineComplete(com.hartwig.events.PipelineComplete) Blob(com.google.cloud.storage.Blob) AnalysisOutputBlob(com.hartwig.events.AnalysisOutputBlob) AddDatatype(com.hartwig.pipeline.metadata.AddDatatype) PubsubMessage(com.google.pubsub.v1.PubsubMessage) Test(org.junit.Test)

Example 5 with StageOutput

use of com.hartwig.pipeline.StageOutput in project pipeline5 by hartwigmedical.

the class StageRunnerTest method usesPersistedOutputWhenEarlierThanStartingPoint.

@Test
public void usesPersistedOutputWhenEarlierThanStartingPoint() {
    when(startingPoint.usePersisted(NAMESPACE)).thenReturn(true);
    final StageOutput persistedOutput = mock(StageOutput.class);
    when(stage.persistedOutput(METADATA)).thenReturn(persistedOutput);
    when(stage.shouldRun(ARGUMENTS)).thenReturn(true);
    when(stage.tumorReferenceCommands(METADATA)).thenReturn(simpleBash());
    assertThat(victim.run(METADATA, stage)).isEqualTo(persistedOutput);
}
Also used : StageOutput(com.hartwig.pipeline.StageOutput) Test(org.junit.Test)

Aggregations

StageOutput (com.hartwig.pipeline.StageOutput)5 Blob (com.google.cloud.storage.Blob)3 Test (org.junit.Test)3 AnalysisOutputBlob (com.hartwig.events.AnalysisOutputBlob)2 PipelineComplete (com.hartwig.events.PipelineComplete)2 PipelineState (com.hartwig.pipeline.PipelineState)2 PipelineStatus (com.hartwig.pipeline.execution.PipelineStatus)2 AddDatatype (com.hartwig.pipeline.metadata.AddDatatype)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Publisher (com.google.cloud.pubsub.v1.Publisher)1 Bucket (com.google.cloud.storage.Bucket)1 Storage (com.google.cloud.storage.Storage)1 PubsubMessage (com.google.pubsub.v1.PubsubMessage)1 Run (com.hartwig.api.model.Run)1 SampleSet (com.hartwig.api.model.SampleSet)1 Analysis (com.hartwig.events.Analysis)1 Molecule (com.hartwig.events.Analysis.Molecule)1 Type (com.hartwig.events.Analysis.Type)1