Skip to content

Commit

Permalink
Allow Nextflow to manage Docker FS mounts
Browse files Browse the repository at this point in the history
Former-commit-id: 3d787f8
  • Loading branch information
HarryHung committed Mar 7, 2023
1 parent b7bdc86 commit 9011f80
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 37 deletions.
22 changes: 8 additions & 14 deletions modules/lineage.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@ process GET_POPPUNK_DB {

input:
val db_remote
val local
path local

output:
env POPPUNK_DB_DIR
tuple path(local), env(DB_NAME)

shell:
'''
DB_NAME=$(basename !{db_remote} .tar.gz)
if [ ! -f !{local}/$DB_NAME/done_poppunk_$DB_NAME ] || [ ! -f !{local}/$DB_NAME/$DB_NAME.h5 ]; then
rm -rf !{local}/$DB_NAME
mkdir -p !{local}
wget !{db_remote} -O poppunk_db.tar.gz
tar -xzf poppunk_db.tar.gz -C !{local}
rm poppunk_db.tar.gz
touch !{local}/$DB_NAME/done_poppunk_$DB_NAME
fi
POPPUNK_DB_DIR=!{local}/$DB_NAME
'''
}

Expand All @@ -38,25 +35,22 @@ process GET_POPPUNK_EXT_CLUSTERS {

input:
val ext_clusters_remote
val local
path local

output:
env EXT_CLUSTERS_PATH
env EXT_CLUSTERS_FILE

shell:
'''
EXT_CLUSTERS_FILE=$(basename !{ext_clusters_remote})
if [ ! -f !{local}/$EXT_CLUSTERS_FILE ] || [ ! -f !{local}/done_$EXT_CLUSTERS_FILE ]; then
rm -f !{local}/$EXT_CLUSTERS_FILE
mkdir -p !{local}
rm -f !{local}/$EXT_CLUSTERS_FILE !{local}/done_$EXT_CLUSTERS_FILE
wget !{ext_clusters_remote} -O !{local}/$EXT_CLUSTERS_FILE
touch !{local}/done_$EXT_CLUSTERS_FILE
fi
EXT_CLUSTERS_PATH=!{local}/$EXT_CLUSTERS_FILE
'''
}

Expand All @@ -67,8 +61,8 @@ process LINEAGE {
label 'poppunk_container'

input:
path poppunk_db
path poppunk_ext_clusters
tuple path(poppunk_dir), val(db_name)
val ext_clusters_file
path poppunk_qfile

output:
Expand All @@ -77,7 +71,7 @@ process LINEAGE {
shell:
'''
sed 's/^/prefix_/' !{poppunk_qfile} > safe_qfile.txt
poppunk_assign --db !{poppunk_db} --external-clustering !{poppunk_ext_clusters} --query safe_qfile.txt --output output --threads $(nproc)
poppunk_assign --db !{poppunk_dir}/!{db_name} --external-clustering !{poppunk_dir}/!{ext_clusters_file} --query safe_qfile.txt --output output --threads $(nproc)
sed 's/^prefix_//' output/output_external_clusters.csv > result.csv
'''
}
19 changes: 10 additions & 9 deletions modules/mapping.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ process GET_REF_GENOME_BWA_DB_PREFIX {

input:
path reference
val local
path local

output:
val "$local/ref"
tuple path(local), env(PREFIX)

shell:
'''
if [ ! -f !{local}/done_bwa_db_!{reference} ] || [ ! -f !{local}/ref.amb ] || [ ! -f !{local}/ref.ann ] || [ ! -f !{local}/ref.bwt ] || [ ! -f !{local}/ref.pac ] || [ ! -f !{local}/ref.sa ] ; then
rm -rf !{local}
mkdir -p !{local}
PREFIX=ref
if [ ! -f !{local}/done_bwa_db_!{reference} ] || [ ! -f !{local}/$PREFIX.amb ] || [ ! -f !{local}/$PREFIX.ann ] || [ ! -f !{local}/$PREFIX.bwt ] || [ ! -f !{local}/$PREFIX.pac ] || [ ! -f !{local}/$PREFIX.sa ] ; then
rm -rf !{local}/{,.[!.],..?}*
bwa index -p ref !{reference}
bwa index -p $PREFIX !{reference}
mv ref.amb ref.ann ref.bwt ref.pac ref.sa -t !{local}
mv $PREFIX.amb $PREFIX.ann $PREFIX.bwt $PREFIX.pac $PREFIX.sa -t !{local}
touch !{local}/done_bwa_db_!{reference}
fi
Expand All @@ -32,15 +33,15 @@ process MAPPING {
label 'bwa_container'

input:
val reference_prefix
tuple path(bwa_ref_db_dir), val(prefix)
tuple val(sample_id), path(read1), path(read2), path(unpaired)

output:
tuple val(sample_id), path("${sample_id}_mapped.sam"), emit: sam

shell:
'''
bwa mem -t $(nproc) !{reference_prefix} <(zcat -f -- < !{read1}) <(zcat -f -- < !{read2}) > !{sample_id}_mapped.sam
bwa mem -t $(nproc) !{bwa_ref_db_dir}/!{prefix} <(zcat -f -- < !{read1}) <(zcat -f -- < !{read2}) > !{sample_id}_mapped.sam
'''
}

Expand Down
18 changes: 10 additions & 8 deletions modules/serotype.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ process GET_SEROBA_DB {

input:
val remote
val local
path local

output:
env CREATE_DB, emit: create_db
Expand All @@ -15,7 +15,7 @@ process GET_SEROBA_DB {
'''
# Assume up-to-date if done_seroba exists and the host cannot be resolved (often means the Internet is not available)
if [ ! -f !{local}/done_seroba ] || !((git -C !{local} pull || echo 'Already up-to-date') | grep -q 'Already up[- ]to[- ]date'); then
rm -rf !{local}
rm -rf !{local}/{,.[!.],..?}*
git clone !{remote} !{local}
CREATE_DB=true
Expand All @@ -31,17 +31,19 @@ process CREATE_SEROBA_DB {
label 'seroba_container'

input:
val local
path seroba_dir
val create_db

output:
val "$local/database"
tuple path(seroba_dir), env(DATABASE)

shell:
'''
DATABASE=database
if [ !{create_db} = true ]; then
seroba createDBs !{local}/database/ 71
touch !{local}/done_seroba
seroba createDBs !{seroba_dir}/$DATABASE/ 71
touch !{seroba_dir}/done_seroba
fi
'''
}
Expand All @@ -51,15 +53,15 @@ process SEROTYPE {
label 'seroba_container'

input:
val database
tuple path(seroba_dir), val(database)
tuple val(sample_id), path(read1), path(read2), path(unpaired)

output:
tuple val(sample_id), env(SEROTYPE), env(SEROBA_COMMENT), emit: result

shell:
'''
seroba runSerotyping !{database} !{read1} !{read2} !{sample_id}
seroba runSerotyping !{seroba_dir}/!{database} !{read1} !{read2} !{sample_id}
SEROTYPE=$(awk -F'\t' '{ print $2 }' !{sample_id}/pred.tsv)
SEROBA_COMMENT=$(awk -F'\t' '$3!=""{ print $3 } $3==""{ print "_" }' !{sample_id}/pred.tsv)
Expand Down
9 changes: 4 additions & 5 deletions modules/taxonomy.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ process GET_KRAKEN_DB {

input:
val remote
val local
path local

output:
val local
path local

shell:
'''
DB_NAME=$(basename !{remote})
if [ ! -f !{local}/done_kraken_${DB_NAME} ] || [ ! -f !{local}/hash.k2d ]; then
rm -rf !{local}
mkdir -p !{local}
rm -rf !{local}/{,.[!.],..?}*
wget !{remote} -O kraken_db.tar.gz
tar -xzf kraken_db.tar.gz -C !{local}
Expand All @@ -33,7 +32,7 @@ process TAXONOMY {
label 'kraken2_container'

input:
val kraken_db
path kraken_db
val kraken2_memory_mapping
tuple val(sample_id), path(read1), path(read2), path(unpaired)

Expand Down
2 changes: 1 addition & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ process {
// Enable the use of Docker container
docker {
enabled = true
runOptions = '-v $HOME:$HOME -u $(id -u):$(id -g)'
runOptions = '-u $(id -u):$(id -g)'
}

0 comments on commit 9011f80

Please sign in to comment.