Search in sources :

Example 1 with OutputFile

use of com.hartwig.pipeline.execution.vm.OutputFile in project pipeline5 by hartwigmedical.

the class GridssRerun method execute.

@Override
public VirtualMachineJobDefinition execute(final InputBundle inputs, final RuntimeBucket runtimeBucket, final BashStartupScript commands, final RuntimeFiles executionFlags) {
    // Inputs
    final ResourceFiles resourceFiles = ResourceFilesFactory.buildResourceFiles(RefGenomeVersion.V37);
    final String set = inputs.get("set").inputValue();
    final String tumorSampleName = inputs.get("tumor_sample").inputValue();
    final String referenceSampleName = inputs.get("reference_sample").inputValue();
    final InputFileDescriptor remoteTumorFile = inputs.get("tumor_cram");
    final InputFileDescriptor remoteReferenceFile = inputs.get("ref_cram");
    final InputFileDescriptor runData = inputs.get();
    final RemoteLocationsApi locationsApi = new RemoteLocationsApi(runData.billedProject(), tumorSampleName);
    InputDownload tumorBamDownload = new InputDownload(locationsApi.getTumorAlignment());
    InputDownload tumorBamIndexDownload = new InputDownload(locationsApi.getTumorAlignmentIndex());
    InputDownload referenceBamDownload = new InputDownload(locationsApi.getReferenceAlignment());
    InputDownload referenceBamIndexDownload = new InputDownload(locationsApi.getReferenceAlignmentIndex());
    final InputFileDescriptor remoteTumorIndex = remoteTumorFile.index();
    final InputFileDescriptor remoteReferenceIndex = remoteReferenceFile.index();
    final String localTumorFile = localFilename(remoteTumorFile);
    final String localReferenceFile = localFilename(remoteReferenceFile);
    final String tumorBamPath = localTumorFile.replace("cram", "bam");
    final String refBamPath = localReferenceFile.replace("cram", "bam");
    Driver driver = new Driver(resourceFiles, VmDirectories.outputFile(tumorSampleName + ".assembly.bam")).tumorSample(tumorSampleName, tumorBamPath).referenceSample(referenceSampleName, refBamPath);
    GridssAnnotation viralAnnotation = new GridssAnnotation(resourceFiles, false);
    SubStageInputOutput unfilteredVcfOutput = driver.andThen(viralAnnotation).apply(SubStageInputOutput.empty(tumorSampleName));
    final OutputFile unfilteredVcf = unfilteredVcfOutput.outputFile();
    final OutputFile unfilteredVcfIndex = unfilteredVcf.index(".tbi");
    final GoogleStorageLocation unfilteredVcfRemoteLocation = remoteUnfilteredVcfArchivePath(set, tumorSampleName);
    final GoogleStorageLocation unfilteredVcfIndexRemoteLocation = index(unfilteredVcfRemoteLocation, ".tbi");
    // COMMANDS
    commands.addCommand(new ExportPathCommand(new BwaCommand()));
    commands.addCommand(new ExportPathCommand(new SamtoolsCommand()));
    commands.addCommand(() -> remoteTumorFile.toCommandForm(localTumorFile));
    commands.addCommand(() -> remoteTumorIndex.toCommandForm(localFilename(remoteTumorIndex)));
    commands.addCommand(() -> remoteReferenceFile.toCommandForm(localReferenceFile));
    commands.addCommand(() -> remoteReferenceIndex.toCommandForm(localFilename(remoteReferenceIndex)));
    if (!localTumorFile.equals(tumorBamPath)) {
        commands.addCommands(cramToBam(localTumorFile));
    }
    if (!localReferenceFile.equals(refBamPath)) {
        commands.addCommands(cramToBam(localReferenceFile));
    }
    commands.addCommands(unfilteredVcfOutput.bash());
    commands.addCommand(() -> unfilteredVcf.copyToRemoteLocation(unfilteredVcfRemoteLocation));
    commands.addCommand(() -> unfilteredVcfIndex.copyToRemoteLocation(unfilteredVcfIndexRemoteLocation));
    commands.addCommand(new OutputUpload(GoogleStorageLocation.of(runtimeBucket.name(), "gridss"), executionFlags));
    return VirtualMachineJobDefinition.structuralCalling(commands, ResultsDirectory.defaultDirectory());
}
Also used : OutputFile(com.hartwig.pipeline.execution.vm.OutputFile) ExportPathCommand(com.hartwig.pipeline.execution.vm.unix.ExportPathCommand) InputFileDescriptor(com.hartwig.batch.input.InputFileDescriptor) Driver(com.hartwig.pipeline.calling.structural.gridss.stage.Driver) SubStageInputOutput(com.hartwig.pipeline.stages.SubStageInputOutput) GridssAnnotation(com.hartwig.pipeline.calling.structural.gridss.stage.GridssAnnotation) RemoteLocationsApi(com.hartwig.batch.api.RemoteLocationsApi) BwaCommand(com.hartwig.pipeline.calling.command.BwaCommand) ResourceFiles(com.hartwig.pipeline.resource.ResourceFiles) SamtoolsCommand(com.hartwig.pipeline.calling.command.SamtoolsCommand) OutputUpload(com.hartwig.pipeline.execution.vm.OutputUpload) InputDownload(com.hartwig.pipeline.execution.vm.InputDownload) GoogleStorageLocation(com.hartwig.pipeline.storage.GoogleStorageLocation)

Example 2 with OutputFile

use of com.hartwig.pipeline.execution.vm.OutputFile in project pipeline5 by hartwigmedical.

the class SageRerunOld method execute.

@Override
public VirtualMachineJobDefinition execute(final InputBundle inputs, final RuntimeBucket runtimeBucket, final BashStartupScript commands, final RuntimeFiles executionFlags) {
    // Inputs
    final String set = inputs.get("set").inputValue();
    final String tumorSampleName = inputs.get("tumor_sample").inputValue();
    final String referenceSampleName = inputs.get("ref_sample").inputValue();
    final InputFileDescriptor remoteTumorFile = inputs.get("tumor_cram");
    final InputFileDescriptor remoteReferenceFile = inputs.get("ref_cram");
    final InputFileDescriptor remoteTumorIndex = remoteTumorFile.index();
    final InputFileDescriptor remoteReferenceIndex = remoteReferenceFile.index();
    final String localTumorFile = localFilename(remoteTumorFile);
    final String localReferenceFile = localFilename(remoteReferenceFile);
    final String localTumorBam = CONVERT_TO_BAM ? localTumorFile.replace("cram", "bam") : localTumorFile;
    final String localReferenceBam = CONVERT_TO_BAM ? localReferenceFile.replace("cram", "bam") : localReferenceFile;
    final ResourceFiles resourceFiles = ResourceFilesFactory.buildResourceFiles(RefGenomeVersion.V37);
    // Download tumor
    commands.addCommand(() -> remoteTumorFile.toCommandForm(localTumorFile));
    commands.addCommand(() -> remoteTumorIndex.toCommandForm(localFilename(remoteTumorIndex)));
    // Download normal
    commands.addCommand(() -> remoteReferenceFile.toCommandForm(localReferenceFile));
    commands.addCommand(() -> remoteReferenceIndex.toCommandForm(localFilename(remoteReferenceIndex)));
    final SageCommandBuilder sageCommandBuilder = new SageCommandBuilder(resourceFiles).addReference(referenceSampleName, localReferenceBam).addTumor(tumorSampleName, localTumorBam);
    if (PANEL_ONLY) {
        sageCommandBuilder.panelOnly();
    }
    if (inputs.contains("rna")) {
        final InputFileDescriptor remoteRnaBam = inputs.get("rna");
        final InputFileDescriptor remoteRnaBamIndex = remoteRnaBam.index();
        final String localRnaBam = localFilename(remoteRnaBam);
        // Download rna
        commands.addCommand(() -> remoteRnaBam.toCommandForm(localRnaBam));
        commands.addCommand(() -> remoteRnaBamIndex.toCommandForm(localFilename(remoteRnaBamIndex)));
        // Add to sage application
        sageCommandBuilder.addReference(referenceSampleName + "NA", localRnaBam);
    }
    // Convert to bam if necessary
    if (!localTumorFile.equals(localTumorBam)) {
        commands.addCommands(cramToBam(localTumorFile));
    }
    if (!localReferenceFile.equals(localReferenceBam)) {
        commands.addCommands(cramToBam(localReferenceFile));
    }
    SageApplication sageApplication = new SageApplication(sageCommandBuilder);
    SageSomaticPostProcess sagePostProcess = new SageSomaticPostProcess(tumorSampleName, resourceFiles);
    SubStageInputOutput sageOutput = sageApplication.andThen(sagePostProcess).apply(SubStageInputOutput.empty(tumorSampleName));
    commands.addCommands(sageOutput.bash());
    // 8. Archive targeted output
    final GoogleStorageLocation archiveStorageLocation = sageArchiveDirectory(set);
    final OutputFile filteredOutputFile = sageOutput.outputFile();
    final OutputFile filteredOutputFileIndex = filteredOutputFile.index(".tbi");
    final OutputFile unfilteredOutputFile = sageApplication.apply(SubStageInputOutput.empty(tumorSampleName)).outputFile();
    final OutputFile unfilteredOutputFileIndex = unfilteredOutputFile.index(".tbi");
    commands.addCommand(() -> filteredOutputFile.copyToRemoteLocation(archiveStorageLocation));
    commands.addCommand(() -> filteredOutputFileIndex.copyToRemoteLocation(archiveStorageLocation));
    commands.addCommand(() -> unfilteredOutputFile.copyToRemoteLocation(archiveStorageLocation));
    commands.addCommand(() -> unfilteredOutputFileIndex.copyToRemoteLocation(archiveStorageLocation));
    commands.addCommand(() -> bqrFile(tumorSampleName, "png").copyToRemoteLocation(archiveStorageLocation));
    commands.addCommand(() -> bqrFile(tumorSampleName, "tsv").copyToRemoteLocation(archiveStorageLocation));
    commands.addCommand(() -> bqrFile(referenceSampleName, "png").copyToRemoteLocation(archiveStorageLocation));
    commands.addCommand(() -> bqrFile(referenceSampleName, "tsv").copyToRemoteLocation(archiveStorageLocation));
    // Store output
    commands.addCommand(new OutputUpload(GoogleStorageLocation.of(runtimeBucket.name(), "sage"), executionFlags));
    return VirtualMachineJobDefinition.sageSomaticCalling(commands, ResultsDirectory.defaultDirectory());
}
Also used : OutputFile(com.hartwig.pipeline.execution.vm.OutputFile) ImmutableOutputFile(com.hartwig.pipeline.execution.vm.ImmutableOutputFile) ResourceFiles(com.hartwig.pipeline.resource.ResourceFiles) OutputUpload(com.hartwig.pipeline.execution.vm.OutputUpload) InputFileDescriptor(com.hartwig.batch.input.InputFileDescriptor) SageSomaticPostProcess(com.hartwig.pipeline.calling.sage.SageSomaticPostProcess) SubStageInputOutput(com.hartwig.pipeline.stages.SubStageInputOutput) SageCommandBuilder(com.hartwig.pipeline.calling.sage.SageCommandBuilder) GoogleStorageLocation(com.hartwig.pipeline.storage.GoogleStorageLocation) SageApplication(com.hartwig.pipeline.calling.sage.SageApplication)

Example 3 with OutputFile

use of com.hartwig.pipeline.execution.vm.OutputFile in project pipeline5 by hartwigmedical.

the class SelectVariants method bash.

@Override
public List<BashCommand> bash(final OutputFile input, final OutputFile output) {
    List<String> arguments = selectTypes.stream().flatMap(type -> Stream.of("-selectType", type)).collect(Collectors.toList());
    arguments.add("-R");
    arguments.add(referenceFasta);
    arguments.add("-V");
    arguments.add(input.path());
    arguments.add("-o");
    arguments.add(output.path());
    return Collections.singletonList(new GatkCommand(GermlineCaller.TOOL_HEAP, "SelectVariants", arguments.toArray(new String[0])));
}
Also used : List(java.util.List) Stream(java.util.stream.Stream) SubStage(com.hartwig.pipeline.stages.SubStage) BashCommand(com.hartwig.pipeline.execution.vm.BashCommand) OutputFile(com.hartwig.pipeline.execution.vm.OutputFile) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) FileTypes(com.hartwig.pipeline.datatypes.FileTypes) GatkCommand(com.hartwig.pipeline.execution.vm.GatkCommand) GatkCommand(com.hartwig.pipeline.execution.vm.GatkCommand)

Example 4 with OutputFile

use of com.hartwig.pipeline.execution.vm.OutputFile in project pipeline5 by hartwigmedical.

the class SageGermlinePostProcess method bash.

@Override
public List<BashCommand> bash(final OutputFile input, final OutputFile output) {
    final List<BashCommand> result = Lists.newArrayList();
    SubStage passFilter = new PassFilter();
    OutputFile finalOutputFile = OutputFile.of(sampleName.sampleName(), SAGE_GERMLINE_FILTERED, FileTypes.GZIPPED_VCF);
    result.addAll(passFilter.bash(input, finalOutputFile));
    return result;
}
Also used : OutputFile(com.hartwig.pipeline.execution.vm.OutputFile) SubStage(com.hartwig.pipeline.stages.SubStage) BashCommand(com.hartwig.pipeline.execution.vm.BashCommand)

Example 5 with OutputFile

use of com.hartwig.pipeline.execution.vm.OutputFile in project pipeline5 by hartwigmedical.

the class SageSomaticPostProcess method bash.

@Override
public List<BashCommand> bash(final OutputFile input, final OutputFile output) {
    final List<BashCommand> result = Lists.newArrayList();
    SubStage passFilter = new PassFilter();
    OutputFile finalOutputFile = OutputFile.of(tumorSampleName.sampleName(), SAGE_SOMATIC_FILTERED, FileTypes.GZIPPED_VCF);
    result.addAll(passFilter.bash(input, finalOutputFile));
    return result;
}
Also used : OutputFile(com.hartwig.pipeline.execution.vm.OutputFile) SubStage(com.hartwig.pipeline.stages.SubStage) BashCommand(com.hartwig.pipeline.execution.vm.BashCommand)

Aggregations

OutputFile (com.hartwig.pipeline.execution.vm.OutputFile)6 InputFileDescriptor (com.hartwig.batch.input.InputFileDescriptor)3 BashCommand (com.hartwig.pipeline.execution.vm.BashCommand)3 OutputUpload (com.hartwig.pipeline.execution.vm.OutputUpload)3 ResourceFiles (com.hartwig.pipeline.resource.ResourceFiles)3 SubStage (com.hartwig.pipeline.stages.SubStage)3 SubStageInputOutput (com.hartwig.pipeline.stages.SubStageInputOutput)3 GoogleStorageLocation (com.hartwig.pipeline.storage.GoogleStorageLocation)3 BwaCommand (com.hartwig.pipeline.calling.command.BwaCommand)2 SamtoolsCommand (com.hartwig.pipeline.calling.command.SamtoolsCommand)2 GridssAnnotation (com.hartwig.pipeline.calling.structural.gridss.stage.GridssAnnotation)2 ExportPathCommand (com.hartwig.pipeline.execution.vm.unix.ExportPathCommand)2 RemoteLocationsApi (com.hartwig.batch.api.RemoteLocationsApi)1 ImmutableInputFileDescriptor (com.hartwig.batch.input.ImmutableInputFileDescriptor)1 SageApplication (com.hartwig.pipeline.calling.sage.SageApplication)1 SageCommandBuilder (com.hartwig.pipeline.calling.sage.SageCommandBuilder)1 SageSomaticPostProcess (com.hartwig.pipeline.calling.sage.SageSomaticPostProcess)1 AllocateEvidence (com.hartwig.pipeline.calling.structural.gridss.command.AllocateEvidence)1 SoftClipsToSplitReads (com.hartwig.pipeline.calling.structural.gridss.command.SoftClipsToSplitReads)1 Driver (com.hartwig.pipeline.calling.structural.gridss.stage.Driver)1