annotate 0.3.0/subworkflows/process_fastq.nf @ 92:295c2597a475

"planemo upload"
author kkonganti
date Tue, 19 Jul 2022 10:07:24 -0400
parents
children
rev   line source
kkonganti@92 1 // Include any necessary methods and modules
kkonganti@92 2 include { stopNow; validateParamsForFASTQ } from "${params.routines}"
kkonganti@92 3 include { GEN_SAMPLESHEET } from "${params.modules}${params.fs}gen_samplesheet${params.fs}main"
kkonganti@92 4 include { SAMPLESHEET_CHECK } from "${params.modules}${params.fs}samplesheet_check${params.fs}main"
kkonganti@92 5 include { CAT_FASTQ } from "${params.modules}${params.fs}cat${params.fs}fastq${params.fs}main"
kkonganti@92 6 include { SEQKIT_SEQ } from "${params.modules}${params.fs}seqkit${params.fs}seq${params.fs}main"
kkonganti@92 7
kkonganti@92 8 // Validate 4 required workflow parameters if
kkonganti@92 9 // FASTQ files are the input for the
kkonganti@92 10 // entry point.
kkonganti@92 11 validateParamsForFASTQ()
kkonganti@92 12
kkonganti@92 13 // Start the subworkflow
kkonganti@92 14 workflow PROCESS_FASTQ {
kkonganti@92 15 main:
kkonganti@92 16 versions = Channel.empty()
kkonganti@92 17 input_ch = Channel.empty()
kkonganti@92 18 reads = Channel.empty()
kkonganti@92 19
kkonganti@92 20 def input = file( (params.input ?: params.metadata) )
kkonganti@92 21
kkonganti@92 22 if (params.input) {
kkonganti@92 23 def fastq_files = []
kkonganti@92 24
kkonganti@92 25 if (params.fq_suffix == null) {
kkonganti@92 26 stopNow("We need to know what suffix the FASTQ files ends with inside the\n" +
kkonganti@92 27 "directory. Please use the --fq_suffix option to indicate the file\n" +
kkonganti@92 28 "suffix by which the files are to be collected to run the pipeline on.")
kkonganti@92 29 }
kkonganti@92 30
kkonganti@92 31 if (params.fq_strandedness == null) {
kkonganti@92 32 stopNow("We need to know if the FASTQ files inside the directory\n" +
kkonganti@92 33 "are sequenced using stranded or non-stranded sequencing. This is generally\n" +
kkonganti@92 34 "required if the sequencing experiment is RNA-SEQ. For almost all of the other\n" +
kkonganti@92 35 "cases, you can probably use the --fq_strandedness unstranded option to indicate\n" +
kkonganti@92 36 "that the reads are unstranded.")
kkonganti@92 37 }
kkonganti@92 38
kkonganti@92 39 if (params.fq_filename_delim == null || params.fq_filename_delim_idx == null) {
kkonganti@92 40 stopNow("We need to know the delimiter of the filename of the FASTQ files.\n" +
kkonganti@92 41 "By default the filename delimiter is _ (underscore). This delimiter character\n" +
kkonganti@92 42 "is used to split and assign a group name. The group name can be controlled by\n" +
kkonganti@92 43 "using the --fq_filename_delim_idx option (1-based). For example, if the FASTQ\n" +
kkonganti@92 44 "filename is WT_REP1_001.fastq, then to create a group WT, use the following\n" +
kkonganti@92 45 "options: --fq_filename_delim _ --fq_filename_delim_idx 1")
kkonganti@92 46 }
kkonganti@92 47
kkonganti@92 48 if (!input.exists()) {
kkonganti@92 49 stopNow("The input directory,\n${params.input}\ndoes not exist!")
kkonganti@92 50 }
kkonganti@92 51
kkonganti@92 52 input.eachFileRecurse {
kkonganti@92 53 it.name.endsWith("${params.fq_suffix}") ? fastq_files << it : fastq_files << null
kkonganti@92 54 }
kkonganti@92 55
kkonganti@92 56 if (fastq_files.findAll{ it != null }.size() == 0) {
kkonganti@92 57 stopNow("The input directory,\n${params.input}\nis empty! or does not " +
kkonganti@92 58 "have FASTQ files ending with the suffix: ${params.fq_suffix}")
kkonganti@92 59 }
kkonganti@92 60
kkonganti@92 61 GEN_SAMPLESHEET( Channel.fromPath(params.input, type: 'dir') )
kkonganti@92 62 GEN_SAMPLESHEET.out.csv.set{ input_ch }
kkonganti@92 63 versions.mix( GEN_SAMPLESHEET.out.versions )
kkonganti@92 64 .set { versions }
kkonganti@92 65 } else if (params.metadata) {
kkonganti@92 66 if (!input.exists()) {
kkonganti@92 67 stopNow("The metadata CSV file,\n${params.metadata}\ndoes not exist!")
kkonganti@92 68 }
kkonganti@92 69
kkonganti@92 70 if (input.size() <= 0) {
kkonganti@92 71 stopNow("The metadata CSV file,\n${params.metadata}\nis empty!")
kkonganti@92 72 }
kkonganti@92 73
kkonganti@92 74 Channel.fromPath(params.metadata, type: 'file')
kkonganti@92 75 .set { input_ch }
kkonganti@92 76 }
kkonganti@92 77
kkonganti@92 78 SAMPLESHEET_CHECK( input_ch )
kkonganti@92 79 .csv
kkonganti@92 80 .splitCsv( header: true, sep: ',')
kkonganti@92 81 .map { create_fastq_channel(it) }
kkonganti@92 82 .groupTuple(by: [0])
kkonganti@92 83 .branch {
kkonganti@92 84 meta, fastq ->
kkonganti@92 85 single : fastq.size() == 1
kkonganti@92 86 return [ meta, fastq.flatten() ]
kkonganti@92 87 multiple : fastq.size() > 1
kkonganti@92 88 return [ meta, fastq.flatten() ]
kkonganti@92 89 }
kkonganti@92 90 .set { reads }
kkonganti@92 91
kkonganti@92 92 CAT_FASTQ( reads.multiple )
kkonganti@92 93 .catted_reads
kkonganti@92 94 .mix( reads.single )
kkonganti@92 95 .set { processed_reads }
kkonganti@92 96
kkonganti@92 97 if (params.fq_filter_by_len.toInteger() > 0) {
kkonganti@92 98 SEQKIT_SEQ( processed_reads )
kkonganti@92 99 .fastx
kkonganti@92 100 .set { processed_reads }
kkonganti@92 101
kkonganti@92 102 versions.mix( SEQKIT_SEQ.out.versions.first().ifEmpty(null) )
kkonganti@92 103 .set { versions }
kkonganti@92 104 }
kkonganti@92 105
kkonganti@92 106 versions.mix(
kkonganti@92 107 SAMPLESHEET_CHECK.out.versions,
kkonganti@92 108 CAT_FASTQ.out.versions.first().ifEmpty(null)
kkonganti@92 109 )
kkonganti@92 110 .set { versions }
kkonganti@92 111
kkonganti@92 112 emit:
kkonganti@92 113 processed_reads
kkonganti@92 114 versions
kkonganti@92 115 }
kkonganti@92 116
kkonganti@92 117 // Function to get list of [ meta, [ fq1, fq2 ] ]
kkonganti@92 118 def create_fastq_channel(LinkedHashMap row) {
kkonganti@92 119
kkonganti@92 120 def meta = [:]
kkonganti@92 121 meta.id = row.sample
kkonganti@92 122 meta.single_end = row.single_end.toBoolean()
kkonganti@92 123 meta.strandedness = row.strandedness
kkonganti@92 124 meta.id = meta.id.split(params.fq_filename_delim)[0..params.fq_filename_delim_idx.toInteger() - 1]
kkonganti@92 125 .join(params.fq_filename_delim)
kkonganti@92 126 meta.id = (meta.id =~ /\./ ? meta.id.take(meta.id.indexOf('.')) : meta.id)
kkonganti@92 127
kkonganti@92 128 def array = []
kkonganti@92 129
kkonganti@92 130 if (!file(row.fq1).exists()) {
kkonganti@92 131 stopNow("Please check input metadata CSV. The following Read 1 FASTQ file does not exist!" +
kkonganti@92 132 "\n${row.fq1}")
kkonganti@92 133 }
kkonganti@92 134 if (meta.single_end) {
kkonganti@92 135 array = [ meta, [ file(row.fq1) ] ]
kkonganti@92 136 } else {
kkonganti@92 137 if (!file(row.fq2).exists()) {
kkonganti@92 138 stopNow("Please check input metadata CSV. The following Read 2 FASTQ file does not exist!" +
kkonganti@92 139 "\n${row.fq2}")
kkonganti@92 140 }
kkonganti@92 141 array = [ meta, [ file(row.fq1), file(row.fq2) ] ]
kkonganti@92 142 }
kkonganti@92 143 return array
kkonganti@92 144 }