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

Disable BWAMEM2 index when no short reads data #100

Merged
merged 2 commits into from
Aug 1, 2024
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
53 changes: 38 additions & 15 deletions subworkflows/local/prepare_genome.nf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ workflow PREPARE_GENOME {
take:
fasta // channel: [ meta, /path/to/fasta ]


main:
ch_versions = Channel.empty()

Expand All @@ -33,24 +32,27 @@ workflow PREPARE_GENOME {
UNMASK ( ch_fasta )
ch_versions = ch_versions.mix ( UNMASK.out.versions )


// Generate BWA index
if ( params.bwamem2_index ) {
Channel.fromPath ( params.bwamem2_index )
| combine ( ch_fasta )
| map { bwa, meta, fa -> [ meta, bwa ] }
| set { ch_bwamem }

if ( params.bwamem2_index.endsWith('.tar.gz') ) {
ch_bwamem2_index = UNTAR ( ch_bwamem ).untar
ch_versions = ch_versions.mix ( UNTAR.out.versions )
if ( checkShortReads(params.input) ) {
if ( params.bwamem2_index ) {
Channel.fromPath ( params.bwamem2_index )
| combine ( ch_fasta )
| map { bwa, meta, fa -> [ meta, bwa ] }
| set { ch_bwamem }

if ( params.bwamem2_index.endsWith('.tar.gz') ) {
ch_bwamem2_index = UNTAR ( ch_bwamem ).untar
ch_versions = ch_versions.mix ( UNTAR.out.versions.first() )
} else {
ch_bwamem2_index = ch_bwamem
}

} else {
ch_bwamem2_index = ch_bwamem
ch_bwamem2_index = BWAMEM2_INDEX ( UNMASK.out.fasta ).index
ch_versions = ch_versions.mix ( BWAMEM2_INDEX.out.versions.first() )
}

} else {
ch_bwamem2_index = BWAMEM2_INDEX ( UNMASK.out.fasta ).index
ch_versions = ch_versions.mix ( BWAMEM2_INDEX.out.versions )
ch_bwamem2_index = Channel.empty()
}


Expand All @@ -59,3 +61,24 @@ workflow PREPARE_GENOME {
bwaidx = ch_bwamem2_index.first() // channel: [ meta, /path/to/bwamem2/index_dir/ ]
versions = ch_versions // channel: [ versions.yml ]
}

def checkShortReads(filePath, columnToCheck="datatype") {
// Define the target values to check
def valuesToCheck = ['illumina', 'hic']
// Read the CSV file
def csvLines = new File(filePath).readLines()
// Extract the header and find the index of the column
def header = csvLines[0].split(',')
def columnIndex = header.findIndexOf { it == columnToCheck }
// Check if the column index was found
if (columnIndex == -1) {
println "Column '${columnToCheck}' not found in the CSV header."
return false
}
// Check for the values in the specified column and return true if found
def containsValues = csvLines[1..-1].any { line ->
def columns = line.split(',')
valuesToCheck.contains(columns[columnIndex].toLowerCase())
}
return containsValues
}
4 changes: 0 additions & 4 deletions workflows/readmapping.nf
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ workflow READMAPPING {

ch_versions = ch_versions.mix ( INPUT_CHECK.out.versions )


//
// SUBWORKFLOW: Uncompress and prepare reference genome files
//
ch_fasta
| map { [ [ id: it.baseName ], it ] }
| set { ch_genome }
Expand Down
Loading