@@ -69,6 +69,33 @@ def dataset_size():
6969 "SITE_PM2C~SYNTH_04" : 20
7070 }
7171
72+ def genomic_hits_in_dataset ():
73+ return {
74+ "SITE_PM2C~SYNTH_01" : 1 ,
75+ "SITE_PM2C~SYNTH_02" : 1 ,
76+ "SITE_PM2C~SYNTH_03" : 0 ,
77+ "SITE_PM2C~SYNTH_04" : 0
78+ }
79+
80+ def genomic_variants_per_sample ():
81+ return {
82+ "SITE_PM2C~SYNTH_02" : {
83+ "SAMPLE_0061" : 3 ,
84+ "SAMPLE_0062" : 3
85+ },
86+ "SITE_PM2C~SYNTH_01" : {
87+ "SAMPLE_NULL_0002" : 2 ,
88+ "SAMPLE_NULL_0001" : 2
89+ }
90+ }
91+
92+ def genomic_and_clinical_hits_in_dataset ():
93+ return {
94+ "SITE_PM2C~SYNTH_01" : 1 ,
95+ "SITE_PM2C~SYNTH_02" : 1 ,
96+ "SITE_PM2C~SYNTH_03" : 0 ,
97+ "SITE_PM2C~SYNTH_04" : 0
98+ }
7299
73100## Keycloak tests:
74101
@@ -683,6 +710,22 @@ def sample_request_body(filter_id, granularity="record"):
683710 }
684711
685712
713+ def sample_genomic_request_body (gene_id , granularity = "record" ):
714+ return {
715+ "meta" : {
716+ "apiVersion" : "v2.0.0"
717+ },
718+ "query" : {
719+ "requestedGranularity" : granularity ,
720+ "requestParameters" : {
721+ "g_variant" : {
722+ "gene_id" : gene_id
723+ }
724+ }
725+ }
726+ }
727+
728+
686729@pytest .mark .parametrize ("user, dataset" , user_auth_datasets ())
687730def test_beacon_query (user , dataset ):
688731 """Test whether a user can execute a query."""
@@ -710,15 +753,40 @@ def test_beacon_query(user, dataset):
710753 # Ensure that the discovery query also matches up
711754 assert response .json ()["info" ]["patients_per_program" ][dataset ] == dataset_size ()[dataset ]
712755
756+ # Switch to a query on variants in a given gene
757+ body = sample_genomic_request_body (f"SLX9" )
758+ response = requests .post (
759+ f"{ ENV ['CANDIG_URL' ]} /candig-api/v1/beacon/persons" ,
760+ headers = headers ,
761+ json = body
762+ )
763+ assert response .status_code == 200
764+ if user != "CANDIG_NOT_ADMIN2" :
765+ assert len (response .json ()["response" ]["resultSets" ][0 ]["results" ]) == min (10 , genomic_hits_in_dataset ()[dataset ])
766+ assert response .json ()["response" ]["resultSets" ][0 ]["resultsCount" ] == genomic_hits_in_dataset ()[dataset ]
767+ assert response .json ()["info" ]["patients_per_program" ][dataset ] == genomic_hits_in_dataset ()[dataset ]
768+
769+ # Switch to a query on both gene and clinical feature
770+ body = sample_request_body (f"dataset_id:{ dataset } " )
771+ body ["query" ]["requestParameters" ] = { "g_variant" : { "gene_id" : "SLX9" } }
772+ response = requests .post (
773+ f"{ ENV ['CANDIG_URL' ]} /candig-api/v1/beacon/persons" ,
774+ headers = headers ,
775+ json = body
776+ )
777+ assert response .status_code == 200
778+ if user != "CANDIG_NOT_ADMIN2" :
779+ assert len (response .json ()["response" ]["resultSets" ][0 ]["results" ]) == min (10 , genomic_and_clinical_hits_in_dataset ()[dataset ])
780+ assert response .json ()["response" ]["resultSets" ][0 ]["resultsCount" ] == genomic_and_clinical_hits_in_dataset ()[dataset ]
781+ assert response .json ()["info" ]["patients_per_program" ][dataset ] == genomic_and_clinical_hits_in_dataset ()[dataset ]
782+
713783 # Switch to a query on a specific thing
714784 body = sample_request_body ("ICD10:C06.9" )
715785 response = requests .post (
716786 f"{ ENV ['CANDIG_URL' ]} /candig-api/v1/beacon/persons" ,
717787 headers = headers ,
718788 json = body
719789 )
720- print (body )
721- print (response .json ())
722790 assert response .status_code == 200
723791
724792 if user != "CANDIG_NOT_ADMIN2" :
@@ -816,6 +884,33 @@ def test_beacon_granularity_unauth(user, dataset):
816884 assert response .json ()["info" ]["patients_per_program" ][dataset ] == dataset_size ()[dataset ]
817885
818886
887+ @pytest .mark .parametrize ("user, dataset" , user_auth_datasets ())
888+ def test_beacon_genomic (user , dataset ):
889+ """Test whether a user can execute a genomic variants quick search."""
890+ token = get_token (
891+ username = ENV [f"{ user } _USER" ],
892+ password = ENV [f"{ user } _PASSWORD" ],
893+ )
894+ headers = {
895+ "Authorization" : f"Bearer { token } " ,
896+ "Content-Type" : "application/json; charset=utf-8" ,
897+ }
898+ body = sample_genomic_request_body (f"LOC102723996" )
899+
900+ response = requests .post (
901+ f"{ ENV ['CANDIG_URL' ]} /candig-api/v1/beacon/g_variants" ,
902+ headers = headers ,
903+ json = body
904+ )
905+ assert response .status_code == 200
906+
907+ # Ensure that the dataset is included in the result
908+ # print(response.json())
909+ this_dataset = response .json ()["estimatedResults" ][dataset ]
910+ for sample in this_dataset :
911+ assert sample ["variant_count" ] == genomic_variants_per_sample ()[dataset ][sample ["submitter_sample_id" ]]
912+
913+
819914## Htsget tests:
820915
821916# def test_ingest_not_admin_htsget():
0 commit comments