Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function for mapcombinemultimap #339

Merged
merged 7 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions subworkflows/local/profiling.nf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ include { KRAKENUNIQ_PRELOADEDKRAKENUNIQ } from '../../modules/nf
include { GANON_CLASSIFY } from '../../modules/nf-core/ganon/classify/main'
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
*/
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 PROFILING {
take:
reads // [ [ meta ], [ reads ] ]
Expand Down Expand Up @@ -236,18 +261,7 @@ workflow PROFILING {
.filter { meta, db -> meta.tool == 'centrifuge' }
.map { meta, db -> [meta.db_name, meta, db] }

// We must combine the _results_ file to get correct output - sending the report file will
// weirdly still produce valid-looking output, however the numbers are nonsense.
// Unfortunately the Centrifuge documentation for this was unclear as to _which_ outfile
// goes into it.
ch_input_for_centrifuge_kreport = CENTRIFUGE_CENTRIFUGE.out.results
.map { meta, profile -> [meta.db_name, meta, profile] }
.combine(ch_database_for_centrifugekreport, by: 0)
.multiMap {
key, meta, profile, db_meta, db ->
profile: [meta, profile]
db: db
}
ch_input_for_centrifuge_kreport = combineProfilesWithDatabase(CENTRIFUGE_CENTRIFUGE.out.report, ch_database_for_centrifugekreport)

// Generate profile
CENTRIFUGE_KREPORT (ch_input_for_centrifuge_kreport.profile, ch_input_for_centrifuge_kreport.db)
Expand Down Expand Up @@ -290,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
Loading