igvteam / igv-notebook

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

bam in mounted directory doesn't load with 'path' #26

Open mpgriesh opened 9 months ago

mpgriesh commented 9 months ago

Hi,

Thanks for this software!

I am trying to use igv-notebook to view alignments against bacterial genomes but I'm having trouble adding .bam tracks. These files all work as expected on the desktop app.

I am working within VSCode using the Jupyter extension. I am running notebook 6.4.11 and my python kernel is 3.9.7. I open the folder where the .ipynb is stored and can access the track files from that location relatively.

I am using the following code:

`import igv_notebook igv_notebook.init()

fm043 = igv_notebook.Browser( { "reference": { "id": "FM_043", "name": "FM_043", "fastaPath": "flye/assembly.fasta", "indexPath": "flye/assembly.fasta.fai" }, "locus": "contig_5:18,000-30,000" } )

fm043.load_track( { "name": "FM043_flye", "path": "annotation/flye_igv.bed", "format": "bed", "type": "annotation", "height":120, "indexed": False, "color": "red" } )

fm043.load_track( { "name": "FM043_flye", "path": "align/flye_alignment.sorted.bam", "indexPath": "align/flye_alignment.sorted.bam.bai", "format": "bam", "height": 240, "type": "alignment", "color": "blue" } )`

This works for the genome and annotation track! The bam file though fails to load even after 30 minutes. Sometimes a 408 error is output which suggests the server connection is too slow.

image

When I try to repeat the same process but instead downloading the relevant files locally, the .bam file still doesn't load. The bam file in this case is ~200Mb which I wouldn't expect to be problematic. In the /Examples section, there is reference to the url approach functioning better than the path approach. Is that all that is going on here?

jrobinso commented 9 months ago

I don't know anything about the VS code Jupyter extension. However you can't use true local paths with Jupyter Lab. In Jupyter Notebook you can, but it is not as effecient as using a relative URL and letting the Jupyter server itself handle the file loading.

If you want to use the local file ("path") option, have you tried using absolute paths to the files? That would be the first thing I would try. If using relative paths use "urls", although its sometimes tricky figuring out what the root path is for a Jupyter server.

jrobinso commented 9 months ago

The local "path" option was primarily added for Colab notebooks. It can also be useful for Jupyter Notebook if the paths are outside the file tree of the Jupyter server, but in that case you almost have to use absolute paths (start with "/").

mpgriesh commented 9 months ago

Thanks for the quick reply!

I just tried it with 'url' instead of 'path' and I am actually getting the same behavior.

fm043.load_track( { "name": "bam", "url": "/Volumes/.../flye_alignment.sorted.bam", "indexURL": "/Volumes/.../flye_alignment.sorted.bam.bai", "format": "bam", "height": 240, "type": "alignment", "color": "blue" }

image

When I try the tutorial example with hg19, it loads in a second so I don't think it's a problem with VSCode.

jrobinso commented 9 months ago

For sure you can't use an absolute path with "url" and "indexURL". I was suggesting you try the absolute paths with the "path" / "indexPath" options if that's what you want to do.

The url will be relative to your Jupyter file tree root, generally the startup directory of the Jupyter server. If you are running Jupyter lab there is actually a user interface to find the URL. Is your data in the Jupyter file tree (i.e. under the root directory of the Jupyter server)?