g2nb / igv-jupyter

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

Can't access local file: range-byte header ignored #7

Closed jfear closed 8 years ago

jfear commented 8 years ago

I have been trying to load local files using igv.js-jupyter

Your example code works.

from igv import IGV, Reference, Track

igv_tracks = IGV(locus="chr1:155,160,475-155,184,282", reference=Reference(id="hg19"), tracks=[Track(
    name="Genes", 
    url="//s3.amazonaws.com/igv.broadinstitute.org/annotations/hg19/genes/gencode.v18.collapsed.bed",
    index_url="//s3.amazonaws.com/igv.broadinstitute.org/annotations/hg19/genes/gencode.v18.collapsed.bed.idx", 
    display_mode="EXPANDED")])

igv_tracks

However, if I download your BED and IDX files and try:

igv_tracks = IGV(locus="chr1:155,160,475-155,184,282", reference=Reference(id="hg19"), tracks=[Track(
    name="Genes", 
    url="//localhost:8888/files/tmp/gencode.v18.collapsed.bed",
    index_url="//localhost:8888/files/tmp/gencode.v18.collapsed.bed.idx", 
    display_mode="EXPANDED")])
igv_tracks

I get the following:

image

The jupyter console gives me a 302:

image

I can download the files by pasting the url into my browser.

And the Chrome developer tool network pane gives the two files with the correct file sizes.

image

Thanks for your help. Justin

turner commented 8 years ago

Yes, I have reproduced this. I am looking into it.

jrobinso commented 8 years ago

Hi, the problem is the web server (Jupyter server) does not support range request headers. The consequence of this you can't server indexed files to IGV. Your example should work if you just remove the index_url parameter. The larger consequence is you cannot server large files, such as bam and fasta files, that require an index with this server. A workaround if you need to serve files from your local machine is to run another webserver to serve them, such as apache or flask. Flask does not support range headers out-of-the-box but can be configured to do so.

I will update the readme to alert other users to this issue. Apologies for the delay, we were investigating the possibility of configuring the Jupyter server to support range headers.

jfear commented 8 years ago

Thank you. I can confirm that my example works if I change the above to:

igv_tracks = IGV(locus="chr1:155,160,475-155,184,282", reference=Reference(id="hg19"), tracks=[Track(
    name="Genes", 
    url="//localhost:8888/files/gencode.v18.collapsed.bed",
    index_url=False, 
    display_mode="EXPANDED")])
igv_tracks

I will play with setting up an apache instance and playing with that to see if I can get BAMS working.

jfear commented 8 years ago

I was able to get things working. Thanks again for the guidance.

I am posting information incase others are trying to do something similar.

I set up a apache server on a CentOS 7 VM, attached is my httpd.conf (totally not secure, just quick and dirty): httpd.conf.txt

I was not able to access the VM by IP (probably something silly), so I ended up doing some SSH port forwarding:

VIRTUAL_IP_ADDRESS=10.22.1.21
ssh -M -S virtual-ctrl-socket -fnNT -L 8989:localhost:80 $VIRTUAL_IP_ADDRESS

Then in the notebook I can connect with:

from igv import IGV, Reference, Track

igv_tracks = IGV(locus="chr2L:100-10,000", reference=Reference(id='dm6', fastaURL='//localhost:8989/dm6-noextra.fasta'),
                tracks=[Track(name='Genes', type='annotation', format='gff', 
                              url='//localhost:8989/dmel-all-r6.09.chr.sort.gtf',
                             index_url='//localhost:8989/dmel-all-r6.09.chr.sort.gtf.idx',
                             display_mode='EXPANDED')])
igv_tracks
qingpeng commented 6 years ago

Any new solution for this other than launching an Apache server?

Also, I couldn't read a .bed file from local directory, as shown above...

jrobinso commented 6 years ago

You can use any server meeting the requirements described here: https://github.com/igvteam/igv.js/wiki/Data-Server-Requirements

Others have configured Jupyter to support this, and I understand the latest Jupyter is configured like this out-of--the box. However I cannot help you with Jupyter configuration, I am not an expert. Do our example notebooks work for you? Have you followed the installation instructions on our wiki?