IGV Web App inside Flask Server
1
0
Entering edit mode
5.4 years ago
milind_ag ▴ 10

Hi,

Has anyone here ever used the IGV javascript web app, and tried to embed it inside a flask server? I'm having trouble with uploading custom user defined BAM/BAI files.

flask igv alignment bam • 3.1k views
ADD COMMENT
0
Entering edit mode

Hi, I was successful in running and using the igv.js for my purposes, however I didn't use BAM/BAI. I would suggest to read carefully and/or post an issue to https://github.com/igvteam/igv.js/issues. From my experience, the response time is quite fast.

ADD REPLY
0
Entering edit mode

Hi, thanks for responding. They have indeed been responsive but this is something that they, unfortunately, don't support out of the box. IGV.js works great within the node app they built, but its hard to use the JS library inside custom servers, ex. Flask. Thanks again!

ADD REPLY
0
Entering edit mode

Well, I didn't made it clear, but I'm using the igv.js inside the Flask server ;).

So I've got the impression that the bam/bai was the main issue.

ADD REPLY
0
Entering edit mode

Haha the bam/bai was indeed the main issue. The files are so huge that I can't perform an actual upload. IGV.js would need to "stream" these files from a cross origin resource/server, depending on the request window (chr1: 10000-10020) . I was hoping someone knew how to do that from scratch. Their web app supports this functionality, but in-housing it is preferred due to stability reasons.

And if you're not supporting bam/bai, then what does your flask/igv hybrid do? I'm curious. ;)

ADD REPLY
0
Entering edit mode

I need to show genomic loci with reference and custom annotations for multiple (eg 100) sequences at once (multiple ivg instances, one web page).

To the "stream", if you mean that igv needs to read only part of the file. I've done just that - but for indexed gff and fasta files. I've needed to be able to show genomes with automatically added tracks, so the data server is the same flask server. So no cross origin requests.

@app.route('/loadgenome/<genomefile>')
def igv_genome_load(genomefile):
    # serve genome files (from db, read only)
    # resolve file you want to load from <genomefile> somehow (this must be the file the igv.js is asking for) 
    #...
    range_header = request.headers.get('Range', None)

    if not range_header:
        return send_from_directory(pp, genomefile)

    return ranged_data_response(range_header, genomefile)

# from the igv.js server
def ranged_data_response(range_header, file_path):
    m = re.search('(\d+)-(\d*)', range_header)
    if not m:
        return "Error: unexpected range header syntax: {}".format(range_header)
    size = os.path.getsize(file_path)
    offset = int(m.group(1))
    length = int(m.group(2) or size) - offset + 1
    data = None
    with open(file_path, 'rb') as f:
        f.seek(offset)
        data = f.read(length)
    rv = Response(data, 206, mimetype="application/octet-stream", direct_passthrough=True)
    rv.headers['Content-Range'] = 'bytes {0}-{1}/{2}'.format(offset, offset + length-1, size)
    return rv

From the igv.js documentation I gues that you will need the bam mimetype https://github.com/igvteam/igv.js/wiki/Data-Server-Requirements.

ADD REPLY
0
Entering edit mode

Oh wow, that's a lot of sequences at once! And thanks for sharing your code, this is super helpful. I will try to adapt it for BAM/BAI files. I do have to make cross-origin requests so we'll see how that works out.

ADD REPLY
1
Entering edit mode
4.5 years ago
Jim Robinson ▴ 300

Hi, sorry I missed this. Please post igv questions to one of our forums, we are very responsive and if we're not post again.

igv.js works fine with flask for BAM files or any other file type igv.js supports. We have a project with it embedded out-of-the box at https://github.com/igvteam/igv.js-flask.

ADD COMMENT

Login before adding your answer.

Traffic: 2158 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6