hms-dbmi / chromoscope

Interactive multiscale visualization for structural variation in human genomes
https://chromoscope.bio/
MIT License
60 stars 6 forks source link

Things left for the Python package #98

Open sehilyi opened 1 year ago

sehilyi commented 1 year ago

Required

If Possible

sehilyi commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago
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>
""")