use of com.hartwig.patient.Sample 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.Sample in project pipeline5 by hartwigmedical.
the class LocalSomaticMetadataTest method setUp.
@Before
public void setUp() throws Exception {
setId = "setId";
tumorName = "CORE123T";
refName = "CORE123R";
jsonSampleSource = mock(JsonSampleSource.class);
tumorSample = mock(Sample.class);
final Sample refSample = mock(Sample.class);
stagedOutputPublisher = mock(StagedOutputPublisher.class);
victim = new LocalSomaticMetadata(Arguments.testDefaultsBuilder().setId(setId).build(), jsonSampleSource, stagedOutputPublisher);
when(jsonSampleSource.sample(SampleType.REFERENCE)).thenReturn(Optional.of(refSample));
when(tumorSample.name()).thenReturn(tumorName);
when(refSample.name()).thenReturn(refName);
}
use of com.hartwig.patient.Sample 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.Sample 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.Sample in project pipeline5 by hartwigmedical.
the class SbpSampleReaderTest method parsesPatientNameFromReadsFile.
@Test
public void parsesPatientNameFromReadsFile() {
returnJson(FASTQ_JSON);
Sample sample = victim.read(EXISTS);
assertThat(sample.name()).isEqualTo(SAMPLE_NAME);
}
Aggregations