igv javascript (igv.js) viewer accessing large BAM hosted on Flask web server

507 views
Skip to first unread message

Nikolas Pontikos

unread,
Jul 6, 2016, 5:10:06 AM7/6/16
to igv-help
I'm running the igv.js in my browser and trying to view regions in a whole exome BAM file hosted on my web server.

I am running a Python Flask web server so I could write some Python to handle requests from the igv.js client.
However igv.js seems to only be able to download whole BAM files and can't read from a stream (as far as I am aware).

Is there a way of getting the client to request and display only a region instead of the entire BAM file (it is far too big to load in the web browser)?

Many Thanks,

Nikolas.

Jim Robinson

unread,
Jul 6, 2016, 10:49:38 AM7/6/16
to igv-...@googlegroups.com
That's exactly how it works (it requests only the region on screen).   I suspect your flask server is ignoring the range-byte request.    Be sure your server supports range-byte requests.


--

---
You received this message because you are subscribed to the Google Groups "igv-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to igv-help+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/igv-help/cc3abe6f-fefe-43cf-af05-0ff109b00703%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikolas Pontikos

unread,
Jul 6, 2016, 2:46:35 PM7/6/16
to igv-...@googlegroups.com
Thanks Jim.

I've been trying to get my python Flask server to handle the requests
from igv.js.

However it's still trying to download the whole BAM file.

I think it is because when the client does the initial HEAD, the
server responds with a "Content-Length" which is the size of the whole
file?

Am I meant to calculate, server-side, what the Content-Length is
supposed to be, based on the viewing coordinates, or does the
javascript figure that out and makes the appropriate requests?

This is what my javascript looks like:

var tracks=[];
tracks.push({
url: '/read_viz/bam/gencode.v19.sorted.bed',
name: "gencode v19",
displayMode: "SQUISHED"
});
var options = {
showCommandBar: true,
genome: 'hg19',
locus: '2:240981885-240981895',
showKaryo: false,
tracks: tracks,
};

igv.createBrowser($("#igv-container")[0], options);
var track={ type: 'bam', indexed: true, alignmentShading: 'strand',
url: '/read_viz/bam/OXF_3018', name: '', height: 300, minHeight: 300,
autoHeight: false, readgroup: '' };
igv.browser.loadTrack(track);


And this is what my server side code looks like:


@app.route('/read_viz/bam/<sample>')
def read_viz(sample):
headers=Headers()
headers.add('Content-Transfer-Encoding','binary')
headers.add('Accept-Ranges', 'bytes')
headers.add('X-Frame-Options','SAMEORIGIN')
if sample.endswith('.bai'):
bamfile='/slms/UGI/vm_exports/vyp/phenotips/uclex_files/bam/OXF_3018_sorted_unique.bam.bai'
size = os.path.getsize(bamfile)
else:
bamfile='/slms/UGI/vm_exports/vyp/phenotips/uclex_files/bam/OXF_3018_sorted_unique.bam'
size = 1000
status = 200
begin = 0
end = size-1
if request.headers.has_key("Range"):
status = 206
headers.add('Accept-Ranges','bytes')
ranges = re.findall(r"\d+", request.headers["Range"])
begin = int( ranges[0] )
if len(ranges)>1:
end = int( ranges[1] )
headers.add('Content-Range','bytes %s-%s/%s' %
(str(begin),str(end),str(end-begin)) )
headers.add('Content-Length',str((end-begin)+1))
#Add mimetype
mimetype = "application/octet-stream"
response = Response( file(bamfile), status=status,
mimetype=mimetype, headers=headers, direct_passthrough=True)
#enable browser file caching with etags
response.cache_control.public = True
response.make_conditional(request)
return response
> You received this message because you are subscribed to a topic in the
> Google Groups "igv-help" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/igv-help/xH-Zn_jISYE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> igv-help+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/igv-help/577D1A7D.7060004%40broadinstitute.org.

Jim Robinson

unread,
Jul 7, 2016, 6:16:58 PM7/7/16
to igv-...@googlegroups.com
Hi,

The Content-Length should return the size of the whole file, that is
normal. You are not meant to calculate anything on the server side,
but if a range-byte header is included in the request you must return
only that range. I don't know the language you are using, but it looks
like the code is not doing that, rather it is streaming back the entire
file. Its not enough to just set headers, you have to read that
specific range of bytes from the file and only return that in the
response. Its actually very bad to set 206 and then return the whole
file (206 is the partial response code).

I could be wrong in my reading of your code, again I don't know Flask.
BTW, the proper forum for igv.js issues is github.com/igvteam/igv.js/issues.

Jim

Nikolas Pontikos

unread,
Jul 8, 2016, 5:21:25 PM7/8/16
to igv-...@googlegroups.com
Thank you Jim, I have got it working now. 
To view this discussion on the web visit https://groups.google.com/d/msgid/igv-help/00ef57a6-5a89-0398-c321-3b78dd342cec%40broadinstitute.org.

gau...@pieriandx.com

unread,
Feb 11, 2017, 11:26:20 PM2/11/17
to igv-help
Hi Team,

I am looking for IGV.js documentation. I could not find any.

- Areas which i am interested to  ->

What is the use of IGV.js how it is different from IGV desktop?

What all information user might be interested while analyzing the IGV.js 

Please help

Thanks & Regards
Gaurav

James Robinson

unread,
Feb 13, 2017, 4:20:08 PM2/13/17
to igv-help
Hi, did you follow the link on this page?  




--

---
You received this message because you are subscribed to the Google Groups "igv-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to igv-help+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/igv-help/387cb028-fbfc-4007-aeee-3d11d6610fe3%40googlegroups.com.

Gaurav Singh

unread,
Feb 13, 2017, 11:05:53 PM2/13/17
to igv-...@googlegroups.com
Hi, i followed that link, but that mainly for developers, i am a bioinformatician, and i am more of interested in usability perspective rather than development. 

--

---
You received this message because you are subscribed to a topic in the Google Groups "igv-help" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/igv-help/xH-Zn_jISYE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to igv-help+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/igv-help/CACOP%2Bpv4TNGBFDDfu0Py7kiAmVTnaUTYV9WEV0YQQmMduK_5%3Dw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages