File size: 7,315 Bytes
c2a02c6
 
 
 
 
 
 
 
 
 
 
8a2e1bf
c2a02c6
c8b993f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d7f3a7
 
 
9e2f96b
0d7f3a7
c2a02c6
8a2e1bf
 
 
c2a02c6
8a2e1bf
c2a02c6
 
 
 
 
 
744531f
43efedb
 
 
 
 
 
 
c2a02c6
b27ef4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e2f96b
 
c8b993f
 
 
 
806931d
c8b993f
 
 
 
 
 
 
 
1597000
c8b993f
 
 
 
 
 
 
 
 
 
 
 
 
 
b8f1d1d
1597000
c8b993f
 
 
 
 
1597000
c8b993f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8f1d1d
1597000
c8b993f
 
 
b8f1d1d
1597000
 
 
 
 
717778f
 
 
 
c8b993f
 
 
1597000
 
c8b993f
 
717778f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import streamlit as st
import pandas as pd 
from os import path
import sys
import streamlit.components.v1 as components
sys.path.append('code/')
#sys.path.append('ASCARIS/code/') 
import pdb_featureVector
import alphafold_featureVector
import argparse
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode,GridUpdateMode
import base64
showWarningOnDirectExecution = False

def download_button(object_to_download, download_filename):
  
    if isinstance(object_to_download, pd.DataFrame):
        object_to_download = object_to_download.to_csv(index=False)

    # Try JSON encode for everything else
    else:
        object_to_download = json.dumps(object_to_download)
    try:
        # some strings <-> bytes conversions necessary here
        b64 = base64.b64encode(object_to_download.encode()).decode()

    except AttributeError as e:
        b64 = base64.b64encode(object_to_download).decode()

    dl_link = f"""<html><head><title>Start Auto Download file</title><script src="http://code.jquery.com/jquery-3.2.1.min.js"></script><script>$('<a href="data:text/csv;base64,{b64}" download="{download_filename}">')[0].click()</script></head></html>"""
    return dl_link


def download_df():
    components.html(
        download_button(selected_df, st.session_state.filename),
        height=0,
    )

    
# Check if 'key' already exists in session_state
# If not, then initialize it
if 'visibility' not in st.session_state:
    st.session_state['visibility'] = 'hidden'
    st.session_state.disabled = False

original_title = '<p style="font-family:Trebuchet MS; color:#FD7456; font-size: 25px; font-weight:bold; text-align:center">ASCARIS</p>'
st.markdown(original_title, unsafe_allow_html=True)
original_title = '<p style="font-family:Trebuchet MS; color:#FD7456; font-size: 25px; font-weight:bold; text-align:center">(Annotation and StruCture-bAsed RepresentatIon of Single amino acid variations)</p>'
st.markdown(original_title, unsafe_allow_html=True)
 
st.write('')
st.write('')
st.write('')
st.write('')


with st.form('mform', clear_on_submit=False):
    source = st.selectbox('Select the protein structure resource (1: PDB-SwissModel-Modbase, 2: AlphaFold)',[1,2])
    impute = st.selectbox('Imputation',[True, False])
    input_data = st.text_input('Enter SAV data points (Format Provided Below)', "P13637-T-613-M, Q9Y4W6-N-432-T",label_visibility=st.session_state.visibility,
            disabled=st.session_state.disabled,
            placeholder=st.session_state.visibility,
            )
    

    parser = argparse.ArgumentParser(description='ASCARIS')
    
    parser.add_argument('-s', '--source_option',
                        help='Selection of input structure data.\n 1: PDB Structures (default), 2: AlphaFold Structures',
                        default=1)
    parser.add_argument('-i', '--input_datapoint',
                        help='Input file or query datapoint\n Option 1: Comma-separated list of idenfiers (UniProt ID-wt residue-position-mutated residue (e.g. Q9Y4W6-N-432-T or Q9Y4W6-N-432-T, Q9Y4W6-N-432-T)) \n Option 2: Enter comma-separated file path')
    
    parser.add_argument('-impute', '--imputation_state', default='True',
                        help='Whether resulting feature vector should be imputed or not. Default True.')
    
    args = parser.parse_args()
    
    input_set = input_data
    mode = source
    impute = impute
    submitted = st.form_submit_button(label="Submit", help=None, on_click=None, args=None, kwargs=None, type="secondary", disabled=False, use_container_width=False)
    st.write('submitted', submitted)
    print('*****************************************')
    print('Feature vector generation is in progress. \nPlease check log file for updates..')
    print('*****************************************')
    mode = int(mode)
    
    
    
    
        
    with st.spinner('In progress...This may take a while...'):
        try:
            if mode == 1:
                selected_df = pdb_featureVector.pdb(input_set, mode, impute)
                """
                int_builder = GridOptionsBuilder.from_dataframe(selected_df)
                int_builder.configure_default_column(editable=False, filterable=True, cellStyle={'text-align': 'center'})
                int_builder.configure_pagination(enabled=True, paginationAutoPageSize=False, paginationPageSize=10)
                int_builder.configure_selection(selection_mode='multiple', use_checkbox=True)
                gridoptions = int_builder.build()
                int_return = AgGrid(selected_df,
                            width='100%',
                            height=(len(selected_df) + 4) * 35.2 + 3,
                            theme='light',
                            enable_enterprise_modules=False,
                            gridOptions=gridoptions,
                            fit_columns_on_grid_load=False,
                            update_mode=GridUpdateMode.SELECTION_CHANGED, # or MODEL_CHANGED
                            custom_css={".ag-header-cell-label": {"justify-content": "center"}})
                st.write('INT return1', int_return)
                """
                st.success('Feature vector successfully created.')
    
                
            elif mode == 2:
                selected_df = alphafold_featureVector.alphafold(input_set, mode, impute)
                """
                int_builder = GridOptionsBuilder.from_dataframe(selected_df)
                int_builder.configure_default_column(editable=False, filterable=True, cellStyle={'text-align': 'center'})
                int_builder.configure_pagination(enabled=True, paginationAutoPageSize=False, paginationPageSize=10)
                int_builder.configure_selection(selection_mode='multiple', use_checkbox=True)
                gridoptions = int_builder.build()
                int_return = AgGrid(selected_df,
                            width='100%',
                            height=(len(selected_df) + 4) * 35.2 + 3,
                            theme='light',
                            enable_enterprise_modules=False,
                            gridOptions=gridoptions,
                            fit_columns_on_grid_load=False,
                            update_mode=GridUpdateMode.SELECTION_CHANGED, # or MODEL_CHANGED
                            custom_css={".ag-header-cell-label": {"justify-content": "center"}})
                st.success('Feature vector successfully created.')
                st.write('INT return2', int_return)
                """
            else:
                
                int_return = pd.DataFrame()
                st.write('INT return3', int_return)
            #st.write('INTTTT', int_return)
            #selected_row = int_return["selected_rows"]
            #st.write('selected_rows', selected_rows)
            #st.write('selected_row', selected_row)
            #selected_df = pd.DataFrame(selected_row, columns=selected_df.columns)
            st.write(selected_df)
            st.text_input("Enter filename", key="filename")
            submit = st.form_submit_button("Download", on_click=selected_df)
            
        except:
            pass
            selected_df = pd.DataFrame()
            #int_return = pd.DataFrame()
            #st.write('INT return4', int_return)