@@ -789,27 +789,38 @@ workflow DIFFERENTIALABUNDANCE {
789789 .groupTuple() // [ meta, [meta with contrast], [functional results] ]
790790 .map { [it[0 ], it. tail(). tail(). flatten()] } // [ meta, [functional results] ]
791791
792- // If users provide a `report_grouping_variable` then update the contrasts file 'variable' column with that information
792+ // If users provide a `report_grouping_variable` then update the contrasts file 'variable' column with that information
793+ // Split the CSV once at the start
794+ ch_split = ch_validated_contrast
795+ .splitCsv(header : true , sep : ' \t ' )
796+
797+ // If the user provided a grouping variable, fill missing/NA values
793798 if (params. report_grouping_variable) {
794- ch_validated_contrast = ch_validated_contrast
795- .splitCsv(header : true , sep : ' \t ' )
799+ ch_split = ch_split
796800 .map { meta, row ->
797801 def variable = row. variable?. trim()
798802 if (! variable || variable == ' NA' ) {
799803 row. variable = params. report_grouping_variable
800804 }
801805 [meta, row]
802806 }
803- .groupTuple()
804- .map { meta, rows ->
805- def header = rows[0 ]. keySet(). join(' \t ' )
806- def lines = rows. collect { it. values(). join(' \t ' ) }
807- def content = ([header] + lines). join(' \n ' )
808- def outFile = file(" ${ workflow.workDir} /${ meta.id ?: meta.paramset_name} _contrast_variable_filled.tsv" )
809- outFile. text = content
810- [meta, outFile]
811- }
812807 }
808+
809+ // Now remove any rows where variable is still empty
810+ ch_validated_contrast = ch_split
811+ .filter { meta, row ->
812+ def variable = row. variable?. trim()
813+ variable
814+ }
815+ .groupTuple()
816+ .map { meta, rows ->
817+ def header = rows[0 ]. keySet(). join(' \t ' )
818+ def lines = rows. collect { it. values(). join(' \t ' ) }
819+ def content = ([header] + lines). join(' \n ' )
820+ def outFile = file(" ${ workflow.workDir} /${ meta.id ?: meta.paramset_name} _contrast_variable_filled.tsv" )
821+ outFile. text = content
822+ [meta, outFile]
823+ }
813824 // Prepare input for report generation
814825 // Each paramset will generate one markdown report by gathering all the files created with the same paramset
815826
0 commit comments