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

Things left for the Python package #98

Open
1 of 3 tasks
sehilyi opened this issue Apr 21, 2023 · 4 comments
Open
1 of 3 tasks

Things left for the Python package #98

sehilyi opened this issue Apr 21, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@sehilyi
Copy link
Member

sehilyi commented Apr 21, 2023

Required

  • Publish a Python package
  • Add documentation with a separate sidebar menu (e.g., "Using a Python Package")

If Possible

  • Support rendering individual views (e.g., chromoscope.overview())
@sehilyi sehilyi added the enhancement New feature or request label Apr 21, 2023
@sehilyi
Copy link
Member Author

sehilyi commented Apr 24, 2023

@manzt Can you suggeset a way to enable the Python package to visualize individual views of Chromoscope? My thought was that (1) we can publish a JS library that exposes several Gosling spec template functions (e.g., createOverviewSpec(), createSvSpec(), etc) and (2) use them in Python somehow (e.g., gosling.embed(ele, createOverviewSpec({ config })) using AnyWidget?).

@manzt
Copy link
Member

manzt commented Apr 25, 2023

You shouldn't need to publish a second package. You could easily create an HTML template and inline the JavaScript like in Gos and write the spec directly:

_HTML_TEMPLATE = jinja2.Template("""
<div id="{{ output_id }"></div>
<script type="application/javascript">// load gosling</script>
<script>
  
  const templateType = "{{ template_type }}";
  let templateFn;
  if (templateType === "sv") {
    templateFn = ...
  } else if (templateType == "overview") {
    templateFn = ...
  }
  const spec = templateFn(JSON.parse(({{ config_json }}));
  gosling.embed(document.getElementById("#{{ output_id }}", spec);
</script>
""")

html = _HTML_TEMPLATE.render(
  output_id=uuid.uuid4().hex, # unique id for the page
  template_type="sv",
  config_json=json.dumps(config),
)

@sehilyi
Copy link
Member Author

sehilyi commented Apr 25, 2023

@manzt But, we want to reuse template codes already implemented in JS (e.g., here) so that visualizations generated by the JS library and the Python package can be consistent. In this case, should we still not need to publish the second package?

@sehilyi
Copy link
Member Author

sehilyi commented May 10, 2023

esbuild --bundle src/track/coverage.ts --outfile coverage.js
_TEMPLATE = jinja2.Template("""

<script>
""" + pathlib.Path("./coverage.js").read_text() + """
</script>

<script>
  console.log(coverage) // imported as global above
</script>
""")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants