Dash-Bio load local files into igv-component


i want to load local files like .fa, .gtf, .bed, .bedgraph into the igv component. For example like this:


thaliana = {
        "id": "tair",
        "name": "A. thaliana (TAIR 10)",
        "sourceType": "file",
        "fastaURL": "samples/TAIR10_chr_all.fas",
        "tracks": [
                "name": "Genes",
                "type": "annotation",
                "format": "gtf",
                "sourceType": "file",
                "url": "samples/Araport11_protein_coding.201606.gtf.gz",

bedgraph = {
        'id': 'tair10',
        'name': "Annotation",
        'type': "annotation",
        'format': "bed",
        'sourceType': "file",
        'url': "./samples/Araport11_protein_coding.201606.bed",
        'displayMode': "EXPANDED"

The bedgraph is another example. It would be set to the reference, instead of thaliana. But it will not load the local files. If i change the id: “tair” to id:“tair10” it will load from the list of pre-defined reference genomes. The following changes i also tried to run.

  • str(pathlib.Path(file).parent/ ‘samples/TAIR10_chr_all.fas’)
  • pathlib.Path(absolute_path_string).as_uri()
  • os.path.realpath(‘TAIR10_chr_all.fas’)

How can i load local files into the igv-component?

1 Like

I just had to do this also. Since the igv component expects files to be coming from a server, I just used the flask instance running the dash app to serve the files.

YOUR_DATA_DIR should be the local path. Note that this will expose anything in that directory!

Here’s a toy example.

import dash_bio
from flask import send_from_directory


def send_bw(path):
    response = send_from_directory(YOUR_DATA_DIR,path)
    return response

def make_igv(sample_ids,gene_ids):
                } ]
    return igv

Flask is supposedly known for not being very performant with respect to serving static files, so I suspect you could get a lot of performance improvement by setting up another server like nginx to serve the track data. But for my purposes it was sufficient.

1 Like