-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from phac-nml/expected-clusters
Add module to create the expected_clusters file for gas-call
- Loading branch information
Showing
10 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
process CLUSTER_FILE { | ||
tag "Create cluster file for GAS call" | ||
label 'process_single' | ||
|
||
input: | ||
val meta | ||
|
||
output: | ||
path("expected_clusters.txt"), emit: text | ||
|
||
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(delimiter).size() }.max() ?: 0 | ||
|
||
// 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(delimiter) | ||
def line = [id, address] + levels.collect { it.toString() } | ||
outputLines << line.join("\t") | ||
} | ||
|
||
// Write the text file, iterating over each sample | ||
task.workDir.resolve("expected_clusters.txt").withWriter { writer -> | ||
outputLines.each { line -> | ||
writer.writeLine(line) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
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 | ||
sampleQ 1.1.3 1 1 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sample_id l1 l2 l3 | ||
sampleQ 1 2 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters