igvteam / igv-notebook

Module for embedding igv.js in an IPython notebook
MIT License
61 stars 14 forks source link

Option to allow SVG output #6

Closed shunhuahan closed 2 years ago

shunhuahan commented 2 years ago

Hi,

Thanks for creating this amazing python package! I'm trying to figure out ways automate generating IGV screenshots using igv-notebook and seems like it lacks the SVG output option (currently I need to manually right click the navigator panel to output SVG). I wonder if it's possible that you could enable an option to convert browser content to SVG/PNG format (https://github.com/igvteam/igv.js/wiki/Browser-API-2.0#tosvg)?

Thanks, Shunhua

jrobinso commented 2 years ago

I am guessing you want to get the SVG on the python (server) side, correct? For which platform (Notebook, Lab, Colab). The client-server messaging options are different for each.

shunhuahan commented 2 years ago

@jrobinso thanks for responding! Yes, I'm trying to get the SVG on the python side and I'm using Jupyter Notebook as the platform.

jrobinso commented 2 years ago

Yes I think this can be supported for Notebook and possibly Colab, but not for JupyterLab. Not in this project anyway. Leave this open, I will get to it when I can.

jrobinso commented 2 years ago

Its tricky because this will be asyncronous, the SVG will need to be returned to python via a "comm" message unless you know another way. However I think in python we'll want to make it appear synchronous so we can write something like

svg = b.get_svg()

... do stuff with svg

My idea right now is to poll until the comm message with the svg is received, with a timeout of a second or two. If you have other ideas please post them here.

shunhuahan commented 2 years ago

Hi Jim, I think your idea to SVG appear synchronous makes sense. I currently don't know what other ways to get the SVG..

Related to SVG output, one feature that would be potentially nice to have is to have igv-notebook directly generates the SVG without having to render the browser and load alignments/annotations inside the Notebook. This would make sense if users need to generate large amount of IGV screenshots for many samples (Traditionally people have to use igv --batch via command line).

Shunhua

jrobinso commented 2 years ago

I'm not sure that's possible, well anything is possible but would be a substantial amount of work. What you see is dependent on the DOM, which the browser renders. BTW the equivalent is not possible with IGV either, you need a graphics system to render IGV to get screenshots. Some people use a virtual X emulator, but still from IGV's perspective it is rendered in a window.

shunhuahan commented 2 years ago

@jrobinso Thanks for the explanation! I guess I should use this package in Jupyter Notebook to render a small set of IGV pileups instead of trying to do large amount of samples to maintain reasonable memory usage.

jrobinso commented 2 years ago

I'm not sure notebooks + igv.js is going to be a good platform for doing large numbers of pileups in an automated way, the asynchronous nature of data loading and rendering is going to be an issue for one thing.

On Wed, May 4, 2022 at 5:21 PM Shunhua Han @.***> wrote:

@jrobinso https://github.com/jrobinso Thanks for the explanation! I guess I should use this package in Jupyter Notebook to render a small set of IGV pileups instead of trying to do large amount of samples to maintain reasonable memory usage.

— Reply to this email directly, view it on GitHub https://github.com/igvteam/igv-notebook/issues/6#issuecomment-1118051552, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHD2HHZTBOMSLIXUU7F24TVIMIAXANCNFSM5U5IYL2A . You are receiving this because you were mentioned.Message ID: @.***>

jrobinso commented 2 years ago

For example, assume "get_svg" were available, if you call it immediately after creating the igv instance you will get nothing or a blank svg since nothing has been rendered yet. This could be problematic.

On Wed, May 4, 2022 at 6:11 PM James Robinson @.***> wrote:

I'm not sure notebooks + igv.js is going to be a good platform for doing large numbers of pileups in an automated way, the asynchronous nature of data loading and rendering is going to be an issue for one thing.

On Wed, May 4, 2022 at 5:21 PM Shunhua Han @.***> wrote:

@jrobinso https://github.com/jrobinso Thanks for the explanation! I guess I should use this package in Jupyter Notebook to render a small set of IGV pileups instead of trying to do large amount of samples to maintain reasonable memory usage.

— Reply to this email directly, view it on GitHub https://github.com/igvteam/igv-notebook/issues/6#issuecomment-1118051552, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHD2HHZTBOMSLIXUU7F24TVIMIAXANCNFSM5U5IYL2A . You are receiving this because you were mentioned.Message ID: @.***>

shunhuahan commented 2 years ago

@jrobinso I see, thanks for explaining the asynchronous issue in more details! In this case I might need to think of alternative strategies if I want to generate large numbers of pileups automatically. Please feel free to close this SVG output request.

jrobinso commented 2 years ago

Yes, I didn't consider that myself at first I just realized it when working on this. igv.js is designed for user interaction, not serial blocking execution, which is at the root of this problem. IGV desktop goes into a special mode when running batch scripts where the UI is locked and everything is synchronous. There is already a python project for creating batch screenshots from IGV desktop, this project could perhaps be used from notebooks. The project is here: https://github.com/stevekm/IGV-snapshot-automator