use of com.hartwig.pipeline.alignment.AlignmentOutput in project pipeline5 by hartwigmedical.
the class BwaAlignerTest method returnsProvidedBamIfInSample.
@Test
public void returnsProvidedBamIfInSample() throws Exception {
when(sampleSource.sample(METADATA)).thenReturn(Sample.builder(METADATA.sampleName()).bam("gs://bucket/path/reference.bam").build());
AlignmentOutput output = victim.run(METADATA);
assertThat(output.alignments()).isEqualTo(GoogleStorageLocation.of("bucket", "path/reference.bam"));
assertThat(output.sample()).isEqualTo(METADATA.sampleName());
assertThat(output.status()).isEqualTo(PipelineStatus.PROVIDED);
}
use of com.hartwig.pipeline.alignment.AlignmentOutput in project pipeline5 by hartwigmedical.
the class BwaAligner method run.
public AlignmentOutput run(final SingleSampleRunMetadata metadata) throws Exception {
StageTrace trace = new StageTrace(NAMESPACE, metadata.sampleName(), StageTrace.ExecutorType.COMPUTE_ENGINE).start();
RuntimeBucket rootBucket = RuntimeBucket.from(storage, NAMESPACE, metadata, arguments, labels);
Sample sample = sampleSource.sample(metadata);
if (sample.bam().isPresent()) {
String noPrefix = sample.bam().orElseThrow().replace("gs://", "");
int firstSlash = noPrefix.indexOf("/");
String bucket = noPrefix.substring(0, firstSlash);
String path = noPrefix.substring(firstSlash + 1);
return AlignmentOutput.builder().sample(metadata.sampleName()).status(PipelineStatus.PROVIDED).maybeAlignments(GoogleStorageLocation.of(bucket, path)).build();
}
final ResourceFiles resourceFiles = buildResourceFiles(arguments);
sampleUpload.run(sample, rootBucket);
List<Future<PipelineStatus>> futures = new ArrayList<>();
List<GoogleStorageLocation> perLaneBams = new ArrayList<>();
List<ReportComponent> laneLogComponents = new ArrayList<>();
List<GoogleStorageLocation> laneFailedLogs = new ArrayList<>();
for (Lane lane : sample.lanes()) {
RuntimeBucket laneBucket = RuntimeBucket.from(storage, laneNamespace(lane), metadata, arguments, labels);
BashStartupScript bash = BashStartupScript.of(laneBucket.name());
InputDownload first = new InputDownload(GoogleStorageLocation.of(rootBucket.name(), fastQFileName(sample.name(), lane.firstOfPairPath())));
InputDownload second = new InputDownload(GoogleStorageLocation.of(rootBucket.name(), fastQFileName(sample.name(), lane.secondOfPairPath())));
bash.addCommand(first).addCommand(second);
bash.addCommands(OverrideReferenceGenomeCommand.overrides(arguments));
SubStageInputOutput alignment = new LaneAlignment(arguments.sbpApiRunId().isPresent(), resourceFiles.refGenomeFile(), first.getLocalTargetPath(), second.getLocalTargetPath(), metadata.sampleName(), lane).apply(SubStageInputOutput.empty(metadata.sampleName()));
perLaneBams.add(GoogleStorageLocation.of(laneBucket.name(), resultsDirectory.path(alignment.outputFile().fileName())));
bash.addCommands(alignment.bash()).addCommand(new OutputUpload(GoogleStorageLocation.of(laneBucket.name(), resultsDirectory.path()), RuntimeFiles.typical()));
futures.add(executorService.submit(() -> runWithRetries(metadata, laneBucket, VirtualMachineJobDefinition.alignment(laneId(lane).toLowerCase(), bash, resultsDirectory))));
laneLogComponents.add(new RunLogComponent(laneBucket, laneNamespace(lane), Folder.from(metadata), resultsDirectory));
laneFailedLogs.add(GoogleStorageLocation.of(laneBucket.name(), RunLogComponent.LOG_FILE));
}
AlignmentOutput output;
if (lanesSuccessfullyComplete(futures)) {
List<InputDownload> laneBams = perLaneBams.stream().map(InputDownload::new).collect(Collectors.toList());
BashStartupScript mergeMarkdupsBash = BashStartupScript.of(rootBucket.name());
laneBams.forEach(mergeMarkdupsBash::addCommand);
SubStageInputOutput merged = new MergeMarkDups(laneBams.stream().map(InputDownload::getLocalTargetPath).filter(path -> path.endsWith("bam")).collect(Collectors.toList())).apply(SubStageInputOutput.empty(metadata.sampleName()));
mergeMarkdupsBash.addCommands(merged.bash());
mergeMarkdupsBash.addCommand(new OutputUpload(GoogleStorageLocation.of(rootBucket.name(), resultsDirectory.path()), RuntimeFiles.typical()));
PipelineStatus status = runWithRetries(metadata, rootBucket, VirtualMachineJobDefinition.mergeMarkdups(mergeMarkdupsBash, resultsDirectory));
ImmutableAlignmentOutput.Builder outputBuilder = AlignmentOutput.builder().sample(metadata.sampleName()).status(status).maybeAlignments(GoogleStorageLocation.of(rootBucket.name(), resultsDirectory.path(merged.outputFile().fileName()))).addAllReportComponents(laneLogComponents).addAllFailedLogLocations(laneFailedLogs).addFailedLogLocations(GoogleStorageLocation.of(rootBucket.name(), RunLogComponent.LOG_FILE)).addReportComponents(new RunLogComponent(rootBucket, Aligner.NAMESPACE, Folder.from(metadata), resultsDirectory));
if (!arguments.outputCram()) {
outputBuilder.addReportComponents(new SingleFileComponent(rootBucket, Aligner.NAMESPACE, Folder.from(metadata), bam(metadata.sampleName()), bam(metadata.sampleName()), resultsDirectory), new SingleFileComponent(rootBucket, Aligner.NAMESPACE, Folder.from(metadata), bai(bam(metadata.sampleName())), bai(bam(metadata.sampleName())), resultsDirectory)).addDatatypes(new AddDatatype(DataType.ALIGNED_READS, metadata.barcode(), new ArchivePath(Folder.from(metadata), BwaAligner.NAMESPACE, bam(metadata.sampleName()))), new AddDatatype(DataType.ALIGNED_READS_INDEX, metadata.barcode(), new ArchivePath(Folder.from(metadata), BwaAligner.NAMESPACE, bai(metadata.sampleName()))));
}
output = outputBuilder.build();
} else {
output = AlignmentOutput.builder().sample(metadata.sampleName()).status(PipelineStatus.FAILED).build();
}
trace.stop();
executorService.shutdown();
return output;
}
use of com.hartwig.pipeline.alignment.AlignmentOutput in project pipeline5 by hartwigmedical.
the class SingleSamplePipeline method run.
public PipelineState run(final SingleSampleRunMetadata metadata) throws Exception {
LOGGER.info("Pipeline5 single sample pipeline starting for sample name [{}] with id [{}] {}", metadata.sampleName(), metadata.barcode(), arguments.runId().map(runId -> String.format("using run tag [%s]", runId)).orElse(""));
PipelineState state = new PipelineState();
final ResourceFiles resourceFiles = buildResourceFiles(arguments);
AlignmentOutput alignmentOutput = convertCramsIfNecessary(arguments, metadata, state);
eventListener.alignmentComplete(alignmentOutput);
if (state.shouldProceed()) {
Future<BamMetricsOutput> bamMetricsFuture = executorService.submit(() -> stageRunner.run(metadata, new BamMetrics(resourceFiles, alignmentOutput, persistedDataset, arguments)));
Future<SnpGenotypeOutput> unifiedGenotyperFuture = executorService.submit(() -> stageRunner.run(metadata, new SnpGenotype(resourceFiles, alignmentOutput)));
Future<FlagstatOutput> flagstatOutputFuture = executorService.submit(() -> stageRunner.run(metadata, new Flagstat(alignmentOutput, persistedDataset)));
Future<CramOutput> cramOutputFuture = executorService.submit(() -> stageRunner.run(metadata, new CramConversion(alignmentOutput, metadata.type(), resourceFiles)));
if (metadata.type().equals(SingleSampleRunMetadata.SampleType.REFERENCE)) {
Future<GermlineCallerOutput> germlineCallerFuture = executorService.submit(() -> stageRunner.run(metadata, new GermlineCaller(alignmentOutput, resourceFiles, persistedDataset)));
GermlineCallerOutput germlineCallerOutput = futurePayload(germlineCallerFuture);
germlineCallerOutputQueue.put(germlineCallerOutput);
report.add(state.add(germlineCallerOutput));
}
BamMetricsOutput bamMetricsOutput = futurePayload(bamMetricsFuture);
metricsOutputQueue.put(bamMetricsOutput);
FlagstatOutput flagstatOutput = futurePayload(flagstatOutputFuture);
flagstatOutputQueue.put(flagstatOutput);
report.add(state.add(bamMetricsOutput));
report.add(state.add(futurePayload(unifiedGenotyperFuture)));
report.add(state.add(flagstatOutput));
report.add(state.add(futurePayload(cramOutputFuture)));
report.compose(metadata, "SingleSample");
eventListener.complete(state);
}
return state;
}
use of com.hartwig.pipeline.alignment.AlignmentOutput in project pipeline5 by hartwigmedical.
the class PersistedAlignmentTest method returnsCramsInConventionalLocationIfNoPersistedAndUseCrams.
@Test
public void returnsCramsInConventionalLocationIfNoPersistedAndUseCrams() {
PersistedAlignment victim = new PersistedAlignment(new NoopPersistedDataset(), Arguments.testDefaultsBuilder().useCrams(true).build());
AlignmentOutput output = victim.run(TestInputs.referenceRunMetadata());
assertThat(output.sample()).isEqualTo("reference");
assertThat(output.status()).isEqualTo(PipelineStatus.PERSISTED);
assertThat(output.alignments()).isEqualTo(GoogleStorageLocation.of("bucket", "set/reference/cram/reference.cram"));
}
use of com.hartwig.pipeline.alignment.AlignmentOutput in project pipeline5 by hartwigmedical.
the class PersistedAlignmentTest method returnsPersistedCramsWhenExists.
@Test
public void returnsPersistedCramsWhenExists() {
PersistedDataset persistedDataset = mock(PersistedDataset.class);
when(persistedDataset.path(TestInputs.referenceRunMetadata().sampleName(), DataType.ALIGNED_READS)).thenReturn(Optional.of(PERSISTED_REFERENCE_CRAM));
PersistedAlignment victim = new PersistedAlignment(persistedDataset, Arguments.testDefaults());
AlignmentOutput output = victim.run(TestInputs.referenceRunMetadata());
assertThat(output.sample()).isEqualTo("reference");
assertThat(output.status()).isEqualTo(PipelineStatus.PERSISTED);
assertThat(output.alignments()).isEqualTo(PERSISTED_REFERENCE_CRAM);
}
Aggregations