Hack90 commited on
Commit
9c65bf3
·
verified ·
1 Parent(s): 6516856

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -2
app.py CHANGED
@@ -15,6 +15,16 @@ import numpy as np
15
  import matplotlib.pyplot as plt
16
  import matplotlib.style as mplstyle
17
  from pathlib import Path
 
 
 
 
 
 
 
 
 
 
18
 
19
  # Mapping of nucleotides to float coordinates
20
  mapping_easy = {
@@ -881,8 +891,50 @@ with ui.navset_card_tab(id="tab"):
881
  filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
882
  fig = plot_persistence_homology(filtered_df['Sequence'], filtered_df['Organism_Name'])
883
  return fig
884
- with ui.nav_panel("Viral Model"):
885
- gr.load("models/Hack90/virus_pythia_31_1024").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886
 
887
  with ui.nav_panel("Viral Model Training"):
888
  ui.page_opts(fillable=True)
@@ -915,6 +967,7 @@ with ui.navset_card_tab(id="tab"):
915
  mpl.rcParams.update(mpl.rcParamsDefault)
916
  fig = plot_loss_rates(df, '14M')
917
  return fig
 
918
 
919
  # @render.image
920
  # def image():
 
15
  import matplotlib.pyplot as plt
16
  import matplotlib.style as mplstyle
17
  from pathlib import Path
18
+ from shiny import render
19
+ from shiny.express import input, ui
20
+ import pandas as pd
21
+ from pathlib import Path
22
+ import matplotlib.pyplot as plt
23
+ import numpy as np
24
+ import pandas as pd
25
+ from scipy.interpolate import interp1d
26
+ import numpy as np
27
+
28
 
29
  # Mapping of nucleotides to float coordinates
30
  mapping_easy = {
 
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)
 
967
  mpl.rcParams.update(mpl.rcParamsDefault)
968
  fig = plot_loss_rates(df, '14M')
969
  return fig
970
+
971
 
972
  # @render.image
973
  # def image():