From e91b6c26f4d15c9f1fafce19e649294b699a0c56 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 16 Oct 2023 18:07:51 +0200 Subject: [PATCH 01/12] loading funcoup --- src/python/views/demo_00_funcoup/__init__.py | 270 +++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 src/python/views/demo_00_funcoup/__init__.py diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py new file mode 100644 index 0000000..fbcdd7b --- /dev/null +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -0,0 +1,270 @@ +import graphistry, os, pandas as pd, streamlit as st +from components import GraphistrySt, URLParam +from graphistry import PyGraphistry +from css import all_css +from time import sleep +import logging + +############################################ +# +# DASHBOARD SETTINGS +# +############################################ +# Controls how entrypoint.py picks it up + + +app_id = 'app_00' +logger = logging.getLogger(app_id) +urlParams = URLParam(app_id) + + +def info(): + return { + 'id': app_id, + 'name': 'Bio: FUNCOUP', + 'enabled': True, + 'tags': ['demo', 'demo_bio'] + } + + +def run(): + run_all() + + +############################################ +# +# CUSTOM CSS +# +############################################ +# Have fun! + +def custom_css(): + + all_css() # our favorites + + +############################################ +# +# SIDEBAR RENDER AERA +# +############################################ +# Given URL params, render left sidebar form and return combined filter settings + +# #https://docs.streamlit.io/en/stable/api.html#display-interactive-widgets +def sidebar_area(): + st.sidebar.title("Pick an Organism") + option_to_label = { + 'A.thaliana': 'A.thaliana', + 'B.subtilis': 'B.subtilis', + 'B.taurus': 'B.taurus', + 'C.elegans': 'C.elegans', + 'C.familiaris': 'C.familiaris', + 'C.intestinalis': 'C.intestinalis', + 'D.discoideum': 'D.discoideum', + 'D.melanogaster': 'D.melanogaster', + 'D.rerio': 'D.rerio', + 'E.coli': 'E.coli', + 'G.gallus': 'G.gallus', + 'H.sapiens': 'H.sapiens', + 'M.jannascii': 'M.jannascii', + 'M.musculus': 'M.musculus', + 'O.sativa': 'O.sativa', + 'P.falciparum': 'P.falciparum', + 'R.norvegicus': 'R.norvegicus', + 'S.cerevisiae': 'S.cerevisiae', + 'S,pombe': 'S.pombe', + 'S.scrofa': 'S.scrofa', + 'S.solfataticus': 'S.solfataricus', + } + + base_url = os.environ['BASE_URL'] + + st.sidebar.title("Edge Type") + option_to_label = { + 'PFC': 'The confidence Score', + 'FBS_max': 'The final Bayesian Score (FBS) of the strongest coupling class', + 'FBS_*': 'Bayesian Score of all coupling classes', + 'LLR_*': 'Log Likelihood Ratio (LLRs) of the different evidence types', + 'LLR_*': 'LLRs of the evidence types from the differrent species', + 'Max_category': 'strongest couping class for this pair. This is also the class for which the LLRs are given' + } + + filter_by_node_org_init = urlParams.get_field('filter_by_org', default='all') + filter_by_node_org = \ + st.sidebar.selectbox( + 'Filter nodes by:', + ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_node_org_init), + index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_node_org_init), + format_func=(lambda option: option_to_label[option])) + urlParams.set_field('filter_by_org', filter_by_node_org) + + edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org+'_compact.gz', sep='\t') + + + filter_by_node_type_init = urlParams.get_field('filter_by_type', default='all') + filter_by_node_type = \ + st.sidebar.selectbox( + 'Filter nodes by:', + ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type_init), + index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type), + format_func=(lambda option: option_to_label[option])) + urlParams.set_field('filter_by_type', filter_by_node_type) + + filter_by_net_type_init = urlParams.get_field('filter_by_net', default='all') + filter_by_net_type = \ + st.sidebar.selectbox( + 'Filter nodes by:', + ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_net_type_init), + index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_net_type), + format_func=(lambda option: option_to_label[option])) + urlParams.set_field('filter_by_type', filter_by_net_type) + + + return { + # 'n': n, + 'edges_df': edges_df, + 'organism': filter_by_node_org, + 'node_type': filter_by_node_type, + 'net_type': filter_by_net_type, + } + + +############################################ +# +# FILTER PIPELINE +# +############################################ +# Given filter settings, generate/cache/return dataframes & viz + +#@st.cache(suppress_st_warning=True, allow_output_mutation=True) +@st.cache_data +def run_filters(node_type, organism, net_type, edges_df): + + filtered_edges_df = edges_df['Gene_1','Gene_2',node_type] + + # filtered_edges_df = edges_df + # if node_type == 'all': + # pass + # elif node_type == 'odd': + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] % 2 == 1 ] + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] % 2 == 1 ] + # elif node_type == 'even': + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] % 2 == 0 ] + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] % 2 == 0 ] + # else: + # raise Exception('Unknown filter1 option result: %s' % node_type) + + # if node_range[0] > 0: + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] >= node_range[0] ] + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] >= node_range[0] ] + # if node_range[1] <= n: + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] <= node_range[1] ] + # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] <= node_range[1] ] + + # include viz generation as part of cache + url = plot_url(filtered_edges_df) + + return { + 'edges_df': filtered_edges_df, + 'url': url + } + + +############################################ +# +# VIZ +# +############################################ + + +def plot_url(edges_df): + + # nodes_df = pd.DataFrame({ + # 'n': pd.concat([edges_df['s'], edges_df['d']]).unique() + # }) + + # nodes_df['nc'] = nodes_df['n'].apply(lambda v: 0x01000000 * round(255 * v / n)) + + logger.info('Starting graphistry plot') + if not GraphistrySt().test_login(): + return '' + + url = graphistry\ + .bind(source="Gene_1", destination="Gene_2")\ + .edges(edges_df)\ + # .nodes(nodes_df)\ + # .bind(node='n', point_color='nc')\ + .settings(url_params={ + 'pointSize': 0.3, + 'splashAfter': 'false', + 'bg': '%23' + 'f0f2f6' + })\ + .plot(render=False) + + logger.info('Generated viz, got back urL: %s', url) + + return url + + +############################################ +# +# MAIN RENDER AERA +# +############################################ +# Given configured filters and computed results (cached), render + +def main_area(edges_df, url): + + logger.debug('rendering main area, with url: %s', url) + gst = GraphistrySt() + if PyGraphistry._is_authenticated: + gst.render_url(url) + else: + st.title("Welcome to graph-app-kit!") + st.write(""" + This particular demo requires configuring your graph-app-kit with service credentials for + accessing your Graphistry server + + If this is the first time you are seeing graph-app-kit, it is Graphistry's open-source extension + of the https://streamlit.io/ low-code Python dashboarding tool. It adds: + * Optional Docker, Docker Compose, and AWS CloudFormation self-hosted quick launchers + * Multiple dashboard support + * Optional GPU & AI dependencies (Nvidia driver, RAPIDS, PyTorch) aligned with Graphistry releases + * Graph computing dependencies (Gremlin, TigerGraph, ...) + * A Graphistry plotting component + + Starting with Graphistry 2.39, graph-app-kit comes prebundled: + * Public and staff-only Private dashboards + * Control access via User -> Admin port -> DJANGO-WAFFLE -> Flags" + * ... then edit to desired visibility for flag_show_public_dashboard, flag_show_private_dashboard + * ... and optionally prevent running of the services via your docker-compose.override.yml + """) + + +############################################ +# +# Putting it all together +# +############################################ + +def run_all(): + + custom_css() + + try: + + # Render sidebar and get current settings + sidebar_filters = sidebar_area() + + # logger.debug('sidebar_filters: %s', sidebar_filters) + + # Compute filter pipeline (with auto-caching based on filter setting inputs) + # Selective mark these as URL params as well + filter_pipeline_result = run_filters(**sidebar_filters) + + # Render main viz area based on computed filter pipeline results and sidebar settings + main_area(**filter_pipeline_result) + + except Exception as exn: + st.write('Error loading dashboard') + st.write(exn) From a9a420605a347f998265f8dccd9ef9aa07864a43 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 16 Oct 2023 18:26:08 +0200 Subject: [PATCH 02/12] loading funcoup --- src/python/views/demo_00_funcoup/__init__.py | 30 +++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index fbcdd7b..6f22235 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -89,41 +89,39 @@ def sidebar_area(): 'Max_category': 'strongest couping class for this pair. This is also the class for which the LLRs are given' } - filter_by_node_org_init = urlParams.get_field('filter_by_org', default='all') - filter_by_node_org = \ + filter_by_org_type_init = urlParams.get_field('filter_by_org', default='all') + filter_by_org_type = \ st.sidebar.selectbox( 'Filter nodes by:', - ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_node_org_init), - index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_node_org_init), + ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus'), + index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_org_type_init), format_func=(lambda option: option_to_label[option])) - urlParams.set_field('filter_by_org', filter_by_node_org) + urlParams.set_field('filter_by_org', filter_by_org_type) - edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org+'_compact.gz', sep='\t') - - - filter_by_node_type_init = urlParams.get_field('filter_by_type', default='all') + filter_by_node_type_init = urlParams.get_field('filter_by_node', default='all') filter_by_node_type = \ st.sidebar.selectbox( 'Filter nodes by:', - ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type_init), - index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type), + ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category') + index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type_init), format_func=(lambda option: option_to_label[option])) - urlParams.set_field('filter_by_type', filter_by_node_type) + urlParams.set_field('filter_by_node', filter_by_node_type) filter_by_net_type_init = urlParams.get_field('filter_by_net', default='all') filter_by_net_type = \ st.sidebar.selectbox( 'Filter nodes by:', - ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_net_type_init), - index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_net_type), + ('compact','full'), + index=('compact','full').index(filter_by_net_type_init), format_func=(lambda option: option_to_label[option])) - urlParams.set_field('filter_by_type', filter_by_net_type) + urlParams.set_field('filter_by_net', filter_by_net_type) + edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org+'_'filter_by_net_type'+.gz', sep='\t') return { # 'n': n, 'edges_df': edges_df, - 'organism': filter_by_node_org, + 'organism': filter_by_org_type, 'node_type': filter_by_node_type, 'net_type': filter_by_net_type, } From 7a42bc48df3b773bdfabdf48b713c51ec694698e Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 16 Oct 2023 19:03:36 +0200 Subject: [PATCH 03/12] loading funcoup --- src/python/views/demo_00_funcoup/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index 6f22235..0914440 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -13,7 +13,7 @@ # Controls how entrypoint.py picks it up -app_id = 'app_00' +app_id = 'app_05' logger = logging.getLogger(app_id) urlParams = URLParam(app_id) @@ -23,7 +23,7 @@ def info(): 'id': app_id, 'name': 'Bio: FUNCOUP', 'enabled': True, - 'tags': ['demo', 'demo_bio'] + 'tags': ['bio', 'large', 'funcoup','demo'], } @@ -102,7 +102,7 @@ def sidebar_area(): filter_by_node_type = \ st.sidebar.selectbox( 'Filter nodes by:', - ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category') + ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category'), index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type_init), format_func=(lambda option: option_to_label[option])) urlParams.set_field('filter_by_node', filter_by_node_type) @@ -116,7 +116,7 @@ def sidebar_area(): format_func=(lambda option: option_to_label[option])) urlParams.set_field('filter_by_net', filter_by_net_type) - edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org+'_'filter_by_net_type'+.gz', sep='\t') + edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org_type+'_'+filter_by_net_type+'.gz', sep='\t') return { # 'n': n, @@ -190,8 +190,6 @@ def plot_url(edges_df): url = graphistry\ .bind(source="Gene_1", destination="Gene_2")\ .edges(edges_df)\ - # .nodes(nodes_df)\ - # .bind(node='n', point_color='nc')\ .settings(url_params={ 'pointSize': 0.3, 'splashAfter': 'false', From d9398f8cd0c743e677a1b89414b421021f64f2b0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 17 Oct 2023 16:06:42 +0200 Subject: [PATCH 04/12] working funcoup demo --- src/python/requirements-app.txt | 3 +- src/python/views/demo_00_funcoup/__init__.py | 128 +++++++++++++------ 2 files changed, 89 insertions(+), 42 deletions(-) diff --git a/src/python/requirements-app.txt b/src/python/requirements-app.txt index 0762aaf..1f87424 100644 --- a/src/python/requirements-app.txt +++ b/src/python/requirements-app.txt @@ -1,3 +1,4 @@ ### ### Use this file for your custom view requirements here vs in the requirements-system.txt -### \ No newline at end of file +### +umap-learn diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index 0914440..2c92ab2 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -13,7 +13,7 @@ # Controls how entrypoint.py picks it up -app_id = 'app_05' +app_id = 'app_00' logger = logging.getLogger(app_id) urlParams = URLParam(app_id) @@ -53,7 +53,7 @@ def custom_css(): # #https://docs.streamlit.io/en/stable/api.html#display-interactive-widgets def sidebar_area(): st.sidebar.title("Pick an Organism") - option_to_label = { + species_to_label = { 'A.thaliana': 'A.thaliana', 'B.subtilis': 'B.subtilis', 'B.taurus': 'B.taurus', @@ -79,8 +79,18 @@ def sidebar_area(): base_url = os.environ['BASE_URL'] + filter_by_org_type_init = urlParams.get_field('filter_by_org', default='H.sapiens') + filter_by_org_type = \ + st.sidebar.selectbox( + 'Choose species:', + ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus'), + index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_org_type_init), + format_func=(lambda option: species_to_label[option])) + urlParams.set_field('filter_by_org', filter_by_org_type) + + st.sidebar.title("Edge Type") - option_to_label = { + edge_to_label = { 'PFC': 'The confidence Score', 'FBS_max': 'The final Bayesian Score (FBS) of the strongest coupling class', 'FBS_*': 'Bayesian Score of all coupling classes', @@ -89,41 +99,56 @@ def sidebar_area(): 'Max_category': 'strongest couping class for this pair. This is also the class for which the LLRs are given' } - filter_by_org_type_init = urlParams.get_field('filter_by_org', default='all') - filter_by_org_type = \ - st.sidebar.selectbox( - 'Filter nodes by:', - ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus'), - index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_org_type_init), - format_func=(lambda option: option_to_label[option])) - urlParams.set_field('filter_by_org', filter_by_org_type) - - filter_by_node_type_init = urlParams.get_field('filter_by_node', default='all') + filter_by_node_type_init = urlParams.get_field('filter_by_node', default='PFC') filter_by_node_type = \ st.sidebar.selectbox( - 'Filter nodes by:', + 'Filter node by:', ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category'), index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type_init), - format_func=(lambda option: option_to_label[option])) + format_func=(lambda option: edge_to_label[option])) urlParams.set_field('filter_by_node', filter_by_node_type) - filter_by_net_type_init = urlParams.get_field('filter_by_net', default='all') + + st.sidebar.title("Net Type") + net_to_label = { + 'compact': 'compact', + 'full': 'full', + } + + filter_by_net_type_init = urlParams.get_field('filter_by_net', default='compact') filter_by_net_type = \ st.sidebar.selectbox( - 'Filter nodes by:', + 'Filter net by:', ('compact','full'), index=('compact','full').index(filter_by_net_type_init), - format_func=(lambda option: option_to_label[option])) + format_func=(lambda option: net_to_label[option])) urlParams.set_field('filter_by_net', filter_by_net_type) + + + st.sidebar.title("Umap Type") + umap_to_label = { + True: True, + False: False, + } + + filter_by_umap_type_init = urlParams.get_field('filter_by_umap', default=False) + filter_by_umap_type = \ + st.sidebar.selectbox( + 'Filter umap by:', + (True,False), + index=(True,False).index(filter_by_umap_type_init), + format_func=(lambda option: umap_to_label[option])) + urlParams.set_field('filter_by_umap', filter_by_umap_type) + # edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_B.taurus_compact.gz', sep='\t') edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org_type+'_'+filter_by_net_type+'.gz', sep='\t') return { - # 'n': n, 'edges_df': edges_df, - 'organism': filter_by_org_type, - 'node_type': filter_by_node_type, - 'net_type': filter_by_net_type, + # 'org_type': filter_by_org_type, + # 'node_type': filter_by_node_type, + # 'net_type': filter_by_net_type, + 'umap_type': filter_by_umap_type, } @@ -136,10 +161,12 @@ def sidebar_area(): #@st.cache(suppress_st_warning=True, allow_output_mutation=True) @st.cache_data -def run_filters(node_type, organism, net_type, edges_df): - - filtered_edges_df = edges_df['Gene_1','Gene_2',node_type] +def run_filters(edges_df,umap_type=False): + filtered_edges_df = edges_df[:100000] #[['2:Gene1','3:Gene2','1:FBS_max','#0:PFC']] + filtered_edges_df = filtered_edges_df.replace({'ENSG00000':''},regex=True) + # filtered_edges_df.rename(columns={'2:Gene1':'Gene1','3:Gene2':'Gene2','#0:PFC':'PFC','1:FBS_max':'FBS'},inplace=True) + filtered_edges_df.columns=filtered_edges_df.columns.str.split(':').str[1] # filtered_edges_df = edges_df # if node_type == 'all': # pass @@ -160,7 +187,7 @@ def run_filters(node_type, organism, net_type, edges_df): # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] <= node_range[1] ] # include viz generation as part of cache - url = plot_url(filtered_edges_df) + url = plot_url(filtered_edges_df,umap_type) return { 'edges_df': filtered_edges_df, @@ -175,27 +202,46 @@ def run_filters(node_type, organism, net_type, edges_df): ############################################ -def plot_url(edges_df): +def plot_url(edges_df,umap_type=False): - # nodes_df = pd.DataFrame({ - # 'n': pd.concat([edges_df['s'], edges_df['d']]).unique() - # }) + nodes_df = pd.DataFrame({ + 'n': pd.concat([edges_df['Gene1'], edges_df['Gene2']]).unique() + }) + n = len(nodes_df) - # nodes_df['nc'] = nodes_df['n'].apply(lambda v: 0x01000000 * round(255 * v / n)) + nodes_df['nc'] = nodes_df['n'].replace('ENSG00000','',regex=True) + nodes_df['nc'] = pd.to_numeric(nodes_df['nc'], errors='coerce') + nodes_df['nc'] = nodes_df['nc'].fillna(0).apply(lambda v: 0x01000000 * round(255 * v / n)) logger.info('Starting graphistry plot') if not GraphistrySt().test_login(): return '' - - url = graphistry\ - .bind(source="Gene_1", destination="Gene_2")\ - .edges(edges_df)\ - .settings(url_params={ - 'pointSize': 0.3, - 'splashAfter': 'false', - 'bg': '%23' + 'f0f2f6' - })\ - .plot(render=False) + + if umap_type == False: + url = graphistry\ + .edges(edges_df)\ + .bind(source="Gene1", destination="Gene2")\ + .nodes(nodes_df)\ + .bind(node='n', point_color='nc')\ + .settings(url_params={ + 'pointSize': 0.3, + 'splashAfter': 'false', + 'bg': '%23' + 'f0f2f6' + })\ + .plot(render=False) + elif umap_type == True: + url = graphistry\ + .edges(edges_df)\ + .bind(source="Gene1", destination="Gene2")\ + .nodes(nodes_df)\ + .bind(node='n', point_color='nc')\ + .settings(url_params={ + 'pointSize': 0.3, + 'splashAfter': 'false', + 'bg': '%23' + 'f0f2f6' + })\ + .umap(engine='umap_learn')\ + .plot(render=False) logger.info('Generated viz, got back urL: %s', url) From cc73870c3d18dc07151ea46afe0320a9468317c7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 17 Oct 2023 16:27:15 +0200 Subject: [PATCH 05/12] add colors, dc --- src/python/requirements-app.txt | 1 + src/python/views/demo_00_funcoup/__init__.py | 35 ++++---------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/python/requirements-app.txt b/src/python/requirements-app.txt index 1f87424..20120a3 100644 --- a/src/python/requirements-app.txt +++ b/src/python/requirements-app.txt @@ -2,3 +2,4 @@ ### Use this file for your custom view requirements here vs in the requirements-system.txt ### umap-learn +dirty_cat diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index 2c92ab2..616dd87 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -72,7 +72,7 @@ def sidebar_area(): 'P.falciparum': 'P.falciparum', 'R.norvegicus': 'R.norvegicus', 'S.cerevisiae': 'S.cerevisiae', - 'S,pombe': 'S.pombe', + 'S.pombe': 'S.pombe', 'S.scrofa': 'S.scrofa', 'S.solfataticus': 'S.solfataricus', } @@ -83,8 +83,8 @@ def sidebar_area(): filter_by_org_type = \ st.sidebar.selectbox( 'Choose species:', - ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus'), - index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','R.norvegicus','S.cerevisiae','S,pombe','S.scrofa','S.solfataticus').index(filter_by_org_type_init), + ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataticus'), + index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataticus').index(filter_by_org_type_init), format_func=(lambda option: species_to_label[option])) urlParams.set_field('filter_by_org', filter_by_org_type) @@ -140,7 +140,6 @@ def sidebar_area(): format_func=(lambda option: umap_to_label[option])) urlParams.set_field('filter_by_umap', filter_by_umap_type) - # edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_B.taurus_compact.gz', sep='\t') edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org_type+'_'+filter_by_net_type+'.gz', sep='\t') return { @@ -163,28 +162,9 @@ def sidebar_area(): @st.cache_data def run_filters(edges_df,umap_type=False): - filtered_edges_df = edges_df[:100000] #[['2:Gene1','3:Gene2','1:FBS_max','#0:PFC']] + filtered_edges_df = edges_df filtered_edges_df = filtered_edges_df.replace({'ENSG00000':''},regex=True) - # filtered_edges_df.rename(columns={'2:Gene1':'Gene1','3:Gene2':'Gene2','#0:PFC':'PFC','1:FBS_max':'FBS'},inplace=True) filtered_edges_df.columns=filtered_edges_df.columns.str.split(':').str[1] - # filtered_edges_df = edges_df - # if node_type == 'all': - # pass - # elif node_type == 'odd': - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] % 2 == 1 ] - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] % 2 == 1 ] - # elif node_type == 'even': - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] % 2 == 0 ] - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] % 2 == 0 ] - # else: - # raise Exception('Unknown filter1 option result: %s' % node_type) - - # if node_range[0] > 0: - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] >= node_range[0] ] - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] >= node_range[0] ] - # if node_range[1] <= n: - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['s'] <= node_range[1] ] - # filtered_edges_df = filtered_edges_df[ filtered_edges_df['d'] <= node_range[1] ] # include viz generation as part of cache url = plot_url(filtered_edges_df,umap_type) @@ -209,9 +189,8 @@ def plot_url(edges_df,umap_type=False): }) n = len(nodes_df) - nodes_df['nc'] = nodes_df['n'].replace('ENSG00000','',regex=True) - nodes_df['nc'] = pd.to_numeric(nodes_df['nc'], errors='coerce') - nodes_df['nc'] = nodes_df['nc'].fillna(0).apply(lambda v: 0x01000000 * round(255 * v / n)) + nodes_df['ind'] = nodes_df.index + nodes_df['nc'] = nodes_df['ind'].apply(lambda v: 0x01000000 * round(255 * v / n,2)) logger.info('Starting graphistry plot') if not GraphistrySt().test_login(): @@ -240,7 +219,7 @@ def plot_url(edges_df,umap_type=False): 'splashAfter': 'false', 'bg': '%23' + 'f0f2f6' })\ - .umap(engine='umap_learn')\ + .umap(feature_engine='dirty_cat',engine='umap_learn')\ .plot(render=False) logger.info('Generated viz, got back urL: %s', url) From 83f37a1558494257e28cf9f157685f10c5d2c679 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 17 Oct 2023 16:32:41 +0200 Subject: [PATCH 06/12] add colors, dc --- src/python/views/demo_00_funcoup/__init__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index 616dd87..02acfec 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -162,15 +162,13 @@ def sidebar_area(): @st.cache_data def run_filters(edges_df,umap_type=False): - filtered_edges_df = edges_df - filtered_edges_df = filtered_edges_df.replace({'ENSG00000':''},regex=True) - filtered_edges_df.columns=filtered_edges_df.columns.str.split(':').str[1] + edges_df.columns=edges_df.columns.str.split(':').str[1] # include viz generation as part of cache - url = plot_url(filtered_edges_df,umap_type) + url = plot_url(edges_df,umap_type) return { - 'edges_df': filtered_edges_df, + 'edges_df': edges_df, 'url': url } From bb75404eb5e086e47a24c36d80aef7b569341fee Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 17 Oct 2023 16:43:34 +0200 Subject: [PATCH 07/12] fix names --- src/python/views/demo_00_funcoup/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index 02acfec..c3ef9be 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -66,7 +66,7 @@ def sidebar_area(): 'E.coli': 'E.coli', 'G.gallus': 'G.gallus', 'H.sapiens': 'H.sapiens', - 'M.jannascii': 'M.jannascii', + 'M.jannaschii': 'M.jannaschii', 'M.musculus': 'M.musculus', 'O.sativa': 'O.sativa', 'P.falciparum': 'P.falciparum', @@ -74,7 +74,7 @@ def sidebar_area(): 'S.cerevisiae': 'S.cerevisiae', 'S.pombe': 'S.pombe', 'S.scrofa': 'S.scrofa', - 'S.solfataticus': 'S.solfataricus', + 'S.solfataricus': 'S.solfataricus', } base_url = os.environ['BASE_URL'] @@ -83,8 +83,8 @@ def sidebar_area(): filter_by_org_type = \ st.sidebar.selectbox( 'Choose species:', - ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataticus'), - index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannascii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataticus').index(filter_by_org_type_init), + ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannaschii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataricus'), + index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannaschii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataricus').index(filter_by_org_type_init), format_func=(lambda option: species_to_label[option])) urlParams.set_field('filter_by_org', filter_by_org_type) @@ -162,13 +162,15 @@ def sidebar_area(): @st.cache_data def run_filters(edges_df,umap_type=False): - edges_df.columns=edges_df.columns.str.split(':').str[1] + filtered_edges_df = edges_df + # filtered_edges_df = filtered_edges_df.replace({'ENSG00000':''},regex=True) + filtered_edges_df.columns=filtered_edges_df.columns.str.split(':').str[1] # include viz generation as part of cache - url = plot_url(edges_df,umap_type) + url = plot_url(filtered_edges_df,umap_type) return { - 'edges_df': edges_df, + 'edges_df': filtered_edges_df, 'url': url } From 97237034238ca6a35496d9bbd35416be1bb64a22 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 19 Oct 2023 13:17:25 +0200 Subject: [PATCH 08/12] reorder menu, full net umap --- src/python/views/demo_00_funcoup/__init__.py | 92 ++++++++++++-------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index c3ef9be..18510a9 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -52,7 +52,7 @@ def custom_css(): # #https://docs.streamlit.io/en/stable/api.html#display-interactive-widgets def sidebar_area(): - st.sidebar.title("Pick an Organism") + st.sidebar.title("Select a Species") species_to_label = { 'A.thaliana': 'A.thaliana', 'B.subtilis': 'B.subtilis', @@ -82,34 +82,14 @@ def sidebar_area(): filter_by_org_type_init = urlParams.get_field('filter_by_org', default='H.sapiens') filter_by_org_type = \ st.sidebar.selectbox( - 'Choose species:', + 'Choose organism:', ('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannaschii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataricus'), index=('A.thaliana', 'B.subtilis', 'B.taurus','C.elegans','C.familiaris','C.intestinalis','D.discoideum','D.melanogaster','D.rerio','E.coli','G.gallus','H.sapiens','M.jannaschii','M.musculus','O.sativa','P.falciparum','R.norvegicus','S.cerevisiae','S.pombe','S.scrofa','S.solfataricus').index(filter_by_org_type_init), format_func=(lambda option: species_to_label[option])) urlParams.set_field('filter_by_org', filter_by_org_type) - st.sidebar.title("Edge Type") - edge_to_label = { - 'PFC': 'The confidence Score', - 'FBS_max': 'The final Bayesian Score (FBS) of the strongest coupling class', - 'FBS_*': 'Bayesian Score of all coupling classes', - 'LLR_*': 'Log Likelihood Ratio (LLRs) of the different evidence types', - 'LLR_*': 'LLRs of the evidence types from the differrent species', - 'Max_category': 'strongest couping class for this pair. This is also the class for which the LLRs are given' - } - - filter_by_node_type_init = urlParams.get_field('filter_by_node', default='PFC') - filter_by_node_type = \ - st.sidebar.selectbox( - 'Filter node by:', - ('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category'), - index=('PFC','FBS_max','FBS_*','LLR_*','LLR_*','Max_category').index(filter_by_node_type_init), - format_func=(lambda option: edge_to_label[option])) - urlParams.set_field('filter_by_node', filter_by_node_type) - - - st.sidebar.title("Net Type") + st.sidebar.title("Network Type") net_to_label = { 'compact': 'compact', 'full': 'full', @@ -118,14 +98,51 @@ def sidebar_area(): filter_by_net_type_init = urlParams.get_field('filter_by_net', default='compact') filter_by_net_type = \ st.sidebar.selectbox( - 'Filter net by:', + 'Select FunCoup Network:', ('compact','full'), index=('compact','full').index(filter_by_net_type_init), format_func=(lambda option: net_to_label[option])) urlParams.set_field('filter_by_net', filter_by_net_type) - st.sidebar.title("Umap Type") + st.sidebar.title("Choose Edge Weight") + edge_to_label = {'PFC':'PFC', 'FBS_max':'FBS_max', 'FBS_PPI':'FBS_PPI', + 'FBS_Metabolic':'FBS_Metabolic', 'FBS_Signaling':'FBS_Signaling', 'LLR_MEX':'LLR_MEX', 'LLR_PIN':'LLR_PIN', + 'LLR_SCL':'LLR_SCL', 'LLR_PHP':'LLR_PHP', 'LLR_MIR':'LLR_MIR', 'LLR_TFB':'LLR_TFB', 'LLR_PEX':'LLR_PEX', + 'LLR_GIN':'LLR_GIN', 'LLR_DOM':'LLR_DOM', 'LLR_QMS':'LLR_QMS', 'LLR_HSA':'LLR_HSA', 'LLR_MMU':'LLR_MMU', + 'LLR_RNO':'LLR_RNO', 'LLR_CFA':'LLR_CFA', 'LLR_GGA':'LLR_GGA', 'LLR_DRE':'LLR_DRE', 'LLR_CIN':'LLR_CIN', + 'LLR_DME':'LLR_DME', 'LLR_CEL':'LLR_CEL', 'LLR_BTA':'LLR_BTA', 'LLR_SCE':'LLR_SCE', 'LLR_ATH':'LLR_ATH', + 'LLR_SPO':'LLR_SPO', 'LLR_BSU':'LLR_BSU', 'LLR_ECO':'LLR_ECO', 'LLR_PFA':'LLR_PFA', 'LLR_DDI':'LLR_DDI', + 'LLR_SSO':'LLR_SSO', 'LLR_SSC':'LLR_SSC', 'LLR_MJA':'LLR_MJA', 'LLR_OSA':'LLR_OSA','Max_category':'Max_category' + } + + filter_by_node_type_init = urlParams.get_field('filter_by_node', default='PFC') + filter_by_node_type = \ + st.sidebar.selectbox( + 'if UMAP=True, all edges used:', + ('PFC', 'FBS_max', 'FBS_PPI', + 'FBS_Metabolic', 'FBS_Signaling', 'LLR_MEX', 'LLR_PIN', + 'LLR_SCL', 'LLR_PHP', 'LLR_MIR', 'LLR_TFB', 'LLR_PEX', + 'LLR_GIN', 'LLR_DOM', 'LLR_QMS', 'LLR_HSA', 'LLR_MMU', + 'LLR_RNO', 'LLR_CFA', 'LLR_GGA', 'LLR_DRE', 'LLR_CIN', + 'LLR_DME', 'LLR_CEL', 'LLR_BTA', 'LLR_SCE', 'LLR_ATH', + 'LLR_SPO', 'LLR_BSU', 'LLR_ECO', 'LLR_PFA', 'LLR_DDI', + 'LLR_SSO', 'LLR_SSC', 'LLR_MJA', 'LLR_OSA', + 'Max_category'), + index=('PFC', 'FBS_max', 'FBS_PPI', + 'FBS_Metabolic', 'FBS_Signaling', 'LLR_MEX', 'LLR_PIN', + 'LLR_SCL', 'LLR_PHP', 'LLR_MIR', 'LLR_TFB', 'LLR_PEX', + 'LLR_GIN', 'LLR_DOM', 'LLR_QMS', 'LLR_HSA', 'LLR_MMU', + 'LLR_RNO', 'LLR_CFA', 'LLR_GGA', 'LLR_DRE', 'LLR_CIN', + 'LLR_DME', 'LLR_CEL', 'LLR_BTA', 'LLR_SCE', 'LLR_ATH', + 'LLR_SPO', 'LLR_BSU', 'LLR_ECO', 'LLR_PFA', 'LLR_DDI', + 'LLR_SSO', 'LLR_SSC', 'LLR_MJA', 'LLR_OSA', + 'Max_category').index(filter_by_node_type_init), + format_func=(lambda option: edge_to_label[option])) + urlParams.set_field('filter_by_node', filter_by_node_type) + + + st.sidebar.title("UMAP T/F") umap_to_label = { True: True, False: False, @@ -134,7 +151,7 @@ def sidebar_area(): filter_by_umap_type_init = urlParams.get_field('filter_by_umap', default=False) filter_by_umap_type = \ st.sidebar.selectbox( - 'Filter umap by:', + 'If Full Network, run and plot UMAP:', (True,False), index=(True,False).index(filter_by_umap_type_init), format_func=(lambda option: umap_to_label[option])) @@ -145,7 +162,7 @@ def sidebar_area(): return { 'edges_df': edges_df, # 'org_type': filter_by_org_type, - # 'node_type': filter_by_node_type, + 'node_type': filter_by_node_type, # 'net_type': filter_by_net_type, 'umap_type': filter_by_umap_type, } @@ -160,18 +177,18 @@ def sidebar_area(): #@st.cache(suppress_st_warning=True, allow_output_mutation=True) @st.cache_data -def run_filters(edges_df,umap_type=False): +def run_filters(edges_df, node_type, umap_type=False): filtered_edges_df = edges_df # filtered_edges_df = filtered_edges_df.replace({'ENSG00000':''},regex=True) filtered_edges_df.columns=filtered_edges_df.columns.str.split(':').str[1] # include viz generation as part of cache - url = plot_url(filtered_edges_df,umap_type) + url = plot_url(filtered_edges_df,node_type,umap_type) return { 'edges_df': filtered_edges_df, - 'url': url + 'url': url, } @@ -182,7 +199,7 @@ def run_filters(edges_df,umap_type=False): ############################################ -def plot_url(edges_df,umap_type=False): +def plot_url(edges_df,node_type, umap_type=False): nodes_df = pd.DataFrame({ 'n': pd.concat([edges_df['Gene1'], edges_df['Gene2']]).unique() @@ -199,7 +216,7 @@ def plot_url(edges_df,umap_type=False): if umap_type == False: url = graphistry\ .edges(edges_df)\ - .bind(source="Gene1", destination="Gene2")\ + .bind(source="Gene1", destination="Gene2", weight=node_type)\ .nodes(nodes_df)\ .bind(node='n', point_color='nc')\ .settings(url_params={ @@ -209,18 +226,17 @@ def plot_url(edges_df,umap_type=False): })\ .plot(render=False) elif umap_type == True: - url = graphistry\ - .edges(edges_df)\ + AA = graphistry\ + .nodes(edges_df)\ .bind(source="Gene1", destination="Gene2")\ - .nodes(nodes_df)\ - .bind(node='n', point_color='nc')\ .settings(url_params={ 'pointSize': 0.3, 'splashAfter': 'false', 'bg': '%23' + 'f0f2f6' })\ - .umap(feature_engine='dirty_cat',engine='umap_learn')\ - .plot(render=False) + .umap(feature_engine='dirty_cat',engine='umap_learn',memoize=True) + emb2=AA._node_embedding + url=graphistry.nodes(emb2.reset_index(),'index').edges(AA._edges,'_src_implicit','_dst_implicit').bind(point_x="x",point_y="y").settings(url_params={"play":0}).addStyle(bg={'color': '#eee'}).plot(render=False) logger.info('Generated viz, got back urL: %s', url) From 91d90816e24cee27260a20bc7bce7ad6f29dfef4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 19 Oct 2023 13:19:19 +0200 Subject: [PATCH 09/12] full bsubtilis umap default --- src/python/views/demo_00_funcoup/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_00_funcoup/__init__.py index 18510a9..6462b04 100644 --- a/src/python/views/demo_00_funcoup/__init__.py +++ b/src/python/views/demo_00_funcoup/__init__.py @@ -79,7 +79,7 @@ def sidebar_area(): base_url = os.environ['BASE_URL'] - filter_by_org_type_init = urlParams.get_field('filter_by_org', default='H.sapiens') + filter_by_org_type_init = urlParams.get_field('filter_by_org', default='B.subtilis') filter_by_org_type = \ st.sidebar.selectbox( 'Choose organism:', @@ -95,7 +95,7 @@ def sidebar_area(): 'full': 'full', } - filter_by_net_type_init = urlParams.get_field('filter_by_net', default='compact') + filter_by_net_type_init = urlParams.get_field('filter_by_net', default='full') filter_by_net_type = \ st.sidebar.selectbox( 'Select FunCoup Network:', @@ -148,7 +148,7 @@ def sidebar_area(): False: False, } - filter_by_umap_type_init = urlParams.get_field('filter_by_umap', default=False) + filter_by_umap_type_init = urlParams.get_field('filter_by_umap', default=True) filter_by_umap_type = \ st.sidebar.selectbox( 'If Full Network, run and plot UMAP:', From 239a7bf94357a7d456107f4b9c6f7ea53675a04b Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 20 Oct 2023 09:19:03 +0200 Subject: [PATCH 10/12] rename demo --- .../views/{demo_00_funcoup => demo_bio_01_funcoup}/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/python/views/{demo_00_funcoup => demo_bio_01_funcoup}/__init__.py (100%) diff --git a/src/python/views/demo_00_funcoup/__init__.py b/src/python/views/demo_bio_01_funcoup/__init__.py similarity index 100% rename from src/python/views/demo_00_funcoup/__init__.py rename to src/python/views/demo_bio_01_funcoup/__init__.py From b888a6cdefa3f76b80045999cf68385349cadd58 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 23 Nov 2023 13:49:01 +0800 Subject: [PATCH 11/12] reorganized for clarity --- .../views/demo_bio_01_funcoup/__init__.py | 93 ++++++------------- 1 file changed, 29 insertions(+), 64 deletions(-) diff --git a/src/python/views/demo_bio_01_funcoup/__init__.py b/src/python/views/demo_bio_01_funcoup/__init__.py index 6462b04..7b3f204 100644 --- a/src/python/views/demo_bio_01_funcoup/__init__.py +++ b/src/python/views/demo_bio_01_funcoup/__init__.py @@ -13,7 +13,7 @@ # Controls how entrypoint.py picks it up -app_id = 'app_00' +app_id = 'app_bio_01' logger = logging.getLogger(app_id) urlParams = URLParam(app_id) @@ -88,82 +88,44 @@ def sidebar_area(): format_func=(lambda option: species_to_label[option])) urlParams.set_field('filter_by_org', filter_by_org_type) - - st.sidebar.title("Network Type") - net_to_label = { - 'compact': 'compact', - 'full': 'full', + st.sidebar.title("Select a Network Type") + umap_to_label = { + True: 'UMAP', + False: 'FunCoup', } - - filter_by_net_type_init = urlParams.get_field('filter_by_net', default='full') - filter_by_net_type = \ + + filter_by_umap_type_init = urlParams.get_field('filter_by_umap', default='FunCoup') + filter_by_umap_type = \ st.sidebar.selectbox( - 'Select FunCoup Network:', - ('compact','full'), - index=('compact','full').index(filter_by_net_type_init), - format_func=(lambda option: net_to_label[option])) - urlParams.set_field('filter_by_net', filter_by_net_type) - - - st.sidebar.title("Choose Edge Weight") - edge_to_label = {'PFC':'PFC', 'FBS_max':'FBS_max', 'FBS_PPI':'FBS_PPI', - 'FBS_Metabolic':'FBS_Metabolic', 'FBS_Signaling':'FBS_Signaling', 'LLR_MEX':'LLR_MEX', 'LLR_PIN':'LLR_PIN', - 'LLR_SCL':'LLR_SCL', 'LLR_PHP':'LLR_PHP', 'LLR_MIR':'LLR_MIR', 'LLR_TFB':'LLR_TFB', 'LLR_PEX':'LLR_PEX', - 'LLR_GIN':'LLR_GIN', 'LLR_DOM':'LLR_DOM', 'LLR_QMS':'LLR_QMS', 'LLR_HSA':'LLR_HSA', 'LLR_MMU':'LLR_MMU', - 'LLR_RNO':'LLR_RNO', 'LLR_CFA':'LLR_CFA', 'LLR_GGA':'LLR_GGA', 'LLR_DRE':'LLR_DRE', 'LLR_CIN':'LLR_CIN', - 'LLR_DME':'LLR_DME', 'LLR_CEL':'LLR_CEL', 'LLR_BTA':'LLR_BTA', 'LLR_SCE':'LLR_SCE', 'LLR_ATH':'LLR_ATH', - 'LLR_SPO':'LLR_SPO', 'LLR_BSU':'LLR_BSU', 'LLR_ECO':'LLR_ECO', 'LLR_PFA':'LLR_PFA', 'LLR_DDI':'LLR_DDI', - 'LLR_SSO':'LLR_SSO', 'LLR_SSC':'LLR_SSC', 'LLR_MJA':'LLR_MJA', 'LLR_OSA':'LLR_OSA','Max_category':'Max_category' - } + 'Display functional coupling network (select link evidence below) or UMAP against all 40 evidence types:', + (True,False), + index=(True,False).index(filter_by_umap_type_init), + format_func=(lambda option: umap_to_label[option])) + urlParams.set_field('filter_by_umap', filter_by_umap_type) + + if filter_by_umap_type is 'UMAP': + filter_by_net_type = 'full' + else: + filter_by_net_type = 'compact' + + st.sidebar.title("Select an Evidence Type") + edge_to_label = {'PFC':'PFC', 'FBS_max':'FBS_max'} filter_by_node_type_init = urlParams.get_field('filter_by_node', default='PFC') filter_by_node_type = \ st.sidebar.selectbox( - 'if UMAP=True, all edges used:', - ('PFC', 'FBS_max', 'FBS_PPI', - 'FBS_Metabolic', 'FBS_Signaling', 'LLR_MEX', 'LLR_PIN', - 'LLR_SCL', 'LLR_PHP', 'LLR_MIR', 'LLR_TFB', 'LLR_PEX', - 'LLR_GIN', 'LLR_DOM', 'LLR_QMS', 'LLR_HSA', 'LLR_MMU', - 'LLR_RNO', 'LLR_CFA', 'LLR_GGA', 'LLR_DRE', 'LLR_CIN', - 'LLR_DME', 'LLR_CEL', 'LLR_BTA', 'LLR_SCE', 'LLR_ATH', - 'LLR_SPO', 'LLR_BSU', 'LLR_ECO', 'LLR_PFA', 'LLR_DDI', - 'LLR_SSO', 'LLR_SSC', 'LLR_MJA', 'LLR_OSA', - 'Max_category'), - index=('PFC', 'FBS_max', 'FBS_PPI', - 'FBS_Metabolic', 'FBS_Signaling', 'LLR_MEX', 'LLR_PIN', - 'LLR_SCL', 'LLR_PHP', 'LLR_MIR', 'LLR_TFB', 'LLR_PEX', - 'LLR_GIN', 'LLR_DOM', 'LLR_QMS', 'LLR_HSA', 'LLR_MMU', - 'LLR_RNO', 'LLR_CFA', 'LLR_GGA', 'LLR_DRE', 'LLR_CIN', - 'LLR_DME', 'LLR_CEL', 'LLR_BTA', 'LLR_SCE', 'LLR_ATH', - 'LLR_SPO', 'LLR_BSU', 'LLR_ECO', 'LLR_PFA', 'LLR_DDI', - 'LLR_SSO', 'LLR_SSC', 'LLR_MJA', 'LLR_OSA', - 'Max_category').index(filter_by_node_type_init), + 'for FunCoup Network display', + ('PFC', 'FBS_max'), + index=('PFC', 'FBS_max').index(filter_by_node_type_init), format_func=(lambda option: edge_to_label[option])) urlParams.set_field('filter_by_node', filter_by_node_type) - - st.sidebar.title("UMAP T/F") - umap_to_label = { - True: True, - False: False, - } - - filter_by_umap_type_init = urlParams.get_field('filter_by_umap', default=True) - filter_by_umap_type = \ - st.sidebar.selectbox( - 'If Full Network, run and plot UMAP:', - (True,False), - index=(True,False).index(filter_by_umap_type_init), - format_func=(lambda option: umap_to_label[option])) - urlParams.set_field('filter_by_umap', filter_by_umap_type) edges_df = pd.read_csv('https://funcoup.org/downloads/download.action?type=network&instanceID=24480085&fileName=FC5.0_'+filter_by_org_type+'_'+filter_by_net_type+'.gz', sep='\t') return { 'edges_df': edges_df, - # 'org_type': filter_by_org_type, 'node_type': filter_by_node_type, - # 'net_type': filter_by_net_type, 'umap_type': filter_by_umap_type, } @@ -201,6 +163,8 @@ def run_filters(edges_df, node_type, umap_type=False): def plot_url(edges_df,node_type, umap_type=False): + edges_df.replace({'ENSG00000':''},regex=True,inplace=True) ## remove ENSG00000 from gene names for better compression + nodes_df = pd.DataFrame({ 'n': pd.concat([edges_df['Gene1'], edges_df['Gene2']]).unique() }) @@ -216,7 +180,7 @@ def plot_url(edges_df,node_type, umap_type=False): if umap_type == False: url = graphistry\ .edges(edges_df)\ - .bind(source="Gene1", destination="Gene2", weight=node_type)\ + .bind(source="Gene1", destination="Gene2", edge_weight=node_type)\ .nodes(nodes_df)\ .bind(node='n', point_color='nc')\ .settings(url_params={ @@ -224,8 +188,9 @@ def plot_url(edges_df,node_type, umap_type=False): 'splashAfter': 'false', 'bg': '%23' + 'f0f2f6' })\ - .plot(render=False) + .plot(render=False)#, as_files=True, suffix='.html', output=None, open=False) elif umap_type == True: + AA = graphistry\ .nodes(edges_df)\ .bind(source="Gene1", destination="Gene2")\ From de163be06b6f9182427c5801a34e2e2be7599897 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 5 Apr 2024 19:07:02 +0800 Subject: [PATCH 12/12] removed req --- src/python/requirements-app.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/python/requirements-app.txt b/src/python/requirements-app.txt index 20120a3..d9658a5 100644 --- a/src/python/requirements-app.txt +++ b/src/python/requirements-app.txt @@ -1,5 +1,3 @@ ### ### Use this file for your custom view requirements here vs in the requirements-system.txt ### -umap-learn -dirty_cat