Skip to content

Commit 8aa4613

Browse files
committed
work in progress
1 parent d0edf83 commit 8aa4613

2 files changed

Lines changed: 25 additions & 71 deletions

File tree

cleanup-workdir/main.nf

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ params.cpus = 1
4242
params.mem = 1 // GB
4343
params.publish_dir = "" // set to empty string will disable publishDir
4444

45-
4645
// tool specific parmas go here, add / change as needed
47-
params.input_file = ""
48-
params.output_pattern = "*" // output file name pattern
46+
params.files_to_delete = "NO_FILE"
47+
params.virtual_dep_flag = true // default to true, ie, dep is always satisfied
4948

5049

5150
process cleanupWorkdir {
@@ -55,22 +54,31 @@ process cleanupWorkdir {
5554
cpus params.cpus
5655
memory "${params.mem} GB"
5756

58-
input: // input, make update as needed
59-
path input_file
57+
input:
58+
path files_to_delete // more accurately, other non-hidden files in the same folder will be deleted as well
59+
val virtual_dep_flag // for specifying steps do not produce output files but produce values, set those values here
6060

61-
output: // output, make update as needed
62-
path "output_dir/${params.output_pattern}", emit: output_file
61+
output:
62+
stdout
6363

6464
script:
65-
// add and initialize variables here as needed
66-
6765
"""
68-
mkdir -p output_dir
69-
70-
main.py \
71-
-i ${input_file} \
72-
-o output_dir
73-
66+
set -euxo pipefail
67+
68+
IFS=" "
69+
read -a files <<< "${files_to_delete}"
70+
for f in "\${files[@]}"
71+
do
72+
dir_to_rm=\$(dirname \$(readlink -f \$f))
73+
74+
if [[ \$dir_to_rm != ${workflow.workDir}/* ]]; then # skip dir not under workdir, like from input file dir
75+
echo "Not delete: \$dir_to_rm/*\"
76+
continue
77+
fi
78+
79+
rm -fr \$dir_to_rm/* # delete all files and subdirs but not hidden ones
80+
echo "Deleted: \$dir_to_rm/*"
81+
done
7482
"""
7583
}
7684

@@ -79,6 +87,7 @@ process cleanupWorkdir {
7987
// using this command: nextflow run <git_acc>/<repo>/<pkg_name>/<main_script>.nf -r <pkg_name>.v<pkg_version> --params-file xxx
8088
workflow {
8189
cleanupWorkdir(
82-
file(params.input_file)
90+
file(params.files_to_delete),
91+
params.virtual_dep_flag
8392
)
8493
}

cleanup-workdir/main.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)