Skip to content

Commit

Permalink
Reorganise reference data and params
Browse files Browse the repository at this point in the history
  • Loading branch information
scwatts committed Mar 15, 2024
1 parent 1b9a467 commit 20ad49e
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 115 deletions.
18 changes: 9 additions & 9 deletions lib/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ class Utils {
public static void createStubPlaceholders(params) {

def fps = [
params.genome_fasta,
params.genome_fai,
params.genome_dict,
params.genome_bwa_index,
params.genome_bwa_index_image,
params.genome_gridss_index,
params.virusbreakenddb_path,
params.ref_data.genome_fasta,
params.ref_data.genome_fai,
params.ref_data.genome_dict,
params.ref_data.genome_bwa_index,
params.ref_data.genome_bwa_index_image,
params.ref_data.genome_gridss_index,
params.ref_data.virusbreakenddb_path,
]

params.hmf_data_paths[params.genome_version]
params.hmf_data_paths[params.ref_data.genome_version]
.each { k, v ->
fps << "${params.hmf_data_path.replaceAll('/$', '')}/${v}"
}

if(params.containsKey('panel')) {
params.panel_data_paths[params.panel][params.genome_version]
params.panel_data_paths[params.panel][params.ref_data.genome_version]
.each { k, v ->
fps << "${params.panel_data_path.replaceAll('/$', '')}/${v}"
}
Expand Down
105 changes: 45 additions & 60 deletions lib/WorkflowMain.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,38 @@ class WorkflowMain {
//
public static void setParamsDefaults(params, log) {

// Set defaults common to all run configuration

def default_invalid = false

if (params.containsKey('genome_version')) {
params.genome_version = params.genome_version.toString()
// Set defaults common to all run configuration

if (params.genome_version !== null) {
params.ref_data.genome_version = params.genome_version.toString()
} else if (Constants.GENOMES_VERSION_37.contains(params.genome)) {
params.genome_version = '37'
params.ref_data.genome_version = '37'
} else if (Constants.GENOMES_VERSION_38.contains(params.genome)) {
params.genome_version = '38'
params.ref_data.genome_version = '38'
} else {
default_invalid = true
}

if (params.containsKey('genome_type')) {
params.genome_type = params.genome_type
if (params.genome_type !== null) {
params.ref_data.genome_type = params.genome_type
} else if (Constants.GENOMES_ALT.contains(params.genome)) {
params.genome_type = 'alt'
params.ref_data.genome_type = 'alt'
} else if (Constants.GENOMES_DEFINED.contains(params.genome)) {
params.genome_type = 'no_alt'
params.ref_data.genome_type = 'no_alt'
} else {
default_invalid = true
}

if (!params.containsKey('hmf_data_path')) {
if (params.genome_version == '37') {
params.hmf_data_path = Constants.HMF_DATA_37_PATH
} else if (params.genome_version == '38') {
params.hmf_data_path = Constants.HMF_DATA_38_PATH
}
if (params.hmf_data_path !== null) {
params.ref_data.hmf_data_path = params.hmf_data_path
} else if (params.ref_data.genome_version == '37') {
params.ref_data.hmf_data_path = Constants.HMF_DATA_37_PATH
} else if (params.ref_data.genome_version == '38') {
params.ref_data.hmf_data_path = Constants.HMF_DATA_38_PATH
} else {
default_invalid = true
}

// Bad configuration, catch in validateParams
Expand All @@ -49,7 +51,7 @@ class WorkflowMain {
// Set defaults specific to run configuration without attempting to validate

def run_mode
if (params.containsKey('mode') && params.mode !== null) {
if (params.mode !== null) {
run_mode = Utils.getRunMode(params.mode, log)
} else {
// Bad configuration, catch in validateParams
Expand All @@ -59,14 +61,16 @@ class WorkflowMain {
if (run_mode === Constants.RunMode.TARGETED) {

// Attempt to set default panel data path; make no assumption on valid 'panel' value
if (!params.containsKey('panel_data_path') && params.containsKey('panel')) {

if (params.panel_data_path !== null) {
params.ref_data.panel_data_path = params.panel_data_path
} else if (params.panel !== null ) {
if (params.panel == 'tso500' && params.genome_version == '37') {
params.panel_data_path = Constants.TSO500_PANEL_37_PATH
params.ref_data.panel_data_path = Constants.TSO500_PANEL_37_PATH
} else if (params.panel == 'tso500' && params.genome_version == '38') {
params.panel_data_path = Constants.TSO500_PANEL_38_PATH
params.ref_data.panel_data_path = Constants.TSO500_PANEL_38_PATH
}
}

}

def stages = Processes.getRunStages(
Expand All @@ -77,27 +81,21 @@ class WorkflowMain {
)

if (stages.virusinterpreter && run_mode === Constants.RunMode.WGTS) {
if (!params.containsKey('virusbreakenddb_path')) {
params.virusbreakenddb_path = Constants.VIRUSBREAKENDDB_PATH
if (params.virusbreakenddb_path !== null) {
params.ref_data.virusbreakenddb_path = params.virusbreakenddb_path
} else {
params.ref_data.virusbreakenddb_path = Constants.VIRUSBREAKENDDB_PATH
}
}

if (stages.lilac) {
if (params.genome_version == '38' && params.genome_type == 'alt' && !params.containsKey('hla_slice_bed')) {
params.hla_slice_bed = Constants.HLA_SLICE_BED_GRCH38_ALT_PATH
if (params.hla_slice_bed !== null) {
params.ref_data.hla_slice_bed = params.hla_slice_bed
} else if (params.genome_version == '38' && params.genome_type == 'alt') {
params.ref_data.hla_slice_bed = Constants.HLA_SLICE_BED_GRCH38_ALT_PATH
}
}

if (stages.isofox && !params.containsKey('isofox_read_length')) {

if (run_mode === Constants.RunMode.WGTS) {
params.isofox_read_length = Constants.DEFAULT_ISOFOX_READ_LENGTH_WTS
} else if (run_mode === Constants.RunMode.TARGETED) {
params.isofox_read_length = Constants.DEFAULT_ISOFOX_READ_LENGTH_TARGETED
}

}

}

//
Expand All @@ -107,71 +105,58 @@ class WorkflowMain {

// Common parameters

if (!params.genome) {
if (!params.ref_data.genome) {
log.error "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Genome must be set using the --genome CLI argument or in a configuration file.\n" +
" Currently, the available genome are:\n" +
" ${params.genomes.keySet().join(", ")}\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
System.exit(1)
} else if (!params.genomes.containsKey(params.genome)) {
} else if (!params.genomes.containsKey(params.ref_data.genome)) {
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Genome '${params.genome}' not found in any config files provided to the pipeline.\n" +
" Genome '${params.ref_data.genome}' not found in any config files provided to the pipeline.\n" +
" Currently, the available genome are:\n" +
" ${params.genomes.keySet().join(", ")}\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
System.exit(1)
}

if (!Constants.GENOMES_SUPPORTED.contains(params.genome)) {
if (!params.containsKey('force_genome') || !params.force_genome) {
log.error "ERROR: currently only the GRCh37_hmf and GRCh38_hmf genomes are supported but got ${params.genome}" +
if (!Constants.GENOMES_SUPPORTED.contains(params.ref_data.genome)) {
if (!params.ref_data.force_genome) {
log.error "ERROR: currently only the GRCh37_hmf and GRCh38_hmf genomes are supported but got ${params.ref_data.genome}" +
", please adjust the --genome argument accordingly or override with --force_genome."
System.exit(1)
} else {
log.warn "currently only the GRCh37_hmf and GRCh38_hmf genomes are supported but forcing to " +
"proceed with \"${params.genome}\""
"proceed with \"${params.ref_data.genome}\""
}
}

if (!params.genome_version) {
if (!params.ref_data.genome_version) {
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Genome version wasn't provided and genome '${params.genome}' is not defined in \n" +
" Genome version wasn't provided and genome '${params.ref_data.genome}' is not defined in \n" +
" genome version list.\n" +
" Currently, the list of genomes in the version list include:\n" +
" ${Constants.GENOMES_DEFINED.join(", ")}\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
System.exit(1)
}

if (!params.genome_type) {
if (!params.ref_data.genome_type) {
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Genome type wasn't provided and genome '${params.genome}' is not defined in \n" +
" Genome type wasn't provided and genome '${params.ref_data.genome}' is not defined in \n" +
" genome type list.\n" +
" Currently, the list of genomes in the type list include:\n" +
" ${Constants.GENOMES_DEFINED.join(", ")}\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
System.exit(1)
}

if (!params.hmf_data_path) {
if (!params.ref_data.hmf_data_path) {
log.error "ERROR: HMF data path wasn't provided"
System.exit(1)
}

// NOTE(SW): this could be moved to the wgts.nf where we check that input files exist
def null_check = [
'genome_fasta',
'genome_type',
'genome_version',
]
null_check.each { k ->
if (!params[k]) {
log.error "ERROR: '${k}' cannot be set to null in any configuration and must be adjusted or removed to proceed."
System.exit(1)
}
}

// Run configuration specific parameters

if (!params.mode) {
Expand Down
19 changes: 13 additions & 6 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ include { getGenomeAttribute } from './subworkflows/local/utils_nfcore_oncoanaly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

params.genome_fasta = getGenomeAttribute('fasta')
params.genome_fai = getGenomeAttribute('fai')
params.genome_dict = getGenomeAttribute('dict')
params.genome_bwa_index = getGenomeAttribute('bwa_index')
params.genome_bwa_index_image = getGenomeAttribute('bwa_index_image')
params.genome_gridss_index = getGenomeAttribute('gridss_index')
// Reference config lifted up into params.ref_data to conform to standards/linting
params.ref_data = [
genome: params.genome,
force_genome: params.force_genome,
]

params.ref_data.genome_fasta = getGenomeAttribute('fasta')
params.ref_data.genome_fai = getGenomeAttribute('fai')
params.ref_data.genome_dict = getGenomeAttribute('dict')
params.ref_data.genome_bwa_index = getGenomeAttribute('bwa_index')
params.ref_data.genome_bwa_index_image = getGenomeAttribute('bwa_index_image')
params.ref_data.genome_gridss_index = getGenomeAttribute('gridss_index')

WorkflowMain.setParamsDefaults(params, log)
WorkflowMain.validateParams(params, log)

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ params {
genome = null
genome_version = null
genome_type = null
force_genome = null
force_genome = false

igenomes_base = 's3://ngi-igenomes/igenomes'
igenomes_ignore = false
Expand Down Expand Up @@ -77,7 +77,7 @@ params {
// Schema validation default options
validationFailUnrecognisedParams = false
validationLenientMode = true
validationSchemaIgnoreParams = 'genomes,igenomes_base,hmf_data_paths,panel_data_paths'
validationSchemaIgnoreParams = 'genomes,igenomes_base,ref_data,hmf_data_paths,panel_data_paths'
validationShowHiddenParams = false
validate_params = true

Expand Down
1 change: 1 addition & 0 deletions nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"force_genome": {
"type": "boolean",
"description": "Skip check for restricted genome.",
"default": false,
"fa_icon": "fas fa-palette"
},
"processes_manual": {
Expand Down
Loading

0 comments on commit 20ad49e

Please sign in to comment.