Luuk Harbers
08/12/2025, 11:42 AMresume after a specific join operation in nf-core/scnanoseq (https://github.com/nf-core/scnanoseq/blob/05d705a301a262669c2252c890106e31a28a120e/subworkflows/local/quantify_scrna_isoquant.nf#L95C16-L95C17)
I was reading some of the discussions and also found the gotcha explaining some of it here: https://midnighter.github.io/nextflow-gotchas/gotchas/join-on-map-fails-resume/
I was now simply wondering what the best way is to implement this is (nf-core) workflows. If it's using the proposed solution in that gotcha, I'm a little bit lost on how to properly include that in a pipeline :')
Edit: maybe slightly different issue (?)Luuk Harbers
08/12/2025, 11:58 AMnextflow run nf-core/scnanoseq -profile test,singularity --outdir ./results
Interrupt the run when it gets to ISOQUANT() and then -resume .
Interestingly if I .view() the channels that its joining I get this on the first run (fresh run):
[[id:ERR9958133.REF_chr21], /scratch/leuven/364/vsc36452/work/b4/f45c1ca534367bd42f91ad30c22e19/ERR9958133.REF_chr21.bam]
[[id:ERR9958134.REF_chr21], /scratch/leuven/364/vsc36452/work/e0/0e0575d492989cdd7ef4e833c1856c/ERR9958134.REF_chr21.bam]
[[id:ERR9958133.REF_chr21], /scratch/leuven/364/vsc36452/work/c4/3fa9c1c91ec1fccf42bf64d55ecaf3/ERR9958133.REF_chr21.bam.bai]
[[id:ERR9958134.REF_chr21], /scratch/leuven/364/vsc36452/work/e8/cb23a937654c7e8bf221ed73ba66e5/ERR9958134.REF_chr21.bam.bai]
And the following on the resume:
[[id:ERR9958134.REF_chr21], /scratch/leuven/364/vsc36452/work/f0/9f002c6243809543228e96763852e2/ERR9958134.REF_chr21.bam]
[[id:ERR9958133.REF_chr21], /scratch/leuven/364/vsc36452/work/5c/c5526de32640d21f565d6e5f3ff055/ERR9958133.REF_chr21.bam]
[[id:ERR9958134.REF_chr21, sample_name:ERR9958134, chr:REF_chr21], /scratch/leuven/364/vsc36452/work/5c/93350f8a8d9bc45979cfd5e2572d84/ERR9958134.REF_chr21.bam.bai]
[[id:ERR9958133.REF_chr21, sample_name:ERR9958133, chr:REF_chr21], /scratch/leuven/364/vsc36452/work/06/5e9c6548b6acc1973051430a5325b1/ERR9958133.REF_chr21.bam.bai]Luuk Harbers
08/12/2025, 12:02 PMbai channel suddenly got a different meta? 🤯Luuk Harbers
08/12/2025, 12:09 PMbai channel to have the same meta (even though it should have as you can see from run #1).
SAMTOOLS_INDEX_SPLIT( ch_split_bam )
ch_split_bai = SAMTOOLS_INDEX_SPLIT.out.bai
.map { meta, bai ->
meta = ['id': meta.id]
[ meta, bai ]
}
The entire relevant piece of code after editing.
//
// MODULE: Bamtools split
//
BAMTOOLS_SPLIT ( in_bam )
ch_versions = ch_versions.mix(BAMTOOLS_SPLIT.out.versions.first())
ch_split_bam = BAMTOOLS_SPLIT.out.bam
.map{
meta, bam ->
[bam]
}
.flatten()
.map{
bam ->
bam_basename = bam.toString().split('/')[-1]
split_bam_basename = bam_basename.split(/\./)
meta = [
'id': split_bam_basename.take(split_bam_basename.size()-1).join("."),
]
[ meta, bam ]
}.view()
//
// MODULE: Samtools Index
//
SAMTOOLS_INDEX_SPLIT( ch_split_bam )
ch_split_bai = SAMTOOLS_INDEX_SPLIT.out.bai
.map { meta, bai ->
meta = ['id': meta.id]
[ meta, bai ]
}
ch_versions = ch_versions.mix(SAMTOOLS_INDEX_SPLIT.out.versions.first())
ch_split_bai.view()
//
// MODULE: Isoquant
//
ISOQUANT (
ch_split_bam
.join(ch_split_bai, by: [0])
.map{
meta, bam, bai ->
bam_basename = bam.toString().split('/')[-1]
split_bam_basename = bam_basename.split(/\./)
chr = [
'chr': split_bam_basename[1].replace("REF_","")
]
[ chr, meta, bam, bai]
}
.combine(ch_split_fasta, by: [0])
.combine(ch_split_fai, by: [0])
.combine(ch_split_gtf, by: [0])
.map{
chr, meta, bam, bai, fasta, fai, gtf ->
meta.sample_name = meta.id.split(/\./)[0]
meta.chr = meta.id.split(/\./)[1]
[ meta, bam, bai, fasta, fai, gtf ]
},
'tag:CB'
)
ch_versions = ch_versions.mix(ISOQUANT.out.versions)
Original relevant chunk of code: https://github.com/nf-core/scnanoseq/blob/05d705a301a262669c2252c890106e31a28a120e/subworkflows/local/quantify_scrna_isoquant.nf#L65Nicolas Vannieuwkerke
08/12/2025, 12:15 PMmeta.sample_name = meta.id.split(/\./)[0] is considered a bad practice and probably has something to do with the issue you are encountering. This also overwrites older references to the same meta map in earlier parts of the code. Doing it like this should fix that issue:
def new_meta = meta + [sample_name:meta.id.split(/\./)[0]]
Basically whenever you want to change something in the meta map you should ensure that a new map is being created. If you want to change or add entries, you can use the code above and if you want to remove a field you can do something like this:
def new_meta = meta - meta.subMap("sample_name")Luuk Harbers
08/12/2025, 12:17 PMdef new_meta = meta + [sample_name:meta.id.split(/\./)[0]]
notation but pitching in at a pipeline and I did not notice the difference and didnt think more of it. But thats a good (and very valuable) reminder. I'll change them to the proper notation!Luuk Harbers
08/12/2025, 12:19 PMNicolas Vannieuwkerke
08/12/2025, 12:22 PMLuuk Harbers
08/12/2025, 12:57 PMdef x = ... instead of x = ...?Nicolas Vannieuwkerke
08/12/2025, 12:58 PMdef means setting the variable locally, so it's only available in the closure you are working in. This prevents overwrites of global variablesLuuk Harbers
08/12/2025, 12:58 PM