Commit cfcff692 authored by Tamara Hodgetts's avatar Tamara Hodgetts
Browse files

Merge branch 'get-chrom-sizes' into dev

parents 9e331787 a20936da
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@
            "cat/fastq": {
                "git_sha": "3aacd46da2b221ed47aaa05c413a828538d2c2ae"
            },
            "custom/getchromsizes": {
                "git_sha": "13b8a16f4a6945af9df146b67972eb70b52e9844"
            },
            "deeptools/computematrix": {
                "git_sha": "49da8642876ae4d91128168cd0db4f1c858d7792"
            },
+78 −0
Original line number Diff line number Diff line
//
//  Utility functions used in nf-core DSL2 module files
//

//
// Extract name of software tool from process name using $task.process
//
def getSoftwareName(task_process) {
    return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()
}

//
// Extract name of module from process name using $task.process
//
def getProcessName(task_process) {
    return task_process.tokenize(':')[-1]
}

//
// Function to initialise default values and to generate a Groovy Map of available options for nf-core modules
//
def initOptions(Map args) {
    def Map options = [:]
    options.args            = args.args ?: ''
    options.args2           = args.args2 ?: ''
    options.args3           = args.args3 ?: ''
    options.publish_by_meta = args.publish_by_meta ?: []
    options.publish_dir     = args.publish_dir ?: ''
    options.publish_files   = args.publish_files
    options.suffix          = args.suffix ?: ''
    return options
}

//
// Tidy up and join elements of a list to return a path string
//
def getPathFromList(path_list) {
    def paths = path_list.findAll { item -> !item?.trim().isEmpty() }      // Remove empty entries
    paths     = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes
    return paths.join('/')
}

//
// Function to save/publish module results
//
def saveFiles(Map args) {
    def ioptions  = initOptions(args.options)
    def path_list = [ ioptions.publish_dir ?: args.publish_dir ]

    // Do not publish versions.yml unless running from pytest workflow
    if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) {
        return null
    }
    if (ioptions.publish_by_meta) {
        def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta
        for (key in key_list) {
            if (args.meta && key instanceof String) {
                def path = key
                if (args.meta.containsKey(key)) {
                    path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key]
                }
                path = path instanceof String ? path : ''
                path_list.add(path)
            }
        }
    }
    if (ioptions.publish_files instanceof Map) {
        for (ext in ioptions.publish_files) {
            if (args.filename.endsWith(ext.key)) {
                def ext_list = path_list.collect()
                ext_list.add(ext.value)
                return "${getPathFromList(ext_list)}/$args.filename"
            }
        }
    } else if (ioptions.publish_files == null) {
        return "${getPathFromList(path_list)}/$args.filename"
    }
}
+4 −8
Original line number Diff line number Diff line
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './common/functions'
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'

params.options = [:]
options        = initOptions(params.options)

/*
 * Get chromosome sizes from a fasta file
 */
process GET_CHROM_SIZES {
process CUSTOM_GETCHROMSIZES {
    tag "$fasta"
    label 'process_low'
    publishDir "${params.outdir}",
        mode: params.publish_dir_mode,
        saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:"genome", publish_id:'') }
        saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) }

    conda (params.enable_conda ? "bioconda::samtools=1.14" : null)
    if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
@@ -30,14 +27,13 @@ process GET_CHROM_SIZES {
    path  "versions.yml", emit: versions

    script:
    def software = 'samtools'
    """
    samtools faidx $fasta
    cut -f 1,2 ${fasta}.fai > ${fasta}.sizes

    cat <<-END_VERSIONS > versions.yml
    ${getProcessName(task.process)}:
        samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
        ${getSoftwareName(task.process)}: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
    END_VERSIONS
    """
}
+39 −0
Original line number Diff line number Diff line
name: custom_getchromsizes
description: Generates a FASTA file of chromosome sizes and a fasta index file
keywords:
  - fasta
  - chromosome
  - indexing
tools:
  - samtools:
      description: Tools for dealing with SAM, BAM and CRAM files
      homepage: http://www.htslib.org/
      documentation: http://www.htslib.org/doc/samtools.html
      tool_dev_url: https://github.com/samtools/samtools
      doi: 10.1093/bioinformatics/btp352
      licence: ['MIT']

input:
  - fasta:
      type: file
      description: FASTA file
      pattern: "*.{fasta}"

output:
  - sizes:
      type: file
      description: File containing chromosome lengths
      pattern: "*.{sizes}"
  - fai:
      type: file
      description: FASTA index file
      pattern: "*.{fai}"
  - versions:
      type: file
      description: File containing software version
      pattern: "versions.yml"


authors:
  - "@tamara-hodgetts"
  - "@chris-cheshire"
+4 −4
Original line number Diff line number Diff line
@@ -11,8 +11,8 @@ include { GUNZIP as GUNZIP_FASTA } from "../../modules/nf-co
include { GUNZIP as GUNZIP_SPIKEIN_FASTA             } from "../../modules/nf-core/modules/gunzip/main.nf"     addParams( options: params.spikein_genome_options    )
include { GUNZIP as GUNZIP_GTF                       } from "../../modules/nf-core/modules/gunzip/main.nf"     addParams( options: params.genome_options            )
include { GUNZIP as GUNZIP_BED                       } from "../../modules/nf-core/modules/gunzip/main.nf"     addParams( options: params.genome_options            )
include { GET_CHROM_SIZES                            } from "../../modules/local/get_chrom_sizes"              addParams( options: params.genome_options            )
include { GET_CHROM_SIZES as GET_SPIKEIN_CHROM_SIZES } from "../../modules/local/get_chrom_sizes"              addParams( options: params.spikein_genome_options    )
include { CUSTOM_GETCHROMSIZES                            } from "../../modules/nf-core/modules/custom/getchromsizes/main.nf"              addParams( options: params.genome_options            )
include { CUSTOM_GETCHROMSIZES as GET_SPIKEIN_CHROM_SIZES } from "../../modules/nf-core/modules/custom/getchromsizes/main.nf"               addParams( options: params.spikein_genome_options    )
include { UNTAR as UNTAR_BT2_INDEX                   } from "../../modules/nf-core/modules/untar/main.nf"      addParams( options: params.bt2_index_options         )
include { UNTAR as UNTAR_SPIKEIN_BT2_INDEX           } from "../../modules/nf-core/modules/untar/main.nf"      addParams( options: params.bt2_spikein_index_options )
include { BOWTIE2_BUILD                              } from "../../modules/nf-core/modules/bowtie2/build/main" addParams( options: params.bt2_index_options         )
@@ -72,8 +72,8 @@ workflow PREPARE_GENOME {
    /*
    * Create chromosome sizes file
    */
    ch_chrom_sizes = GET_CHROM_SIZES ( ch_fasta ).sizes
    ch_versions    = ch_versions.mix(GET_CHROM_SIZES.out.versions)
    ch_chrom_sizes = CUSTOM_GETCHROMSIZES ( ch_fasta ).sizes
    ch_versions    = ch_versions.mix(CUSTOM_GETCHROMSIZES.out.versions)


    /*