Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Adding neuroglancer utility #381

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions ingestion_tools/scripts/neuroglancer_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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, 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)


if __name__ == "__main__":
cli()
Loading