I think I am misunderstanding something very basic...
# help
n
I think I am misunderstanding something very basic about
file.name
and
file.baseName
: I am trying to do something very simple: if a file is zipped (bz2, xz, gz) I want to remove the extension, if it is not, then keep it.
Copy code
outname = ["xz", "bz2", "gz"].contains("${infile.extension}") ? "${infile.baseName}" : "${infile.name}"
outfile = task.ext.prefix ? "${task.ext.prefix}.gz" : "${outname}.gz"
This works ok for unzipped files, they receive
.gz
in addition to their original extension, but something that is
vcf.gz
becomes
vcf.gz.gz
. It seems like baseName does not remove the extension, but why?
n
what is your
task.ext.prefix
set as?
n
it should be unset
The issue seems to be related not to
baseName
, but to this:
["xz", "bz2", "gz"].contains("${infile.extension}")
this works though:
Copy code
def prefix = task.ext.prefix ?: (in_ext == "xz" || in_ext == "bz2" || in_ext == "gz") ? "${infile.baseName}" : "${infile.name}"
it seems like
file.extension.toString()
fixes this, but I do not understand why the extension is not a string to being with?
m
it should be a string already according to the docs... https://docs.seqera.io/nextflow/reference/stdlib-types#extension-string what nextflow version are you using
n
I am using 25.10.4