Skip to content

Commit

Permalink
Merge pull request #1 from jpalmer37/allow-per-sample-references
Browse files Browse the repository at this point in the history
Added compatability for per-sample reference
  • Loading branch information
jpalmer37 authored Oct 7, 2024
2 parents 4a7631e + 980c469 commit 81bdebb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
35 changes: 30 additions & 5 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,42 @@ include { count_variants } from './modules/snippy.nf'
include { qualimap_bamqc } from './modules/snippy.nf'

workflow {
ch_ref = Channel.fromPath( "${params.ref}", type: 'file')



// samplesheet input
if (params.samplesheet_input != 'NO_FILE') {
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], it['R1'], it['R2']] }

// if --ref file provided, use this reference for all entries
if (params.ref != 'NO_FILE'){
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], it['R1'], it['R2']] }
ch_ref = ch_fastq.map{it -> it[0]}.combine(Channel.fromPath( "${params.ref}", type: 'file'))

// if no --ref file provided, look for REF column in the samplesheet on a per-sample basis
} else {
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], it['R1'], it['R2'], it['REF']] }
ch_ref = ch_fastq.map{it -> [it[0], it[3]]}
ch_fastq = ch_fastq.map{it -> it.subList(0,3)}
}

// fastq input
} else {
ch_fastq = Channel.fromFilePairs( params.fastq_search_path, flat: true ).map{ it -> [it[0].split('_')[0], it[1], it[2]] }.unique{ it -> it[0] }
if (params.ref != 'NO_FILE'){
ch_fastq = Channel.fromFilePairs( params.fastq_search_path, flat: true ).map{ it -> [it[0].split('_')[0], it[1], it[2]] }.unique{ it -> it[0] }
ch_ref = ch_fastq.map{it -> it[0]}.combine(Channel.fromPath( "${params.ref}", type: 'file'))
} else {
error "ERROR: Reference file must be supplied with --ref when using --fastq_input"
}

}

// FORMAT:
// ch_fastq: [sample_id, r1_fastq_path, r2_fastq_path]
// ch_ref: [sample_id, reference_path]

main:
fastp(ch_fastq)
snippy(fastp.out.reads.combine(ch_ref))
snippy(fastp.out.reads.join(ch_ref))
qualimap_bamqc(snippy.out.alignment)
count_variants(snippy.out.variants_csv.combine(ch_ref))
count_variants(snippy.out.variants_csv.join(ch_ref))
}
1 change: 1 addition & 0 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ manifest {
params {
samplesheet_input = 'NO_FILE'
fastq_input = 'NO_FILE'
ref = 'NO_FILE'
illumina_suffixes = ['*_R{1,2}_001', '*_R{1,2}', '*_{1,2}' ]
fastq_exts = ['.fastq.gz', '.fq.gz', '.fastq', '.fq']
fastq_search_path = makeFastqSearchPath( illumina_suffixes, fastq_exts )
Expand Down

0 comments on commit 81bdebb

Please sign in to comment.