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
>
https://groups.google.com/d/msgid/igv-help/577D1A7D.7060004%40broadinstitute.org.