Skip to content

Commit

Permalink
Use function everywhwere
Browse files Browse the repository at this point in the history
  • Loading branch information
jfy133 committed Aug 1, 2023
1 parent 3be05ce commit e38b36a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
47 changes: 20 additions & 27 deletions subworkflows/local/profiling.nf
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@ include { GANON_CLASSIFY } from '../../modules/nf
include { GANON_REPORT } from '../../modules/nf-core/ganon/report/main'


// Custom Functions

/**
* Combine profiles with their original database, then separate into two channels.
*
* The channel elements are assumed to be tuples one of [ meta, profile ], and the
* database to be of [db_key, meta, database_file].
*
* @param ch_profile A channel containing a meta and the profilign report of a given profiler
* @param ch_database A channel containing a key, the database meta, and the database file/folders itself
* @return A multiMap'ed output channel with two sub channels, one with the profile and the other with the db
*/
* Combine profiles with their original database, then separate into two channels.
*
* The channel elements are assumed to be tuples one of [ meta, profile ], and the
* database to be of [db_key, meta, database_file].
*
* @param ch_profile A channel containing a meta and the profilign report of a given profiler
* @param ch_database A channel containing a key, the database meta, and the database file/folders itself
* @return A multiMap'ed output channel with two sub channels, one with the profile and the other with the db
*/
def combineProfilesWithDatabase(ch_profile, ch_database) {

return ch_profile
.map { meta, profile -> [meta.db_name, meta, profile] }
.combine(ch_database, by: 0)
.multiMap {
key, meta, profile, db_meta, db ->
profile: [meta, profile]
db: db
}
return ch_profile
.map { meta, profile -> [meta.db_name, meta, profile] }
.combine(ch_database, by: 0)
.multiMap {
key, meta, profile, db_meta, db ->
profile: [meta, profile]
db: db
}
}


workflow PROFILING {
take:
reads // [ [ meta ], [ reads ] ]
Expand Down Expand Up @@ -303,15 +304,7 @@ workflow PROFILING {
.filter { meta, db -> meta.tool == 'kaiju' }
.map { meta, db -> [meta.db_name, meta, db] }

ch_input_for_kaiju2table = KAIJU_KAIJU.out.results
.map { meta, profile -> [meta.db_name, meta, profile] }
.combine(ch_database_for_kaiju2table, by: 0)
.multiMap {
key, meta, profile, db_meta, db ->
profile: [meta, profile]
db: db
}

ch_input_for_kaiju2table = combineProfilesWithDatabase(KAIJU_KAIJU.out.results, ch_database_for_kaiju2table)
// Generate profile
KAIJU_KAIJU2TABLE_SINGLE ( ch_input_for_kaiju2table.profile, ch_input_for_kaiju2table.db, params.kaiju_taxon_rank)
ch_versions = ch_versions.mix( KAIJU_KAIJU2TABLE_SINGLE.out.versions )
Expand Down
42 changes: 26 additions & 16 deletions subworkflows/local/standardisation_profiles.nf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ include { METAPHLAN_MERGEMETAPHLANTABLES
include { MOTUS_MERGE } from '../../modules/nf-core/motus/merge/main'
include { GANON_TABLE } from '../../modules/nf-core/ganon/table/main'

// Custom Functions

/**
* Combine profiles with their original database, then separate into two channels.
*
* The channel elements are assumed to be tuples one of [ meta, profile ], and the
* database to be of [db_key, meta, database_file].
*
* @param ch_profile A channel containing a meta and the profilign report of a given profiler
* @param ch_database A channel containing a key, the database meta, and the database file/folders itself
* @return A multiMap'ed output channel with two sub channels, one with the profile and the other with the db
*/
def combineProfilesWithDatabase(ch_profile, ch_database) {

return ch_profile
.map { meta, profile -> [meta.db_name, meta, profile] }
.combine(ch_database, by: 0)
.multiMap {
key, meta, profile, db_meta, db ->
profile: [meta, profile]
db: db
}
}

workflow STANDARDISATION_PROFILES {
take:
classifications
Expand Down Expand Up @@ -117,14 +141,7 @@ workflow STANDARDISATION_PROFILES {
[[id:it[0]], it[1]]
}

ch_input_for_kaiju2tablecombine = ch_profiles_for_kaiju
.map { meta, profile -> [meta.id, meta, profile] }
.combine(ch_input_databases.kaiju.map{meta, db -> [meta.db_name, meta, db]}, by: 0)
.multiMap {
key, meta, profile, db_meta, db ->
profile: [meta, profile]
db: db
}
ch_input_for_kaiju2tablecombine = combineProfilesWithDatabase(ch_profiles_for_kaiju, ch_input_databases.kaiju)

KAIJU_KAIJU2TABLE_COMBINED ( ch_input_for_kaiju2tablecombine.profile, ch_input_for_kaiju2tablecombine.db, params.kaiju_taxon_rank)
ch_multiqc_files = ch_multiqc_files.mix( KAIJU_KAIJU2TABLE_COMBINED.out.summary )
Expand Down Expand Up @@ -172,14 +189,7 @@ workflow STANDARDISATION_PROFILES {
[[id:it[0]], it[1]]
}

ch_input_for_motusmerge = ch_profiles_for_motus
.map { meta, profile -> [meta.id, meta, profile] }
.combine(ch_input_databases.motus.map{meta, db -> [meta.db_name, meta, db]}, by: 0)
.multiMap {
key, meta, profile, db_meta, db ->
profile: [meta, profile]
db: db
}
ch_input_for_motusmerge = combineProfilesWithDatabase(ch_profiles_for_motus, ch_input_databases.motus)

MOTUS_MERGE ( ch_input_for_motusmerge.profile, ch_input_for_motusmerge.db, motu_version )
ch_versions = ch_versions.mix( MOTUS_MERGE.out.versions )
Expand Down

0 comments on commit e38b36a

Please sign in to comment.