Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#310](https://github.com/nf-core/bacass/pull/310) Use nf-core Medaka, add BUSCO to MultiQC, and fix Dragonflye channels
- [#316](https://github.com/nf-core/bacass/pull/316) Reorganize result output directories
- [#317](https://github.com/nf-core/bacass/pull/317) Improve MultiQC assembly summary tables
- [#324](https://github.com/nf-core/bacass/pull/324) Improved kmerfinder_summary_download subworkflow for correct reference matching

### `Added`

Expand Down
43 changes: 26 additions & 17 deletions subworkflows/local/kmerfinder_summary_download/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,32 @@ workflow KMERFINDER_SUMMARY_DOWNLOAD {
)
ch_versions = ch_versions.mix(KMERFINDER_FIND_WINNER_REFERENCE.out.versions)

// Prepare channel for NCBI_DATASETS_DOWNLOAD
// Extract base accession from winner file (remove assembly version)
ch_accessions_for_download = KMERFINDER_FIND_WINNER_REFERENCE.out.winner
.map { _refmeta, winner_file ->
// Preserve the winner selected for each species. This key must also be used
// when associating the downloaded reference with the sample assemblies.
// Deriving an accession from an arbitrary report in the species group can
// select a different reference and leave the downstream joins empty.
ch_winner_references = KMERFINDER_FIND_WINNER_REFERENCE.out.winner
.map { species, winner_file ->
def full_accession = winner_file.text.trim()
// Extract base accession: GCF_002795805.1_ASM279580v1 → GCF_002795805.1
def base_accession = full_accession.split('_')[0] + '_' + full_accession.split('_')[1]
return tuple([id: base_accession], base_accession)
return tuple(species, base_accession)
}

// Prepare channel for NCBI_DATASETS_DOWNLOAD.
ch_accessions_for_download = ch_winner_references
.map { _species, base_accession -> tuple([id: base_accession], base_accession) }

// MODULE: Download reference genomes using NCBI datasets CLI
NCBI_DATASETS_DOWNLOAD (
ch_accessions_for_download
)
ch_versions = ch_versions.mix(NCBI_DATASETS_DOWNLOAD.out.versions)

// Organize sample assemblies into channels based on their corresponding reference files.
ch_reports_byreference
.map { species, meta, report_txt, fasta ->
// Extract base accession from the first report to match with downloads
def first_line = report_txt[0].text.split('\n').find { line -> !line.startsWith('#') && line.trim() }
def full_accession = first_line ? first_line.split('\t')[0] : null
def base_accession = full_accession ? full_accession.split('_')[0] + '_' + full_accession.split('_')[1] : null
return tuple(base_accession, species, meta, report_txt, fasta)
}
.filter { base_accession, _species, _meta, _report_txt, _fasta -> base_accession != null }
// Associate each species with the reference selected by
// KMERFINDER_FIND_WINNER_REFERENCE and its downloaded files.
ch_winner_references
.map { species, base_accession -> tuple(base_accession, species) }
.join(
NCBI_DATASETS_DOWNLOAD.out.fna.map { meta, fna -> tuple(meta.id, fna) },
by: 0
Expand All @@ -106,8 +106,17 @@ workflow KMERFINDER_SUMMARY_DOWNLOAD {
by: 0
)
.map {
base_accession, _species, meta, _report_txt, fasta, fna, gff ->
return tuple([id: base_accession], meta, fasta, fna, gff)
base_accession, species, fna, gff ->
return tuple(species, [id: base_accession], fna, gff)
}
.set { ch_reference_by_species }

// Add every assembly in a species group to that species' selected reference.
ch_reports_byreference
.join(ch_reference_by_species, by: 0)
.map {
_species, meta, _report_txt, fasta, refmeta, fna, gff ->
return tuple(refmeta, meta, fasta, fna, gff)
}
.set { ch_consensus_byrefseq }

Expand Down
Loading