Skip to content
Snippets Groups Projects
main.nf 2.19 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'
params.genomes = []
params.ref = params.genome ? params.genomes[ params.genome ].ref ?: false : false
Gervaise Henry's avatar
Gervaise Henry committed
params.expectCells = 10000
params.forceCells = 0

println params.genome
println params.genomes[ params.genome ].ref
println params.ref

Gervaise Henry's avatar
Gervaise Henry committed
// Check inputs
if( params.ref ){
Gervaise Henry's avatar
Gervaise Henry committed
  refLocation = Channel
    .fromPath(params.ref)
    .ifEmpty { exit 1, "referene not found: ${params.ref}" }
Gervaise Henry's avatar
Gervaise Henry committed
} else {
  exit 1, "No reference genome specified."
Gervaise Henry's avatar
Gervaise Henry committed
}

// Define List of Files
fastqList = Channel
  .fromPath(params.fastq)
  .flatten()
  .map { file -> [ file.getFileName().toString(), file.toString() ].join("\t") }
  .collectFile(name: 'fileList.tsv', newLine: true)

// Define regular variables
expectCells = params.expectCells
forceCells = params.forceCells

process checkDesignFile {

  publishDir "$baseDir/output", mode: 'copy'

  input:

  params.designFile
  file fastqList

  output:

  file("design.csv") into designPaths

  script:

  """
  module load python/3.6.1-2-anaconda
  python3 $baseDir/scripts/check_design.py -d $params.designFile -f $fastqList
  """
}

// 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 }


process count {
  tag "$sample"

  publishDir "$baseDir/output", mode: 'copy'

  input:

  set sample, file("${sample}_S1_L00?_R1_001.fastq.gz"), file("${sample}_S1_L00?_R2_001.fastq.gz") from samples
  file ref from refLocation.first()
  expectCells
  forceCells

  output:

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

  script:
  """
  module load cellranger/2.1.1
  """
Gervaise Henry's avatar
Gervaise Henry committed
  if (forceCells == 0){
Gervaise Henry's avatar
Gervaise Henry committed
    """
    cellranger count --id="$sample" --transcriptome="$ref" --fastqs=. --sample="$sample" --expect-cells=$expectCells
    """
  } else {
    """
Gervaise Henry's avatar
Gervaise Henry committed
    cellranger count --id="$sample" --transcriptome="$ref" --fastqs=. --sample="$sample" --force-cells=$forceCells
Gervaise Henry's avatar
Gervaise Henry committed
    """
  }
Gervaise Henry's avatar
Gervaise Henry committed
}