Skip to content

Commit

Permalink
Merge branch 'Derek-Furst/update-derived-queries' of https://github.c…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanzhou committed Oct 31, 2023
2 parents 77bd01a + 04c38e7 commit df5fd75
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/app_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,9 @@ def get_prov_info(neo4j_driver, param_dict, published_only):
if published_only:
published_only_query_string = f" AND toUpper(ds.status) = 'PUBLISHED'"
published_only_revisions_string = f" WHERE toUpper(rev.status) = 'PUBLISHED'"
query = (f"MATCH (ds:Dataset)<-[:ACTIVITY_OUTPUT]-(a)<-[:ACTIVITY_INPUT]-(firstSample:Sample)<-[*]-(donor:Donor)"
f"WHERE not (ds)-[:REVISION_OF]->(:Dataset)"
query = (f"MATCH (ds:Dataset)<-[:ACTIVITY_OUTPUT]-(a:Activity)<-[*]-(firstSample:Sample)<-[*]-(donor:Donor)"
f" WHERE not (ds)-[:REVISION_OF]->(:Dataset)"
f" AND NOT toLower(a.creation_action) ENDS WITH 'process'"
f"{group_uuid_query_string}"
f"{dataset_status_query_string}"
f"{published_only_query_string}"
Expand All @@ -598,7 +599,8 @@ def get_prov_info(neo4j_driver, param_dict, published_only):
f" {organ_query_string} (donor)-[:ACTIVITY_INPUT]->(oa)-[:ACTIVITY_OUTPUT]->(organ:Sample {{sample_category:'organ'}})-[*]->(ds)"
f" {organ_where_clause}"
f" WITH ds, FIRSTSAMPLE, DONOR, REVISIONS, METASAMPLE, RUISAMPLE, COLLECT(DISTINCT organ) AS ORGAN "
f" OPTIONAL MATCH (ds)-[:ACTIVITY_INPUT]->(a3)-[:ACTIVITY_OUTPUT]->(processed_dataset:Dataset)"
f" OPTIONAL MATCH (ds)-[*]->(a3)-[:ACTIVITY_OUTPUT]->(processed_dataset:Dataset)"
f" WHERE toLower(a3.creation_action) ENDS WITH 'process'"
f" WITH ds, FIRSTSAMPLE, DONOR, REVISIONS, METASAMPLE, RUISAMPLE, ORGAN, COLLECT(distinct processed_dataset) AS PROCESSED_DATASET"
f" RETURN ds.uuid, FIRSTSAMPLE, DONOR, RUISAMPLE, ORGAN, ds.hubmap_id, ds.status, ds.group_name,"
f" ds.group_uuid, ds.created_timestamp, ds.created_by_user_email, ds.last_modified_timestamp, "
Expand Down Expand Up @@ -684,7 +686,7 @@ def get_prov_info(neo4j_driver, param_dict, published_only):
"""
def get_individual_prov_info(neo4j_driver, dataset_uuid):
query = (f"MATCH (ds:Dataset {{uuid: '{dataset_uuid}'}})<-[*]-(firstSample:Sample)<-[*]-(donor:Donor)"
f" WHERE (:Dataset)<-[]-()<-[]-(firstSample)"
f" WHERE (:Dataset)<-[:ACTIVITY_OUTPUT]-(:Activity)<-[:ACTIVITY_INPUT]-(firstSample)"
f" WITH ds, COLLECT(distinct donor) AS DONOR, COLLECT(distinct firstSample) AS FIRSTSAMPLE"
f" OPTIONAL MATCH (ds)<-[*]-(metaSample:Sample)"
f" WHERE NOT metaSample.metadata IS NULL AND NOT TRIM(metaSample.metadata) = ''"
Expand All @@ -695,7 +697,8 @@ def get_individual_prov_info(neo4j_driver, dataset_uuid):
# specimen_type -> sample_category 12/15/2022
f" OPTIONAL match (donor)-[:ACTIVITY_INPUT]->(oa)-[:ACTIVITY_OUTPUT]->(organ:Sample {{sample_category:'organ'}})-[*]->(ds)"
f" WITH ds, FIRSTSAMPLE, DONOR, METASAMPLE, RUISAMPLE, COLLECT(distinct organ) AS ORGAN "
f" OPTIONAL MATCH (ds)-[:ACTIVITY_INPUT]->(a3)-[:ACTIVITY_OUTPUT]->(processed_dataset:Dataset)"
f" OPTIONAL MATCH (ds)-[*]->(a3)-[:ACTIVITY_OUTPUT]->(processed_dataset:Dataset)"
f" WHERE toLower(a3.creation_action) ENDS WITH 'process'"
f" WITH ds, FIRSTSAMPLE, DONOR, METASAMPLE, RUISAMPLE, ORGAN, COLLECT(distinct processed_dataset) AS PROCESSED_DATASET"
f" RETURN ds.uuid, FIRSTSAMPLE, DONOR, RUISAMPLE, ORGAN, ds.hubmap_id, ds.status, ds.group_name,"
f" ds.group_uuid, ds.created_timestamp, ds.created_by_user_email, ds.last_modified_timestamp, "
Expand Down Expand Up @@ -867,7 +870,7 @@ def get_sample_prov_info(neo4j_driver, param_dict, public_only):
# specimen_type -> sample_category 12/15/2022
f" OPTIONAL MATCH (s)<-[*]-(organ:Sample{{sample_category: 'organ'}})"
f" WITH s, organ, d"
f" MATCH (s)<-[]-()<-[]-(da)"
f" MATCH (s)<-[:ACTIVITY_OUTPUT]-(:Activity)<-[:ACTIVITY_INPUT]-(da)"
f" RETURN s.uuid, s.lab_tissue_sample_id, s.group_name, s.created_by_user_email, s.metadata, s.rui_location,"
f" d.uuid, d.metadata, organ.uuid, organ.sample_category, organ.metadata, da.uuid, da.entity_type, "
f"s.sample_category, organ.organ, s.organ, s.hubmap_id, s.submission_id, organ.hubmap_id, organ.submission_id, "
Expand Down Expand Up @@ -976,7 +979,7 @@ def get_paired_dataset(neo4j_driver, uuid, data_type, search_depth):
number_of_jumps = f"*..{search_depth}"
data_type = f"['{data_type}']"
query = (
f'MATCH (ds:Dataset)<-[*]-(s:Sample) WHERE ds.uuid = "{uuid}" AND (:Dataset)<-[]-()<-[]-(s)'
f'MATCH (ds:Dataset)<-[*]-(s:Sample) WHERE ds.uuid = "{uuid}" AND (:Dataset)<-[:ACTIVITY_OUTPUT]-(:Activity)<-[:ACTIVITY_INPUT]-(s)'
f'MATCH (ods)<-[{number_of_jumps}]-(s) WHERE ods.data_types = "{data_type}"'
f'return ods.uuid as uuid, ods.status as status'
)
Expand Down

0 comments on commit df5fd75

Please sign in to comment.