Skip to content

Commit

Permalink
Provide tests and data structure for bam and pod5 registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffengreiner committed Oct 24, 2024
1 parent d43dd4a commit a472f51
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class OxfordNanoporeExperimentSpec extends Specification {
Map minimalDataStructurePooled

@Shared
Map minimalDoradoDataStructure
Map minimalPod5DoradoDataStructure

@Shared
Map minimalBamDoradoDataStructure

@Shared
Map fullDoradoDataStructure
Expand Down Expand Up @@ -96,8 +99,12 @@ class OxfordNanoporeExperimentSpec extends Specification {
stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(folder+"valid-minimal-structure-pooled.json")
minimalDataStructurePooled = (Map) new JsonSlurper().parse(stream)
// read in minimal required example with dorado based basecalling
stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(folder+"valid-minimal-structure-dorado-basecaller.json")
minimalDoradoDataStructure = (Map) new JsonSlurper().parse(stream)
stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(folder+"valid-minimal-structure-pod5-dorado-basecaller.json")
minimalPod5DoradoDataStructure = (Map) new JsonSlurper().parse(stream)
stream.close()
// read in minimal required example with dorado based basecalling
stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(folder+"valid-minimal-structure-bam-dorado-basecaller.json")
minimalBamDoradoDataStructure = (Map) new JsonSlurper().parse(stream)
stream.close()
// read in minimal required example with dorado based basecalling
stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(folder+"valid-example-dorado-basecaller.json")
Expand Down Expand Up @@ -210,9 +217,9 @@ class OxfordNanoporeExperimentSpec extends Specification {
assert measurements[0].asicTemp == "32.631687"
}

def "Create sample Oxford Nanopore experiment successfully for dorado basecaller generated minimal structure"() {
def "Create sample Oxford Nanopore experiment successfully for pod5 generated minimal structure"() {
given:
final def example = minimalDoradoDataStructure
final def example = minimalPod5DoradoDataStructure

when:
final def experiment = OxfordNanoporeExperiment.create(example)
Expand All @@ -222,8 +229,24 @@ class OxfordNanoporeExperimentSpec extends Specification {
assert experiment.sampleCode == "QABCD001AB"
assert measurements.size() == 1
assert measurements[0].asicTemp == "32.631687"
assert measurements[0].getRawDataPerSample(experiment).get("QABCD001AB").containsKey("pod5skip")
assert measurements[0].getRawDataPerSample(experiment).get("QABCD001AB").containsKey("fast5skip")
assert measurements[0].getRawDataPerSample(experiment).get("QABCD001AB").containsKey("pod5pass")
assert measurements[0].getRawDataPerSample(experiment).get("QABCD001AB").containsKey("pod5fail")
}

def "Create sample Oxford Nanopore experiment successfully for bam generated minimal structure"() {
given:
final def example = minimalBamDoradoDataStructure

when:
final def experiment = OxfordNanoporeExperiment.create(example)
final def measurements = experiment.getMeasurements()

then:
assert experiment.sampleCode == "QABCD001AB"
assert measurements.size() == 1
assert measurements[0].asicTemp == "32.631687"
assert measurements[0].getRawDataPerSample(experiment).get("QABCD001AB").containsKey("bampass")
assert measurements[0].getRawDataPerSample(experiment).get("QABCD001AB").containsKey("bamfail")
}

def "Create sample Oxford Nanopore experiment successfully for dorado basecaller generated full structure"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package life.qbic.datamodel.datasets.datastructure

import life.qbic.datamodel.datasets.ExperimentFolder
import life.qbic.datamodel.datasets.OxfordNanoporeMeasurement
import life.qbic.datamodel.datasets.datastructure.files.nanopore.BamFile
import life.qbic.datamodel.datasets.datastructure.files.nanopore.Fast5File
import life.qbic.datamodel.datasets.datastructure.files.nanopore.FastQFile
import life.qbic.datamodel.datasets.datastructure.files.nanopore.Pod5File
import life.qbic.datamodel.datasets.datastructure.folders.DataFolder
import life.qbic.datamodel.datasets.datastructure.folders.nanopore.*
import spock.lang.Shared
Expand Down Expand Up @@ -38,9 +40,13 @@ class OxfordNanoporeMeasurementSpec extends Specification {
@Shared
UnclassifiedFastQFolder unclassifiedFastQFolder
@Shared
Pod5SkipFolder pod5SkipFolder
Pod5PassFolder pod5PassedFolder
@Shared
Fast5SkipFolder fast5SkipFolder
Pod5FailFolder pod5FailedFolder
@Shared
BamPassFolder bamPassedFolder
@Shared
BamFailFolder bamFailedFolder

@Shared
Map metaData
Expand All @@ -62,6 +68,8 @@ class OxfordNanoporeMeasurementSpec extends Specification {
]
def fast5File = Fast5File.create("test.fast5", "root/test.fast5")
def fastQFile = FastQFile.create("test.fastq", "root/test.fastq")
def pod5File = Pod5File.create("test.pod5", "root/test.pod5")
def bamFile = BamFile.create("test.bam", "root/test.bam")
fast5FailedFolder = Fast5FailFolder.create("fast5_fail","root/fast5_fail", [fast5File])
fast5PassedFolder = Fast5PassFolder.create("fast5_pass","root/fast5_pass", [fast5File])
fastQFailedFolder = FastQFailFolder.create("fastq_fail", "root/fastq_fail", [fastQFile])
Expand All @@ -74,6 +82,10 @@ class OxfordNanoporeMeasurementSpec extends Specification {
// Content for the pooled samples including unclassified folders
unclassifiedFast5Folder = UnclassifiedFast5Folder.create("unclassified", "fast5_fail/unclassified", [fast5File])
unclassifiedFastQFolder = UnclassifiedFastQFolder.create("unclassified", "fastq_pass/unclassified", [fastQFile])
bamFailedFolder = BamFailFolder.create("bam_fail", "root/bam_fail", [bamFile])
bamPassedFolder = BamPassFolder.create("bam_pass","root/bam_pass", [bamFile])
pod5FailedFolder = Pod5FailFolder.create("pod5_fail", "root/pod5_fail", [pod5File])
pod5PassedFolder = Pod5PassFolder.create("pod5_pass","root/pod5_pass", [pod5File])
}

def "create simple measurement successfully"() {
Expand Down Expand Up @@ -235,16 +247,33 @@ class OxfordNanoporeMeasurementSpec extends Specification {

}

def "If both pod5 skip and fast5 skip folder are empty, an IllegalStateException shall be thrown"() {
def "If both pod5 pass and pod5 fail folder are empty, an IllegalStateException shall be thrown"() {
given:
def emptyPod5SkipFolder = Pod5SkipFolder.create("pod5_skip","root/pod5_skip", [])
def emptyFast5SkipFolder = Fast5SkipFolder.create("fast5_skip","root/fast5_skip", [])
def emptyPod5PassFolder = Pod5PassFolder.create("pod5_pass","root/pod5_pass", [])
def emptyPod5FailFolder = Pod5FailFolder.create("pod5_fail","root/pod5_fail", [])

when:
OxfordNanoporeMeasurement.create(
"20200219_1107_1-E3-H3_PAE26974_454b8dc6",
"path/20200219_1107_1-E3-H3_PAE26974_454b8dc6",
[emptyPod5SkipFolder, emptyFast5SkipFolder],
[emptyPod5PassFolder, emptyPod5FailFolder],
metaData)

then:
thrown(IllegalStateException)

}

def "If both bam pass and bam fail folder are empty, an IllegalStateException shall be thrown"() {
given:
def emptyBamPassFolder = BamPassFolder.create("bam_pass","root/bam_pass", [])
def emptyBamFailFolder = BamFailFolder.create("bam_fail","root/bam_fail", [])

when:
OxfordNanoporeMeasurement.create(
"20200219_1107_1-E3-H3_PAE26974_454b8dc6",
"path/20200219_1107_1-E3-H3_PAE26974_454b8dc6",
[emptyBamPassFolder, emptyBamFailFolder],
metaData)

then:
Expand Down Expand Up @@ -282,6 +311,46 @@ class OxfordNanoporeMeasurementSpec extends Specification {
noExceptionThrown()
}

def "If either bam pass or bam folder is empty, no IllegalStateException shall be thrown"() {
given:
def emptyBamFailFolder = BamFailFolder.create("bam_fail","root/bam_fail", [])
def emptyBamPassFolder = BamPassFolder.create("bam_pass","root/bam_pass", [])
when:
OxfordNanoporeMeasurement.create(
"20200219_1107_1-E3-H3_PAE26974_454b8dc6",
"path/20200219_1107_1-E3-H3_PAE26974_454b8dc6",
[bamPassedFolder, emptyBamFailFolder],
metaData)
OxfordNanoporeMeasurement.create(
"20200219_1107_1-E3-H3_PAE26974_454b8dc6",
"path/20200219_1107_1-E3-H3_PAE26974_454b8dc6",
[emptyBamPassFolder, bamFailedFolder],
metaData)
then:
noExceptionThrown()
}

def "If either pod5 pass or pod5 folder is empty, no IllegalStateException shall be thrown"() {
given:
def emptyPod5FailedFolder = Pod5FailFolder.create("pod5_fail","root/pod5_fail", [])
def emptyPod5PassedFolder = Pod5PassFolder.create("pod5_pass","root/pod5_pass", [])
when:
OxfordNanoporeMeasurement.create(
"20200219_1107_1-E3-H3_PAE26974_454b8dc6",
"path/20200219_1107_1-E3-H3_PAE26974_454b8dc6",
[pod5PassedFolder, emptyPod5FailedFolder],
metaData)

OxfordNanoporeMeasurement.create(
"20200219_1107_1-E3-H3_PAE26974_454b8dc6",
"path/20200219_1107_1-E3-H3_PAE26974_454b8dc6",
[emptyPod5PassedFolder, pod5FailedFolder],
metaData)
then:
noExceptionThrown()
}


def "missing adapter metadata shall return an empty String and not be null"() {
given:
def metaData = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package life.qbic.datamodel.datasets.datastructure.files.nanopore

import spock.lang.Specification

/**
* <add class description here>
*
*/
class BamFileSpec extends Specification {

def "shall create a BamFile instance"() {
given:
final name = "test_file.bam"
final relativePath = "root/test_file.bam"

when:
def dataObject = BamFile.create(name, relativePath)

then:
assert dataObject instanceof BamFile
assert dataObject.relativePath == relativePath
assert dataObject.name == name
}

def "name not matching schema shall throw IllegalArgumentException"() {
given:
final name = "test_file.bum"
final relativePath = "root/test_file.bum"

when:
def dataObject = BamFile.create(name, relativePath)

then:
thrown(IllegalArgumentException)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package life.qbic.datamodel.datasets.datastructure.files.nanopore

import spock.lang.Specification

/**
* <add class description here>
*
*/
class Pod5FileSpec extends Specification {

def "shall create a Pod5 instance"() {
given:
final name = "test_file.pod5"
final relativePath = "root/test_file.pod5"

when:
def dataObject = Pod5File.create(name, relativePath)

then:
assert dataObject instanceof Pod5File
assert dataObject.relativePath == relativePath
assert dataObject.name == name
}

def "name not matching schema shall throw IllegalArgumentException"() {
given:
final name = "test_file.pad4"
final relativePath = "root/test_file.pad4"

when:
def dataObject = Pod5File.create(name, relativePath)

then:
thrown(IllegalArgumentException)
}

}
Loading

0 comments on commit a472f51

Please sign in to comment.