1+ from functools import cached_property
12from typing import Optional , Dict , Union , Callable , List
23import warnings
34
@@ -40,9 +41,6 @@ def __init__(
4041 # to the superclass constructor.
4142 super ().__init__ (** kwargs )
4243
43- # Set up cache variables.
44- self ._cache_annotator = None
45-
4644 def _snp_df_melt (self , * , ds_snp : xr .Dataset ) -> pd .DataFrame :
4745 """Set up a dataframe with SNP site and filter data,
4846 melting each alternate allele into a separate row."""
@@ -81,13 +79,12 @@ def _snp_df_melt(self, *, ds_snp: xr.Dataset) -> pd.DataFrame:
8179
8280 return df_snps
8381
82+ @cached_property
8483 def _snp_effect_annotator (self ):
8584 """Set up variant effect annotator."""
86- if self ._cache_annotator is None :
87- self ._cache_annotator = veff .Annotator (
88- genome = self .open_genome (), genome_features = self .genome_features ()
89- )
90- return self ._cache_annotator
85+ return veff .Annotator (
86+ genome = self .open_genome (), genome_features = self .genome_features ()
87+ )
9188
9289 @_check_types
9390 @doc (
@@ -112,7 +109,7 @@ def snp_effects(
112109 df_snps = self ._snp_df_melt (ds_snp = ds_snp )
113110
114111 # Setup variant effect annotator.
115- ann = self ._snp_effect_annotator ()
112+ ann = self ._snp_effect_annotator
116113
117114 # Add effects to the dataframe.
118115 ann .get_effects (transcript = transcript , variants = df_snps )
@@ -249,7 +246,7 @@ def snp_allele_frequencies(
249246
250247 if effects :
251248 # Add effect annotations.
252- ann = self ._snp_effect_annotator ()
249+ ann = self ._snp_effect_annotator
253250 ann .get_effects (
254251 transcript = transcript , variants = df_snps , progress = self ._progress
255252 )
@@ -453,6 +450,7 @@ def snp_allele_frequencies_advanced(
453450 chunks : base_params .chunks = base_params .native_chunks ,
454451 inline_array : base_params .inline_array = base_params .inline_array_default ,
455452 taxon_by : frq_params .taxon_by = frq_params .taxon_by_default ,
453+ filter_unassigned : Optional [frq_params .filter_unassigned ] = None ,
456454 ) -> xr .Dataset :
457455 # Load sample metadata.
458456 df_samples = self .sample_metadata (
@@ -467,6 +465,7 @@ def snp_allele_frequencies_advanced(
467465 area_by = area_by ,
468466 period_by = period_by ,
469467 taxon_by = taxon_by ,
468+ filter_unassigned = filter_unassigned ,
470469 )
471470
472471 # Group samples to make cohorts.
@@ -586,7 +585,7 @@ def snp_allele_frequencies_advanced(
586585 frequency = np .compress (loc_variant , frequency , axis = 0 )
587586
588587 # Set up variant effect annotator.
589- ann = self ._snp_effect_annotator ()
588+ ann = self ._snp_effect_annotator
590589
591590 # Add effects to the dataframe.
592591 ann .get_effects (
@@ -684,6 +683,7 @@ def aa_allele_frequencies_advanced(
684683 chunks : base_params .chunks = base_params .native_chunks ,
685684 inline_array : base_params .inline_array = base_params .inline_array_default ,
686685 taxon_by : frq_params .taxon_by = frq_params .taxon_by_default ,
686+ filter_unassigned : Optional [frq_params .filter_unassigned ] = None ,
687687 ) -> xr .Dataset :
688688 # Begin by computing SNP allele frequencies.
689689 ds_snp_frq = self .snp_allele_frequencies_advanced (
@@ -702,6 +702,7 @@ def aa_allele_frequencies_advanced(
702702 chunks = chunks ,
703703 inline_array = inline_array ,
704704 taxon_by = taxon_by ,
705+ filter_unassigned = filter_unassigned ,
705706 )
706707
707708 # N.B., we need to worry about the possibility of the
@@ -832,7 +833,7 @@ def snp_genotype_allele_counts(
832833 df_snps = pd .concat ([df_snps , df_counts ], axis = 1 )
833834
834835 # Add effect annotations.
835- ann = self ._snp_effect_annotator ()
836+ ann = self ._snp_effect_annotator
836837 ann .get_effects (
837838 transcript = transcript , variants = df_snps , progress = self ._progress
838839 )
0 commit comments