Hi, I realized, that it seems like bool inputs tha...
# help
n
Hi, I realized, that it seems like bool inputs that are provided via a samplesheet are converted to Strings. What is the best way to avoid this?
n
Not sure how this deals with the things that come in via
.splitCsv
has the csv input always been all strings?
m
hmm, not sure. Do you know, @Nicolas Vannieuwkerke ?
n
How are you reading the samplesheet? .splitCsv does not have any type casting AFAIK so CSV and TSV samplesheet values will always be String values.
n
Hm, that's good to know, I will need to update a bunch of stuff. Is there a csv reader with typecasting?
n
You can use #C056RQB10LU which contains a
samplesheetToList
function that validates and converts a samplesheet to a list
❤️ 1
n
Is there also
samplesheetToMap
?
n
Nope, but you could set all values as meta values and then it will create a list of maps, one map per samplesheet entry
n
Hm, I am not sure if that will work for me, especially because of:
It is the order of fields in the sample sheet JSON schema which defines the order of items in the channel returned by
samplesheetToList()
, not the order of fields in the sample sheet file.
But still useful for other cases probably
n
That's not the case if you make all values meta values
n
Ah, I get it now
In my case they actually are meta values so that makes sense
🙌 1
n
I'm planning on implementing a new
samplesheetToRecords
function to support record types in the future so that might be useful for you then
Perfect!
n
Thanks a lot, that is probably much better than typecasting everything manually
n
Glad I could help 😛 let me know if something is not working as expected
n
I have never used nf-schema, in my case my samplesheet schema is almost fully identical with my params; can I just use
nextflow_schema.json
as a basis, and add the meta fields?
n
That should be possible, although I've never tried it myself
n
When I try this, for example:
Copy code
"shortread_F": {
                "type": "string",
                "description": "Path to forward short reads",
                "meta": ["shortread_F"]
            }
and then later try:
Copy code
file(meta.shortread_F)
I get:
Copy code
Unknown method invocation `getFileSystem` on ArrayList type
Is there an easy way to solve that?
meta.shortread_F[0]
seems to work
n
You can let nf-schema convert that to a file object automatically using
"format": "file-path"
. This error usually means that the file has not been given via the samplesheet and that it defaults to
[]
which is the default value if something is missing. It would also help if you could show me the output of the function
n
ah, I will try file-path
yes, it was
[]
probably
🙌 1
n
You can also change the default value with
"default": <default-value>
n
It would also help if you could show me the output of the function
You mean the function that fails?
Copy code
if (!file(row.shortread_F).exists()) {
        exit(1, "ERROR: shortread_F fastq file does not exist!\n${row.shortread_F}")
    }
n
no the output of
samplesheetToList
sorry I should have been more clear
n
It looks like this:
Copy code
Parsed samplesheet: [meta:[id:[null], group:[null], ontreads:[[]], hifireads:[[]], strategy:[single], assembler:[hifiasm], assembler_ont:[[]], assembler_hifi:[hifiasm], assembly_scaffolding_order:[ont_on_hifi], assembler_ont_args:[[]], assembler_h
ifi_args:[[]], hifiasm_args:[[]], flye_args:[[]], polish:[null], ont_collect:[[]], ont_adapters:[[]], ont_fastplong_args:[[]], jellyfish:[[]], jellyfish_k:[null], jellyfish_size:[200M], hifi_adapters:[[]], hifi_fastplong_args:[[]], medaka_model:[[
]], scaffold_longstitch:[[]], scaffold_links:[[]], scaffold_ragtag:[[]], scaffold_hic:[false], use_ref:[[]], hic_aligner:[bwa-mem2], hic_F:[[]], hic_R:[null], hic_trim:[[]], genome_size:[[]], ref_fasta:[[]], ref_gff:[[]], flye_mode:[--nano-hq], as
sembly:[[]], ref_map_bam:[[]], assembly_map_bam:[[]], qc_reads:ont, qc_reads_path:[[]], quast:[[]], busco:[[]], busco_lineage:[auto_euk], busco_db:[[]], meryl_k:[21], merqury:[false], lift_annotations:[false], shortread_F:[[]], shortread_R:[[]], p
aired:[[]], use_short_reads:[[]], shortread_trim:[[]]]]
I think I need to default to
null
, or anything else that will evaluate to false with
?
also a bit confused that id is
null
(that was a different problem, solved)
Can I do:
"default": "${params.paramname}"
?
n
not in the schema but you can easily do this in pipeline code like this:
meta.key = meta.get("key", params.paramname}
n
not sure if I get what you mean, or if that is meaningfully different from what I am already doing wich is basically:
Copy code
.map{ it -> [meta:[key: it.meta.key ?: params.key ]]}
n
does that work? 😅 but yeah it should be very similar
n
it used to work, but I am bit worried that with keys receiving defaults from nf-schema it will no longer work
unless they all get
null
defaults
n
[]
is also considered
false
in groovy so that's fine
n
hm, not so sure
n
But if I get it right you have a map containing one value which is the meta, which itself is a map of values?
n
everything that is
[[]]
in the dumped output above should have a value
yes, I am fully committed to the
meta-map
n
It's weird that these values are lists of lists though 🤔 could you send me your full schema?
n
Here comes my schema:
I edited some things to have
null
defaults while we were talking, so if those do not match the output earlier, that is why
n
your schema looks fine 😛
n
Great 😄
n
Could you also point me to some code with nf-schema?
Preferably the code that generated your output from before
n
it is the same as before except that it starts:
ch_samplesheet = channel.fromList(samplesheetToList(params.input, "assets/schema_input.json"))
👀 1
instead of
fromPath.splitCsv
n
That should be fine, let me know if you have a PR I can try some things then 😛
n
I can create a PR if you would like to do some things 🙂
n
That would be wonderful 😛
Always nice to see people trying something exotic with nf-schema 😛
n
n
okay give me some time 😛 I'll see if I can reproduce it, were you just using the test profile for this?
n
What I want to do is simple: If something comes in via the samplesheet, give it the samplesheet value in
meta.key
, if it does not come via the samplesheet give it the value of
params.key
👀 1
yes
n
Is the meta key name always the same as the parameter? Because that could be simplified 😛
n
yes, it is always the same, because otherwise I would get completely lost lol
n
Perfect!
n
There is one exception: github.com/nf-core/genomeassembler/blob/…/main.nf#… but I can probably find a way to handle that
It seems that my map operation is what turns everything into lists, but idk why
🙌 1
n
Okay so your code seems to make the lists in lists somehow because the output of
samplesheetToList
is correct, I'll dig a bit deeper 😛
🙌 1
n
Its nice that we reach the same conclusion
n
I see the problem,
samplesheetToList
creates a list with one value (the meta map) so your
it
is actually
List[meta]
instead of just
meta
. You need to fetch it from it like that.
The reason that it worked was because Groovy has a feature that you could get all values in a list maps by key. So
it = [ [ id: 'test'], [ id:'test2' ] ]
would return
["test", "test2"]
if you tried
it.id
And for the defaults you could do something like this:
Copy code
input_ch.map { it ->
    def meta = it[0]
    return meta.collectEntries { key, val -> [ key, val ?: params.get(key) ] }
}
This will populate all empty values with their parameter default 🙂
(just keep in mind that if values are set to false that they will also not pass this check so you might want to update the check a bit more)
n
amazing
thanks so much
this will make everything cleaner, and probably create a few new edge cases 😄
🤣 1
n
You're welcome! You can still apply some manual code on the output of the
collectEntries
method 😉
🙌 1
n
Always happy to apply some manual code
n
Hack away 😉