Skip to content

Commit

Permalink
Merge pull request #20 from CanDIG/bugfix/genomic-completeness
Browse files Browse the repository at this point in the history
Bugfix: Missing data and completeness data
  • Loading branch information
OrdiNeu authored Mar 1, 2024
2 parents 6317082 + 78f56c2 commit eac49e5
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions query_server/query_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,27 @@ def get_summary_stats(donors, headers):
# A donor's date of birth is defined as the (negative) interval between actual DOB and the date of first diagnosis
# So we just use that info
donors_by_id[donor["submitter_donor_id"]] = donor
age = abs(donor['date_of_birth']['month_interval']) // 12
age = age // 10 * 10
if age < 20:
add_or_increment(age_at_diagnosis, '0-19 Years')
elif age > 79:
add_or_increment(age_at_diagnosis, '80+ Years')
else:
add_or_increment(age_at_diagnosis, f'{age}-{age+9} Years')
if donor['date_of_birth'] and donor['date_of_birth']['month_interval']:
age = abs(donor['date_of_birth']['month_interval']) // 12
age = age // 10 * 10
if age < 20:
add_or_increment(age_at_diagnosis, '0-19 Years')
elif age > 79:
add_or_increment(age_at_diagnosis, '80+ Years')
else:
add_or_increment(age_at_diagnosis, f'{age}-{age+9} Years')

# Cancer types
for cancer_type in donor['primary_site']:
if cancer_type in cancer_type_count:
cancer_type_count[cancer_type] += 1
else:
cancer_type_count[cancer_type] = 1
if donor['primary_site']:
for cancer_type in donor['primary_site']:
if cancer_type in cancer_type_count:
cancer_type_count[cancer_type] += 1
else:
cancer_type_count[cancer_type] = 1
program_id = donor['program_id']
if program_id in patients_per_cohort:
patients_per_cohort[program_id] += 1
else:
elif program_id is not None:
patients_per_cohort[program_id] = 1

# Treatment types
Expand Down Expand Up @@ -285,6 +287,12 @@ def query(treatment="", primary_site="", chemotherapy="", immunotherapy="", horm

@app.route('/genomic_completeness')
def genomic_completeness():
# Add a service token to the headers so that Katsu will know this is from the query service:
headers = {}
for k in request.headers.keys():
headers[k] = request.headers[k]
headers["X-Service-Token"] = config.SERVICE_TOKEN

params = { 'page_size': PAGE_SIZE }
url = f"{config.KATSU_URL}/v2/authorized/sample_registrations/"
r = safe_get_request_json(requests.get(f"{url}?{urllib.parse.urlencode(params)}",
Expand All @@ -302,7 +310,7 @@ def genomic_completeness():
# Check with HTSGet to see whether or not this sample is complete
r = requests.get(f"{config.HTSGET_URL}/htsget/v1/samples/{sample_id}",
# Reuse their bearer token
headers=request.headers)
headers=headers)
if r.ok:
r_json = r.json()
retVal[program_id]
Expand Down

0 comments on commit eac49e5

Please sign in to comment.