Search in sources :

Example 1 with SambambaCommand

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

the class RnaStarMapping method execute.

@Override
public VirtualMachineJobDefinition execute(InputBundle inputs, RuntimeBucket bucket, BashStartupScript startupScript, RuntimeFiles executionFlags) {
    InputFileDescriptor descriptor = inputs.get();
    final String batchInputs = descriptor.inputValue();
    final String[] batchItems = batchInputs.split(",");
    // required format: SampleId,RefGenomeVersion (37 by default),FASTA file bucket
    /*
        if(batchItems.length != 2)
        {
            System.out.print(String.format("invalid input arguments(%s) - expected SampleId,RefGenomeVersion,FastqFileBucketDir", batchInputs));
            return null;
        }
        */
    final String sampleId = batchItems[0];
    final RefGenomeVersion refGenomeVersion = batchItems.length >= 2 ? RefGenomeVersion.valueOf(batchItems[1]) : V37;
    final String sampleBucket = batchItems[2];
    /*
        if(batchItems.length >= 3)
        {
            final String fastqFilelist = batchItems[2];

            final List<String> sampleFastqFiles = getSampleFastqFileList(sampleId, fastqFilelist);

            if(sampleFastqFiles.isEmpty()) {
                System.out.print(String.format("sampleId(%s) fastq files not found", sampleId));
                return null;
            }

            // copy down FASTQ files for this sample
            for(final String fastqFile : sampleFastqFiles)
            {
                startupScript.addCommand(() -> format("gsutil -u hmf-crunch cp %s %s", fastqFile, VmDirectories.INPUT));
            }
        }
        else
        {
            // expected location: "gs://cpct02010255tii-rna-reads/1.3/CPCT02010255TII_AHWGLNBGX5_S4_L002_R1_001.fastq.gz
            final String sampleFastqFiles = String.format("gs://%s-rna-reads/1.3/*.fastq.gz", sampleId.toLowerCase());
            startupScript.addCommand(() -> format("gsutil -u hmf-crunch cp %s %s", sampleFastqFiles, VmDirectories.INPUT));
        }
        */
    final String sampleFastqFiles = String.format("%s/*.fastq.gz", sampleBucket);
    startupScript.addCommand(() -> format("gsutil -u hmf-crunch cp %s %s", sampleFastqFiles, VmDirectories.INPUT));
    // locate the FASTQ files for reads 1 and 2
    final String r1Files = format("$(ls %s/*_R1* | tr '\\n' ',')", VmDirectories.INPUT);
    final String r2Files = format("$(ls %s/*_R2* | tr '\\n' ',')", VmDirectories.INPUT);
    // copy reference files for STAR
    final String starGenomeDir = getRnaResourceDirectory(refGenomeVersion, STAR_DIR);
    final String localStarGenomeDir = String.format("%s/%s", VmDirectories.INPUT, STAR_DIR);
    startupScript.addCommand(() -> format("mkdir %s", localStarGenomeDir));
    startupScript.addCommand(() -> format("gsutil -u hmf-crunch cp %s/* %s", starGenomeDir, localStarGenomeDir));
    final String threadCount = Bash.allCpus();
    startupScript.addCommand(() -> format("cd %s", VmDirectories.OUTPUT));
    // run the STAR mapper
    final String[] starArgs = { "--runThreadN", threadCount, "--genomeDir", localStarGenomeDir, "--genomeLoad", "NoSharedMemory", "--readFilesIn", r1Files, r2Files, "--readFilesCommand", "zcat", "--outSAMtype", "BAM", "Unsorted", "--outSAMunmapped", "Within", "--outBAMcompression", "0", "--outSAMattributes", "All", "--outFilterMultimapNmax", "10", "--outFilterMismatchNmax", "3", "limitOutSJcollapsed", "3000000", "--chimSegmentMin", "10", "--chimOutType", "WithinBAM", "SoftClip", "--chimJunctionOverhangMin", "10", "--chimSegmentReadGapMax", "3", "--chimScoreMin", "1", "--chimScoreDropMax", "30", "--chimScoreJunctionNonGTAG", "0", "--chimScoreSeparation", "1", "--outFilterScoreMinOverLread", "0.33", "--outFilterMatchNminOverLread", "0.33", "--outFilterMatchNmin", "35", "--alignSplicedMateMapLminOverLmate", "0.33", "--alignSplicedMateMapLmin", "35", "--alignSJstitchMismatchNmax", "5", "-1", "5", "5" };
    startupScript.addCommand(new VersionedToolCommand("star", "STAR", "2.7.3a", starArgs));
    final String bamFile = "Aligned.out.bam";
    // sort the BAM
    final String sortedBam = sampleId + ".sorted.bam";
    final String[] sortArgs = { "sort", "-@", threadCount, "-m", "2G", "-T", "tmp", "-O", "bam", bamFile, "-o", sortedBam };
    startupScript.addCommand(new VersionedToolCommand("samtools", "samtools", Versions.SAMTOOLS, sortArgs));
    // mark duplicate fragment reads within the BAM
    final String sortedDedupedBam = sampleId + ".sorted.dups.bam";
    final String[] dupArgs = { "markdup", "-t", threadCount, "--overflow-list-size=45000000", sortedBam, sortedDedupedBam };
    startupScript.addCommand(new SambambaCommand(dupArgs));
    final String[] indexArgs = { "index", sortedDedupedBam };
    startupScript.addCommand(new VersionedToolCommand("samtools", "samtools", Versions.SAMTOOLS, indexArgs));
    // clean up intermediary BAMs
    startupScript.addCommand(() -> format("rm -f %s", bamFile));
    startupScript.addCommand(() -> format("rm -f %s", sortedBam));
    final String starStats = "Log.final.out";
    final String statsFile = sampleId + "." + starStats;
    startupScript.addCommand(() -> format("mv %s %s", starStats, statsFile));
    // run QC stats on the fast-Qs as well
    // final String fastqcOutputDir = format("%s/fastqc", VmDirectories.OUTPUT);
    // startupScript.addCommand(() -> format("mkdir %s", fastqcOutputDir));
    // final String allFastQs = format("%s/*gz", VmDirectories.INPUT);
    // final String[] fastqcArgs = {"-o", fastqcOutputDir, allFastQs};
    // TEMP until reimage has taken place
    // startupScript.addCommand(() -> format("chmod a+x /opt/tools/fastqc/0.11.4/fastqc"));
    // startupScript.addCommand(new VersionedToolCommand("fastqc", "fastqc", "0.11.4", fastqcArgs));
    // upload the results
    startupScript.addCommand(new OutputUpload(GoogleStorageLocation.of(bucket.name(), "star"), executionFlags));
    // copy results to crunch
    final String samplesDir = String.format("%s/%s", getRnaCohortDirectory(refGenomeVersion), "samples");
    startupScript.addCommand(() -> format("gsutil -m cp %s/* %s/%s/", VmDirectories.OUTPUT, samplesDir, sampleId));
    return ImmutableVirtualMachineJobDefinition.builder().name("rna-star-mapping").startupCommand(startupScript).namespacedResults(ResultsDirectory.defaultDirectory()).workingDiskSpaceGb(500).performanceProfile(VirtualMachinePerformanceProfile.custom(12, 48)).build();
}
Also used : OutputUpload(com.hartwig.pipeline.execution.vm.OutputUpload) InputFileDescriptor(com.hartwig.batch.input.InputFileDescriptor) RefGenomeVersion(com.hartwig.pipeline.resource.RefGenomeVersion) SambambaCommand(com.hartwig.pipeline.execution.vm.SambambaCommand) VersionedToolCommand(com.hartwig.pipeline.calling.command.VersionedToolCommand)

Example 2 with SambambaCommand

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

the class Bam2Fastq method execute.

@Override
public VirtualMachineJobDefinition execute(InputBundle inputs, RuntimeBucket bucket, BashStartupScript startupScript, RuntimeFiles executionFlags) {
    InputFileDescriptor descriptor = inputs.get();
    String localCopyOfBam = format("%s/%s", VmDirectories.INPUT, new File(descriptor.inputValue()).getName());
    startupScript.addCommand(() -> descriptor.toCommandForm(localCopyOfBam));
    startupScript.addCommand(new PipeCommands(new SambambaCommand("view", "-H", localCopyOfBam), () -> "grep ^@RG", () -> "grep -cP \"_L00[1-8]_\""));
    List<String> picargs = ImmutableList.of("SamToFastq", "ODIR=" + VmDirectories.OUTPUT, "OPRG=true", "RGT=ID", "NON_PF=true", "RC=true", "I=" + localCopyOfBam);
    startupScript.addCommand(new JavaJarCommand("picard", "2.18.27", "picard.jar", "16G", picargs));
    startupScript.addCommand(() -> format("rename 's/(.+)_(.+)_(.+)_(.+)_(.+)__(.+)\\.fastq/$1_$2_$3_$4_R$6_$5.fastq/' %s/*.fastq", VmDirectories.OUTPUT));
    startupScript.addCommand(() -> format("pigz %s/*.fastq", VmDirectories.OUTPUT));
    startupScript.addCommand(new OutputUpload(GoogleStorageLocation.of(bucket.name(), "bam2fastq"), executionFlags));
    return ImmutableVirtualMachineJobDefinition.builder().name("bam2fastq").startupCommand(startupScript).namespacedResults(ResultsDirectory.defaultDirectory()).workingDiskSpaceGb(1800).performanceProfile(VirtualMachinePerformanceProfile.custom(4, 20)).build();
}
Also used : PipeCommands(com.hartwig.pipeline.execution.vm.unix.PipeCommands) OutputUpload(com.hartwig.pipeline.execution.vm.OutputUpload) InputFileDescriptor(com.hartwig.batch.input.InputFileDescriptor) SambambaCommand(com.hartwig.pipeline.execution.vm.SambambaCommand) JavaJarCommand(com.hartwig.pipeline.execution.vm.java.JavaJarCommand) File(java.io.File)

Example 3 with SambambaCommand

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

the class Lilac method addSliceCommands.

private void addSliceCommands(final List<BashCommand> commands, final String sampleName, final String inputBamFile, final String slicedBamFile) {
    commands.add(new SambambaCommand("slice", "-L", resourceFiles.hlaRegionBed(), "-o", slicedBamFile, inputBamFile));
    commands.add(new SambambaCommand("index", slicedBamFile));
}
Also used : SambambaCommand(com.hartwig.pipeline.execution.vm.SambambaCommand)

Aggregations

SambambaCommand (com.hartwig.pipeline.execution.vm.SambambaCommand)3 InputFileDescriptor (com.hartwig.batch.input.InputFileDescriptor)2 OutputUpload (com.hartwig.pipeline.execution.vm.OutputUpload)2 VersionedToolCommand (com.hartwig.pipeline.calling.command.VersionedToolCommand)1 JavaJarCommand (com.hartwig.pipeline.execution.vm.java.JavaJarCommand)1 PipeCommands (com.hartwig.pipeline.execution.vm.unix.PipeCommands)1 RefGenomeVersion (com.hartwig.pipeline.resource.RefGenomeVersion)1 File (java.io.File)1