Skip to content

Commit

Permalink
Merge branch 'isb-cgc-test' of https://github.com/isb-cgc/ISB-CGC-Common
Browse files Browse the repository at this point in the history
 into isb-cgc-prod-sp
  • Loading branch information
s-paquette committed Sep 27, 2019
2 parents f41b092 + 8f6e1da commit 033f7e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion accounts/service_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def get_django_values():
try:
from django.conf import settings
values.append(settings.CLIENT_EMAIL)
values.append(settings.WEB_CLIENT_ID)
values.append(settings.GOOGLE_CLIENT_ID)
except Exception as e:
logger.error("Could not read Service Account settings from Django configuration.")
logger.exception(e)
Expand Down
18 changes: 9 additions & 9 deletions cohorts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from django.core.exceptions import ObjectDoesNotExist


def create_cohort(user, filters=None, name=None, source_id=None):
def create_cohort(user, filters=None, name=None, source_id=None, case_insens=True):

if not filters and not name:
# Can't save/edit a cohort when nothing is being changed!
Expand Down Expand Up @@ -64,7 +64,7 @@ def create_cohort(user, filters=None, name=None, source_id=None):
if source_progs:
source_prog_filters = {x: {} for x in source_progs if x not in list(barcodes.keys())}
if len(source_prog_filters):
source_prog_barcodes = get_sample_case_list_bq(source_id, source_prog_filters, long_form=True)
source_prog_barcodes = get_sample_case_list_bq(source_id, source_prog_filters, long_form=True, case_insens=True)
for prog in source_prog_barcodes:
barcodes[prog] = source_prog_barcodes[prog]

Expand Down Expand Up @@ -166,7 +166,7 @@ def create_cohort(user, filters=None, name=None, source_id=None):


# Get samples and cases by querying BQ tables
def get_sample_case_list_bq(cohort_id=None, inc_filters=None, comb_mut_filters='OR', long_form=False):
def get_sample_case_list_bq(cohort_id=None, inc_filters=None, comb_mut_filters='OR', long_form=False, case_insens=True):

comb_mut_filters = comb_mut_filters.upper()

Expand Down Expand Up @@ -292,7 +292,7 @@ def get_sample_case_list_bq(cohort_id=None, inc_filters=None, comb_mut_filters='
joins = ""

if len(data_type_filters) > 0:
data_type_where_clause = BigQuerySupport.build_bq_filter_and_params(data_type_filters)
data_type_where_clause = BigQuerySupport.build_bq_filter_and_params(data_type_filters, case_insens=case_insens)
data_avail_sample_subquery = (data_avail_sample_query % data_avail_table) + ' WHERE ' + \
data_type_where_clause['filter_string']
parameters += data_type_where_clause['parameters']
Expand All @@ -304,9 +304,9 @@ def get_sample_case_list_bq(cohort_id=None, inc_filters=None, comb_mut_filters='
# Send in a type schema for Biospecimen, because sample_type is an integer encoded as a string,
# so detection will not work properly
type_schema = {x['name']: x['type'] for x in biospec_fields}
where_clause['biospec'] = BigQuerySupport.build_bq_filter_and_params(filters['biospec'], field_prefix='bs.', type_schema=type_schema)
where_clause['biospec'] = BigQuerySupport.build_bq_filter_and_params(filters['biospec'], field_prefix='bs.', type_schema=type_schema, case_insens=case_insens)
if len(list(filters['clin'].keys())):
where_clause['clin'] = BigQuerySupport.build_bq_filter_and_params(filters['clin'], field_prefix='cl.')
where_clause['clin'] = BigQuerySupport.build_bq_filter_and_params(filters['clin'], field_prefix='cl.', case_insens=case_insens)

mut_query_job = None

Expand Down Expand Up @@ -344,12 +344,12 @@ def get_sample_case_list_bq(cohort_id=None, inc_filters=None, comb_mut_filters='
this_filter = {}
this_filter[filter] = build_queries[build]['raw_filters'][filter]
build_queries[build]['filter_str_params'].append(BigQuerySupport.build_bq_filter_and_params(
this_filter, comb_mut_filters, build+'_{}'.format(str(filter_num))
this_filter, comb_mut_filters, build+'_{}'.format(str(filter_num)), case_insens=case_insens
))
filter_num += 1
elif comb_mut_filters == 'OR':
build_queries[build]['filter_str_params'].append(BigQuerySupport.build_bq_filter_and_params(
build_queries[build]['raw_filters'], comb_mut_filters, build
build_queries[build]['raw_filters'], comb_mut_filters, build, case_insens=case_insens
))

# Create the queries and their parameters
Expand Down Expand Up @@ -391,7 +391,7 @@ def get_sample_case_list_bq(cohort_id=None, inc_filters=None, comb_mut_filters='
any_filter = {}
any_filter[filter] = build_queries[build]['not_any'][not_any]
filter_str_param = BigQuerySupport.build_bq_filter_and_params(
any_filter,param_suffix=build+'_any_{}'.format(any_count)
any_filter,param_suffix=build+'_any_{}'.format(any_count), case_insens=case_insens
)

build_queries[build]['filter_str_params'].append(filter_str_param)
Expand Down
8 changes: 4 additions & 4 deletions google_helpers/bigquery/bq_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def insert_job_batch_and_get_results(cls, query_set):
#
# TODO: add support for DATES
@staticmethod
def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with_count_toggle=False, field_prefix=None, type_schema=None):
def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with_count_toggle=False, field_prefix=None, type_schema=None, case_insens=True):
result = {
'filter_string': '',
'parameters': []
Expand Down Expand Up @@ -609,7 +609,7 @@ def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with
# Scalar param
query_param['parameterValue']['value'] = values[0]
if query_param['parameterType']['type'] == 'STRING':
if '%' in values[0]:
if '%' in values[0] or case_insens:
filter_string += "LOWER({}{}) LIKE LOWER(@{})".format('' if not field_prefix else field_prefix, attr, param_name)
else:
filter_string += "{}{} = @{}".format('' if not field_prefix else field_prefix, attr,
Expand Down Expand Up @@ -654,9 +654,9 @@ def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with
query_param['parameterType']['arrayType'] = {
'type': parameter_type
}
query_param['parameterValue'] = {'arrayValues': [{'value': x} for x in values]}
query_param['parameterValue'] = {'arrayValues': [{'value': x.lower() if parameter_type == 'STRING' else x} for x in values]}

filter_string += "{}{} IN UNNEST(@{})".format('' if not field_prefix else field_prefix, attr, param_name)
filter_string += "LOWER({}{}) IN UNNEST(@{})".format('' if not field_prefix else field_prefix, attr, param_name)

if with_count_toggle:
filter_string = "({}) OR @{}_filtering = 'not_filtering'".format(filter_string,param_name)
Expand Down
2 changes: 1 addition & 1 deletion google_helpers/resourcemanager_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def get_special_crm_resource():
has the Browser (or Viewer, Editor, Owner) role on the other project.
"""
credentials = GoogleCredentials.from_stream(
settings.USER_GCP_ACCESS_CREDENTIALS).create_scoped(CRM_SCOPES)
settings.MONITORING_SA_ACCESS_CREDENTIALS).create_scoped(CRM_SCOPES)
service = build_with_retries('cloudresourcemanager', 'v1beta1', credentials, 2)
return service

0 comments on commit 033f7e6

Please sign in to comment.