File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2238,8 +2238,17 @@ def plot_haplotype_network(
22382238 color_discrete_map_display = None
22392239 ht_color_counts = None
22402240 if color is not None :
2241+ # Check if the color column exists in the dataframe
2242+ if color not in df_haps .columns :
2243+ raise ValueError (
2244+ f"Column '{ color } ' specified for coloring not found in sample data. Available columns: { ', ' .join (df_haps .columns )} "
2245+ )
22412246 # sanitise color column - necessary to avoid grey pie chart segments
2242- df_haps ["partition" ] = df_haps [color ].str .replace (r"\W" , "" , regex = True )
2247+ df_haps ["partition" ] = (
2248+ df_haps [color ].str .replace (r"\W" , "" , regex = True )
2249+ if color in df_haps .columns
2250+ else None
2251+ )
22432252
22442253 # extract all unique values of the color column
22452254 color_values = df_haps ["partition" ].fillna ("<NA>" ).unique ()
You can’t perform that action at this time.
0 commit comments