Skip to content

Commit

Permalink
Merge pull request #190 from maxulysse/better_syntax
Browse files Browse the repository at this point in the history
tiny refactor
  • Loading branch information
maxulysse authored Aug 25, 2023
2 parents 54e7d7d + 698fab1 commit 493a544
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 82 deletions.
99 changes: 62 additions & 37 deletions main.nf
Original file line number Diff line number Diff line change
@@ -1,70 +1,94 @@
#!/usr/bin/env nextflow
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================================================================================
nf-core/fetchngs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================================================================================
Github : https://github.com/nf-core/fetchngs
Website: https://nf-co.re/fetchngs
Slack : https://nfcore.slack.com/channels/fetchngs
----------------------------------------------------------------------------------------
========================================================================================
*/

nextflow.enable.dsl = 2

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================================================================================
VALIDATE & PRINT PARAMETER SUMMARY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================================================================================
*/

WorkflowMain.initialise(workflow, params, log)

// Check if --input file is empty
ch_input = file(params.input, checkIfExists: true)
if (ch_input.isEmpty()) {exit 1, "File provided with --input is empty: ${ch_input.getName()}!"}
if (ch_input.isEmpty()) { error("File provided with --input is empty: ${ch_input.getName()}!") }

// Read in ids from --input file
Channel
.from(file(params.input, checkIfExists: true))
ch_ids = Channel.from(file(params.input, checkIfExists: true))
.splitCsv(header:false, sep:'', strip:true)
.map { it[0] }
.unique()
.set { ch_ids }

// Auto-detect input type
def input_type = ''
if (WorkflowMain.isSraId(ch_input)) { input_type = 'sra' }
else if (WorkflowMain.isSynapseId(ch_input)) { input_type = 'synapse' }
else { error('Ids provided via --input not recognised please make sure they are either SRA / ENA / GEO / DDBJ or Synapse ids!') }
if (params.input_type != input_type) { error("Ids auto-detected as ${input_type}. Please provide '--input_type ${input_type}' as a parameter to the pipeline!") }

/*
========================================================================================
VALIDATE INPUTS
========================================================================================
*/

if (params.input_type == 'sra') {
def valid_params = [
ena_metadata_fields : ['run_accession', 'experiment_accession', 'library_layout', 'fastq_ftp', 'fastq_md5']
]

def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params)

// Validate input parameters
WorkflowSra.initialise(params, valid_params)
}

if (params.input_type == 'synapse') {

def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params)

// Create channel for synapse config
if (params.synapse_config) {
ch_synapse_config = file(params.synapse_config, checkIfExists: true)
} else {
error('Please provide a Synapse config file for download authentication!')
}

}

/*
========================================================================================
IMPORT MODULES/SUBWORKFLOWS
IMPORT MODULES
========================================================================================
*/

include { CUSTOM_DUMPSOFTWAREVERSIONS } from './modules/nf-core/custom/dumpsoftwareversions'
include { MULTIQC_MAPPINGS_CONFIG } from './modules/local/multiqc_mappings_config'

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NAMED WORKFLOW FOR PIPELINE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================================================================================
IMPORT WORKFLOWS
========================================================================================
*/

// Auto-detect input id type
def input_type = ''
if (WorkflowMain.isSraId(ch_input)) {
input_type = 'sra'
} else if (WorkflowMain.isSynapseId(ch_input)) {
input_type = 'synapse'
} else {
exit 1, 'Ids provided via --input not recognised please make sure they are either SRA / ENA / GEO / DDBJ or Synapse ids!'
}
if (params.input_type == 'sra') include { SRA } from './workflows/sra'
if (params.input_type == 'synapse') include { SYNAPSE } from './workflows/synapse'

if (params.input_type == input_type) {
if (params.input_type == 'sra') {
include { SRA } from './workflows/sra'
} else if (params.input_type == 'synapse') {
include { SYNAPSE } from './workflows/synapse'
}
} else {
exit 1, "Ids auto-detected as ${input_type}. Please provide '--input_type ${input_type}' as a parameter to the pipeline!"
}
/*
========================================================================================
NAMED WORKFLOW FOR PIPELINE
========================================================================================
*/

//
// WORKFLOW: Run main nf-core/fetchngs analysis pipeline depending on type of identifier provided
Expand All @@ -77,20 +101,20 @@ workflow NFCORE_FETCHNGS {
// WORKFLOW: Download FastQ files for SRA / ENA / GEO / DDBJ ids
//
if (params.input_type == 'sra') {
SRA ( ch_ids )
SRA(ch_ids)
ch_versions = ch_versions.mix(SRA.out.versions)
//
// MODULE: Create a MultiQC config file with sample name mappings
//
if (params.sample_mapping_fields) {
MULTIQC_MAPPINGS_CONFIG (SRA.out.mappings)
MULTIQC_MAPPINGS_CONFIG(SRA.out.mappings)
ch_versions = ch_versions.mix(MULTIQC_MAPPINGS_CONFIG.out.versions)
}
//
// WORKFLOW: Download FastQ files for Synapse ids
//
} else if (params.input_type == 'synapse') {
SYNAPSE ( ch_ids )
SYNAPSE(ch_ids, ch_synapse_config)
ch_versions = ch_versions.mix(SYNAPSE.out.versions)
}

Expand Down Expand Up @@ -127,11 +151,12 @@ workflow.onComplete {
NfcoreTemplate.email(workflow, params, summary_params, projectDir, log)
}
NfcoreTemplate.summary(workflow, params, log)
WorkflowSra.curateSamplesheetWarn(log)
if (params.input_type == 'sra') { WorkflowSra.curateSamplesheetWarn(log) }
if (params.input_type == 'synapse') { WorkflowSynapse.curateSamplesheetWarn(log) }
}

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================================================================================
THE END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================================================================================
*/
15 changes: 0 additions & 15 deletions workflows/sra/main.nf
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
========================================================================================
VALIDATE INPUTS
========================================================================================
*/

def valid_params = [
ena_metadata_fields : ['run_accession', 'experiment_accession', 'library_layout', 'fastq_ftp', 'fastq_md5']
]

def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params)

// Validate input parameters
WorkflowSra.initialise(params, valid_params)

/*
========================================================================================
IMPORT LOCAL MODULES/SUBWORKFLOWS
Expand Down
32 changes: 2 additions & 30 deletions workflows/synapse/main.nf
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
========================================================================================
VALIDATE INPUTS
========================================================================================
*/

def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params)

// Create channel for synapse config
if (params.synapse_config) {
ch_synapse_config = file(params.synapse_config, checkIfExists: true)
} else {
exit 1, 'Please provide a Synapse config file for download authentication!'
}

/*
========================================================================================
IMPORT LOCAL MODULES/SUBWORKFLOWS
Expand All @@ -34,7 +19,8 @@ include { SYNAPSE_MERGE_SAMPLESHEET } from '../../modules/local/synapse_merge_sa
workflow SYNAPSE {

take:
ids // channel: [ ids ]
ids // channel: [ ids ]
ch_synapse_config // channel: [ synapse_config ]

main:
ch_versions = Channel.empty()
Expand Down Expand Up @@ -125,20 +111,6 @@ workflow SYNAPSE {
versions = ch_versions.unique()
}

/*
========================================================================================
COMPLETION EMAIL AND SUMMARY
========================================================================================
*/

workflow.onComplete {
if (params.email || params.email_on_fail) {
NfcoreTemplate.email(workflow, params, summary_params, projectDir, log)
}
NfcoreTemplate.summary(workflow, params, log)
WorkflowSynapse.curateSamplesheetWarn(log)
}

/*
========================================================================================
THE END
Expand Down

0 comments on commit 493a544

Please sign in to comment.