Hack90 commited on
Commit
19a59f0
1 Parent(s): befa5fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -42
app.py CHANGED
@@ -831,49 +831,54 @@ def compare_persistence_homology(dna_sequence1, dna_sequence2):
831
  return distance
832
 
833
  ############################################################# UI #################################################################
 
834
  ui.page_opts(fillable=True)
835
- ui.panel_title("How similar are viruses, to themselves and others? Do they have undelying structure?")
836
- with ui.layout_columns():
837
- with ui.card():
838
- ui.input_selectize(
839
- "virus_selector",
840
- "Select your viruses:",
841
- virus,
842
- multiple=True,
843
- )
844
- with ui.card():
845
- ui.input_selectize(
846
- "plot_type",
847
- "Select your method:",
848
- ["Chaos Game Representation", "2D Line", "ColorSquare", "Persistant Homology", "Wens Method"],
849
- multiple=False,
850
- )
851
-
852
- ############################################################# Plotting ########################################################
853
- here = Path(__file__).parent
854
- @render.plot
855
- def plot():
856
- #ds = load_dataset('Hack90/virus_tiny')
857
- df = pd.read_parquet('virus_ds.parquet')
858
- df = df[df['Organism_Name'].isin(input.virus_selector())]
859
- # group by virus
860
- grouped = df.groupby('Organism_Name')['Sequence'].apply(list)
861
- # plot the comparison
862
- fig = None
863
- if input.plot_type() == "2D Line":
864
- fig = plot_2d_comparison(grouped, grouped.index)
865
- if input.plot_type() == "ColorSquare":
866
- filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
867
- fig = plot_color_square(filtered_df['Sequence'], filtered_df['Organism_Name'].unique())
868
- if input.plot_type() == "Wens Method":
869
- fig = wens_method_heatmap(df, df['Organism_Name'].unique())
870
- if input.plot_type() == "Chaos Game Representation":
871
- filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
872
- fig = plot_fcgr(filtered_df['Sequence'], df['Organism_Name'].unique())
873
- if input.plot_type() == "Persistant Homology":
874
- filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
875
- fig = plot_persistence_homology(filtered_df['Sequence'], filtered_df['Organism_Name'])
876
- return fig
 
 
 
 
877
 
878
  # @render.image
879
  # def image():
 
831
  return distance
832
 
833
  ############################################################# UI #################################################################
834
+
835
  ui.page_opts(fillable=True)
836
+
837
+ with ui.navset_card_tab(id="tab"):
838
+ with ui.nav_panel("Viral Macrostructure"):
839
+ ui.page_opts(fillable=True)
840
+ ui.panel_title("Do viruses have underlying structure?")
841
+ with ui.layout_columns():
842
+ with ui.card():
843
+ ui.input_selectize(
844
+ "virus_selector",
845
+ "Select your viruses:",
846
+ virus,
847
+ multiple=True,
848
+ )
849
+ with ui.card():
850
+ ui.input_selectize(
851
+ "plot_type",
852
+ "Select your method:",
853
+ ["Chaos Game Representation", "2D Line", "ColorSquare", "Persistant Homology", "Wens Method"],
854
+ multiple=False,
855
+ )
856
+
857
+ ############################################################# Plotting ########################################################
858
+ here = Path(__file__).parent
859
+ @render.plot
860
+ def plot():
861
+ #ds = load_dataset('Hack90/virus_tiny')
862
+ df = pd.read_parquet('virus_ds.parquet')
863
+ df = df[df['Organism_Name'].isin(input.virus_selector())]
864
+ # group by virus
865
+ grouped = df.groupby('Organism_Name')['Sequence'].apply(list)
866
+ # plot the comparison
867
+ fig = None
868
+ if input.plot_type() == "2D Line":
869
+ fig = plot_2d_comparison(grouped, grouped.index)
870
+ if input.plot_type() == "ColorSquare":
871
+ filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
872
+ fig = plot_color_square(filtered_df['Sequence'], filtered_df['Organism_Name'].unique())
873
+ if input.plot_type() == "Wens Method":
874
+ fig = wens_method_heatmap(df, df['Organism_Name'].unique())
875
+ if input.plot_type() == "Chaos Game Representation":
876
+ filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
877
+ fig = plot_fcgr(filtered_df['Sequence'], df['Organism_Name'].unique())
878
+ if input.plot_type() == "Persistant Homology":
879
+ filtered_df = df.groupby('Organism_Name').apply(filter_and_select).reset_index(drop=True)
880
+ fig = plot_persistence_homology(filtered_df['Sequence'], filtered_df['Organism_Name'])
881
+ return fig
882
 
883
  # @render.image
884
  # def image():