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

Feat/nf tests #350

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
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 .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.config linguist-language=nextflow
*.nf.test linguist-language=nextflow
tests/**/*nf.test.snap linguist-generated
modules/nf-core/** linguist-generated
subworkflows/nf-core/** linguist-generated
99 changes: 49 additions & 50 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
name: nf-core CI
# This workflow runs the pipeline with the minimal test dataset to check that it completes without any syntax errors
name: nf-core CI
on:
push:
branches:
- dev
pull_request:
branches:
- dev
- master
release:
types: [published]
types:
- "published"

env:
NXF_ANSI_LOG: false
NFTEST_VER: "0.7.3"

concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: true

jobs:
define_nxf_versions:
name: Choose nextflow versions to test against depending on target branch
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.nxf_versions.outputs.matrix }}
steps:
- id: nxf_versions
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.base_ref }}" == "dev" && "${{ matrix.NXF_VER }}" != "latest-everything" ]]; then
echo matrix='["latest-everything"]' | tee -a $GITHUB_OUTPUT
else
echo matrix='["latest-everything", "22.10.1"]' | tee -a $GITHUB_OUTPUT
fi

test:
name: Run pipeline with test data
# Only run on push if this is the nf-core dev branch (merged PRs)
if: "${{ github.event_name != 'push' || (github.event_name == 'push' && github.repository == 'nf-core/chipseq') }}"
name: nf-test
needs: define_nxf_versions
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
NXF_VER:
- "22.10.1"
- "latest-everything"
NXF_VER: ${{ fromJson(needs.define_nxf_versions.outputs.matrix) }}
tags:
- "test_profile"
- "test_skip_trimming"
- "test_skip_consensus_peaks"
- "test_aligner_bowtie2"
- "test_aligner_chromap"
- "test_aligner_star"
profile:
- "docker"

steps:
- name: Check out pipeline code
uses: actions/checkout@v3
Expand All @@ -35,51 +62,23 @@ jobs:
with:
version: "${{ matrix.NXF_VER }}"

- name: Run pipeline with test data
- name: Install nf-test
run: |
nextflow run ${GITHUB_WORKSPACE} -profile test,docker --outdir ./results
wget -qO- https://code.askimed.com/install/nf-test | bash -s $NFTEST_VER
sudo mv nf-test /usr/local/bin/

parameters:
name: Test workflow parameters
if: ${{ github.event_name != 'push' || (github.event_name == 'push' && github.repository == 'nf-core/chipseq') }}
runs-on: ubuntu-latest
strategy:
matrix:
parameters:
- "--skip_trimming"
- "--skip_consensus_peaks"
steps:
- name: Check out pipeline code
uses: actions/checkout@v2

- name: Install Nextflow
- name: Run nf-test
run: |
wget -qO- get.nextflow.io | bash
sudo mv nextflow /usr/local/bin/
nf-test test --tag ${{ matrix.tags }} --profile test,${{ matrix.profile }} --junitxml=test.xml

- name: Run pipeline with various parameters
- name: Output log on failure
if: failure()
run: |
nextflow run ${GITHUB_WORKSPACE} -profile test,docker ${{ matrix.parameters }} --outdir ./results
sudo apt install bat > /dev/null
batcat --decorations=always --color=always ${{ github.workspace }}/.nf-test/tests/*/output/pipeline_info/software_versions.yml

aligners:
name: Test available aligners
if: ${{ github.event_name != 'push' || (github.event_name == 'push' && github.repository == 'nf-core/chipseq') }}
runs-on: ubuntu-latest
strategy:
matrix:
aligner:
- "bowtie2"
- "chromap"
- "star"
steps:
- name: Check out pipeline code
uses: actions/checkout@v2

- name: Install Nextflow
run: |
wget -qO- get.nextflow.io | bash
sudo mv nextflow /usr/local/bin/

- name: Run pipeline with the different aligners available
run: |
nextflow run ${GITHUB_WORKSPACE} -profile test,docker --aligner ${{ matrix.aligner }} --outdir ./results
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: always() # always run even if the previous step fails
with:
report_paths: "*.xml"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ results/
testing/
testing*
*.pyc
.nf-test/
nf-test
4 changes: 4 additions & 0 deletions .nf-core.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
repository_type: pipeline
lint:
files_unchanged:
- .gitattributes
actions_ci: False
16 changes: 16 additions & 0 deletions nf-test.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
config {
// location for all nf-tests
testsDir "tests"

// nf-test directory including temporary files for each test
workDir ".nf-test"

// location of library folder that is added automatically to the classpath
libDir "tests/pipeline/lib/"

// location of an optional nextflow.config file specific for executing tests
configFile "nextflow.config"

// run all test with the defined docker profile from the main nextflow.config
profile ""
}
38 changes: 38 additions & 0 deletions tests/pipeline/lib/UTILS.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Helper functions for pipeline tests

class UTILS {

// Function to remove Nextflow version from software_versions.yml
public static String removeNextflowVersion(outputDir) {
def softwareVersions = path("$outputDir/pipeline_info/software_versions.yml").yaml
if (softwareVersions.containsKey("Workflow")) {
softwareVersions.Workflow.remove("Nextflow")
}
return softwareVersions
}

// Function to filter lines from a file and return a new file
public static File filterLines(String inFilePath, int linesToSkip) {
if (linesToSkip >= 0) {
File inputFile = new File(inFilePath)
File outputFile = new File(inFilePath + ".filtered")
def lineCount = 0
inputFile.eachLine { line ->
lineCount++
if (lineCount > linesToSkip) {
outputFile.append(line + '\n')
}
}
return outputFile
} else {
File inputFile = new File(inFilePath)
File outputFile = new File(inFilePath + ".filtered")
def lines = inputFile.readLines()
def totalLines = lines.size()
lines.take(totalLines + linesToSkip).each { line ->
outputFile.append(line + '\n')
}
return outputFile
}
}
}
43 changes: 43 additions & 0 deletions tests/pipeline/test.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
nextflow_pipeline {

name "Test Workflow main.nf"
script "main.nf"
tag "test_profile"
tag "pipeline"

test("Default Test Profile") {

when {
params {
outdir = "$outputDir"
}
}

then {
assertAll(
{ assert workflow.success },
{ assert snapshot(UTILS.removeNextflowVersion("$outputDir")).match("software_versions") },
{ assert snapshot(path("$outputDir/bwa/mergedLibrary/SPT5_INPUT_REP1.mLb.clN.sorted.bam"),
path("$outputDir/bwa/mergedLibrary/SPT5_INPUT_REP2.mLb.clN.sorted.bam"),
path("$outputDir/bwa/mergedLibrary/SPT5_T0_REP1.mLb.clN.sorted.bam"),
path("$outputDir/bwa/mergedLibrary/SPT5_T0_REP2.mLb.clN.sorted.bam"),
path("$outputDir/bwa/mergedLibrary/SPT5_T15_REP1.mLb.clN.sorted.bam"),
path("$outputDir/bwa/mergedLibrary/SPT5_T15_REP2.mLb.clN.sorted.bam")).match("bwa/mergedLibrary/") },
{ assert new File("$outputDir/bwa/mergedLibrary/bigwig/").exists() },
{ assert new File("$outputDir/bwa/mergedLibrary/deepTools/").exists() },
{ assert new File("$outputDir/bwa/mergedLibrary/macs2/").exists() },
{ assert new File("$outputDir/bwa/mergedLibrary/phantompeakqualtools/").exists() },
{ assert new File("$outputDir/bwa/mergedLibrary/picard_metrics/").exists() },
{ assert new File("$outputDir/bwa/mergedLibrary/samtools_stats/").exists() },
{ assert new File("$outputDir/fastqc/").exists() },
{ assert snapshot(path("$outputDir/genome").list()).match("genome") },
{ assert new File("$outputDir/igv/").exists() },
{ assert new File("$outputDir/multiqc/").exists() },
{ assert new File("$outputDir/pipeline_info/").exists() },
{ assert new File("$outputDir/trimgalore/").exists() }
)
}

}

}
28 changes: 28 additions & 0 deletions tests/pipeline/test.nf.test.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions tests/pipeline/test_aligner_bowtie2.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
nextflow_pipeline {

name "Test Workflow main.nf"
script "main.nf"
tag "test_aligner_bowtie2"
tag "pipeline"

test("Aligner - Bowtie2") {

when {
params {
outdir = "$outputDir"
aligner = "bowtie2"
}
}

then {
assertAll(
{ assert workflow.success },
{ assert snapshot(UTILS.removeNextflowVersion("$outputDir")).match("software_versions") },
{ assert new File("$outputDir/bowtie2/mergedLibrary/SPT5_INPUT_REP1.mLb.clN.sorted.bam").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/SPT5_INPUT_REP2.mLb.clN.sorted.bam").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/SPT5_T0_REP1.mLb.clN.sorted.bam").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/SPT5_T0_REP2.mLb.clN.sorted.bam").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/SPT5_T15_REP1.mLb.clN.sorted.bam").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/SPT5_T15_REP2.mLb.clN.sorted.bam").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/bigwig/").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/deepTools/").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/macs2/").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/phantompeakqualtools/").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/picard_metrics/").exists() },
{ assert new File("$outputDir/bowtie2/mergedLibrary/samtools_stats/").exists() },
{ assert new File("$outputDir/fastqc/").exists() },
{ assert snapshot(path("$outputDir/genome").list()).match("genome") },
{ assert new File("$outputDir/igv/").exists() },
{ assert new File("$outputDir/multiqc/").exists() },
{ assert new File("$outputDir/pipeline_info/").exists() },
{ assert new File("$outputDir/trimgalore/").exists() }
)
}

}

}
17 changes: 17 additions & 0 deletions tests/pipeline/test_aligner_bowtie2.nf.test.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions tests/pipeline/test_aligner_chromap.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
nextflow_pipeline {

name "Test Workflow main.nf"
script "main.nf"
tag "test_aligner_chromap"
tag "pipeline"

test("Aligner - Chromap") {

when {
params {
outdir = "$outputDir"
aligner = "chromap"
}
}

then {
assertAll(
{ assert workflow.success },
{ assert snapshot(UTILS.removeNextflowVersion("$outputDir")).match("software_versions") },
{ assert snapshot(path("$outputDir/chromap/mergedLibrary/SPT5_INPUT_REP1.mLb.clN.sorted.bam"),
path("$outputDir/chromap/mergedLibrary/SPT5_INPUT_REP2.mLb.clN.sorted.bam"),
path("$outputDir/chromap/mergedLibrary/SPT5_T0_REP1.mLb.clN.sorted.bam"),
path("$outputDir/chromap/mergedLibrary/SPT5_T0_REP2.mLb.clN.sorted.bam"),
path("$outputDir/chromap/mergedLibrary/SPT5_T15_REP1.mLb.clN.sorted.bam"),
path("$outputDir/chromap/mergedLibrary/SPT5_T15_REP2.mLb.clN.sorted.bam")).match("bwa/mergedLibrary/") },
{ assert new File("$outputDir/chromap/mergedLibrary/bigwig/").exists() },
{ assert new File("$outputDir/chromap/mergedLibrary/deepTools/").exists() },
{ assert new File("$outputDir/chromap/mergedLibrary/macs2/").exists() },
{ assert new File("$outputDir/chromap/mergedLibrary/phantompeakqualtools/").exists() },
{ assert new File("$outputDir/chromap/mergedLibrary/picard_metrics/").exists() },
{ assert new File("$outputDir/chromap/mergedLibrary/samtools_stats/").exists() },
{ assert new File("$outputDir/fastqc/").exists() },
{ assert snapshot(path("$outputDir/genome").list()).match("genome") },
{ assert new File("$outputDir/igv/").exists() },
{ assert new File("$outputDir/multiqc/").exists() },
{ assert new File("$outputDir/pipeline_info/").exists() },
{ assert new File("$outputDir/trimgalore/").exists() }
)
}

}

}
Loading