From 5677a4391a0d14e2dd09d0032cf1494f44afef14 Mon Sep 17 00:00:00 2001 From: Manasa Venkatakrishnan Date: Mon, 9 Dec 2024 14:18:08 -0800 Subject: [PATCH 1/3] chore: Adding neuroglancer utility --- ingestion_tools/scripts/neuroglancer_util.py | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ingestion_tools/scripts/neuroglancer_util.py diff --git a/ingestion_tools/scripts/neuroglancer_util.py b/ingestion_tools/scripts/neuroglancer_util.py new file mode 100644 index 000000000..f61730ad4 --- /dev/null +++ b/ingestion_tools/scripts/neuroglancer_util.py @@ -0,0 +1,45 @@ +import json +import urllib.parse +import webbrowser + +import click +import cryoet_data_portal as cdp + +STAGING_GRAPHQL_URL = "https://genuine-satyr.staging-cryoet.staging.czi.team/graphql" +STAGING_FILESERVER = "https://files.cryoet.staging.si.czi.technology/" + +PROD_FILESERVER = "https://files.cryoetdataportal.cziscience.com/" + + +@click.group() +@click.pass_context +def cli(ctx): + pass + + +def print_neuroglancer_links(run_id: int, client: cdp.Client, dest_fileserver: str, print_link: bool): + run = cdp.Run.get_by_id(client, run_id) + for tomogram in run.tomograms: + if neuroglancer_config := tomogram.neuroglancer_config: + new_config = neuroglancer_config.replace(PROD_FILESERVER, dest_fileserver) + config_json = json.loads(new_config) + ng_url = "https://neuroglancer-demo.appspot.com/#!" + urllib.parse.quote( + json.dumps(config_json, separators=(",", ":")), + ) + if print_link: + print(f"Tomogram id={tomogram.id} processing={tomogram.processing}") + print(ng_url + "\n" * 3) + webbrowser.open(ng_url, new=0, autoraise=True) + + +@cli.command() +@click.argument("run_id", required=True, type=int) +@click.argument("graphql_url", required=False, type=str, default=STAGING_GRAPHQL_URL) +@click.argument("output_fileserver", required=False, type=str, default=STAGING_FILESERVER) +@click.option("--print-link", type=bool, is_flag=True, default=False) +def translate_env(run_id: int, graphql_url, output_fileserver: str, print_link: bool): + print_neuroglancer_links(run_id, cdp.Client(graphql_url), output_fileserver, print_link) + + +if __name__ == "__main__": + cli() From 1f6dafab1edf85c56562ea119319f348868cbe4c Mon Sep 17 00:00:00 2001 From: Manasa Venkatakrishnan Date: Wed, 11 Dec 2024 11:16:44 -0800 Subject: [PATCH 2/3] adding documentation --- ingestion_tools/scripts/neuroglancer_util.py | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ingestion_tools/scripts/neuroglancer_util.py b/ingestion_tools/scripts/neuroglancer_util.py index f61730ad4..90028432d 100644 --- a/ingestion_tools/scripts/neuroglancer_util.py +++ b/ingestion_tools/scripts/neuroglancer_util.py @@ -36,8 +36,25 @@ def print_neuroglancer_links(run_id: int, client: cdp.Client, dest_fileserver: s @click.argument("run_id", required=True, type=int) @click.argument("graphql_url", required=False, type=str, default=STAGING_GRAPHQL_URL) @click.argument("output_fileserver", required=False, type=str, default=STAGING_FILESERVER) -@click.option("--print-link", type=bool, is_flag=True, default=False) -def translate_env(run_id: int, graphql_url, output_fileserver: str, print_link: bool): +@click.option( + "--print-link", type=bool, is_flag=True, default=False, help="print the neuroglancer link to the consoles", +) +def translate_env(run_id: int, graphql_url, output_fileserver: str, print_link: bool) -> None: + """ + Translate the neuroglancer links from one environment to another + + @param run_id: id of the run in the environment where we are fetching the neuroglancer config + + @param graphql_url: graphql url of the environment the client should point to, defaults to staging + + @param output_fileserver: fileserver of the environment the client should point to, defaults to staging + + @param print_link: print the neuroglancer link to the consoles + + This can be called from the command line as follows: + + python3 neuroglancer_util.py translate-env 123 --print-link + """ print_neuroglancer_links(run_id, cdp.Client(graphql_url), output_fileserver, print_link) From e8dad3d99d084d7762d6e09878811d68471d62ea Mon Sep 17 00:00:00 2001 From: Manasa Venkatakrishnan Date: Thu, 19 Dec 2024 15:42:26 -0800 Subject: [PATCH 3/3] Adding support to fetch by ds_id and run_name --- ingestion_tools/scripts/neuroglancer_util.py | 54 ++++++++++++++++---- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/ingestion_tools/scripts/neuroglancer_util.py b/ingestion_tools/scripts/neuroglancer_util.py index 90028432d..ab4d704e8 100644 --- a/ingestion_tools/scripts/neuroglancer_util.py +++ b/ingestion_tools/scripts/neuroglancer_util.py @@ -33,29 +33,61 @@ def print_neuroglancer_links(run_id: int, client: cdp.Client, dest_fileserver: s @cli.command() -@click.argument("run_id", required=True, type=int) @click.argument("graphql_url", required=False, type=str, default=STAGING_GRAPHQL_URL) @click.argument("output_fileserver", required=False, type=str, default=STAGING_FILESERVER) @click.option( - "--print-link", type=bool, is_flag=True, default=False, help="print the neuroglancer link to the consoles", + "-rn-id", + "--run-id", + type=int, + default=None, + help="id of the run in the environment where we are fetching the neuroglancer config", ) -def translate_env(run_id: int, graphql_url, output_fileserver: str, print_link: bool) -> None: +@click.option("-ds-id", "--dataset-id", type=int, default=None, help="Dataset id to which the run belongs") +@click.option("-rn", "--run-name", type=str, default=None, help="Name of the run") +@click.option( + "--print-link", + type=bool, + is_flag=True, + default=False, + help="print the neuroglancer link to the consoles", +) +def translate_env( + graphql_url, + output_fileserver: str, + run_id: int, + dataset_id: int, + run_name: str, + print_link: bool, +) -> None: """ - Translate the neuroglancer links from one environment to another - - @param run_id: id of the run in the environment where we are fetching the neuroglancer config + Translate the neuroglancer links from one environment to another. You can either provide the run_id or the + dataset_id and run_name. @param graphql_url: graphql url of the environment the client should point to, defaults to staging - @param output_fileserver: fileserver of the environment the client should point to, defaults to staging - + @param run_id: id of the run in the environment where we are fetching the neuroglancer config + @param dataset_id: dataset id to which the run belongs + @param run_name: Name of the run @param print_link: print the neuroglancer link to the consoles - This can be called from the command line as follows: - python3 neuroglancer_util.py translate-env 123 --print-link + python3 neuroglancer_util.py translate-env --run-id 123 --print-link + python3 neuroglancer_util.py translate-env --rn-id 123 + + python3 neuroglancer_util.py translate-env --run-name "TS_026" --dataset-id 10000 + python3 neuroglancer_util.py translate-env -rn "TS_026" -ds-id 10000 """ - print_neuroglancer_links(run_id, cdp.Client(graphql_url), output_fileserver, print_link) + client = cdp.Client(graphql_url) + if run_id: + print_neuroglancer_links(run_id, client, output_fileserver, print_link) + elif dataset_id and run_name: + run = cdp.Run.find(client, [cdp.Run.dataset_id == dataset_id, cdp.Run.name == run_name]) + if not run: + print(f"No run found for dataset_id={dataset_id} and run_name={run_name}") + return + print_neuroglancer_links(run[0].id, client, output_fileserver, print_link) + else: + print("Please provide either run_id or dataset_id and run_name") if __name__ == "__main__":