Skip to content

Commit

Permalink
Resolved conflicts between dev and update-parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kylacochrane committed Jun 11, 2024
2 parents 04ee4fd + 4acdb8c commit 9be4562
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
19 changes: 14 additions & 5 deletions modules/local/cluster_file/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@ process CLUSTER_FILE {

exec:
def outputLines = []
def delimiter = java.util.regex.Pattern.quote(params.gm_delimiter)

// Determine the maximum number of levels to set the header requirements for each pipeline run
int maxLevels = meta.collect { sample -> sample.address.split("\\.").size() }.max() ?: 0
int maxLevels = meta.collect { sample -> sample.address.split(delimiter).size() }.max() ?: 0

// Generate the header
// Verify each sample is consistent with $maxLevels
meta.each { sample ->
int level = sample.address.split(delimiter).size()
if (level != maxLevels) {
error ("Inconsistent levels found: expected $maxLevels levels but found $level levels in ${sample.id}")
}
}

// Generate the header for the expected_clusters.txt file
def header = ["id", "address"] + (1..maxLevels).collect { "level_$it" }
outputLines << header.join("\t")

// Iterate over each sample in the meta list and pull the relevant information for the text file
meta.each { sample ->
def id = sample.id
def address = sample.address
def levels = address.split("\\.")
def line = [id, address] + levels.collect { it.toString() } + (levels.size()..<maxLevels).collect { "" }
def levels = address.split(delimiter)
def line = [id, address] + levels.collect { it.toString() }
outputLines << line.join("\t")
}

// Write the text file
// Write the text file, iterating over each sample
task.workDir.resolve("expected_clusters.txt").withWriter { writer ->
outputLines.each { line ->
writer.writeLine(line)
Expand Down
2 changes: 1 addition & 1 deletion tests/data/clusters/expected_clusters.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id address level_1 level_2 level_3
sample1 1.1.1 1 1 1
sample2 1.1.1 1 1 1
sample3 2.2.2 2 2 2
sample3 1.1.2 1 1 2
2 changes: 2 additions & 0 deletions tests/data/profiles/expected-profile2.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sample_id l1 l2 l3
sampleQ 1 2 1
58 changes: 58 additions & 0 deletions tests/modules/cluster_file/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
nextflow_process {
name "Test Process CLUSTER_FILE"
script "modules/local/cluster_file/main.nf"
process "CLUSTER_FILE"

test("Test when sample levels are equal") {

when {
process {
"""
input[0] = Channel.of(
[['id':'sample1', 'address':'1.1.1'],
['id':'sample2', 'address':'1.1.1'],
['id':'sample3', 'address':'1.1.2']]
)
"""
}

params {
outdir = "cluster_results"
}
}

then {
assert process.success
assert path("$launchDir/cluster_results").exists()

// Check expected_clusters
def actual_clusters = path("$launchDir/cluster_results/cluster/expected_clusters.txt")
def expected_clusters = path("$baseDir/tests/data/clusters/expected_clusters.txt")
assert actual_clusters.text == expected_clusters.text
}
}

test("Test when sample levels are different") {

when {
process {
"""
input[0] = Channel.of(
[['id':'sample1', 'address':'1.1.1'],
['id':'sample2', 'address':'1.1.1'],
['id':'sample3', 'address':'1.2']]
)
"""
}

params {
outdir = "cluster_results"
}
}

then {
assert process.failed
assert (process.stdout =~ /Inconsistent levels found: expected 3 levels but found 2 levels in sample3/).find()
}
}
}
6 changes: 5 additions & 1 deletion tests/pipelines/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ nextflow_pipeline {
assert path("$launchDir/results").exists()

// Check merged profiles
// TODO check query profile is merged
def actual_profile_ref = path("$launchDir/results/locidex/merge/reference/merged_ref/merged_profiles_ref.tsv")
def expected_profile_tsv = path("$baseDir/tests/data/profiles/expected-profile1.tsv")
assert actual_profile_ref.text == expected_profile_tsv.text

// Check query profiles
def actual_profile_query = path("$launchDir/results/locidex/merge/query/merged_value/merged_profiles_value.tsv")
def expected_profile_query_tsv = path("$baseDir/tests/data/profiles/expected-profile2.tsv")
assert actual_profile_query.text == expected_profile_query_tsv.text

// Check computed pairwise distances
def actual_distances = path("$launchDir/results/distances/results.text")
def expected_distances = path("$baseDir/tests/data/distances/expected_pairwise_dists.txt")
Expand Down

0 comments on commit 9be4562

Please sign in to comment.