-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
284 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import pandas as pd | ||
import sys | ||
|
||
tax_file = sys.argv[1] | ||
out_file = sys.argv[2] | ||
|
||
# Import tsv file | ||
tax_df = pd.read_csv(tax_file, sep="\t") | ||
|
||
# The second column should hold the taxonomy information | ||
tax_col = tax_df.columns[1] | ||
|
||
# Split the values in the tax column | ||
split_tax = tax_df[tax_col].str.split(";", expand=True) | ||
|
||
# Assign names to the new columns with an auto incrementing integer | ||
new_col_names = [f"{tax_col}_{i+1}" for i in range(split_tax.shape[1])] | ||
split_tax.columns = new_col_names | ||
|
||
# Strip whitespace from the tax names | ||
split_tax = split_tax.applymap(lambda x: x.strip() if isinstance(x, str) else x) | ||
|
||
# Drop the original tax column | ||
tax_df = tax_df.drop(columns=[tax_col]) | ||
|
||
# Add the new tax columns to the df | ||
result = pd.concat([tax_df, split_tax], axis=1) | ||
|
||
# Create new tsv file | ||
result.to_csv(out_file, sep="\t", index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
process PHYLOSEQ { | ||
tag "$prefix" | ||
label 'process_low' | ||
|
||
conda "bioconda::bioconductor-phyloseq=1.44.0" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/bioconductor-phyloseq:1.44.0--r43hdfd78af_0' : | ||
'quay.io/biocontainers/bioconductor-phyloseq:1.44.0--r43hdfd78af_0' }" | ||
|
||
input: | ||
tuple val(prefix), path(tax_tsv) | ||
path otu_tsv | ||
path sam_tsv | ||
path tree | ||
|
||
output: | ||
tuple val(prefix), path("*phyloseq.rds"), emit: rds | ||
path "versions.yml" , emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
def sam_tsv = "\"${sam_tsv}\"" | ||
def otu_tsv = "\"${otu_tsv}\"" | ||
def tax_tsv = "\"${tax_tsv}\"" | ||
def tree = "\"${tree}\"" | ||
def prefix = "\"${prefix}\"" | ||
""" | ||
#!/usr/bin/env Rscript | ||
suppressPackageStartupMessages(library(phyloseq)) | ||
otu_df <- read.table($otu_tsv, sep="\\t", header=TRUE, row.names=1) | ||
tax_df <- read.table($tax_tsv, sep="\\t", header=TRUE, row.names=1) | ||
otu_mat <- as.matrix(otu_df) | ||
tax_mat <- as.matrix(tax_df) | ||
OTU <- otu_table(otu_mat, taxa_are_rows=TRUE) | ||
TAX <- tax_table(tax_mat) | ||
phy_obj <- phyloseq(OTU, TAX) | ||
if (file.exists($sam_tsv)) { | ||
sam_df <- read.table($sam_tsv, sep="\\t", header=TRUE, row.names=1) | ||
SAM <- sample_data(sam_df) | ||
phy_obj <- merge_phyloseq(phy_obj, SAM) | ||
} | ||
if (file.exists($tree)) { | ||
TREE <- read_tree($tree) | ||
phy_obj <- merge_phyloseq(phy_obj, TREE) | ||
} | ||
saveRDS(phy_obj, file = paste0($prefix, "_phyloseq.rds")) | ||
# Version information | ||
writeLines(c("\\"${task.process}\\":", | ||
paste0(" R: ", paste0(R.Version()[c("major","minor")], collapse = ".")), | ||
paste0(" phyloseq: ", packageVersion("phyloseq"))), | ||
"versions.yml" | ||
) | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
process PHYLOSEQ_INASV { | ||
label 'process_low' | ||
|
||
conda "conda-forge::sed=4.7" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/ubuntu:20.04' : | ||
'nf-core/ubuntu:20.04' }" | ||
|
||
input: | ||
path(biom_file) | ||
|
||
output: | ||
path( "*.tsv" ) , emit: tsv | ||
path "versions.yml" , emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
""" | ||
tail $biom_file -n +2 | sed '1s/#OTU ID/ASV_ID/' > reformat_$biom_file | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
bash: \$(bash --version | sed -n 1p | sed 's/GNU bash, version //g') | ||
END_VERSIONS | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
process PHYLOSEQ_INTAX { | ||
label 'process_low' | ||
|
||
conda "conda-forge::pandas=1.1.5" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/pandas:1.1.5': | ||
'biocontainers/pandas:1.1.5' }" | ||
|
||
input: | ||
path(tax_tsv) | ||
|
||
output: | ||
path( "*.tsv" ) , emit: tsv | ||
path "versions.yml" , emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
""" | ||
reformat_tax_for_phyloseq.py $tax_tsv reformat_$tax_tsv | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
python: \$(python --version 2>&1 | sed 's/Python //g') | ||
pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)") | ||
END_VERSIONS | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Create phyloseq objects | ||
*/ | ||
|
||
include { PHYLOSEQ } from '../../modules/local/phyloseq' | ||
include { PHYLOSEQ_INASV } from '../../modules/local/phyloseq_inasv' | ||
|
||
workflow PHYLOSEQ_WORKFLOW { | ||
take: | ||
ch_tax | ||
ch_tsv | ||
ch_meta | ||
ch_tree | ||
run_qiime2 | ||
|
||
main: | ||
if ( params.metadata ) { | ||
ch_phyloseq_inmeta = ch_meta.first() // The .first() is to make sure it's a value channel | ||
} else { | ||
ch_phyloseq_inmeta = [] | ||
} | ||
|
||
if ( params.pplace_tree ) { | ||
ch_phyloseq_intree = ch_tree.map { it = it[1] }.first() | ||
} else { | ||
ch_phyloseq_intree = [] | ||
} | ||
|
||
if ( run_qiime2 ) { | ||
if ( params.exclude_taxa != "none" || params.min_frequency != 1 || params.min_samples != 1 ) { | ||
ch_phyloseq_inasv = PHYLOSEQ_INASV ( ch_tsv ).tsv | ||
} else { | ||
ch_phyloseq_inasv = ch_tsv | ||
} | ||
} else { | ||
ch_phyloseq_inasv = ch_tsv | ||
} | ||
|
||
PHYLOSEQ ( ch_tax, ch_phyloseq_inasv, ch_phyloseq_inmeta, ch_phyloseq_intree ) | ||
|
||
emit: | ||
rds = PHYLOSEQ.out.rds | ||
versions= PHYLOSEQ.out.versions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.