Skip to content
Snippets Groups Projects
main.nf 4.45 KiB
Newer Older
David Trudgian's avatar
David Trudgian committed
/*
 * Copyright (c) 2023. The University of Texas Southwestern Medical Center
David Trudgian's avatar
David Trudgian committed
 *
 *   This file is part of the BioHPC Workflow Platform
 *
 * This is a workflow package to run cellranger count on fastq files from single cell RNA data.
David Trudgian's avatar
David Trudgian committed
 *
 * @authors
 * John Lafin
// Parameters for input values
params.sample = "Brain_Tumor_3p_LT"
params.fastq = "${projectDir}/../test_data/Brain_Tumor_3p_LT_fastqs"
params.reference = "hg38"
params.expectCells = 0
params.chemistry = "auto"
params.introns = true
params.noBam = false
params.outDir = "${projectDir}/output"
David Trudgian's avatar
David Trudgian committed

// Run cellranger count
John Lafin's avatar
John Lafin committed
process cr_count {
    publishDir "${outDir}", mode: 'copy'
    queue "256GB,256GBv1"
    module 'cellranger/7.1.0'
    module 'singularity/3.9.9'
John Lafin's avatar
John Lafin committed
        val sample
        path ref
John Lafin's avatar
John Lafin committed
        path fastq
John Lafin's avatar
John Lafin committed
        val expectCells
        val chemistry
        val introns
        val noBam
        path outDir
David Trudgian's avatar
David Trudgian committed

    output:
John Lafin's avatar
John Lafin committed
        tuple val(sample), path("**/outs/**")
        if( expectCells == 0 )
            if( noBam )
            """
            cellranger count --id=$sample \
                            --transcriptome=$ref \
John Lafin's avatar
John Lafin committed
                            --fastqs=. \
                            --sample=$sample \
                            --chemistry=$chemistry \
                            --include-introns=$introns \
                            --no-bam 
            """
            else
            """
            cellranger count --id=$sample \
                            --transcriptome=$ref \
John Lafin's avatar
John Lafin committed
                            --fastqs=. \
                            --sample=$sample \
                            --chemistry=$chemistry \
                            --include-introns=$introns
            """

        else if( expectCells > 0)
            if( noBam )
            """
            cellranger count --id=$sample \
                            --transcriptome=$ref \
John Lafin's avatar
John Lafin committed
                            --fastqs=. \
                            --sample=$sample \
                            --expect-cells=$expectCells \
                            --chemistry=$chemistry \
                            --include-introns=$introns \
                            --no-bam 
            """
            else
            """
            cellranger count --id=$sample \
                            --transcriptome=$ref \
John Lafin's avatar
John Lafin committed
                            --fastqs=. \
                            --sample=$sample \
                            --expect-cells=$expectCells \
                            --chemistry=$chemistry \
                            --include-introns=$introns
            """
John Lafin's avatar
John Lafin committed
// Download reference genome if missing
process get_reference {
    queue "super"
    module 'singularity/3.9.9'

    input:
        val ref_name

    output:
John Lafin's avatar
John Lafin committed
        path ("refdata*", type: "dir")
John Lafin's avatar
John Lafin committed

    script:
        if( ref_name=="hg38" ) {
John Lafin's avatar
John Lafin committed
            wget -q https://cf.10xgenomics.com/supp/cell-exp/refdata-gex-GRCh38-2020-A.tar.gz
            tar -zxf refdata-gex-GRCh38-2020-A.tar.gz
            rm refdata-gex-GRCh38-2020-A.tar.gz
John Lafin's avatar
John Lafin committed
        }
        else if( ref_name=="mm10" ) {
John Lafin's avatar
John Lafin committed
            wget -q https://cf.10xgenomics.com/supp/cell-exp/refdata-gex-mm10-2020-A.tar.gz
            tar -zxf refdata-gex-mm10-2020-A.tar.gz
            rm refdata-gex-mm10-2020-A.tar.gz
John Lafin's avatar
John Lafin committed
workflow {
    // Select reference genome
John Lafin's avatar
John Lafin committed
    if (file(params.reference).exists()) {
        ref = file(params.reference)
    }
    else if (params.reference == "hg38") {
        ref = file("/project/apps_database/cellranger/refdata-gex-GRCh38-2020-A")
    }
    else if (params.reference == "mm10") {
        ref = file("/project/apps_database/cellranger/refdata-gex-mm10-2020-A")
    }
    else {
John Lafin's avatar
John Lafin committed
        ref = file("missing_reference")
John Lafin's avatar
John Lafin committed

    // Download reference if missing
    if( ref.isEmpty() ) {
        ref = get_reference(params.reference)
    }
John Lafin's avatar
John Lafin committed
    // Define channels from variables
    sample = Channel.value(params.sample)
    fastq = Channel.fromPath(params.fastq).collect()
John Lafin's avatar
John Lafin committed
    expectCells = Channel.value(params.expectCells)
    chemistry = Channel.value(params.chemistry)
    introns = Channel.value(params.introns)
    noBam = Channel.value(params.noBam)
    outDir = Channel.value(params.outDir)

    // Run cellranger count
    cr_count(sample, ref, fastq, expectCells, chemistry, introns, noBam, outDir)
John Lafin's avatar
John Lafin committed
}