Skip to content

Commit

Permalink
Merge pull request #132 from pinin4fjords/fix_excluded_samples
Browse files Browse the repository at this point in the history
Fix up sample exclusion options
  • Loading branch information
pinin4fjords authored Jul 25, 2023
2 parents 0ba8a56 + 8a91954 commit 28f0ae0
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 46 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [[#130](https://github.com/nf-core/differentialabundance/pull/130)] - Document reasons for lack of differential expression ([@pinin4fjords](https://github.com/pinin4fjords), review by [@jfy133](https://github.com/jfy133))
- [[#131](https://github.com/nf-core/differentialabundance/pull/131)] - Improve gtf to table configurability ([@pinin4fjords](https://github.com/pinin4fjords), review by [@WackerO](https://github.com/WackerO))
- [[#137](https://github.com/nf-core/differentialabundance/pull/137)] - Add `--sizefactors_from_controls` and `--gene_id_col` for DESeq2 module to modules.config ([@WackerO](https://github.com/WackerO), review by [@pinin4fjords](https://github.com/pinin4fjords))
- [[#145](https://github.com/nf-core/differentialabundance/pull/145)] - Template update for nf-core/tools v2.9 ([@nf-core-bot](https://github.com/nf-core-bot), review by [@pinin4fjords](https://github.com/pinin4fjords), [@WackerO](https://github.com/WackerO))

### `Fixed`

- [[#116](https://github.com/nf-core/differentialabundance/issues/116)] - Skip outlier detection with low replication ([@pinin4fjords](https://github.com/pinin4fjords), review by [@nvnieuwk](https://github.com/nvnieuwk))
- [[#122](https://github.com/nf-core/differentialabundance/pull/126)] - Add spaces to satisfy nf-core download for singularity ([@pinin4fjords](https://github.com/pinin4fjords), review by [@WackerO](https://github.com/WackerO))
- [[#127](https://github.com/nf-core/differentialabundance/issues/127)] - [Bug] Can't pass samplesheet with -c file.config , or -params-file params.yml or directly with --input samplesheet.csv ([@ctuni](https://github.com/ctuni), review by [@pinin4fjords](https://github.com/pinin4fjords))
- [[#138 ](https://github.com/nf-core/differentialabundance/issues/138)]- Fix bugs with --control_features and --sizefactors_from_controls ([@WackerO](https://github.com/WackerO), review by [@pinin4fjords](https://github.com/pinin4fjords))
- [[#138](https://github.com/nf-core/differentialabundance/issues/138)]- Fix bugs with --control_features and --sizefactors_from_controls ([@WackerO](https://github.com/WackerO), review by [@pinin4fjords](https://github.com/pinin4fjords))
- [[#133](https://github.com/nf-core/differentialabundance/issues/133)] - Sample exclusion options fail due to contrast-wise normalisation ([@pinin4fjords](https://github.com/pinin4fjords), review by [@WackerO](https://github.com/WackerO))

## v1.2.0 - 2023-04-19

Expand Down
28 changes: 20 additions & 8 deletions assets/differentialabundance_report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ treatment-mCherry-hND6-batcheffect.deseq2.results.tsv

```{r, echo=FALSE}
prefix_part_names <- c('variable', 'reference', 'target', 'blocking')
diff_prefixes <- sub('-$', '', apply(contrasts[,prefix_part_names], 1, function(x) paste(x, collapse = '-')))
differential_files <- lapply(diff_prefixes, function(d){
differential_files <- lapply(contrasts$id, function(d){
file.path(params$input_dir, paste0(gsub(' |;', '_', d), params$differential_file_suffix))
})
Expand Down Expand Up @@ -328,16 +325,31 @@ differential_results <- lapply(differential_files, function(diff_file){
}
diff
})
names(differential_results) <- diff_prefixes
names(differential_results) <- contrasts$id
```

<!-- Calculate some summary statistics -->

```{r, echo=FALSE}
contrast_descriptions <- paste(contrasts$target, 'versus', contrasts$reference, 'in', contrasts$variable)
with_blocking <- which(contrasts$blocking != '')
contrast_descriptions[with_blocking] <- paste0(contrast_descriptions[with_blocking], " (blocking on ", contrasts$blocking[with_blocking],")")
# Function to make friendly contrast name from contrast components, including optional bits
name_contrast <- function(i){
contrast_name <- paste(contrasts$target[i], 'versus', contrasts$reference[i], 'in', contrasts$variable[i])
contrast_vals <- contrasts[i,]
populated <- colnames(contrasts)[! (is.na(contrast_vals) | contrast_vals == '' | is.null(contrast_vals))]
optional <- setdiff(populated, c('id', 'target', 'reference', 'variable'))
if (length(optional) > 0){
optional_part <- paste0('(', paste(paste(optional, contrasts[i,optional], sep=': '), collapse=', '), ')')
}else{
optional_part <- ''
}
paste(contrast_name, optional_part)
}
contrast_descriptions <- unlist(lapply(1:nrow(contrasts), function(x) name_contrast(x)))
# Check both adjusted and unadjusted p values
Expand Down
39 changes: 34 additions & 5 deletions conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,45 @@ process {
].join(' ').trim() }
}

withName: DESEQ2_DIFFERENTIAL {
withName: DESEQ2_NORM {
ext.prefix = 'all'
publishDir = [
[
path: { "${params.outdir}/tables/differential" },
path: { "${params.outdir}/tables/processed_abundance" },
mode: params.publish_dir_mode,
pattern: '*.deseq2.results.tsv'
pattern: '*.{normalised_counts,vst,rlog}.tsv'
],
]
ext.args = { [
"--sample_id_col \"${params.observations_id_col}\"",
"--test $params.deseq2_test",
"--fit_type $params.deseq2_fit_type",
"--sf_type $params.deseq2_sf_type",
"--min_replicates_for_replace $params.deseq2_min_replicates_for_replace",
"--use_t $params.deseq2_use_t",
"--lfc_threshold $params.deseq2_lfc_threshold",
"--alt_hypothesis $params.deseq2_alt_hypothesis",
"--independent_filtering $params.deseq2_independent_filtering",
"--p_adjust_method $params.deseq2_p_adjust_method",
"--alpha $params.deseq2_alpha",
"--minmu $params.deseq2_minmu",
"--vs_method $params.deseq2_vs_method",
"--vs_blind $params.deseq2_vs_blind",
"--vst_nsub $params.deseq2_vst_nsub",
"--shrink_lfc $params.deseq2_shrink_lfc",
"--cores $params.deseq2_cores",
"--subset_to_contrast_samples $params.differential_subset_to_contrast_samples",
((meta.blocking == null) ? '' : "--blocking_variables $meta.blocking"),
].join(' ').trim() }
}

withName: DESEQ2_DIFFERENTIAL {
ext.prefix = { "${meta.id}" }
publishDir = [
[
path: { "${params.outdir}/tables/processed_abundance" },
path: { "${params.outdir}/tables/differential" },
mode: params.publish_dir_mode,
pattern: '*.{normalised_counts,vst,rlog}.tsv'
pattern: '*.deseq2.results.tsv'
],
[
path: { "${params.outdir}/plots/qc" },
Expand Down Expand Up @@ -151,6 +179,7 @@ process {
}

withName: LIMMA_DIFFERENTIAL {
ext.prefix = { "${meta.id}" }
publishDir = [
[
path: { "${params.outdir}/tables/differential" },
Expand Down
8 changes: 4 additions & 4 deletions modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"nf-core": {
"affy/justrma": {
"branch": "master",
"git_sha": "911696ea0b62df80e900ef244d7867d177971f73",
"git_sha": "d0b4fc03af52a1cc8c6fb4493b921b57352b1dd8",
"installed_by": ["modules"]
},
"atlasgeneannotationmanipulation/gtf2featureannotation": {
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"deseq2/differential": {
"branch": "master",
"git_sha": "911696ea0b62df80e900ef244d7867d177971f73",
"git_sha": "d0b4fc03af52a1cc8c6fb4493b921b57352b1dd8",
"installed_by": ["modules"]
},
"gsea/gsea": {
Expand All @@ -52,7 +52,7 @@
},
"limma/differential": {
"branch": "master",
"git_sha": "911696ea0b62df80e900ef244d7867d177971f73",
"git_sha": "d0b4fc03af52a1cc8c6fb4493b921b57352b1dd8",
"installed_by": ["modules"]
},
"rmarkdownnotebook": {
Expand Down Expand Up @@ -82,7 +82,7 @@
},
"untar": {
"branch": "master",
"git_sha": "5c460c5a4736974abde2843294f35307ee2b0e5e",
"git_sha": "d0b4fc03af52a1cc8c6fb4493b921b57352b1dd8",
"installed_by": ["modules"]
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/nf-core/affy/justrma/main.nf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions modules/nf-core/deseq2/differential/templates/deseq_de.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions modules/nf-core/limma/differential/templates/limma_de.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modules/nf-core/untar/main.nf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions workflows/differentialabundance.nf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ include { SHINYNGS_APP } from '../modules/n
include { SHINYNGS_STATICEXPLORATORY as PLOT_EXPLORATORY } from '../modules/nf-core/shinyngs/staticexploratory/main'
include { SHINYNGS_STATICDIFFERENTIAL as PLOT_DIFFERENTIAL } from '../modules/nf-core/shinyngs/staticdifferential/main'
include { SHINYNGS_VALIDATEFOMCOMPONENTS as VALIDATOR } from '../modules/nf-core/shinyngs/validatefomcomponents/main'
include { DESEQ2_DIFFERENTIAL as DESEQ2_NORM } from '../modules/nf-core/deseq2/differential/main'
include { DESEQ2_DIFFERENTIAL } from '../modules/nf-core/deseq2/differential/main'
include { LIMMA_DIFFERENTIAL } from '../modules/nf-core/limma/differential/main'
include { CUSTOM_MATRIXFILTER } from '../modules/nf-core/custom/matrixfilter/main'
Expand Down Expand Up @@ -270,6 +271,14 @@ workflow DIFFERENTIALABUNDANCE {
}
else{

//

DESEQ2_NORM (
ch_contrasts.first(),
ch_samples_and_matrix,
ch_control_features
)

// Run the DESeq differential module, which doesn't take the feature
// annotations

Expand All @@ -278,16 +287,16 @@ workflow DIFFERENTIALABUNDANCE {
ch_samples_and_matrix,
ch_control_features
)

// Let's make the simplifying assumption that the processed matrices from
// the DESeq runs are the same across contrasts. We run the DESeq process
// with matrices once for each contrast because DESeqDataSetFromMatrix()
// takes the model, and the model can vary between contrasts if the
// blocking factors included differ. But the normalised and
// variance-stabilised matrices are not (IIUC) impacted by the model.

ch_norm = DESEQ2_DIFFERENTIAL.out.normalised_counts.first()
ch_vst = DESEQ2_DIFFERENTIAL.out.vst_counts.first()
ch_norm = DESEQ2_NORM.out.normalised_counts
ch_vst = DESEQ2_NORM.out.vst_counts
ch_differential = DESEQ2_DIFFERENTIAL.out.results

ch_versions = ch_versions
Expand Down

0 comments on commit 28f0ae0

Please sign in to comment.