g2nb / igv-jupyter

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

Specify local file paths outside the project folder #25

Closed khourhin closed 4 years ago

khourhin commented 5 years ago

Hello,

Everything works fine when I'm importing tracks from files located in the current working directory (where the ipynb is located) or in subfolders. I'm specifying tracks like so:

b.load_track(
{
    "name": "mybed",
    "type":"annotation",
    "url": "files/my.bed",
    "format":"bed"
}
)

I would like to be able to load tracks from any place in my local disk (using relative or absolute paths) but I did not succeed so far. I tried: "url":"files/../my.bed" "url":"files/absolute/path/to/my.bed" "url":"localhost:8888/absolute/path/to/my.bed"

After checking, https://github.com/igvteam/igv.js/wiki/Tracks-2.0, I don't see how to specify local files outside the working directory. Is there a dedicated syntax for this ?

Thanks for the help and for a great jupyter extension !

jrobinso commented 5 years ago

Hi @khourhin . Technically you can't load local files via a path into any javascript browser, its not allowed. What's happening with jupyter is those paths are being translated to URLs and loaded from the Jupyter web server running on your machine. I'm not intimately familar with the Jupyter path magic, but you should be able to get it to work via symbolic links from a Jupyter directory.

The last URL you posted should have worked (localhost:8888...). If you paste that URL into a web browser address bar does it load you bed?

khourhin commented 5 years ago

Thanks for the help ! Indeed, I could use symbolic links. Pasted directly in the web browser, this last URL returns a jupyter 404.

I'll look a little bit more into this and let you know if I find something else.

jrobinso commented 5 years ago

A 404 means "not found". You need to construct a URL that works in the web browser address bar, after that it should work as a url in IGV. I'm not a jupyter expert, but I would expect the URL to start with something like localhost:8888/files/.... If you want to use arbitrary directories you could try adding symbolic links to them from the directory that is working, i.e. the directory where "my.bed" is located. If the directory link name is "foo" then localhost:8888/files/foo.bed.

Do some reading about hosting static files from a Jupyter server, that is really what you are trying to do.

khourhin commented 4 years ago

Yes, sorry for the late reply. I intended to dig a little more on file serving with Jupyter and put some guidance here but so far I had no time for this. Hopefully I will at some point ... Thanks again for the help !

JesseRop commented 2 years ago

I was getting the 404 GET error with the latest igv-jupyter version, which doesn't require a URL but works with the file paths, and solved this by putting all my files downstream of the working directory specified when loading JupyterLab.