Skip to content

Commit

Permalink
Start refactoring to use nft-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jfy133 committed Oct 4, 2024
1 parent 9a56d48 commit bb12ca1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 390 deletions.
6 changes: 6 additions & 0 deletions nf-test.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ config {
configFile "tests/nextflow.config"
profile ""

// load the necessary plugins
plugins {
load "[email protected]"
load "[email protected]"
}

}
146 changes: 62 additions & 84 deletions tests/test.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,75 @@ nextflow_pipeline {
}

then {

// Each top level results directory should be tested with individual snapshots/variables
// stable_name_<dir> is for files with varaible md5sums (i.e. content) so only names will be compared
// stable_content_<dir> is for files with stable md5sums (i.e. content) so md5sums will be compared
// For both functions, use the third argument to specify globs to exclude certain files
// If a directory is fully stable, you can drop `stable_name_*`
// Generate with: nf-test test --tag test --profile docker,test --update-snapshot
def stable_name_bamfiltering = getAllFilesFromDir("$outputDir/bam_filtering", true , null, null )
def stable_content_bamfiltering = getAllFilesFromDir("$outputDir/bam_filtering", false, null, null )

assertAll(
{ assert workflow.success },
{ assert snapshot( path("$outputDir/bam_filtering") ).match("bam_filtering") },
{ assert snapshot( path("$outputDir/bam_input_stats") ).match("bam_input_stats") },
{ assert snapshot( path("$outputDir/deduplication") ).match("deduplication") },
{ assert snapshot( path("$outputDir/mapping") ).match("mapping") },
/*
Exceptions (variable md5sums)
*/

// Damage Estimation
{ assert snapshot(
getAllFilesFromDir("$outputDir/damage_estimation/" , ".txt" ),
getAllFilesFromDir("$outputDir/damage_estimation/" , ".json"),
getAllFileNamesFromDir("$outputDir/damage_estimation/" , ".svg" ),
getAllFileNamesFromDir("$outputDir/damage_estimation/" , ".pdf" ),
checkAllFilesNamesFromDirForString("$outputDir/damage_estimation/", '.log', 'FINISHED SUCCESSFULLY'),
).match("damage_estimation")
},
{ assert snapshot( stable_name_bamfiltering*.name, stable_content_bamfiltering ).match("bam_filtering") },
// { assert snapshot( path("$outputDir/bam_input_stats") ).match("bam_input_stats") },
// { assert snapshot( path("$outputDir/deduplication") ).match("deduplication") },
// { assert snapshot( path("$outputDir/mapping") ).match("mapping") },
// /*
// Exceptions (variable md5sums)
// */

// Preprocessing
{ assert snapshot(
getAllFilesFromDir("$outputDir/preprocessing/fastp" , '.json' ),
getAllFileNamesFromDir("$outputDir/preprocessing/fastp" , '.html' ),
checkAllFilesNamesFromDirForString("$outputDir/preprocessing/fastp" , '.log', 'time used:'),
getAllFilesFromDir("$outputDir/preprocessing/fastqc_raw" , '.html' ),
getAllFileNamesFromDir("$outputDir/preprocessing/fastqc_raw" , '.zip' ),
getAllFilesFromDir("$outputDir/preprocessing/fastqc_processed" , '.html' ),
getAllFileNamesFromDir("$outputDir/preprocessing/fastqc_processed" , '.zip' ),
).match("preprocessing" )
},
// // Damage Estimation
// { assert snapshot(
// getAllFilesFromDir("$outputDir/damage_estimation/" , ".txt" ),
// getAllFilesFromDir("$outputDir/damage_estimation/" , ".json"),
// getAllFileNamesFromDir("$outputDir/damage_estimation/" , ".svg" ),
// getAllFileNamesFromDir("$outputDir/damage_estimation/" , ".pdf" ),
// checkAllFilesNamesFromDirForString("$outputDir/damage_estimation/", '.log', 'FINISHED SUCCESSFULLY'),
// ).match("damage_estimation")
// },

// Final BAMs
{ assert snapshot(
getAllFilesFromDir("$outputDir/final_bams" , '.flagstat'),
getAllFileNamesFromDir("$outputDir/final_bams", '.bam' ),
getAllFileNamesFromDir("$outputDir/final_bams", '.bai' ),
).match("final_bams")
},
// // Preprocessing
// { assert snapshot(
// getAllFilesFromDir("$outputDir/preprocessing/fastp" , '.json' ),
// getAllFileNamesFromDir("$outputDir/preprocessing/fastp" , '.html' ),
// checkAllFilesNamesFromDirForString("$outputDir/preprocessing/fastp" , '.log', 'time used:'),
// getAllFilesFromDir("$outputDir/preprocessing/fastqc_raw" , '.html' ),
// getAllFileNamesFromDir("$outputDir/preprocessing/fastqc_raw" , '.zip' ),
// getAllFilesFromDir("$outputDir/preprocessing/fastqc_processed" , '.html' ),
// getAllFileNamesFromDir("$outputDir/preprocessing/fastqc_processed" , '.zip' ),
// ).match("preprocessing" )
// },

// Mapstats
{ assert snapshot(
getAllFilesFromDir("$outputDir/mapstats", '.bed'),
getAllFilesFromDir("$outputDir/mapstats", '.json'),
getAllFilesFromDir("$outputDir/mapstats", '.txt'),
getAllFilesFromDir("$outputDir/mapstats", '.log'),
getAllFilesFromDir("$outputDir/mapstats", '.css'),
getAllFilesFromDir("$outputDir/mapstats", '.png'),
getAllFilesFromDir("$outputDir/mapstats", '.js'),
getAllFileNamesFromDir("$outputDir/mapstats", '.html'), // For variable qualimapReport.html
).match("mapstats")
},
// // Final BAMs
// { assert snapshot(
// getAllFilesFromDir("$outputDir/final_bams" , '.flagstat'),
// getAllFileNamesFromDir("$outputDir/final_bams", '.bam' ),
// getAllFileNamesFromDir("$outputDir/final_bams", '.bai' ),
// ).match("final_bams")
// },

// MultiQC
{ assert snapshot(
path("$outputDir/multiqc/multiqc_report.html").exists()
).match("multiqc")
},
// // Mapstats
// { assert snapshot(
// getAllFilesFromDir("$outputDir/mapstats", '.bed'),
// getAllFilesFromDir("$outputDir/mapstats", '.json'),
// getAllFilesFromDir("$outputDir/mapstats", '.txt'),
// getAllFilesFromDir("$outputDir/mapstats", '.log'),
// getAllFilesFromDir("$outputDir/mapstats", '.css'),
// getAllFilesFromDir("$outputDir/mapstats", '.png'),
// getAllFilesFromDir("$outputDir/mapstats", '.js'),
// getAllFileNamesFromDir("$outputDir/mapstats", '.html'), // For variable qualimapReport.html
// ).match("mapstats")
// },

// // MultiQC
// { assert snapshot(
// path("$outputDir/multiqc/multiqc_report.html").exists()
// ).match("multiqc")
// },

// Versions
{ assert new File("$outputDir/pipeline_info/nf_core_pipeline_software_mqc_versions.yml").exists() },
Expand All @@ -82,36 +93,3 @@ nextflow_pipeline {
}
}
}

// Recursively list all files in a directory and its sub-directories, matching a given suffix
// TODO: use regex pattern instead of suffix?
def getAllFilesFromDir(dir, suffix) {
def output = []
new File(dir).eachFileRecurse() {
if (it.name.toString().endsWith(suffix)) {
output.add(it)
}
}
return output.sort()
}
// Recursively list all files names in a directory and its sub-directories, matching a given suffix, return file names
def getAllFileNamesFromDir(dir, suffix) {
def output = []
new File(dir).eachFileRecurse() {
if (it.name.toString().endsWith(suffix)) {
output.add(it.toString().split("/")[-1])
}
}
return output.sort()
}

// Recursively list all files names in a directory and its sub-directories, matching a given suffix, return if check if given string is in file
def checkAllFilesNamesFromDirForString(dir, suffix, string) {
def output = []
new File(dir).eachFileRecurse() {
if (it.name.toString().endsWith(suffix)) {
output.add(it.text.contains(string))
}
}
return output.sort()
}
Loading

0 comments on commit bb12ca1

Please sign in to comment.