Example #1
0
    def update_protein_options(upload_contents, preloaded):

        dropdown_options = [
            {'label': 1, 'value': 0}
        ]

        if preloaded is not None:
            proteins = pr.read_fasta(preloaded)
        elif upload_contents is not None and preloaded is None:
            data = ''
            try:
                content_type, content_string = upload_contents.split(',')
                data = base64.b64decode(content_string).decode('UTF-8')
            except AttributeError:
                pass
            proteins = pr.read_fasta(data, is_datafile=False)
        else:
            return dropdown_options

        if isinstance(proteins, list):
            dropdown_options = []
            for i in range(len(proteins)):
                dropdown_options.append(dict(
                    label=i+1,
                    value=i
                ))
        return dropdown_options
Example #2
0
    def update_sequence_title(_, entry, preloaded, upload_contents):

        if entry is None:
            return ''

        if preloaded is not None:
            protein = pr.read_fasta(preloaded)[entry]
        elif upload_contents is not None and preloaded is None:
            data = ''
            try:
                content_type, content_string = upload_contents.split(',')
                data = base64.b64decode(content_string).decode('UTF-8')
            except AttributeError:
                pass
            if data == '':
                return ''
            protein = pr.read_fasta(data, is_datafile=False)[entry]
        else:
            return ''

        titles = ['name', 'entry name', 'protein name', 'identifier', 'desc-0']

        for t in titles:
            try:
                return protein['description'][t]
            except KeyError:
                continue

        return ''
Example #3
0
    def update_desc_info(upload_contents, entry, preloaded):

        if entry is None:
            return 'Please select an entry.'

        if preloaded is not None:
            protein = pr.read_fasta(preloaded)[entry]

        elif upload_contents is not None and preloaded is None:
            data = ''

            try:
                content_type, content_string = upload_contents.split(',')
                data = base64.b64decode(content_string).decode('UTF-8')
            except AttributeError:
                pass
            if data == '':
                return []
            try:
                protein = pr.read_fasta(data, is_datafile=False)[entry]
            except Exception:
                return ['NA']
        else:
            return 'Please either upload a file or select one from \
            the dropdown.'

        desc = []
        for key in protein['description']:
            tmp = key.title() + ': ' if 'desc-' not in key else '-'
            tmp += protein['description'][key]
            desc.append(tmp)
            desc.append(html.Br())
        return desc
Example #4
0
    def update_sequence(upload_contents, entry, preloaded):

        if entry is None:
            return ''

        if preloaded is not None:
            protein = pr.read_fasta(preloaded)[entry]
        elif upload_contents is not None and preloaded is None:
            data = ''
            try:
                content_type, content_string = upload_contents.split(',')
                data = base64.b64decode(content_string).decode('UTF-8')
            except AttributeError:
                pass
            if data == '':
                return '-'

            protein = pr.read_fasta(data, is_datafile=False)[entry]
        else:
            return '-'

        return protein['sequence']
Example #5
0
import dash_bio as dashbio
from dash_bio_utils import protein_reader
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

fasta_str = urlreq.urlopen(
    'https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/' +
    'sequence_viewer_P01308.fasta').read()

if PY3:
    fasta_str = fasta_str.decode('utf-8')

seq = protein_reader.read_fasta(fasta_str, is_datafile=False)[0]['sequence']

app.layout = html.Div([
    dashbio.SequenceViewer(id='my-sequence-viewer', sequence=seq),
    html.Div(id='sequence-viewer-output')
])


@app.callback(
    dash.dependencies.Output('sequence-viewer-output', 'children'),
    [dash.dependencies.Input('my-sequence-viewer', 'mouseSelection')])
def update_output(value):
    if value is None or len(value) == 0:
        return 'There is no mouse selection.'
    return 'The mouse selection is {}.'.format(value['selection'])
Example #6
0
from dash_bio_utils import protein_reader
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

fasta_str = urlreq.urlopen(
    'https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/' +
    'sequence_viewer_P01308.fasta'
).read()

if PY3:
    fasta_str = fasta_str.decode('utf-8')

seq = protein_reader.read_fasta(data_string=fasta_str)[0]['sequence']

app.layout = html.Div([
    dashbio.SequenceViewer(
        id='my-sequence-viewer',
        sequence=seq
    ),
    html.Div(id='sequence-viewer-output')
])


@app.callback(
    dash.dependencies.Output('sequence-viewer-output', 'children'),
    [dash.dependencies.Input('my-sequence-viewer', 'mouseSelection')]
)
def update_output(value):
Example #7
0
import json

from dash_bio_utils import pdb_parser, protein_reader, \
    styles_parser, xyz_reader

with open('mol3d_model_data.json', 'w+') as f:
    f.write(
        pdb_parser.create_data(
            '../dashbio_demos/dash-molecule-3d-viewer/data/1bna.pdb'))

with open('mol3d_styles_data.json', 'w+') as f:
    f.write(
        styles_parser.create_style(
            '../dashbio_demos/dash-molecule-3d-viewer/data/1bna.pdb',
            'cartoon', 'atom'))

with open('sequence_viewer_data.json', 'w+') as f:
    f.write(
        json.dumps(
            protein_reader.read_fasta(
                datapath_or_datastring=
                '../dashbio_demos/dash-sequence-viewer/data/P01308.fasta.txt')
            [0]))

with open('speck_data.json', 'w+') as f:
    f.write(
        json.dumps(
            xyz_reader.read_xyz(
                datapath_or_datastring=
                '../dashbio_demos/dash-speck/data/methane.xyz')))
Example #8
0
import dash_bio as dashbio
from dash_bio_utils import protein_reader
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

fasta_str = urlreq.urlopen(
    'https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/' +
    'sequence_viewer_P01308.fasta').read()

if PY3:
    fasta_str = fasta_str.decode('utf-8')

seq = protein_reader.read_fasta(datapath_or_datastring=fasta_str,
                                is_datafile=False)[0]['sequence']

app.layout = html.Div([
    dashbio.SequenceViewer(id='my-sequence-viewer', sequence=seq),
    html.Div(id='sequence-viewer-output')
])


@app.callback(
    dash.dependencies.Output('sequence-viewer-output', 'children'),
    [dash.dependencies.Input('my-sequence-viewer', 'mouseSelection')])
def update_output(value):
    if value is None or len(value) == 0:
        return 'There is no mouse selection.'
    return 'The mouse selection is {}.'.format(value['selection'])
import json

from dash_bio_utils import pdb_parser, protein_reader, \
    styles_parser, xyz_reader

with open('mol3d_model_data.json', 'w+') as f:
    f.write(pdb_parser.create_data(
        '../dashbio_demos/sample_data/molecule3d_1bna.pdb'
    ))

with open('mol3d_styles_data.json', 'w+') as f:
    f.write(styles_parser.create_style(
        '../dashbio_demos/sample_data/molecule3d_1bna.pdb',
        'cartoon',
        'atom'
    ))

with open('sequence_viewer_data.json', 'w+') as f:
    f.write(json.dumps(protein_reader.read_fasta(
        datapath_or_datastring='../dashbio_demos/sample_data/sequence_viewer_P01308.fasta.txt'
    )[0]))

with open('speck_data.json', 'w+') as f:
    f.write(json.dumps(xyz_reader.read_xyz(
        datapath_or_datastring='../dashbio_demos/sample_data/speck_methane.xyz'
    )))