Combining two tuples on differing keys, I don't understand what I'm doing wrong. #4716
-
I have the following (incomplete so far) pipeline, where I'm generating "transforms", from all possible pairs of atlas-template, and template-subject. So far, I think I'm getting the proper pairs. Alongside the process, I've generated IDs from the input files which are coming along for the ride as expected. Now I'd like to take those pairs and generate all possible "pathways" along atlas-template-subject path. Based on my reading of the docs, the "second version" of combine is what I want, https://www.nextflow.io/docs/latest/operator.html#combine as I can join the two channels If I blindly combine the channels, things work as expected, however the combine command: I have reproduced the entire state of the pipeline below as I don't know what might be relevant. Apologies if I'm missing something obvious, its my first day with NextFlow params.primarySpectra = "T1w"
process registerAffine {
input:
tuple val(movingId), path(movingPath), val(fixedId), path(fixedPath)
output:
tuple val(movingId), path(movingPath), emit: moving
tuple val(fixedId), path(fixedPath), emit: fixed
path "${movingId}-${fixedId}_0GenericAffine.mat", emit: affine
script:
'''
antsRegistration_affine_SyN.sh \
--skip-nonlinear \
${moving} \
${fixed} \
${movingId}-${fixedId}_"
'''
stub:
"""
touch ${movingId}-${fixedId}_0GenericAffine.mat
"""
}
process registerNonlinear {
input:
tuple val(movingId), path(movingPath)
tuple val(fixedId), path(fixedPath)
path affineInitializationPath
output:
tuple val(movingId),
val(fixedId),
path("${movingId}-${fixedId}_0GenericAffine.mat"),
path("${movingId}-${fixedId}_1Warp.nii.gz")
script:
'''
antsRegistration_affine_SyN.sh \
--initial-transform ${affineInitializationPath} \
${movingPath} \
${fixedPath} \
${movingId}-${fixedId}_
'''
stub:
"""
touch ${movingId}-${fixedId}_0GenericAffine.mat
touch ${movingId}-${fixedId}_1Warp.nii.gz
touch ${movingId}-${fixedId}_1InverseWarp.nii.gz
"""
}
workflow resampleLabels {
take:
atlasTemplateTransforms
templateSubjectTransforms
labels
main:
atlasTemplateTransforms.view()
templateSubjectTransforms.view()
atlasTemplateTransforms.combine(templateSubjectTransforms, by: [1,0]).view()
}
workflow registerAtlasTemplate {
take:
atlases
templates
main:
atlasTemplatePairs = atlases.combine(templates)
registerNonlinear(registerAffine(atlasTemplatePairs))
emit:
transforms = registerNonlinear.out
}
workflow registerTemplateSubject {
take:
templates
subjects
main:
templateSubjectPairs = templates.combine(subjects)
registerNonlinear(registerAffine(templateSubjectPairs))
emit:
transforms = registerNonlinear.out
}
workflow magetBrain {
take:
atlases
labels
templates
subjects
main:
registerAtlasTemplate(atlases, templates)
registerTemplateSubject(templates, subjects)
resampleLabels(registerAtlasTemplate.out.transforms, registerTemplateSubject.out.transforms, labels)
}
workflow {
// def atlases = Channel.fromPath( 'inputs/atlases/*_' + params.primarySpectra + '.nii.gz' )
def atlases = Channel.fromPath( 'inputs/atlases/*_' + params.primarySpectra + '.nii.gz' )
.map { file -> tuple(file.simpleName.minus("_" + params.primarySpectra), file) }
.groupTuple()
def labels = Channel.fromPath( 'inputs/atlases/*_label_*.nii.gz' )
.map { file -> tuple(file.simpleName - ~/_label.*/, file) }
.groupTuple()
def templates = Channel.fromPath( 'inputs/templates/*_' + params.primarySpectra + '.nii.gz' )
.map { file -> tuple(file.simpleName.minus("_" + params.primarySpectra), file) }
.groupTuple()
def subjects = Channel.fromPath( 'inputs/subjects/*_' + params.primarySpectra + '.nii.gz' )
.map { file -> tuple(file.simpleName.minus("_" + params.primarySpectra), file) }
.groupTuple()
magetBrain(atlases,labels,templates,subjects)
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
If you can see that the combine operator isn't producing anything, it would be good to write a minimal example around that piece. The example should just have some fake values for |
Beta Was this translation helpful? Give feedback.
The issue is that your inputs are mismatched. The template entries are in index 0 on one side and index 1 on the other. Instead you should modify one of the channels so that the template entry is in the same index for both. For example:
So now the template entry should be in index 0 for both channels and then combine will use index 0 by default.