diff --git a/environment.yml b/environment.yml index bb26db4..3cd5fe6 100644 --- a/environment.yml +++ b/environment.yml @@ -8,9 +8,9 @@ channels: dependencies: - plink2 - r=4.1.0 - - r-rmarkdown=2.11 - - r-ggplot2=3.3.5 - - r-dplyr=1.0.7 + - r-rmarkdown=2.16 + - r-ggplot2=3.3.6 + - r-dplyr=1.1.0 - r-dt=0.19 - r-qqman=0.1.8 - r-htmltools=0.5.2 @@ -20,7 +20,7 @@ dependencies: - r-data.table=1.14.0 - r-r.utils=2.10.1 - r-ggrepel=0.9.1 - - pandoc=2.14.2 + - pandoc=2.19.2 - cairo=1.16.0 - xorg-libxt=1.2.1 - fonts-anaconda=1 @@ -28,3 +28,4 @@ dependencies: - unzip=6.0 - bioconductor-ramwas=1.16.0 - bedtools=2.30.0 + - csvtk=0.26.0 diff --git a/files/rsq-report.Rmd b/files/rsq-report.Rmd new file mode 100644 index 0000000..b11883b --- /dev/null +++ b/files/rsq-report.Rmd @@ -0,0 +1,52 @@ +--- +title: "Imputation Quality Report" +output: + rmdformats::robobook: + self_contained: true + thumbnails: false + lightbox: true + gallery: false + highlight: tango +params: + input: "" + name: "" + population: "" + version: "" + date: "" + service: "" +--- + +```{r setup, echo=FALSE, include=FALSE} + +library(ggplot2) +library(dplyr) +``` + +## Parameters + +| Parameter | Value | +|------------------|-----------------------------| +| Job | `r params$name` | +| Pipeline Version | `r params$version` | +| Date | `r params$date` | + +## RSQ Plot +```{r echo=FALSE} +dataset = read.csv(params$input, row.names=NULL, sep = '\t') +dataset_weighted = dataset %>% + group_by ( + X.Bin.Aggregated.by.MAF + ) %>% + summarise ( + mean_MAF = mean(Average.MAF), + variants_sum = sum(X.Variants), + weighted_R2 = weighted.mean(Imputation.R2,X.Variants) + ) + +ggplot() + geom_line(data = dataset_weighted, mapping = aes(x = mean_MAF, y= weighted_R2)) + scale_x_log10() + expand_limits(x = 0, y = 0) + +``` + + +This report has been created with **`r params$service`**. + diff --git a/modules/local/calculate_rsq.nf b/modules/local/calculate_rsq.nf index 47bd761..023c676 100644 --- a/modules/local/calculate_rsq.nf +++ b/modules/local/calculate_rsq.nf @@ -1,6 +1,6 @@ process CALCULATE_RSQ { - publishDir "${params.pubDir}/aggRSquare", mode: 'copy', pattern: '*aggRSquare' + publishDir "${params.pubDir}/rsq", mode: 'copy', pattern: '*aggRSquare' input: tuple val(chr), path(dosage_data), path(sequence_data) @@ -11,5 +11,6 @@ process CALCULATE_RSQ { """ aggRSquare -v ${sequence_data} -i ${dosage_data} -o ${sequence_data.baseName} --d + sed -i '/^##/d' ${sequence_data.baseName}.aggRSquare """ } diff --git a/modules/local/plot_rsq.nf b/modules/local/plot_rsq.nf new file mode 100644 index 0000000..bce7760 --- /dev/null +++ b/modules/local/plot_rsq.nf @@ -0,0 +1,29 @@ +process PLOT_RSQ { + + publishDir "${params.pubDir}/rsq", mode: 'copy', pattern: '*html' + + input: + path(agg_rsq) + path(rsq_report) + + output: + path("*.html") + + script: + """ + csvtk concat -C '\$' -t -T $agg_rsq -o combined.txt + + Rscript -e "require( 'rmarkdown' ); render('${rsq_report}', + params = list( + input = 'combined.txt', + name = '${params.project}', + version = paste('${workflow.manifest.name}', '(v${workflow.manifest.version})'), + date = '${params.project_date}' + ), + intermediates_dir='\$PWD', + knit_root_dir='\$PWD', + output_file='\$PWD/rsq-report.html' + )" + """ + +} diff --git a/nextflow.config b/nextflow.config index a086f8a..7ab8ea1 100644 --- a/nextflow.config +++ b/nextflow.config @@ -1,9 +1,9 @@ manifest { name = 'microarray-eval-nf' - version = '0.0.2' - description = 'Nextflow pipeline to eval microarray chips' + version = '0.1.0' + description = 'Nextflow pipeline to evaluate imputation quality' author = 'Sebastian Schönherr, Lukas Forer, Martin Eberle' - homePage = 'https://github.com/seppinho/exome-cnv-nf' + homePage = 'https://github.com/genepi/microarray-eval-nf' mainScript = 'main.nf' nextflowVersion = '!>=21.04.0' } @@ -11,8 +11,10 @@ manifest { // Global default params, used in configs params { + project_date = "`date`" //Required inputs - wf = null + + workflow_name = null project = null sequence_data = null dosage_data = null diff --git a/workflows/rsq.nf b/workflows/rsq.nf index 4004044..e728bef 100644 --- a/workflows/rsq.nf +++ b/workflows/rsq.nf @@ -1,5 +1,6 @@ include { LIFT_OVER } from '../modules/local/lift_over' include { CALCULATE_RSQ } from '../modules/local/calculate_rsq' +include { PLOT_RSQ } from '../modules/local/plot_rsq' workflow RSQ { @@ -25,7 +26,14 @@ workflow RSQ { r2_input_data_lifted = r2_input_data_combined } - CALCULATE_RSQ ( r2_input_data_lifted ) + CALCULATE_RSQ ( + r2_input_data_lifted + ) + + PLOT_RSQ ( + CALCULATE_RSQ.out.agg_rsquare.collect(), + file("$baseDir/files/rsq-report.Rmd", checkIfExists: true) + ) }