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

fix --metadata_category #451

Merged
merged 4 commits into from
Jun 13, 2022
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### `Fixed`

- [#451](https://github.com/nf-core/ampliseq/pull/451) - Pairwise statistics will be now performed on a subset of metadata columns specified with `--metadata_category` instead of ignoring that setting.
- [#451](https://github.com/nf-core/ampliseq/pull/451) - Replace busybox with Ubuntu base image for GCP support.

### `Dependencies`

### `Removed`
Expand Down
4 changes: 2 additions & 2 deletions modules/local/format_taxonomy.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ process FORMAT_TAXONOMY {

conda (params.enable_conda ? "conda-forge::sed=4.7" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://containers.biocontainers.pro/s3/SingImgsRepo/biocontainers/v1.2.0_cv1/biocontainers_v1.2.0_cv1.img' :
'biocontainers/biocontainers:v1.2.0_cv1' }"
'https://depot.galaxyproject.org/singularity/ubuntu:20.04' :
'ubuntu:20.04' }"

input:
path(database)
Expand Down
4 changes: 2 additions & 2 deletions modules/local/format_taxonomy_qiime.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ process FORMAT_TAXONOMY_QIIME {

conda (params.enable_conda ? "conda-forge::sed=4.7" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://containers.biocontainers.pro/s3/SingImgsRepo/biocontainers/v1.2.0_cv1/biocontainers_v1.2.0_cv1.img' :
'biocontainers/biocontainers:v1.2.0_cv1' }"
'https://depot.galaxyproject.org/singularity/ubuntu:20.04' :
'ubuntu:20.04' }"

input:
path(database)
Expand Down
21 changes: 7 additions & 14 deletions modules/local/metadata_all.nf
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@ process METADATA_ALL {

input:
path(metadata)
val(metadata_category)

output:
stdout

script:
if( !metadata_category ) {
"""
metadata_all.r ${metadata}
"""
metadata_all.r ${metadata}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
R: \$(R --version 2>&1 | sed -n 1p | sed 's/R version //' | sed 's/ (.*//')
END_VERSIONS
"""
} else {
"""
printf ${metadata_category}
"""
}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
R: \$(R --version 2>&1 | sed -n 1p | sed 's/R version //' | sed 's/ (.*//')
END_VERSIONS
"""
}
40 changes: 14 additions & 26 deletions modules/local/qiime2_diversity_alpha.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,26 @@ process QIIME2_DIVERSITY_ALPHA {
container "quay.io/qiime2/core:2021.8"

input:
tuple path(metadata), path(core), val(category)
tuple path(metadata), path(core)

output:
path("alpha_diversity/*"), emit: alpha
path "versions.yml" , emit: versions

script:
if ( category.length() > 0 ) {
"""
export XDG_CONFIG_HOME="\${PWD}/HOME"
"""
export XDG_CONFIG_HOME="\${PWD}/HOME"

qiime diversity alpha-group-significance \
--i-alpha-diversity ${core} \
--m-metadata-file ${metadata} \
--o-visualization ${core.baseName}-vis.qzv
qiime tools export --input-path ${core.baseName}-vis.qzv \
--output-path "alpha_diversity/${core.baseName}"
qiime diversity alpha-group-significance \
--i-alpha-diversity ${core} \
--m-metadata-file ${metadata} \
--o-visualization ${core.baseName}-vis.qzv
qiime tools export --input-path ${core.baseName}-vis.qzv \
--output-path "alpha_diversity/${core.baseName}"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
} else {
"""
mkdir alpha_diversity
echo "" > "alpha_diversity/WARNING No column in ${metadata.baseName} seemed suitable.txt"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
}
48 changes: 16 additions & 32 deletions modules/local/qiime2_diversity_beta.nf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
process QIIME2_DIVERSITY_BETA {
tag "${core.baseName}"
tag "${core.baseName} - ${category}"
label 'process_low'

conda (params.enable_conda ? { exit 1 "QIIME2 has no conda package" } : null)
Expand All @@ -13,37 +13,21 @@ process QIIME2_DIVERSITY_BETA {
path "versions.yml" , emit: versions

script:
if ( category.length() > 0 ) {
"""
export XDG_CONFIG_HOME="\${PWD}/HOME"
"""
export XDG_CONFIG_HOME="\${PWD}/HOME"

IFS=',' read -r -a metacategory <<< \"$category\"
for j in \"\${metacategory[@]}\"
do
qiime diversity beta-group-significance \
--i-distance-matrix ${core} \
--m-metadata-file ${metadata} \
--m-metadata-column \"\$j\" \
--o-visualization ${core.baseName}-\$j.qzv \
--p-pairwise
qiime tools export --input-path ${core.baseName}-\$j.qzv \
--output-path beta_diversity/${core.baseName}-\$j
done
qiime diversity beta-group-significance \
--i-distance-matrix ${core} \
--m-metadata-file ${metadata} \
--m-metadata-column \"${category}\" \
--o-visualization ${core.baseName}-${category}.qzv \
--p-pairwise
qiime tools export --input-path ${core.baseName}-${category}.qzv \
--output-path beta_diversity/${core.baseName}-${category}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
} else {
"""
mkdir beta_diversity
echo "" > "beta_diversity/WARNING No column in ${metadata.baseName} seemed suitable.txt"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
}
45 changes: 13 additions & 32 deletions modules/local/qiime2_filterasv.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,25 @@ process QIIME2_FILTERASV {
container "quay.io/qiime2/core:2021.8"

input:
path(metadata)
path(table)
val(category)
tuple path(metadata), path(table), val(category)

output:
path("*.qza") , emit: qza
path "versions.yml" , emit: versions

script:
if ( category.length() > 0 ) {
"""
export XDG_CONFIG_HOME="\${PWD}/HOME"
"""
export XDG_CONFIG_HOME="\${PWD}/HOME"

IFS=',' read -r -a metacategory <<< \"$category\"
qiime feature-table filter-samples \
--i-table ${table} \
--m-metadata-file ${metadata} \
--p-where \"${category}<>\'\'\" \
--o-filtered-table ${category}.qza

#remove samples that do not have any value
for j in \"\${metacategory[@]}\"
do
qiime feature-table filter-samples \
--i-table ${table} \
--m-metadata-file ${metadata} \
--p-where \"\$j<>\'\'\" \
--o-filtered-table \$j.qza
done

cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
} else {
"""
mkdir beta_diversity
echo "" > "WARNING No column in ${metadata.baseName} seemed suitable.qza"
cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
qiime2: \$( qiime --version | sed -e "s/q2cli version //g" | tr -d '`' | sed -e "s/Run qiime info for more version details.//g" )
END_VERSIONS
"""
}
4 changes: 2 additions & 2 deletions modules/local/rename_raw_data_files.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ process RENAME_RAW_DATA_FILES {

conda (params.enable_conda ? "conda-forge::sed=4.7" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://containers.biocontainers.pro/s3/SingImgsRepo/biocontainers/v1.2.0_cv1/biocontainers_v1.2.0_cv1.img' :
'biocontainers/biocontainers:v1.2.0_cv1' }"
'https://depot.galaxyproject.org/singularity/ubuntu:20.04' :
'ubuntu:20.04' }"

input:
tuple val(meta), path(reads)
Expand Down
8 changes: 6 additions & 2 deletions subworkflows/local/qiime2_ancom.nf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ workflow QIIME2_ANCOM {

main:
//Filter ASV table to get rid of samples that have no metadata values
QIIME2_FILTERASV ( ch_metadata, ch_asv, ch_metacolumn_all )
ch_metadata
.combine( ch_asv )
.combine( ch_metacolumn_all )
.set{ ch_for_filterasv }
QIIME2_FILTERASV ( ch_for_filterasv )

//ANCOM on various taxonomic levels
ch_taxlevel = Channel.from( tax_agglom_min..tax_agglom_max )
ch_metadata
.combine( QIIME2_FILTERASV.out.qza.flatten() )
.combine( QIIME2_FILTERASV.out.qza )
.combine( ch_tax )
.combine( ch_taxlevel )
.set{ ch_for_ancom_tax }
Expand Down
3 changes: 1 addition & 2 deletions subworkflows/local/qiime2_diversity.nf
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ workflow QIIME2_DIVERSITY {
//Print warning if rarefaction depth is <10000
QIIME2_DIVERSITY_CORE.out.depth.subscribe { if ( it.baseName.toString().startsWith("WARNING") ) log.warn it.baseName.toString().replace("WARNING ","QIIME2_DIVERSITY_CORE: ") }

//alpha_diversity ( ch_metadata, DIVERSITY_CORE.out.qza, ch_metacolumn_all )
//alpha_diversity ( ch_metadata, DIVERSITY_CORE.out.qza )
ch_metadata
.combine( QIIME2_DIVERSITY_CORE.out.vector.flatten() )
.combine( ch_metacolumn_all )
.set{ ch_to_diversity_alpha }
QIIME2_DIVERSITY_ALPHA ( ch_to_diversity_alpha )

Expand Down
14 changes: 9 additions & 5 deletions workflows/ampliseq.nf
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ if ( !is_fasta_input && (!params.FW_primer || !params.RV_primer) && !params.skip
System.exit(1)
}

metadata_category = params.metadata_category ?: ""

//only run QIIME2 when taxonomy is actually calculated and all required data is available
if ( !params.enable_conda && !params.skip_taxonomy && !params.skip_qiime ) {
run_qiime2 = true
Expand Down Expand Up @@ -546,13 +544,19 @@ workflow AMPLISEQ {
}

//Select metadata categories for diversity analysis & ancom
if (!params.skip_ancom || !params.skip_diversity_indices) {
METADATA_ALL ( ch_metadata, metadata_category ).set { ch_metacolumn_all }
if (params.metadata_category) {
ch_metacolumn_all = Channel.from(params.metadata_category.tokenize(','))
METADATA_PAIRWISE ( ch_metadata ).set { ch_metacolumn_pairwise }
ch_metacolumn_pairwise = ch_metacolumn_pairwise.splitCsv().flatten()
ch_metacolumn_pairwise = ch_metacolumn_all.join(ch_metacolumn_pairwise)
} else if (!params.skip_ancom || !params.skip_diversity_indices) {
METADATA_ALL ( ch_metadata ).set { ch_metacolumn_all }
//return empty channel if no appropriate column was found
ch_metacolumn_all.branch { passed: it != "" }.set { result }
ch_metacolumn_all = result.passed

ch_metacolumn_all = ch_metacolumn_all.splitCsv().flatten()
METADATA_PAIRWISE ( ch_metadata ).set { ch_metacolumn_pairwise }
ch_metacolumn_pairwise = ch_metacolumn_pairwise.splitCsv().flatten()
} else {
ch_metacolumn_all = Channel.empty()
ch_metacolumn_pairwise = Channel.empty()
Expand Down