Dash-bio unable to load alignemnts

Hello,
I am very very new dash and plotly. I am interested in using dash-bio for our research project; however I am having a hard time replicating the demo code with my own fasta file. Please see the code below. When I try to load the local host link in my browser, I get the error: “Error Loading Layout”. Any help with this would be greatly appreciated.

import urllib.request as urlreq
from dash import Dash, html
import dash_bio as dashbio

app = Dash(__name__)

data = open("test-fasta.fasta").read().encode('utf-8')

app.layout = html.Div([
    dashbio.AlignmentChart(
        id='my-default-alignment-viewer',
        data=data
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

Thank you,
Jeffy

Hi Jeffy,

Welcome to the forum!

The issue is how you are reading the fasta file - the code works fine when I replaced the data variable with the following

data = urlreq.urlopen(
    'https://git.io/alignment_viewer_p53.fasta'
).read().decode('utf-8')

I would recommend looking into libraries for parsing fasta file. This library may do the job.

:dna:

Best,

Shahzeb

Hi Shahzeb,
Thank you for the response. I am not sure I understand the difference between your code vs mine except that you are reading the data from a link and I am reading from a text file, both of the data are formatted similarly. In fact my test-fasta.fasta is simply just a text file version of the information that is in the link you provided.

Please let me know if I am missing some small detail.
Thank you,
Jeffy

Actually I see the problem now. Thank you so much for your response. I will go ahead and try the library you mentioned. :slight_smile:

JJ

Hi,

is there maybe any more detailed solution to parse local fasta files? I tried with biopython and pysam but I can’t make it work. With a regular open(filepath, ‘r’) I can manage to have it displayed in the AlignmentChart, but then the annotations are missing like the sequence names.

Thanks for your help.

Filip

I wonder if it has something to do with how your file is saved, or the contents of the file. I used the following code and I was able to get my alignment chart to display along with the sequence names.

data = open(“test_fasta.fasta”, “r”)
record = data.read()
data.close()

app.layout = html.Div([
dashbio.AlignmentChart(
id=‘my-default-alignment-viewer’,
data=record
)
])

Yes, you are right it has something to do with the file even I couldn’t figure out what is different to other fasta files. But some are displayed correctly and others are not. And it has nothing to do if it’s a .txt or .fasta file.

Weird, but okay at least I know where the error is from.

Thanks.

Filip