Skip to content
Snippets Groups Projects
main.nf 5.41 KiB
Newer Older
Gervaise Henry's avatar
Gervaise Henry committed
#!/usr/bin/env nextflow

// Path to an input file, or a pattern for multiple inputs
// Note - $baseDir is the location of this workflow file main.nf

// Define Input variables
params.fastq = "$baseDir/../test_data/*.fastq.gz"
params.designFile = "$baseDir/../test_data/design.csv"
params.genome = 'GRCh38-3.0.0'
Gervaise Henry's avatar
Gervaise Henry committed
params.expectCells = 10000
params.forceCells = 0
params.kitVersion = 'three'
params.version = '3.0.2'
params.astrocyte = false
params.outDir = "$baseDir/output"
Gervaise Henry's avatar
Gervaise Henry committed

// Assign variables if astrocyte
if (params.astrocyte) {
  print("Running under astrocyte")
  params.genomeLocation = '/project/apps_database/cellranger/refdata-cellranger-'
  if (params.kitVersion == "one") {
    params.chemistryParam ='SC3Pv1'
  } else if (params.kitVersion == "two") {
    params.chemistryParam ='SC3Pv2'
  } else if (params.kitVersion == "three") {
    params.chemistryParam ='SC3Pv3'
  } else {
Gervaise Henry's avatar
Gervaise Henry committed
    params.chemistryParam = 'auto'
} else {
  params.genomes = []
  params.genomeLocation = params.genome ? params.genomes[ params.genome ].loc ?: false : false
  params.chemistry = []
  params.chemistryParam = params.kitVersion ? params.chemistry[ params.kitVersion ].param ?: false : false
}
params.genomeLocationFull = params.genomeLocation+params.genome

// Define regular variables
designLocation = Channel
  .fromPath(params.designFile)
  .ifEmpty { exit 1, "design file not found: ${params.designFile}" }
Gervaise Henry's avatar
Gervaise Henry committed
fastqList = Channel
  .fromPath(params.fastq)
  .flatten()
  .map { file -> [ file.getFileName().toString(), file.toString() ].join("\t") }
  .collectFile(name: 'fileList.tsv', newLine: true)
refLocation = Channel
  .fromPath(params.genomeLocationFull)
  .ifEmpty { exit 1, "referene not found: ${params.genome}" }
Gervaise Henry's avatar
Gervaise Henry committed
expectCells = params.expectCells
forceCells = params.forceCells
chemistryParam = params.chemistryParam
version = params.version
Gervaise Henry's avatar
Gervaise Henry committed

process checkDesignFile {

  publishDir "$outDir/${task.process}", mode: 'copy'
Gervaise Henry's avatar
Gervaise Henry committed

  input:

Gervaise Henry's avatar
Gervaise Henry committed
  file fastqList

  output:

  file("design.checked.csv") into designPaths
Gervaise Henry's avatar
Gervaise Henry committed

  script:

  """
  python3 $baseDir/scripts/check_design.py -d $designLocation -f $fastqList
Gervaise Henry's avatar
Gervaise Henry committed
  """
}

// Parse design file
samples = designPaths
  .splitCsv (sep: ',', header: true)
  .map { row -> [ row.Sample, file(row.fastq_R1), file(row.fastq_R2) ] }
  .groupTuple()
  //.subscribe { println it }

// Duplicate variables
samples.into {
expectCells211 = expectCells
expectCells301 = expectCells
expectCells302 = expectCells
forceCells211 = forceCells
forceCells301 = forceCells
forceCells302 = forceCells
chemistryParam301 = chemistryParam
chemistryParam302 = chemistryParam
  publishDir "$outDir/${task.process}", mode: 'copy'

  input:

  set sample, file("${sample}_S1_L00?_R1_001.fastq.gz"), file("${sample}_S1_L00?_R2_001.fastq.gz") from samples211
  file ref from refLocation211.first()
  expectCells211
  forceCells211

  output:

  file("**/outs/**") into outPaths211

  when:
  version == '2.1.1'
    """
	  hostname
    ulimit -a
    module load cellranger/2.1.1
    cellranger count --id="$sample" --transcriptome="./$ref" --fastqs=. --sample="$sample" --expect-cells=$expectCells211
    """
    """
	  hostname
    ulimit -a
    module load cellranger/2.1.1
    cellranger count --id="$sample" --transcriptome="./$ref" --fastqs=. --sample="$sample" --force-cells=$forceCells211
    """
  publishDir "$outDir/${task.process}", mode: 'copy'
  set sample, file("${sample}_S1_L00?_R1_001.fastq.gz"), file("${sample}_S1_L00?_R2_001.fastq.gz") from samples301
  file ref from refLocation301.first()
  expectCells301
  forceCells301
Gervaise Henry's avatar
Gervaise Henry committed

  version == '3.0.1'
    """
	  hostname
    ulimit -a
    module load cellranger/3.0.1
    cellranger count --id="$sample" --transcriptome="./$ref" --fastqs=. --sample="$sample" --expect-cells=$expectCells301 --chemistry="$chemistryParam301"
    """
    """
	  hostname
    ulimit -a
    module load cellranger/3.0.1
    cellranger count --id="$sample" --transcriptome="./$ref" --fastqs=. --sample="$sample" --force-cells=$forceCells301 --chemistry="$chemistryParam301"
    """
Gervaise Henry's avatar
Gervaise Henry committed

  publishDir "$outDir/${task.process}", mode: 'copy'
Gervaise Henry's avatar
Gervaise Henry committed

  input:

  set sample, file("${sample}_S?_L001_R1_001.fastq.gz"), file("${sample}_S?_L001_R2_001.fastq.gz") from samples302
  file ref from refLocation302.first()
  expectCells302
  forceCells302
Gervaise Henry's avatar
Gervaise Henry committed

  output:

  version == '3.0.2'
Gervaise Henry's avatar
Gervaise Henry committed

  script:
    """
	  hostname
    ulimit -a
    module load cellranger/3.0.2
    cellranger count --id="$sample" --transcriptome="./$ref" --fastqs=. --sample="$sample" --expect-cells=$expectCells302 --chemistry="$chemistryParam302"
    """
Gervaise Henry's avatar
Gervaise Henry committed
  } else {
    """
	  hostname
    ulimit -a
    module load cellranger/3.0.2
    cellranger count --id="$sample" --transcriptome="./$ref" --fastqs=. --sample="$sample" --force-cells=$forceCells302 --chemistry="$chemistryParam302"
    """
Gervaise Henry's avatar
Gervaise Henry committed
  }