use of com.hartwig.patient.Lane 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.patient.Lane in project pipeline5 by hartwigmedical.
the class GoogleStorageSampleSource method sample.
@Override
public Sample sample(final SingleSampleRunMetadata metadata) {
RuntimeBucket runtimeBucket = RuntimeBucket.from(storage, Aligner.NAMESPACE, metadata, arguments, labels);
Iterable<Blob> blobs = runtimeBucket.list("samples/");
if (Iterables.isEmpty(blobs)) {
throw new IllegalArgumentException(String.format("No sample data found in bucket [%s] so there is no input to process. " + "You cannot use the upload=false flag if no sample has already been uploaded", runtimeBucket.name()));
}
String sampleDirectory = "/samples/" + metadata.barcode();
String sampleNameWithPostfix = metadata.barcode();
List<Lane> lanes = FastqFiles.toLanes(StreamSupport.stream(blobs.spliterator(), false).map(Blob::getName).map(File::new).map(File::getName).collect(Collectors.toList()), sampleDirectory, sampleNameWithPostfix);
return Sample.builder(sampleNameWithPostfix).addAllLanes(lanes).build();
}
use of com.hartwig.patient.Lane in project pipeline5 by hartwigmedical.
the class JsonSampleSourceTest method simplePairParsedAndTumorReturned.
@Test
public void simplePairParsedAndTumorReturned() {
JsonSampleSource victim = new JsonSampleSource(Resources.testResource("json_sample_source/single_lane.json"));
Sample sample = victim.sample(TestInputs.tumorRunMetadata());
assertThat(sample.name()).isEqualTo("CPCT12345678T");
assertThat(sample.lanes()).hasSize(1);
Lane lane = sample.lanes().get(0);
assertThat(lane.firstOfPairPath()).isEqualTo("CPCT12345678T_R1.fastq");
assertThat(lane.secondOfPairPath()).isEqualTo("CPCT12345678T_R2.fastq");
assertThat(lane.laneNumber()).isEqualTo("1");
}
use of com.hartwig.patient.Lane in project pipeline5 by hartwigmedical.
the class JsonSampleSourceTest method simplePairParsedAndReferenceReturned.
@Test
public void simplePairParsedAndReferenceReturned() {
JsonSampleSource victim = new JsonSampleSource(Resources.testResource("json_sample_source/single_lane.json"));
Sample sample = victim.sample(TestInputs.referenceRunMetadata());
assertThat(sample.name()).isEqualTo("CPCT12345678R");
assertThat(sample.lanes()).hasSize(1);
Lane lane = sample.lanes().get(0);
assertThat(lane.firstOfPairPath()).isEqualTo("CPCT12345678R_R1.fastq");
assertThat(lane.secondOfPairPath()).isEqualTo("CPCT12345678R_R2.fastq");
assertThat(lane.laneNumber()).isEqualTo("1");
}
use of com.hartwig.patient.Lane in project pipeline5 by hartwigmedical.
the class GoogleStorageSampleSourceTest method verifyFastq.
private void verifyFastq(final String firstOfPair, final String secondOfPair) {
Bucket bucket = mock(Bucket.class);
Blob firstBlob = TestBlobs.blob(firstOfPair);
Blob secondBlob = TestBlobs.blob(secondOfPair);
Page<Blob> page = TestBlobs.pageOf(firstBlob, secondBlob);
when(bucket.list(Storage.BlobListOption.prefix("aligner/samples/"))).thenReturn(page);
when(storage.get(Mockito.anyString())).thenReturn(bucket);
Sample sample = victim.sample(referenceRunMetadata());
assertThat(sample.name()).isEqualTo(TestInputs.referenceSample());
assertThat(sample.lanes()).hasSize(1);
Lane lane = sample.lanes().get(0);
assertThat(lane.firstOfPairPath()).isEqualTo(firstBlob.getName());
assertThat(lane.secondOfPairPath()).isEqualTo(secondBlob.getName());
}
Aggregations