I have the following inside a samplesheet schema: ...
# nf-schema
j
I have the following inside a samplesheet schema:
Copy code
"hifiasm_error_correction_arguments": {
                "type": "string",
                "description": "Command-line arguments to pass to Hifiasm controlling read error correction only: <https://hifiasm.readthedocs.io/en/latest/parameter-reference.html#error-correction-options>",
                "meta": "hifiasm_error_correction_arguments",
                "default": ""
            },
As part of some further pre-processing, I need to take this string, tokenize it and validate the command-line flags. However, the
.tokenize()
call fails because nf-schema
samplesheetToList()
returns this as an
ArrayList
rather than a string. Is this expected behaviour?
n
What version of nf-schema are you using? Some older versions had issues with setting the default values so it could be that
j
2.5.1 according to my config
But in this case it's failing even when running with an explicitly set value as I get an ArrayList containing a string rather than a String
n
That's strange, can you show me the exact output of the
samplesheetToList
function?
j
If I run
.view()
on the channel (I am adding everything to
meta
as I need a map):
Copy code
[[id:baUndUnlc1.pri, long_read_dataset:baUndUnlc1, long_read_platform:pacbio_hifi, long_read_1n_coverage:[], illumina_hic_dataset:baUndUnlc1, illumina_10x_dataset:[], maternal_illumina_dataset:[], paternal_illumina_dataset:[], phased_assembly:false, trio_assembly:false, purge:true, polish:false, scaffold:true, assemble_mito:true, assemble_plastid:true, hifiasm_error_correction_arguments:-f0 --primary, hifiasm_arguments:, purging_cutoffs:[], purge_middle:false, yahs_arguments:, mitohifi_reference_species:[], mitohifi_genetic_code:[], mitohifi_reads_arguments:, mitohifi_contigs_arguments:, oatk_kmer_size:1000, oatk_coverage_cutoff:[], oatk_arguments:, oatk_mito_hmm:/c-zhou/OatkDB/raw/main/v20230921/insecta_mito.fam, oatk_plastid_hmm:/c-zhou/OatkDB/raw/main/v20230921/acrogymnospermae_pltd.fam]]
It looks like a string when printing, but if I run
println meta.hifiasm_error_correction_arguments.getClass()
inside a map operator I get
class java.util.ArrayList
I will try with the latest version to double-check
n
That's weird, what is in your samplesheet?
j
Copy code
- id: baUndUnlc1.pri
  long_read_dataset: baUndUnlc1
  long_read_platform: "pacbio_hifi"
  illumina_hic_dataset: baUndUnlc1
  purge: true
  assemble_mito: true
  assemble_plastid: true
  hifiasm_error_correction_arguments: "-f0 --primary"
  oatk_mito_hmm: <https://github.com/c-zhou/OatkDB/raw/main/v20230921/insecta_mito.fam>
  oatk_plastid_hmm: <https://github.com/c-zhou/OatkDB/raw/main/v20230921/acrogymnospermae_pltd.fam>
n
Ah! Using
-
in yaml files results in a list. Can you try again with single quotes? (Not entirely sure this is the reason, but it could be?)
j
Same thing
🤔 1
n
Can you try with a JSON file to be sure it's not a YAML problem?
Definitely sounds like a bug though!
j
Yes, can give that a try... might take a moment
class java.util.ArrayList
n
That's definitely a bug, can you create an issue with all findings discussed here? You can probably work around the issue now by explicitely converting the meta value to a string in your pipeline code
j
Can do!
n
Thank you very much! I hope to fix this some time in January if my schedule allows it
j
No worries, it's probably a good excuse for me to put this pipeline down and out of mind over Christmas 😅
Oh, and one more discovery - this only occurs using the
meta
schema field. If I just return a list with no meta I correctly get this value as a String
Also happens when parsing CSV
n
Okay thank you for the report! I'll keep you updated 😛
🙌 1
a
I’ve left full details on the issue, but this is not an
nf-schema
bug or related in any way to
nf-schema
. It’s just how Groovy works.
j
Ah, I think I understand. So it’s related to destructuring of the input -
channel.of([[:]]).map { meta -> println meta }
doesn’t destructure the input and pull out the map, it just returns the whole channel entry list. So the solution in this case (I will test later) might be to either unwrap the map from the list (there is only a single map in a list in each channel), or otherwise to do something like
def realmeta = meta[0]
in the closure and operate on that.
a
Yeah, it's just a case of understanding how argument unpacking works with the closure really. A single length item won't "unpack". So you have to just access it like
it[0]
. If you're operating on a meta map it's best practice to make a copy of it anyway. If Groovy didn't have syntactic sugar for lists which let you access attributes of objects in the list using the dot notation, the error would be more obvious (in Python for example you'd get an attribute error)
👍 1