Skip to content

Commit a85cf3d

Browse files
Fix color parameter in plot_haplotype_network function (issue #738)
1 parent 65de70c commit a85cf3d

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

malariagen_data/anopheles.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)