Add in OptiType (configbuilder, type) module(s) (#301)

* Adding in optitype prototype (To be worked on these days)

* I've tried my best 😆

* No idea

* Add in YML stuff

* Fix paths

* Ok, lets try this

* Adding proper options

* Replacec configbuilder thing

* Fix seq_type

* Adding human bam - sarscov doesnt work

* Fix a bunch of things

* -def

* Make this test run

* Fancy as fuck

* Update tests/software/optitype/test.yml

* Add proper tag

* Remove md5sums

Co-authored-by: Kevin Menden <kevin.menden@t-online.de>
This commit is contained in:
Alexander Peltzer 2021-03-23 16:48:05 +01:00 committed by GitHub
parent 246011f59b
commit d13e22dcbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 188 additions and 4 deletions

View file

@ -0,0 +1,60 @@
/*
* -----------------------------------------------------
* 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()
}
/*
* 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_id = args.publish_by_id ?: false
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) {
if (!args.filename.endsWith('.version.txt')) {
def ioptions = initOptions(args.options)
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
if (ioptions.publish_by_id) {
path_list.add(args.publish_id)
}
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"
}
}
}

53
software/optitype/main.nf Normal file
View file

@ -0,0 +1,53 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process OPTITYPE {
tag "$meta.id"
label 'process_medium'
publishDir "${params.outdir}",
mode: params.publish_dir_mode,
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), publish_id:meta.id) }
conda (params.enable_conda ? "bioconda::optitype=1.3.5" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/optitype:1.3.5--0"
} else {
container "quay.io/biocontainers/optitype:1.3.5--0"
}
input:
tuple val(meta), path(bam)
output:
tuple val(meta), path("${prefix}"), emit: output
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
# Create a config for OptiType on a per sample basis with options.args2
#Doing it old school now
echo "[mapping]" > config.ini
echo "razers3=razers3" >> config.ini
echo "threads=$task.cpus" >> config.ini
echo "[ilp]" >> config.ini
echo "$options.args2" >> config.ini
echo "threads=1" >> config.ini
echo "[behavior]" >> config.ini
echo "deletebam=true" >> config.ini
echo "unpaired_weight=0" >> config.ini
echo "use_discordant=false" >> config.ini
# Run the actual OptiType typing with options.args
OptiTypePipeline.py -i ${bam} -c config.ini --${meta.seq_type} $options.args --prefix $prefix --outdir $prefix
#Couldn't find a nicer way of doing this
cat \$(which OptiTypePipeline.py) | grep -e "Version:" | sed -e "s/Version: //g" > ${software}.version.txt
"""
}

View file

@ -0,0 +1,46 @@
name: optitype
description: Perform HLA-I typing of sequencing data
keywords:
- hla-typing
- ILP
- HLA-I
tools:
- optitype:
description: Precision HLA typing from next-generation sequencing data
homepage: https://github.com/FRED-2/OptiType
documentation: https://github.com/FRED-2/OptiType
doi: "10.1093/bioinformatics/btu548"
licence: ['BSD']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
type: file
description: BAM file
pattern: "*.{bam}"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', seq_type:'DNA' ]
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
- output:
type: file
description: OptiType Results Folder
pattern: "${prefix}"
- pdf:
type: file
description: OptiType PDF Plots
pattern: "*.pdf"
authors:
- "@apeltzer"

View file

@ -267,6 +267,10 @@ multiqc:
- software/multiqc/**
- tests/software/multiqc/**
optitype:
- software/optitype/**
- tests/software/optitype/**
pangolin:
- software/pangolin/**
- tests/software/pangolin/**
@ -331,14 +335,14 @@ samtools_index:
- software/samtools/index/**
- tests/software/samtools/index/**
samtools_mpileup:
- software/samtools/mpileup/**
- tests/software/samtools/mpileup/**
samtools_merge:
- software/samtools/merge/**
- tests/software/samtools/merge/**
samtools_mpileup:
- software/samtools/mpileup/**
- tests/software/samtools/mpileup/**
samtools_sort:
- software/samtools/sort/**
- tests/software/samtools/sort/**

Binary file not shown.

View file

@ -0,0 +1,14 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { OPTITYPE } from '../../../software/optitype/main.nf' addParams( options: ['args':'-e 1 -b 0.009', 'args2':'solver=glpk'] )
workflow test_optitype {
def input = []
input = [ [ id:'test', seq_type:'dna' ], // meta map
file("${launchDir}/tests/data/genomics/human/bam/example_pe.bam", checkIfExists: true) ]
OPTITYPE ( input )
}

View file

@ -0,0 +1,7 @@
- name: optitype test_optitype
command: nextflow run tests/software/optitype -entry test_optitype -c tests/config/nextflow.config
tags:
- optitype
files:
- path: output/optitype/test/test_result.tsv
- path: output/optitype/test/test_coverage_plot.pdf