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

Add toy SAM/BAM files, add test for bam_parser.parse_bam_header #46

Merged
merged 2 commits into from
Nov 7, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased]
### Added
- Functional testing framework with concrete tests for `methods.set_env()`
- Functional test for `bam_parser.parse_bam_header()`.

---

Expand Down
52 changes: 52 additions & 0 deletions tests/BamParserTests.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.nio.file.Path
import java.nio.file.Paths

import static groovy.test.GroovyAssert.shouldFail

import nextflow.util.ConfigHelper
import org.junit.Test

import validator.bl.NextflowConfigTests

class BamParserTests extends NextflowConfigTests {
protected Path get_projectDir() {
return Paths.get(
getClass().protectionDomain.codeSource.location.path
).getParent().getParent()
}

@Override
protected def generate_config_text(configobj) {
return """
includeConfig "\${projectDir}/config/bam/bam_parser.config"

${ConfigHelper.toCanonicalString(configobj)}

params.header = bam_parser.parse_bam_header(params.bam_file)
"""
}

@Test
void parse_missing_read_group() {
def bam_path = builder.get_launchDir().resolve("data/toy.bam").toString()
inconfig.params.bam_file = bam_path
expected.params.bam_file = bam_path
expected.params.header = [read_group: []]

compare()
}

@Test
void parse_read_group() {
def bam_path = builder.get_launchDir().resolve("data/toy-rg.bam").toString()
inconfig.params.bam_file = bam_path
expected.params.bam_file = bam_path
expected.params.header = [
read_group: [
[LB: 'lib1', ID: '4', PL: 'illumina', SM: '20', PU: 'unit1'],
]
]

compare()
}
}
6 changes: 6 additions & 0 deletions tests/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Toy SAM / BAM Files
This directory contains valid tiny files for testing.

* `toy.sam` comes from the [samtools repository](https://github.com/samtools/samtools/blob/554bb9043a2da9ea5db85095dce21b742ba1fb71/examples/toy.sam).
* `toy-rg.sam` is `toy.sam` with a manually-added `@RG` header line.
* `toy.bam` and `toy-rg.bam` come from running `samtools view -bS XXX.sam > XXX.bam`.
Binary file added tests/data/toy-rg.bam
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/data/toy-rg.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@SQ SN:ref LN:45
@SQ SN:ref2 LN:40
@RG ID:4 LB:lib1 PL:illumina SM:20 PU:unit1
@CO https://github.com/samtools/samtools/blob/554bb9043a2da9ea5db85095dce21b742ba1fb71/examples/toy.sam
r001 163 ref 7 30 8M4I4M1D3M = 37 39 TTAGATAAAGAGGATACTG * XX:B:S,12561,2,20,112
r002 0 ref 9 30 1S2I6M1P1I1P1I4M2I * 0 0 AAAAGATAAGGGATAAA *
r003 0 ref 9 30 5H6M * 0 0 AGCTAA *
r004 0 ref 16 30 6M14N1I5M * 0 0 ATAGCTCTCAGC *
r003 16 ref 29 30 6H5M * 0 0 TAGGC *
r001 83 ref 37 30 9M = 7 -39 CAGCGCCAT *
x1 0 ref2 1 30 20M * 0 0 aggttttataaaacaaataa ????????????????????
x2 0 ref2 2 30 21M * 0 0 ggttttataaaacaaataatt ?????????????????????
x3 0 ref2 6 30 9M4I13M * 0 0 ttataaaacAAATaattaagtctaca ??????????????????????????
x4 0 ref2 10 30 25M * 0 0 CaaaTaattaagtctacagagcaac ?????????????????????????
x5 0 ref2 12 30 24M * 0 0 aaTaattaagtctacagagcaact ????????????????????????
x6 0 ref2 14 30 23M * 0 0 Taattaagtctacagagcaacta ???????????????????????
Binary file added tests/data/toy.bam
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/data/toy.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@CO https://github.com/samtools/samtools/blob/554bb9043a2da9ea5db85095dce21b742ba1fb71/examples/toy.sam
@SQ SN:ref LN:45
@SQ SN:ref2 LN:40
r001 163 ref 7 30 8M4I4M1D3M = 37 39 TTAGATAAAGAGGATACTG * XX:B:S,12561,2,20,112
r002 0 ref 9 30 1S2I6M1P1I1P1I4M2I * 0 0 AAAAGATAAGGGATAAA *
r003 0 ref 9 30 5H6M * 0 0 AGCTAA *
r004 0 ref 16 30 6M14N1I5M * 0 0 ATAGCTCTCAGC *
r003 16 ref 29 30 6H5M * 0 0 TAGGC *
r001 83 ref 37 30 9M = 7 -39 CAGCGCCAT *
x1 0 ref2 1 30 20M * 0 0 aggttttataaaacaaataa ????????????????????
x2 0 ref2 2 30 21M * 0 0 ggttttataaaacaaataatt ?????????????????????
x3 0 ref2 6 30 9M4I13M * 0 0 ttataaaacAAATaattaagtctaca ??????????????????????????
x4 0 ref2 10 30 25M * 0 0 CaaaTaattaagtctacagagcaac ?????????????????????????
x5 0 ref2 12 30 24M * 0 0 aaTaattaagtctacagagcaact ????????????????????????
x6 0 ref2 14 30 23M * 0 0 Taattaagtctacagagcaacta ???????????????????????
3 changes: 2 additions & 1 deletion tests/suite.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import org.junit.runner.JUnitCore
result = JUnitCore.runClasses \
ExampleTests, \
SetEnvTests, \
AlignMethodsTests
AlignMethodsTests, \
BamParserTests

String message = "Ran: " + result.getRunCount() + ", Ignored: " + result.getIgnoreCount() + ", Failed: " + result.getFailureCount()
if (result.wasSuccessful()) {
Expand Down