mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 02:58:17 +00:00
Implement plink/extract
module (#901)
* Implement PLINK_EXTRACT module * fix plink version number * Update main.nf * Update test_data.config * Update modules/plink/extract/main.nf Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * just use one channel * fix test with new channel input Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
parent
6d3d8306e1
commit
6bb4a6a7ee
7 changed files with 240 additions and 0 deletions
78
modules/plink/extract/functions.nf
Normal file
78
modules/plink/extract/functions.nf
Normal file
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// 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"
|
||||
}
|
||||
}
|
47
modules/plink/extract/main.nf
Normal file
47
modules/plink/extract/main.nf
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process PLINK_EXTRACT {
|
||||
tag "$meta.id"
|
||||
label 'process_low'
|
||||
publishDir "${params.outdir}",
|
||||
mode: params.publish_dir_mode,
|
||||
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) }
|
||||
|
||||
conda (params.enable_conda ? "bioconda::plink=1.90b6.21" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/plink:1.90b6.21--h779adbc_1"
|
||||
} else {
|
||||
container "quay.io/biocontainers/plink:1.90b6.21--h779adbc_1"
|
||||
}
|
||||
|
||||
input:
|
||||
tuple val(meta), path(bed), path(bim), path(fam), path(variants)
|
||||
|
||||
output:
|
||||
tuple val(meta), path("*.bed"), emit: bed
|
||||
tuple val(meta), path("*.bim"), emit: bim
|
||||
tuple val(meta), path("*.fam"), emit: fam
|
||||
path "versions.yml" , emit: versions
|
||||
|
||||
script:
|
||||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||
if( "$bed" == "${prefix}.bed" ) error "Input and output names are the same, use the suffix option to disambiguate"
|
||||
"""
|
||||
plink \\
|
||||
--bfile ${meta.id} \\
|
||||
$options.args \\
|
||||
--extract $variants \\
|
||||
--threads $task.cpus \\
|
||||
--make-bed \\
|
||||
--out $prefix
|
||||
|
||||
cat <<-END_VERSIONS > versions.yml
|
||||
${getProcessName(task.process)}:
|
||||
${getSoftwareName(task.process)}: \$(echo \$(plink --version) | sed 's/^PLINK v//;s/64.*//')
|
||||
END_VERSIONS
|
||||
"""
|
||||
}
|
62
modules/plink/extract/meta.yml
Normal file
62
modules/plink/extract/meta.yml
Normal file
|
@ -0,0 +1,62 @@
|
|||
name: plink_extract
|
||||
description: Subset plink bfiles with a text file of variant identifiers
|
||||
keywords:
|
||||
- extract
|
||||
- plink
|
||||
tools:
|
||||
- plink:
|
||||
description: Whole genome association analysis toolset, designed to perform a range of basic, large-scale analyses in a computationally efficient manner.
|
||||
homepage: None
|
||||
documentation: None
|
||||
tool_dev_url: None
|
||||
doi: ""
|
||||
licence: ['GPL']
|
||||
|
||||
input:
|
||||
- meta:
|
||||
type: map
|
||||
description: |
|
||||
Groovy Map containing sample information
|
||||
e.g. [ id:'test', single_end:false ]
|
||||
- bed:
|
||||
type: file
|
||||
description: PLINK binary biallelic genotype table
|
||||
pattern: "*.{bed}"
|
||||
- bim:
|
||||
type: file
|
||||
description: PLINK extended MAP file
|
||||
pattern: "*.{bim}"
|
||||
- fam:
|
||||
type: file
|
||||
description: PLINK sample information file
|
||||
pattern: "*.{fam}"
|
||||
- variants:
|
||||
type: file
|
||||
description: A text file containing variant identifiers to keep (one per line)
|
||||
pattern: "*.{keep}"
|
||||
|
||||
output:
|
||||
- meta:
|
||||
type: map
|
||||
description: |
|
||||
Groovy Map containing sample information
|
||||
e.g. [ id:'test', single_end:false ]
|
||||
- versions:
|
||||
type: file
|
||||
description: File containing software versions
|
||||
pattern: "versions.yml"
|
||||
- bed:
|
||||
type: file
|
||||
description: PLINK binary biallelic genotype table
|
||||
pattern: "*.{bed}"
|
||||
- bim:
|
||||
type: file
|
||||
description: PLINK extended MAP file
|
||||
pattern: "*.{bim}"
|
||||
- fam:
|
||||
type: file
|
||||
description: PLINK sample information file
|
||||
pattern: "*.{fam}"
|
||||
|
||||
authors:
|
||||
- "@nebfield"
|
|
@ -936,6 +936,10 @@ plasmidid:
|
|||
- modules/plasmidid/**
|
||||
- tests/modules/plasmidid/**
|
||||
|
||||
plink/extract:
|
||||
- modules/plink/extract/**
|
||||
- tests/modules/plink/extract/**
|
||||
|
||||
plink/vcf:
|
||||
- modules/plink/vcf/**
|
||||
- tests/modules/plink/vcf/**
|
||||
|
|
|
@ -119,8 +119,10 @@ params {
|
|||
gnomad_r2_1_1_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/gnomAD.r2.1.1.vcf.gz.tbi"
|
||||
mills_and_1000g_indels_vcf_gz = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/mills_and_1000G.indels.vcf.gz"
|
||||
mills_and_1000g_indels_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/mills_and_1000G.indels.vcf.gz.tbi"
|
||||
|
||||
syntheticvcf_short_vcf_gz = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/syntheticvcf_short.vcf.gz"
|
||||
syntheticvcf_short_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/syntheticvcf_short.vcf.gz.tbi"
|
||||
|
||||
index_salmon = "${test_data_dir}/genomics/homo_sapiens/genome/index/salmon"
|
||||
repeat_expansions = "${test_data_dir}/genomics/homo_sapiens/genome/loci/repeat_expansions.json"
|
||||
}
|
||||
|
|
29
tests/modules/plink/extract/main.nf
Normal file
29
tests/modules/plink/extract/main.nf
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { PLINK_VCF } from '../../../../modules/plink/vcf/main.nf' addParams ( options: [args:'--make-bed --set-missing-var-ids @:#:\\$1:\\$2'])
|
||||
include { PLINK_EXTRACT } from '../../../../modules/plink/extract/main.nf' addParams( options: [suffix:'.extract'] )
|
||||
|
||||
workflow test_plink_extract {
|
||||
|
||||
input = [
|
||||
[ id:'test', single_end:false ], // meta map
|
||||
file(params.test_data['homo_sapiens']['genome']['syntheticvcf_short_vcf_gz'], checkIfExists: true)
|
||||
]
|
||||
|
||||
PLINK_VCF ( input )
|
||||
|
||||
PLINK_VCF.out.bim
|
||||
.splitText(file: 'variants.keep', keepHeader: false, by: 10)
|
||||
.first()
|
||||
.set { ch_variants }
|
||||
|
||||
PLINK_VCF.out.bed
|
||||
.concat(PLINK_VCF.out.bim, PLINK_VCF.out.fam.concat(ch_variants))
|
||||
.groupTuple()
|
||||
.map{ meta, paths -> [meta, paths[0], paths[1], paths[2], paths[3]] }
|
||||
.set { ch_extract }
|
||||
|
||||
PLINK_EXTRACT ( ch_extract )
|
||||
}
|
18
tests/modules/plink/extract/test.yml
Normal file
18
tests/modules/plink/extract/test.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
- name: plink extract test_plink_extract
|
||||
command: nextflow run tests/modules/plink/extract -entry test_plink_extract -c tests/config/nextflow.config
|
||||
tags:
|
||||
- plink
|
||||
- plink/extract
|
||||
files:
|
||||
- path: output/plink/test.bed
|
||||
md5sum: 9121010aba9905eee965e96bc983611d
|
||||
- path: output/plink/test.bim
|
||||
md5sum: 510ec606219ee5daaf5c207cb01554bf
|
||||
- path: output/plink/test.extract.bed
|
||||
md5sum: 9e02f7143bcc756a51f20d50ca7f8032
|
||||
- path: output/plink/test.extract.bim
|
||||
md5sum: 63d190aea4094aa5d042aacd63397f94
|
||||
- path: output/plink/test.extract.fam
|
||||
md5sum: c499456df4da78792ef29934ef3cd47d
|
||||
- path: output/plink/test.fam
|
||||
md5sum: c499456df4da78792ef29934ef3cd47d
|
Loading…
Reference in a new issue