Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiqc metrics #14

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## v1.2.0dev

### New features

1. The metrics are now in the multiqc report instead of in a separate file

### Changes

1. Updated the pipeline template to nf-core v2.13.1
Expand Down
29 changes: 28 additions & 1 deletion main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ include { getGenomeAttribute } from './subworkflows/local/utils_nfcore_wise
params.fasta = getGenomeAttribute('fasta')
params.fai = getGenomeAttribute('fai')

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADDITIONAL INPUT VALIDATION
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

def List val_bin_sizes = params.bin_sizes.split(",").collect { it as Integer }
def Integer lowestBinSize = val_bin_sizes.min()
val_bin_sizes.each { bin_size ->
if(bin_size % lowestBinSize != 0) {
error("""
All bin sizes should be divisible by the lowest bin size!
${bin_size} is not divisible by ${lowestBinSize}...
""")
}
}


/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMPORT FUNCTIONS / MODULES / SUBWORKFLOWS / WORKFLOWS
Expand Down Expand Up @@ -53,7 +71,16 @@ workflow NFCMGG_WISECONDORX {
// WORKFLOW: Run pipeline
//
WISECONDORX (
samplesheet
samplesheet,
params.fasta,
params.fai,
val_bin_sizes,
params.no_metrics,
params.prefix,
params.outdir,
params.multiqc_config,
params.multiqc_logo,
params.multiqc_methods_description ? file(params.multiqc_methods_description, checkIfExists: true) : file("$projectDir/assets/methods_description_template.yml", checkIfExists: true)
)

emit:
Expand Down
2 changes: 1 addition & 1 deletion tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ nextflow_pipeline {
input = "${projectDir}/tests/inputs/samplesheet.csv"
outdir = "${outputDir}"
prefix = "test_reference"
bin_sizes = "10000,5"
bin_sizes = "10,5"
max_cpus = 2
max_memory = '6.GB'
max_time = '6.h'
Expand Down
3 changes: 1 addition & 2 deletions tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

],
[
"metrics.txt:md5,bdb678960431c256e283e21d6e1db1ed",
[
[

Expand All @@ -14,7 +13,7 @@
"multiqc_report.html:md5,d41d8cd98f00b204e9800998ecf8427e"
],
"test_reference_10kbp.npz:md5,d41d8cd98f00b204e9800998ecf8427e",
"test_reference_5bp.npz:md5,d41d8cd98f00b204e9800998ecf8427e"
"test_reference_5kbp.npz:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"meta": {
Expand Down
64 changes: 37 additions & 27 deletions workflows/wisecondorx.nf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ include { methodsDescriptionText } from '../subworkflows/local/utils_nfcore
workflow WISECONDORX {

take:
ch_samplesheet // channel: samplesheet read in from --input
ch_samplesheet // queue channel: samplesheet read in from --input
fasta // string: the reference fasta file
fai // string: the index of the reference fasta file
val_bin_sizes // list: a list of bin sizes to use
no_metrics // boolean: deactivate the generation of metrics
prefix // string: the prefix to be used by the output file
outdir // string: the path of the output directory
multiqc_config // string: the path to the multiqc config
multiqc_logo // string: the path to the multiqc logo
multiqc_methods_description // file: the file containing the multiqc custom method descriptions

main:

Expand All @@ -35,11 +44,11 @@ workflow WISECONDORX {
// Create optional input files
//

ch_fasta = Channel.fromPath(params.fasta, checkIfExists:true)
.map { [[id:params.genome ?: "fasta"], it] }
ch_fasta = Channel.fromPath(fasta, checkIfExists:true)
.map { [[id:"fasta"], it] }
.collect()

if(!params.fai) {
if(!fai) {
SAMTOOLS_FAIDX(
ch_fasta,
[[],[]]
Expand All @@ -49,8 +58,8 @@ workflow WISECONDORX {
SAMTOOLS_FAIDX.out.fai
.set { ch_fai }
} else {
ch_fai = Channel.fromPath(params.fai, checkIfExists:true)
.map { [[id:params.genome ?: "fasta"], it] }
ch_fai = Channel.fromPath(fai, checkIfExists:true)
.map { [[id:"fasta"], it] }
.collect()
}

Expand All @@ -76,7 +85,7 @@ workflow WISECONDORX {
.mix(ch_input.indexed)
.set { ch_indexed }

if(!params.no_metrics){
if(!no_metrics){

//
// Define the gender if it's not given
Expand Down Expand Up @@ -119,6 +128,10 @@ workflow WISECONDORX {
counts
}
.map { genders -> create_metrics(genders)}
.collectFile(name: "metrics_mqc.tsv")
.set { ch_metrics }

ch_multiqc_files = ch_multiqc_files.mix(ch_metrics)

}

Expand All @@ -143,11 +156,11 @@ workflow WISECONDORX {

WISECONDORX_CONVERT.out.npz
.map { meta, npz ->
new_meta = [id:params.prefix ?: dateFormat]
new_meta = [id:prefix ?: dateFormat]
[ new_meta, npz ]
}
.groupTuple() // All files should be present here, so no size is needed
.combine(params.bin_sizes.split(","))
.combine(val_bin_sizes)
.map { meta, npz, bin_size ->
new_meta = meta + [bin_size:bin_size]
[ new_meta, npz ]
Expand All @@ -161,18 +174,18 @@ workflow WISECONDORX {
// Collate and save software versions
//
softwareVersionsToYAML(ch_versions)
.collectFile(storeDir: "${params.outdir}/pipeline_info", name: 'nf_core_pipeline_software_mqc_versions.yml', sort: true, newLine: true)
.collectFile(storeDir: "${outdir}/pipeline_info", name: 'nf_core_pipeline_software_mqc_versions.yml', sort: true, newLine: true)
.set { ch_collated_versions }

//
// MODULE: MultiQC
//
ch_multiqc_config = Channel.fromPath("$projectDir/assets/multiqc_config.yml", checkIfExists: true)
ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath(params.multiqc_config, checkIfExists: true) : Channel.empty()
ch_multiqc_logo = params.multiqc_logo ? Channel.fromPath(params.multiqc_logo, checkIfExists: true) : Channel.empty()
ch_multiqc_custom_config = multiqc_config ? Channel.fromPath(multiqc_config, checkIfExists: true) : Channel.empty()
ch_multiqc_logo = multiqc_logo ? Channel.fromPath(multiqc_logo, checkIfExists: true) : Channel.empty()
summary_params = paramsSummaryMap(workflow, parameters_schema: "nextflow_schema.json")
ch_workflow_summary = Channel.value(paramsSummaryMultiqc(summary_params))
ch_multiqc_custom_methods_description = params.multiqc_methods_description ? file(params.multiqc_methods_description, checkIfExists: true) : file("$projectDir/assets/methods_description_template.yml", checkIfExists: true)
ch_multiqc_custom_methods_description = multiqc_methods_description
ch_methods_description = Channel.value(methodsDescriptionText(ch_multiqc_custom_methods_description))
ch_multiqc_files = ch_multiqc_files.mix(ch_workflow_summary.collectFile(name: 'workflow_summary_mqc.yaml'))
ch_multiqc_files = ch_multiqc_files.mix(ch_collated_versions)
Expand Down Expand Up @@ -202,20 +215,17 @@ def get_gender(tsv) {
}

def create_metrics(genders) {
male = genders["male"]
female = genders["female"]
male_count = male.size()
female_count = female.size()
total_count = male_count + female_count
ratio_male_to_female = male_count / female_count

output = file("${params.outdir}/metrics.txt")
output.write("Ratio male to female: ${ratio_male_to_female}\n")
output.append("Male count: ${male_count}\n")
output.append("Female count: ${female_count}\n")
output.append("Total count: ${total_count}\n")
output.append("Males: ${male.join(',')}\n")
output.append("Females: ${female.join(',')}\n")
def List male = genders["male"]
def List female = genders["female"]
def Integer male_count = male.size()
def Integer female_count = female.size()
def Float male_to_female_ratio = male_count / female_count
def Integer total_count = male_count + female_count

return """# plot_type: 'table'
Male to female ratio\tMale count\tFemale count\tTotal count\tMales\tFemales
${male_to_female_ratio}\t${male_count}\t${female_count}\t${total_count}\t${male.join(",")}\t${female.join(",")}
"""
}

/*
Expand Down
Loading