Skip to content

Commit dd9146b

Browse files
fix: correct sample_query_options use and import order
1 parent 3dc320a commit dd9146b

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

malariagen_data/anoph/phenotypes.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,8 @@ def phenotype_data(
378378
return pd.DataFrame()
379379

380380
# 3. Get sample metadata for all samples that have phenotype data
381-
# The sample_metadata method does not accept a 'df' argument.
382-
# We need to fetch the metadata first, then merge and filter.
383381
try:
384-
df_metadata = self.sample_metadata(
385-
sample_sets=sample_sets_norm,
386-
sample_query_options=sample_query_options,
387-
)
382+
df_metadata = self.sample_metadata(sample_sets=sample_sets_norm)
388383
except Exception as e:
389384
warnings.warn(f"Error fetching sample metadata: {e}")
390385
return pd.DataFrame()
@@ -394,7 +389,7 @@ def phenotype_data(
394389
return pd.DataFrame()
395390

396391
# 4. Merge phenotype data with metadata
397-
# Filter phenotype data to samples present in metadata before merging
392+
# Filter phenotype data to samples present in metadata before merging
398393
metadata_sample_ids = set(df_metadata["sample_id"].unique())
399394
df_phenotypes_filtered = df_phenotypes[
400395
df_phenotypes["sample_id"].isin(metadata_sample_ids)
@@ -407,8 +402,9 @@ def phenotype_data(
407402
# 5. Apply user's sample_query if provided
408403
if sample_query:
409404
try:
410-
# Use pandas query method to filter the merged data
411-
df_merged = df_merged.query(sample_query)
405+
df_merged = df_merged.query(
406+
sample_query, **(sample_query_options or {})
407+
)
412408
except Exception as e:
413409
warnings.warn(f"Error applying sample_query '{sample_query}': {e}")
414410
return pd.DataFrame()

malariagen_data/anopheles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from .anoph.fst import AnophelesFstAnalysis
4242
from .anoph.h12 import AnophelesH12Analysis
4343
from .anoph.h1x import AnophelesH1XAnalysis
44+
from .anoph.phenotypes import AnophelesPhenotypeData
4445
from .mjn import median_joining_network, mjn_graph
4546
from .anoph.hapclust import AnophelesHapClustAnalysis
4647
from .anoph.dipclust import AnophelesDipClustAnalysis
@@ -52,7 +53,7 @@
5253
parse_single_region,
5354
plotly_discrete_legend,
5455
)
55-
from .anoph.phenotypes import AnophelesPhenotypeData
56+
5657

5758
# N.B., we are in the process of breaking up the AnophelesDataResource
5859
# class into multiple parent classes like AnophelesGenomeSequenceData

0 commit comments

Comments
 (0)