I'm writing the above subworkflow. Are groovy fun...
# subworkflows
d
I'm writing the above subworkflow. Are groovy functions which read a file something that should be avoided and replaced with a module? For example
Copy code
// Read the .fai file to extract the number of sequences, the maximum and total sequence length
// Inspired from <https://github.com/nf-core/rnaseq/blob/3.10.1/lib/WorkflowRnaseq.groovy>
def get_sequence_map(fai_file) {
    def n_sequences = 0
    def max_length = 0
    def total_length = 0
    fai_file.eachLine { line ->
        def lspl = line.split('\t')
        // def chrom  = lspl[0]
        def length = lspl[1].toLong()
        n_sequences += 1
        total_length += length
        if (length > max_length) {
            max_length = length
        }
    }

    def sequence_map = [:]
    sequence_map.n_sequences = n_sequences
    sequence_map.total_length = total_length
    if (n_sequences) {
        sequence_map.max_length = max_length
    }
    return sequence_map
}
It's a really small function which will be modified to generate a JSON file instead so we don't pollute meta. It's not doing much so is it worth a module?
m
I think in this case a function or a local process (to expedite scheduling) can be used since a
fai
file is generally very small
We discourage running local functions on (large) data, because the head node then incurs the cost of staging/storage and processing, which is better offloaded to the compute nodes
d
That's great, thanks. All implemented and working great.