a process with conditional channel

154 views
Skip to first unread message

Damian Loska

unread,
Apr 14, 2022, 5:08:38 AM4/14/22
to Nextflow
Hey, is it possible to code a single process with different channels?

nLines_per_WES_bed = ((file(params.bed_flank_100_file).readLines().size()+50)/30).toInteger()

Channel.fromPath( params.bed_flank_100_file ).splitText( by:nLines_per_WES_bed, file:params.yy_splits_dir)
  .into { WESbedSplitsA; WESbedSplitsB; WESbedSplitsC }


Channel.fromPath( params.bed_wgs_file ).splitText( by:1, file:params.yy_splits_dir)
  .into { WGSbedSplitsA; WGSbedSplitsB; WGSbedSplitsC }

wgs=true
process test {
    echo true

    input:
        file(x) from ThisChannel

    script:
        if wgs:
            ThisChannel = WGSbedSplitsA
        else:
            ThisChannel = WESbedSplitsA


"""
echo $x

"""
}


I want a HaplotypeCaller with a different .bed content, depends whether it is WGS or WES.

Thanks
Damian


drhp...@gmail.com

unread,
Apr 20, 2022, 7:27:09 AM4/20/22
to Nextflow

Hi Damian! It might be easier to move that sort of logic outside of the process to make it more generically usable. Something like below:

wgs = true
if (wgs) {
    nLines_per_WES_bed = ((file(params.bed_flank_100_file).readLines().size()+50)/30).toInteger()

    Channel
      .fromPath( params.bed_flank_100_file ).splitText( by:nLines_per_WES_bed, file:params.yy_splits_dir)
      .set { bedSplits }
} else {
    Channel.fromPath( params.bed_wgs_file ).splitText( by:1, file:params.yy_splits_dir)
      .set { bedSplits }
}

And then give the process a single channel called bedSplits.

Damian Loska

unread,
Apr 20, 2022, 7:56:44 AM4/20/22
to next...@googlegroups.com
Yeah, that's what I finally did, but such an approach sets the .bed channel at the very beginning of the script, which means that I can run a WES pipeline, or a WGS pipeline. I wanted to make a "mixed" WES/WGS pipeline, so it would be processed at once, switching WES.bed or WGS.bed depending on the _name_ coded in sample name :)
(xxx_WGS_yyy_zzz_bbb.1.fastq.gz) 

--
You received this message because you are subscribed to a topic in the Google Groups "Nextflow" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nextflow/Yk73IGgPdJI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nextflow+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nextflow/e10849f2-32bf-4b30-9a81-6e24e11e8b9fn%40googlegroups.com.

drhp...@gmail.com

unread,
Apr 20, 2022, 8:31:40 AM4/20/22
to Nextflow

Ah, so in that case you could try to always stage the intervals files for both types of prep. Might also be nicer to encode this sort of sample metadata in a Groovy map. Some pseudo-code in DSL2 below:

WESbedSplits = []
if (params.bed_flank_100_file) {
    nLines_per_WES_bed = ((file(params.bed_flank_100_file).readLines().size()+50)/30).toInteger()

    Channel
      .fromPath( params.bed_flank_100_file ).splitText( by:nLines_per_WES_bed, file:params.yy_splits_dir)
      .set { WESbedSplits }
}

WGSbedSplits = []
if (params.bed_wgs_file) {
    Channel.fromPath( params.bed_wgs_file ).splitText( by:1, file:params.yy_splits_dir)
      .set { WGSbedSplits }
}

process test {

    input:
    tuple val(meta), path(fastq)
    path wes_intervals
    path wgs_intervals

    script:
    if (meta.prep == 'wgs' && wgs_intervals) {
        wxs_opts = "--intervals $wgs_intervals"
    } else if (meta.prep != 'wgs' && wes_intervals) {
        wxs_opts = "--intervals $wes_intervals"
    }
    """
    echo $meta.prep
    echo $wxs_opts
    """
}


Reply all
Reply to author
Forward
0 new messages