Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -844,97 +844,97 @@ def compare_persistence_homology(dna_sequence1, dna_sequence2):
|
|
| 844 |
ui.page_opts(fillable=True)
|
| 845 |
|
| 846 |
with ui.navset_card_tab(id="tab"):
|
| 847 |
-
with ui.nav_panel("Viral Macrostructure"):
|
| 848 |
-
ui.page_opts(fillable=True)
|
| 849 |
-
ui.panel_title("Do viruses have underlying structure?")
|
| 850 |
-
with ui.layout_columns():
|
| 851 |
-
with ui.card():
|
| 852 |
-
ui.input_selectize(
|
| 853 |
-
"virus_selector",
|
| 854 |
-
"Select your viruses:",
|
| 855 |
-
virus,
|
| 856 |
-
multiple=True,
|
| 857 |
-
)
|
| 858 |
-
with ui.card():
|
| 859 |
-
ui.input_selectize(
|
| 860 |
-
"plot_type",
|
| 861 |
-
"Select your method:",
|
| 862 |
-
["Chaos Game Representation", "2D Line", "ColorSquare", "Persistant Homology", "Wens Method"],
|
| 863 |
-
multiple=False,
|
| 864 |
-
)
|
| 865 |
-
|
| 866 |
-
############################################################# Plotting ########################################################
|
| 867 |
-
here = Path(__file__).parent
|
| 868 |
-
import matplotlib as mpl
|
| 869 |
-
@render.plot
|
| 870 |
-
def plot():
|
| 871 |
-
#ds = load_dataset('Hack90/virus_tiny')
|
| 872 |
-
df = pd.read_parquet('virus_ds.parquet')
|
| 873 |
-
df = df[df['Organism_Name'].isin(input.virus_selector())]
|
| 874 |
-
# group by virus
|
| 875 |
-
grouped = df.groupby('Organism_Name')['Sequence'].apply(list)
|
| 876 |
-
mpl.rcParams.update(mpl.rcParamsDefault)
|
| 877 |
-
|
| 878 |
-
# plot the comparison
|
| 879 |
-
fig = None
|
| 880 |
-
if input.plot_type() == "2D Line":
|
| 881 |
-
fig = plot_2d_comparison(grouped, grouped.index)
|
| 882 |
-
if input.plot_type() == "ColorSquare":
|
| 883 |
-
filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
|
| 884 |
-
fig = plot_color_square(filtered_df['Sequence'], filtered_df['Organism_Name'].unique())
|
| 885 |
-
if input.plot_type() == "Wens Method":
|
| 886 |
-
fig = wens_method_heatmap(df, df['Organism_Name'].unique())
|
| 887 |
-
if input.plot_type() == "Chaos Game Representation":
|
| 888 |
-
filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
|
| 889 |
-
fig = plot_fcgr(filtered_df['Sequence'], df['Organism_Name'].unique())
|
| 890 |
-
if input.plot_type() == "Persistant Homology":
|
| 891 |
-
filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
|
| 892 |
-
fig = plot_persistence_homology(filtered_df['Sequence'], filtered_df['Organism_Name'])
|
| 893 |
-
return fig
|
| 894 |
-
# with ui.nav_panel("Viral Model"):
|
| 895 |
-
# gr.load("models/Hack90/virus_pythia_31_1024").launch()
|
| 896 |
-
|
| 897 |
-
# with ui.nav_panel("Viral Microstructure"):
|
| 898 |
# ui.page_opts(fillable=True)
|
| 899 |
-
# ui.panel_title("
|
| 900 |
# with ui.layout_columns():
|
| 901 |
# with ui.card():
|
| 902 |
-
# ui.input_slider("kmer", "kmer", 0, 10, 5)
|
| 903 |
-
# ui.input_slider("top_k", "top:", 0, 1000, 15)
|
| 904 |
-
|
| 905 |
# ui.input_selectize(
|
| 906 |
-
#
|
| 907 |
-
#
|
| 908 |
-
#
|
| 909 |
-
#
|
| 910 |
-
#
|
| 911 |
-
|
| 912 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 913 |
# @render.plot
|
| 914 |
# def plot():
|
| 915 |
-
#
|
| 916 |
-
#
|
| 917 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
# fig = None
|
| 919 |
-
# if input.plot_type() == "
|
| 920 |
-
#
|
| 921 |
-
#
|
| 922 |
-
#
|
| 923 |
-
#
|
| 924 |
-
#
|
| 925 |
-
#
|
| 926 |
-
#
|
| 927 |
-
#
|
| 928 |
-
#
|
| 929 |
-
#
|
| 930 |
-
#
|
| 931 |
-
# fig
|
| 932 |
-
# ax.bar(df['kmer'], df['percent']*100)
|
| 933 |
-
# ax.set_title(f"Most common {k}-mers")
|
| 934 |
-
# ax.set_xlabel("K-mer")
|
| 935 |
-
# ax.set_ylabel("Percentage")
|
| 936 |
-
# ax.set_xticklabels(df['kmer'], rotation=90)
|
| 937 |
# return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 938 |
|
| 939 |
# with ui.nav_panel("Viral Model Training"):
|
| 940 |
# ui.page_opts(fillable=True)
|
|
|
|
| 844 |
ui.page_opts(fillable=True)
|
| 845 |
|
| 846 |
with ui.navset_card_tab(id="tab"):
|
| 847 |
+
# with ui.nav_panel("Viral Macrostructure"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 848 |
# ui.page_opts(fillable=True)
|
| 849 |
+
# ui.panel_title("Do viruses have underlying structure?")
|
| 850 |
# with ui.layout_columns():
|
| 851 |
# with ui.card():
|
|
|
|
|
|
|
|
|
|
| 852 |
# ui.input_selectize(
|
| 853 |
+
# "virus_selector",
|
| 854 |
+
# "Select your viruses:",
|
| 855 |
+
# virus,
|
| 856 |
+
# multiple=True,
|
| 857 |
+
# )
|
| 858 |
+
# with ui.card():
|
| 859 |
+
# ui.input_selectize(
|
| 860 |
+
# "plot_type",
|
| 861 |
+
# "Select your method:",
|
| 862 |
+
# ["Chaos Game Representation", "2D Line", "ColorSquare", "Persistant Homology", "Wens Method"],
|
| 863 |
+
# multiple=False,
|
| 864 |
+
# )
|
| 865 |
+
|
| 866 |
+
# ############################################################# Plotting ########################################################
|
| 867 |
+
# here = Path(__file__).parent
|
| 868 |
+
# import matplotlib as mpl
|
| 869 |
# @render.plot
|
| 870 |
# def plot():
|
| 871 |
+
# #ds = load_dataset('Hack90/virus_tiny')
|
| 872 |
+
# df = pd.read_parquet('virus_ds.parquet')
|
| 873 |
+
# df = df[df['Organism_Name'].isin(input.virus_selector())]
|
| 874 |
+
# # group by virus
|
| 875 |
+
# grouped = df.groupby('Organism_Name')['Sequence'].apply(list)
|
| 876 |
+
# mpl.rcParams.update(mpl.rcParamsDefault)
|
| 877 |
+
|
| 878 |
+
# # plot the comparison
|
| 879 |
# fig = None
|
| 880 |
+
# if input.plot_type() == "2D Line":
|
| 881 |
+
# fig = plot_2d_comparison(grouped, grouped.index)
|
| 882 |
+
# if input.plot_type() == "ColorSquare":
|
| 883 |
+
# filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
|
| 884 |
+
# fig = plot_color_square(filtered_df['Sequence'], filtered_df['Organism_Name'].unique())
|
| 885 |
+
# if input.plot_type() == "Wens Method":
|
| 886 |
+
# fig = wens_method_heatmap(df, df['Organism_Name'].unique())
|
| 887 |
+
# if input.plot_type() == "Chaos Game Representation":
|
| 888 |
+
# filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
|
| 889 |
+
# fig = plot_fcgr(filtered_df['Sequence'], df['Organism_Name'].unique())
|
| 890 |
+
# if input.plot_type() == "Persistant Homology":
|
| 891 |
+
# filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
|
| 892 |
+
# fig = plot_persistence_homology(filtered_df['Sequence'], filtered_df['Organism_Name'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
# return fig
|
| 894 |
+
# with ui.nav_panel("Viral Model"):
|
| 895 |
+
# gr.load("models/Hack90/virus_pythia_31_1024").launch()
|
| 896 |
+
|
| 897 |
+
with ui.nav_panel("Viral Microstructure"):
|
| 898 |
+
ui.page_opts(fillable=True)
|
| 899 |
+
ui.panel_title("Kmer Distribution")
|
| 900 |
+
with ui.layout_columns():
|
| 901 |
+
with ui.card():
|
| 902 |
+
ui.input_slider("kmer", "kmer", 0, 10, 5)
|
| 903 |
+
ui.input_slider("top_k", "top:", 0, 1000, 15)
|
| 904 |
+
|
| 905 |
+
ui.input_selectize(
|
| 906 |
+
"plot_type",
|
| 907 |
+
"Select metric:",
|
| 908 |
+
["percentage", "count"],
|
| 909 |
+
multiple=False,
|
| 910 |
+
)
|
| 911 |
+
|
| 912 |
+
|
| 913 |
+
@render.plot
|
| 914 |
+
def plot():
|
| 915 |
+
df = pd.read_csv('kmers.csv')
|
| 916 |
+
k = input.kmer()
|
| 917 |
+
top_k = input.top_k()
|
| 918 |
+
fig = None
|
| 919 |
+
if input.plot_type() == "count":
|
| 920 |
+
df = df[df['k'] == k]
|
| 921 |
+
df = df.head(top_k)
|
| 922 |
+
fig, ax = plt.subplots()
|
| 923 |
+
ax.bar(df['kmer'], df['count'])
|
| 924 |
+
ax.set_title(f"Most common {k}-mers")
|
| 925 |
+
ax.set_xlabel("K-mer")
|
| 926 |
+
ax.set_ylabel("Count")
|
| 927 |
+
ax.set_xticklabels(df['kmer'], rotation=90)
|
| 928 |
+
if input.plot_type() == "percentage":
|
| 929 |
+
df = df[df['k'] == k]
|
| 930 |
+
df = df.head(top_k)
|
| 931 |
+
fig, ax = plt.subplots()
|
| 932 |
+
ax.bar(df['kmer'], df['percent']*100)
|
| 933 |
+
ax.set_title(f"Most common {k}-mers")
|
| 934 |
+
ax.set_xlabel("K-mer")
|
| 935 |
+
ax.set_ylabel("Percentage")
|
| 936 |
+
ax.set_xticklabels(df['kmer'], rotation=90)
|
| 937 |
+
return fig
|
| 938 |
|
| 939 |
# with ui.nav_panel("Viral Model Training"):
|
| 940 |
# ui.page_opts(fillable=True)
|