Skip to content

Commit

Permalink
fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stolpeo committed Oct 31, 2023
1 parent a4ad26a commit c917a0d
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 255 deletions.
176 changes: 99 additions & 77 deletions maintenance/management/commands/generate_result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from projectroles.models import Project

from variants.models import Case

# from variants.tasks import create_queryresultset as task_create_queryresultset
from variants.tasks import create_queryresultset as task_create_queryresultset
from variants.utils import create_queryresultset


Expand Down Expand Up @@ -69,34 +68,26 @@ def handle(self, *args, **options):
msg_warning = ""

if options["async"]:
count, salvable, duplicates, tsv_lines = create_queryresultset(
count, salvable, duplicates, orphans = create_queryresultset(
options["case_uuid"], options["project_uuid"], options["all"]
)
msg = "Done creating result sets:"
if (
count["smallvariantqueryresultset"]
or count["svqueryresultset"]
or count["sms"]["added"]["flags"]
or count["sms"]["added"]["comments"]
or count["sms"]["added"]["acmg_ratings"]
or count["svs"]["added"]["flags"]
or count["svs"]["added"]["comments"]
or count["sms"]["added"]
or count["svs"]["added"]
or count["sms"]["removed"]
or count["svs"]["removed"]
):
msg += f"""
- SmallVariantQueryResultSets created: {count['smallvariantqueryresultset']}
- SvQueryResultSets created: {count['svqueryresultset']}
- SmallVariantQueryResultSets:
- Added:
- Flags: {count['sms']['added']['flags']}
- Comments: {count['sms']['added']['comments']}
- ACMG ratings: {count['sms']['added']['acmg_ratings']}
- Added: {count['sms']['added']}
- Removed: {count['sms']['removed']}
- SvQueryResultSets:
- Added:
- Flags: {count['svs']['added']['flags']}
- Comments: {count['svs']['added']['comments']}
- Added: {count['svs']['added']}
- Removed: {count['svs']['removed']}"""
else:
msg += "\n- Nothing to do."
Expand Down Expand Up @@ -130,77 +121,108 @@ def handle(self, *args, **options):
- Lost:
- Flags: {count['svs']['lost']['flags']}
- Comments: {count['svs']['lost']['comments']}""".lstrip()
if (
count["sms"]["salvable"]["flags"]
or count["sms"]["salvable"]["comments"]
or count["sms"]["salvable"]["acmg_ratings"]
or count["svs"]["salvable"]["flags"]
or count["svs"]["salvable"]["comments"]
):
with open("salvable.json", "w") as f:
json.dump(salvable, f, indent=1)
# if duplicates["sms"] or duplicates["svs"]:
# msg_warning += f"""
# WARNING! There are duplicate variants:
# - Duplicate small variants: {len(duplicates['sms'])}
# - Duplicate structural variants: {len(duplicates['svs'])}""".lstrip()
# with open("duplicates.json", "w") as f:
# from variants.views import UUIDEncoder
# json.dump(duplicates, f, indent=1, cls=UUIDEncoder)
with open("orphaned_sv_flags.tsv", "w") as f:
f.write(
"case_uuid\tproject\tcase_name\tregion\tlost\tflag_molecular\tflag_visual\tflag_validation\tflag_phenotype_match\tflag_summary\tjson\n"
)
for line in tsv_lines["svs"]["flags"]:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{flag_molecular}\t{flag_visual}\t{flag_validation}\t{flag_phenotype_match}\t{flag_summary}\t{json}\n".format(
**line,
flag_molecular=line["json"]["flag_molecular"],
flag_visual=line["json"]["flag_visual"],
flag_validation=line["json"]["flag_validation"],
flag_phenotype_match=line["json"]["flag_phenotype_match"],
flag_summary=line["json"]["flag_summary"],
if duplicates["sms"] or duplicates["svs"]:
msg_warning += f"""
WARNING! There are duplicate variants:
- Duplicate small variants: {len(duplicates['sms'])}
- Duplicate structural variants: {len(duplicates['svs'])}""".lstrip()
if duplicates["sms"]:
with open("duplicates_sms.json", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tjson\n")
for line in duplicates["sms"]:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{json}\n".format(
**line,
)
)
)
with open("orphaned_sv_comments.tsv", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tlost\tcomment\tjson\n")
for line in tsv_lines["svs"]["comments"]:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{comment}\t{json}\n".format(
**line,
comment=line["json"]["comment"],
if duplicates["svs"]:
with open("duplicates_svs.json", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tjson\n")
for line in duplicates["svs"]:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{json}\n".format(
**line,
)
)
)
with open("orphaned_sm_flags.tsv", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tlost\tjson\n")
for line in tsv_lines["sms"]["flags"]:
print(line)
if orphans["svs"]["flags"]:
with open("orphans_sv_flags.tsv", "w") as f:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{flag_molecular}\t{flag_visual}\t{flag_validation}\t{flag_phenotype_match}\t{flag_summary}\t{json}\n".format(
**line,
flag_molecular=line["json"]["flag_molecular"],
flag_visual=line["json"]["flag_visual"],
flag_validation=line["json"]["flag_validation"],
flag_phenotype_match=line["json"]["flag_phenotype_match"],
flag_summary=line["json"]["flag_summary"],
)
"case_uuid\tproject\tcase_name\tregion\tlost\tflag_molecular\tflag_visual\tflag_validation\tflag_phenotype_match\tflag_summary\tjson\n"
)
with open("orphaned_sm_comments.tsv", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tlost\tcomment\tjson\n")
for line in tsv_lines["sms"]["comments"]:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{comment}\t{json}\n".format(
**line,
comment=line["json"]["comment"],
for line in orphans["svs"]["flags"]:
j = json.loads(line["json"])
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{flag_molecular}\t{flag_visual}\t{flag_validation}\t{flag_phenotype_match}\t{flag_summary}\t{json}\n".format(
**line,
flag_molecular=j["flag_molecular"],
flag_visual=j["flag_visual"],
flag_validation=j["flag_validation"],
flag_phenotype_match=j["flag_phenotype_match"],
flag_summary=j["flag_summary"],
)
)
)
with open("orphaned_sm_acmg_ratings.tsv", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tlost\tjson\n")
for line in tsv_lines["sms"]["acmg_ratings"]:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{json}\n".format(
**line
if orphans["svs"]["comments"]:
with open("orphans_sv_comments.tsv", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tlost\tcomment\tjson\n")
for line in orphans["svs"]["comments"]:
j = json.loads(line["json"])
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{comment}\t{json}\n".format(
**line,
comment=j["text"],
)
)
if orphans["sms"]["flags"]:
with open("orphans_sm_flags.tsv", "w") as f:
f.write(
"case_uuid\tproject\tcase_name\tregion\tlost\tflag_molecular\tflag_visual\tflag_validation\tflag_phenotype_match\tflag_summary\tjson\n"
)

# else:
# task_create_queryresultset.delay(
# options["case_uuid"], options["project_uuid"], options["all"]
# )
# msg = "Pushed creating the query set to background."
for line in orphans["sms"]["flags"]:
j = json.loads(line["json"])
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{flag_molecular}\t{flag_visual}\t{flag_validation}\t{flag_phenotype_match}\t{flag_summary}\t{json}\n".format(
**line,
flag_molecular=j["flag_molecular"],
flag_visual=j["flag_visual"],
flag_validation=j["flag_validation"],
flag_phenotype_match=j["flag_phenotype_match"],
flag_summary=j["flag_summary"],
)
)
if orphans["sms"]["comments"]:
with open("orphans_sm_comments.tsv", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tlost\tcomment\tjson\n")
for line in orphans["sms"]["comments"]:
j = json.loads(line["json"])
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{comment}\t{json}\n".format(
**line,
comment=j["text"],
)
)
if orphans["sms"]["acmg_ratings"]:
with open("orphans_sm_acmg_ratings.tsv", "w") as f:
f.write("case_uuid\tproject\tcase_name\tregion\tlost\tjson\n")
for line in orphans["sms"]["acmg_ratings"]:
f.write(
"{case_uuid}\t{project}\t{case_name}\t{chromosome}:{start}-{end}\t{lost}\t{json}\n".format(
**line
)
)
else:
task_create_queryresultset.delay(
options["case_uuid"], options["project_uuid"], options["all"]
)
msg = "Pushed creating the query set to background."

self.stdout.write(self.style.SUCCESS(msg))
if msg_warning:
Expand Down
4 changes: 4 additions & 0 deletions utils/kickoff_orphaned_annotation_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def run_query(config, settings_endpoint, query_endpoint, case_uuid, case_orphans
return ""
response_json = response.json()
response_json["query_settings"]["genomic_region"] = case_orphans
if "genotype_criteria" in response_json["query_settings"]:
for criteria in response_json["query_settings"]["genotype_criteria"]:
criteria["gt_one_of"].append(".")
criteria["gt_one_of"].append("./.")
url = query_endpoint.format(case_uuid=case_uuid)
response = connect_endpoint(config, url, data=response_json)
if not response:
Expand Down
Loading

0 comments on commit c917a0d

Please sign in to comment.