g2nb / igv-jupyter

Extension for Jupyter which integrates igv.js
MIT License
154 stars 14 forks source link

IGV Browser not ready #29

Closed vanetten closed 4 years ago

vanetten commented 4 years ago

Hey Jim!

I stumbled upon igv-jupyter and tried it out on this Gen3 Jupyter environment I'm working on. I have this odd issue, which might not be an igv-jupyter issue, more likely a problem with my use of it.

When I open a notebook, and run it, IGV does not b.show(), and I get an "IGV Browser not ready" message from b.load_track, with a "Could not open comm -- Error: Class igvcomm not found in registry" error in the console.

However, if I open a new browser window, and re-open the running notebook, and run it again, it works just fine? What am I doing wrong?

Screen Shot 2019-09-26 at 5 01 38 PM Screen Shot 2019-09-26 at 5 03 37 PM

jrobinso commented 4 years ago

My first instinct would be to say the the nb extension is either not installed, or not enabled, but the fact that it works after opening a new browser would suggest that it is. Could you give us the exact steps you took to install it? I'm ccing @tmtabor who is the expert on all things notebook.

@tmtabor @helgathorv Any ideas?

Jupyter notebook is at times a mystery to me.

tmtabor commented 4 years ago

I suspect there's some sort of timing issue going on with the start up of the kernel.

That is, when you first launch a notebook, it starts a Python process on the server which holds the state of the notebook in memory. It also tells your browser to load all the client-side assets, like the widgets and notebook extensions.

Jupyter needs both of these to load before it can open the comm.

If you somehow run the cell before everything is loaded, you might get an error like this. That can happen if, for example, Jupyter is installed on a slow shared file system, or if you have some other slow-to-load extension installed (like rpy2).

My hypothesis is that the reason the widget works when you re-open the notebook is because at that point the kernel's already running. It was started when you opened the notebook the first time, so it's still in memory on the server.

jrobinso commented 4 years ago

Thanks @tmtabor . Anything we can do about that in the extension, such as print a message to the cell that the kernel is not ready? Its not immediately obvious how to do that as the error is thrown in the client. Perhaps we can catch it there and popup an alert dialog?

Also, any idea on how to make this happen (simulate it)?

vanetten commented 4 years ago

If it helps, I can give you access to our Gen3 instance, and the notebook.

Bill

Sent from my iPhone

On Sep 26, 2019, at 8:03 PM, Jim Robinson notifications@github.com wrote:

Thanks @tmtabor . Anything we can do about that in the extension, such as print a message to the cell that the kernel is not ready? Its not immediately obvious how to do that as the error is thrown in the client. Perhaps we can catch it there and popup an alert dialog?

Also, any idea on how to make this happen (simulate it)?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

tmtabor commented 4 years ago

I'd be happy to take a look. Being able to poke around in the javascript console and examine the error would help track down the cause of the issue.

Thorin

On 9/26/19 18:32, vanetten wrote:

If it helps, I can give you access to our Gen3 instance, and the notebook.

Bill

Sent from my iPhone

On Sep 26, 2019, at 8:03 PM, Jim Robinson notifications@github.com wrote:

Thanks @tmtabor . Anything we can do about that in the extension, such as print a message to the cell that the kernel is not ready? Its not immediately obvious how to do that as the error is thrown in the client. Perhaps we can catch it there and popup an alert dialog?

Also, any idea on how to make this happen (simulate it)?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/igvteam/igv-jupyter/issues/29?email_source=notifications&email_token=ACFDFRGH5TT5V42SL7IH3NDQLVPCPA5CNFSM4I27GNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7XNLNI#issuecomment-535745973, or mute the thread https://github.com/notifications/unsubscribe-auth/ACFDFRGYPMIZNXATDHZYYQDQLVPCPANCNFSM4I27GNWQ.

vanetten commented 4 years ago

Give me a google ID for you.

Bill

Sent from my iPhone

On Sep 27, 2019, at 11:18 AM, Thorin Tabor notifications@github.com wrote:

I'd be happy to take a look. Being able to poke around in the javascript console and examine the error would help track down the cause of the issue.

Thorin

On 9/26/19 18:32, vanetten wrote:

If it helps, I can give you access to our Gen3 instance, and the notebook.

Bill

Sent from my iPhone

On Sep 26, 2019, at 8:03 PM, Jim Robinson notifications@github.com wrote:

Thanks @tmtabor . Anything we can do about that in the extension, such as print a message to the cell that the kernel is not ready? Its not immediately obvious how to do that as the error is thrown in the client. Perhaps we can catch it there and popup an alert dialog?

Also, any idea on how to make this happen (simulate it)?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/igvteam/igv-jupyter/issues/29?email_source=notifications&email_token=ACFDFRGH5TT5V42SL7IH3NDQLVPCPA5CNFSM4I27GNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7XNLNI#issuecomment-535745973, or mute the thread https://github.com/notifications/unsubscribe-auth/ACFDFRGYPMIZNXATDHZYYQDQLVPCPANCNFSM4I27GNWQ.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

tmtabor commented 4 years ago

tmtabor [at] cloud.ucsd.edu

vanetten commented 4 years ago

You should be authorized now. I sent directions and the notebook to tmtabor@cloud.ucsd.edu.

Bill

tmtabor commented 4 years ago

I have taken a look and I believe the problem is caused by the way that Jupyter loads extensions.

In particular, the IGV Jupyter extension consists of both Python code, which runs on the server, and Javascript code, which runs in your browser and displays the visualization.

When Jupyter installs the extension, it places the Python code on your Python PATH. It then configures Jupyter to load the Javascript code when the notebook is first opened.

!pip install igv-jupyter

!jupyter serverextension enable --py igv --sys-prefix
!jupyter nbextension install --py igv --sys-prefix
!jupyter nbextension enable --py igv --sys-prefix

import igv

In the example notebook you sent me, it installs the IGV Jupyter extension and then immediately runs it. The import igv works because the Python half of the extension is placed on your Python PATH at install-time. But the visualization fails to load because the Javascript half hasn't been loaded -- since it's loaded when the notebook is first opened, and the notebook was opened before the extension was installed.

Opening the notebook a second time works because at that point the extension has already been installed.

vanetten commented 4 years ago

Is there something you suggest I do differently? Or is the problem in my setup, that I’ll just have to open and run it twice?

On Sep 30, 2019, at 1:09 PM, Thorin Tabor notifications@github.com wrote:

I have taken a look and I believe the problem is caused by the way that Jupyter loads extensions.

In particular, the IGV Jupyter extension consists of both Python code, which runs on the server, and Javascript code, which runs in your browser and displays the visualization.

When Jupyter installs the extension, it places the Python code on your Python PATH. It then configures Jupyter to load the Javascript code when the notebook is first opened.

!pip install igv-jupyter

!jupyter serverextension enable --py igv --sys-prefix !jupyter nbextension install --py igv --sys-prefix !jupyter nbextension enable --py igv --sys-prefix

import igv

In the example notebook you sent me, it installs the IGV Jupyter extension and then immediately runs it. The import igv works because the Python half of the extension is placed on your Python PATH at install-time. But the visualization fails to load because the Javascript half hasn't been loaded -- since it's loaded when the notebook is first opened, and the notebook was opened before the extension was installed.

Opening the notebook a second time works because at that point the extension has already been installed.

tmtabor commented 4 years ago

Unfortunately this is a Jupyter design decision that's a problem at times. Depending on your end goals, things I might suggest include:

If you control what packages are installed by default on your platform, installing IGV Jupyter by default gets around this problem because it will always get loaded when a notebook is opened.

Or, if you're creating a notebook to share with others, having a block of text that simply tells people to reload after installing the extension is an option. With the %%javascript cell magic, you could even have a cell that reloads the notebook for them.

jrobinso commented 4 years ago

@tmtabor Is there anything we can do with how this is packaged? Also, for my education, why does it just work for most people (I can install it) but is not working with Bill's setup.

tmtabor commented 4 years ago

The most common use case is that someone installs the extension using the command line and then opens a notebook to try using it. In this case the extension simply works.

The issue that Bill ran into comes from installing the extension inside of a notebook after it's already been opened, and them immediately attempting to run the extension.

Unfortunately, I'm not aware of any way to package it to get around this issue.

callieboskin commented 4 years ago

Hello! I know this is an old thread, but I have the same issue (b.show() doesn't show anything, and then 'IGV Broswer not ready' when I try to load a track), but it isn't resolved by opening a new tab and trying again. @jrobinso can you explain what you meant about installing/enabling nb_extension?

jrobinso commented 4 years ago

I will defer to @tmtabor wrt "installing/enabling nb_extension". However what version are you using? This was solved long ago, or so we thought.

jrobinso commented 4 years ago

Closed accidentally.

callieboskin commented 4 years ago

Your step-by-step instructions here fixed it! Thanks!

jrobinso commented 4 years ago

@callieboskin OK that's great but do those instructions differ from our readme instructions? That's a rather long thread so I'm not sure what you are referring to precisely.

callieboskin commented 4 years ago

Sorry, the below instructions are what I'm referring to. Create the virtual environment

Install IGV -- note that you would not include the --sys-prefix flag if not in a virtual environment

Run the notebook

jrobinso commented 4 years ago

Those instructions will install a deprecated version of igv. The supported version is "igv-jupyter". The only difference is the pip install line, which should be

pip install igv-jupyter

Those are the same instructions on pypi and distributed in the readme.

callieboskin commented 4 years ago

Interestingly, when I did the first set of instructions (pip install igv), I was able to get b.show() to work, but when I repeated and did pip install igv-jupyter, b.show() stopped working.

jrobinso commented 4 years ago

Interesting indeed. Did you start with a fresh environment?

jrobinso commented 4 years ago

For now stick with "igv", its only 1 version behind. I'm at a loss at the moment.

callieboskin commented 4 years ago

I did start with a fresh environment, yes. It's not working perfect though - I'm unable to load bam files. I'm getting an "error loading track data". It feels likely it's a silly mistake on my part, but if you have any suggestions please let me know!

Thank you for your help, by the way! I'm pretty new to this so all advice is helpful!

helgathorv commented 4 years ago

@callieboskin Are you trying to load the same BAM files in both cases?

callieboskin commented 4 years ago

I actually reran everything again, and managed to get b.show() to work with pip install igv-jupyter. However, my bam files still don't load: I get "Error loading track data". I'm running Jupyter off of Putty, and it seems like restarting everything works sometimes.

jrobinso commented 4 years ago

I think this is resolved.