Protein display

Setup


source

AF_display

 AF_display ()

client side scripts


source

pdbe_molstar

 pdbe_molstar ()

Headers

hdrs = bootstrap_hdrs() + pdbe_molstar()
show(*hdrs)
from ngrok_token import *
url = start_ngrok(token)
ngrok tunnel opened at: https://9771-3-91-16-70.ngrok-free.app
app,rt = fast_app(pico=False,hdrs=hdrs)
server = JupyUvi(app)

Check output format

df = pd.read_parquet('data/AM.parquet')
@rt
def test():
    form = Form(Input(id='uniprot_id'),Button('load'),hx_get='/sdf',target_id='result')
    result = Div(id='result')
    return Div(form, result)

@rt
def sdf(uniprot_id:str):
    protein_data = df[df['uniprot'] == uniprot_id].copy()

    if protein_data.empty:
        return Div('Uniprot id not found in the phosphosite database')

    protein_data['residue'] = protein_data.site.str[1:].astype(int)
    protein_data['CDDM_kinases'] = protein_data['CDDM'].str.split(',').str[:5]
    protein_data['PSPA_kinases'] = protein_data['PSPA'].str.split(',').str[:5]
    protein_data['AM_pathogenicity'] = protein_data['AM_pathogenicity'].round(4)

    # Convert the filtered data to a list of dictionaries
    # It needs to include residue, as it uses residue number to highlight
    out = protein_data[['residue', 'AM_pathogenicity','site_seq','source','CDDM_kinases','PSPA_kinases']]

    return Container(df2html(out))
htmx(url,'/sdf?uniprot_id=P10398')

Protein Display

P10398 P35222

Key listeners:

  • uniprot_id: input text
  • load-protein-btn: click to load new protein
  • myViewer: display protein
  • AF_view: control alphafold color on or off
@rt('/')
def get():
    form = Form(
        Input(type='text', id = 'uniprot_id', placeholder='Enter Uniprot ID (e.g., P10398)'),
        Button('Load Protein', type='button',id='load-protein-btn'),
        id='protein-form',
    )
    viewer = Div(id='myViewer')
    # script = Script(src="./imports/alphafold_display.js")
    AF_button = Button('Turn On/Off Alphafold Color', type='button',id='AF_view'),
    blank=Div(style='height: 600px;')

    return Titled('PDBe Mol* JS Plugin Demo - AlphaFold View', form, AF_button, viewer, AF_script, blank)


@rt('/api/protein/{uniprot_id}')
def get(uniprot_id: str):
    # Filter the dataframe for the given UniProt ID
    protein_data = df[df['uniprot'] == uniprot_id].copy()

    if protein_data.empty:
        return {'error': 'Uniprot id not found in the phosphosite database'}

    protein_data['residue'] = protein_data.site.str[1:].astype(int)
    protein_data['CDDM_kinases'] = protein_data['CDDM'].str.split(',').str[:5]
    protein_data['PSPA_kinases'] = protein_data['PSPA'].str.split(',').str[:5]
    protein_data['AM_pathogenicity'] = protein_data['AM_pathogenicity'].round(4)

    # Convert the filtered data to a list of dictionaries
    # It needs to include residue, as it uses residue number to highlight
    site_data = protein_data[['residue', 'AM_pathogenicity','site_seq','source','CDDM_kinases','PSPA_kinases']].to_dict('records')

    return {'site_data': site_data}
htmx(url,'/')

End

server.stop()
kill_ngrok()
ngrok tunnel killed