Hack90 commited on
Commit
2fa0dd7
·
verified ·
1 Parent(s): e4b2742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -45
app.py CHANGED
@@ -844,53 +844,53 @@ 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
 
 
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