Skip to content

Commit

Permalink
Create RSQ plot from results
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Jun 17, 2024
1 parent c8487ef commit 2af2796
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 10 deletions.
9 changes: 5 additions & 4 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,11 +20,12 @@ 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
- openjdk=11.0.9
- unzip=6.0
- bioconductor-ramwas=1.16.0
- bedtools=2.30.0
- csvtk=0.26.0
52 changes: 52 additions & 0 deletions files/rsq-report.Rmd
Original file line number Diff line number Diff line change
@@ -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)
```

<small>
This report has been created with **`r params$service`**.
</small>
3 changes: 2 additions & 1 deletion modules/local/calculate_rsq.nf
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
"""
}
29 changes: 29 additions & 0 deletions modules/local/plot_rsq.nf
Original file line number Diff line number Diff line change
@@ -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'
)"
"""

}
10 changes: 6 additions & 4 deletions nextflow.config
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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'
}

// 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
Expand Down
10 changes: 9 additions & 1 deletion workflows/rsq.nf
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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)
)

}

Expand Down

0 comments on commit 2af2796

Please sign in to comment.