Skip to content

Commit 84ee235

Browse files
authored
[GEN-2027] Add staging for mutation in cis (#597)
* add staging for mutation in cis * add R tests for getting database to synid mapping table * add more strict conditions
1 parent 8b35c2a commit 84ee235

File tree

5 files changed

+101
-30
lines changed

5 files changed

+101
-30
lines changed

R/mergeCheck.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ parser$add_argument("--staging",
99
action = "store_true",
1010
help = "Use staging files")
1111
args <- parser$parse_args()
12-
testing <- args$testing
13-
staging <- args$staging
12+
testing <- as.logical(args$testing)
13+
staging <- as.logical(args$staging)
1414

1515
library(synapser)
1616
library(VariantAnnotation)
@@ -39,13 +39,10 @@ variant_limit = 100000
3939
tbl_size_limit = 500
4040

4141
#testing = as.logical(args[1])
42-
if (testing) {
43-
databaseSynIdMappingId = 'syn11600968'
44-
} else if (staging) {
45-
databaseSynIdMappingId = 'syn12094210'
46-
} else {
47-
databaseSynIdMappingId = 'syn10967259'
48-
}
42+
databaseSynIdMappingId <- get_database_to_synapse_mapping_synid(
43+
testing=testing, staging=staging
44+
)
45+
4946
databaseSynIdMapping = synTableQuery(sprintf('select * from %s', databaseSynIdMappingId),
5047
includeRowIdAndRowVersion = F)
5148
databaseSynIdMappingDf = synapser::as.data.frame(databaseSynIdMapping)

R/mergecheck_functions.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
#' Gets the database to synapse mapping table's synapse id based on
2+
#' if running in production, testing or staging mode
3+
#' @param testing (logical) running in testing mode
4+
#' @param staging (logical) running in staging mode
5+
get_database_to_synapse_mapping_synid <- function(testing, staging){
6+
if (testing && !staging) {
7+
databaseSynIdMappingId = 'syn11600968'
8+
} else if (staging && !testing) {
9+
databaseSynIdMappingId = 'syn12094210'
10+
} else if (staging && testing) {
11+
stop("Mutation in cis only available in staging or testing mode not both")
12+
} else {
13+
databaseSynIdMappingId = 'syn10967259'
14+
}
15+
return(databaseSynIdMappingId)
16+
}
17+
118
# Update mutation in cis table
219
uploadToTable <- function(tbl, databaseSynId, subSetSamples, centerMappingDf) {
320
# Old samples
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# tests for mergecheck_functions.R
2+
3+
source("../../mergecheck_functions.R")
4+
5+
library(testthat)
6+
7+
8+
test_that("get_database_to_synapse_mapping_synid_gets_correct_synid_for_testing", {
9+
result <- get_database_to_synapse_mapping_synid(
10+
testing = TRUE, staging = FALSE
11+
)
12+
expect_equal(result, "syn11600968")
13+
})
14+
15+
test_that("get_database_to_synapse_mapping_synid_gets_correct_synid_for_staging", {
16+
result <- get_database_to_synapse_mapping_synid(
17+
testing = FALSE, staging = TRUE
18+
)
19+
expect_equal(result, "syn12094210")
20+
})
21+
22+
test_that("get_database_to_synapse_mapping_synid_gets_correct_synid_for_prod", {
23+
result <- get_database_to_synapse_mapping_synid(
24+
testing = FALSE, staging = FALSE
25+
)
26+
expect_equal(result, "syn10967259")
27+
})
28+
29+
test_that("get_database_to_synapse_mapping_synid_throws_error", {
30+
expect_error(get_database_to_synapse_mapping_synid(testing = TRUE, staging = TRUE),
31+
"Mutation in cis only available in staging or testing mode not both")
32+
})
33+
34+
35+

genie/database_to_staging.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,6 @@ def mutation_in_cis_filter(
579579
580580
The mutation in cis script ONLY runs
581581
WHEN the skipMutationsInCis parameter is FALSE
582-
AND
583-
WHEN staging parameter is FALSE
584-
585-
This is because we don't have this set up for staging mode
586-
yet.
587582
588583
Args:
589584
syn: Synapse object
@@ -597,8 +592,8 @@ def mutation_in_cis_filter(
597592
Returns:
598593
pd.Series: Samples to remove
599594
"""
600-
if (not skipMutationsInCis) and (not staging):
601-
command = get_mutation_in_cis_filter_script_cmd(test=test)
595+
if not skipMutationsInCis:
596+
command = get_mutation_in_cis_filter_script_cmd(test=test, staging=staging)
602597
# TODO: use subprocess.run instead
603598
subprocess.check_call(command)
604599
store_mutation_in_cis_files_to_staging(
@@ -616,13 +611,14 @@ def mutation_in_cis_filter(
616611
return (remove_samples, flagged_variants)
617612

618613

619-
def get_mutation_in_cis_filter_script_cmd(test: bool) -> str:
614+
def get_mutation_in_cis_filter_script_cmd(test: bool, staging: bool) -> str:
620615
"""This function gets the mutation_in_cis_filter R script
621-
command call based on whether we are running in test,
616+
command call based on whether we are running in test, staging
622617
or production mode
623618
624619
Args:
625620
test (bool): Testing parameter.
621+
staging (bool): Staging parameter. Default is False.
626622
627623
Returns:
628624
str: Full command call for the mergeCheck script
@@ -631,8 +627,16 @@ def get_mutation_in_cis_filter_script_cmd(test: bool) -> str:
631627
os.path.dirname(os.path.abspath(__file__)), "../R/mergeCheck.R"
632628
)
633629
command = ["Rscript", mergeCheck_script]
634-
if test:
630+
if test and not staging:
635631
command.append("--testing")
632+
if staging and not test:
633+
command.append("--staging")
634+
elif test and staging:
635+
raise ValueError(
636+
"Mutation in cis only available in staging or testing mode not both"
637+
)
638+
else:
639+
pass
636640
return command
637641

638642

tests/test_database_to_staging.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,9 @@ def test_that_store_maf_in_bed_filtered_variants_has_expected_calls(syn):
488488
[
489489
(True, False, False),
490490
(False, False, False),
491+
(False, True, False),
491492
],
492-
ids=[
493-
"testing_mode",
494-
"prod_mode",
495-
],
493+
ids=["testing_mode", "prod_mode", "staging_mode"],
496494
)
497495
def test_that_mutation_in_cis_filter_has_expected_calls_when_mutations_in_cis_is_not_skipped(
498496
syn, test, staging, skip_mutations_in_cis
@@ -544,7 +542,7 @@ def test_that_mutation_in_cis_filter_has_expected_calls_when_mutations_in_cis_is
544542
staging=staging,
545543
)
546544
# check expected calls with expected params
547-
patch_get_cmd.assert_called_once_with(test=test)
545+
patch_get_cmd.assert_called_once_with(test=test, staging=staging)
548546
patch_check_call.assert_called_once_with("test_cmd")
549547
patch_store_mutation_in_cis_files.assert_called_once_with(
550548
syn=syn,
@@ -592,13 +590,11 @@ def test_that_mutation_in_cis_filter_has_expected_calls_when_mutations_in_cis_is
592590
[
593591
(True, False, True),
594592
(False, False, True),
595-
(False, True, False),
596593
(False, True, True),
597594
],
598595
ids=[
599596
"testing_mode_skip_mutations_in_cis",
600597
"prod_mode_skip_mutations_in_cis",
601-
"staging_mode",
602598
"staging_mode_skip_mutations_in_cis",
603599
],
604600
)
@@ -692,32 +688,54 @@ def test_that_mutation_in_cis_filter_has_expected_calls_when_mutations_in_cis_is
692688

693689

694690
@pytest.mark.parametrize(
695-
"test, expected_cmd",
691+
"test, staging, expected_cmd",
696692
[
697693
(
698694
True,
695+
False,
699696
[
700697
"Rscript",
701698
"/home/test_dir/Genie/../R/mergeCheck.R",
702699
"--testing",
703700
],
704701
),
705702
(
703+
False,
706704
False,
707705
[
708706
"Rscript",
709707
"/home/test_dir/Genie/../R/mergeCheck.R",
710708
],
711709
),
710+
(
711+
False,
712+
True,
713+
["Rscript", "/home/test_dir/Genie/../R/mergeCheck.R", "--staging"],
714+
),
712715
],
713-
ids=["testing_mode", "prod_mode"],
716+
ids=["testing_mode", "prod_mode", "staging_mode"],
714717
)
715-
def test_that_get_mutation_in_cis_filter_cmd_returns_correct_cmd(test, expected_cmd):
718+
def test_that_get_mutation_in_cis_filter_cmd_returns_correct_cmd(
719+
test, staging, expected_cmd
720+
):
716721
with patch.object(os.path, "dirname", return_value="/home/test_dir/Genie/"):
717-
cmd = database_to_staging.get_mutation_in_cis_filter_script_cmd(test=test)
722+
cmd = database_to_staging.get_mutation_in_cis_filter_script_cmd(
723+
test=test, staging=staging
724+
)
718725
assert cmd == expected_cmd
719726

720727

728+
def test_that_get_mutation_in_cis_filter_cmd_raises_value_error():
729+
with patch.object(os.path, "dirname", return_value="/home/test_dir/Genie/"):
730+
with pytest.raises(
731+
ValueError,
732+
match="Mutation in cis only available in staging or testing mode not both",
733+
):
734+
database_to_staging.get_mutation_in_cis_filter_script_cmd(
735+
test=True, staging=True
736+
)
737+
738+
721739
@pytest.mark.parametrize(
722740
"flagged_df, expected_flagged_variants",
723741
[

0 commit comments

Comments
 (0)