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 )
@@ -586,7 +583,7 @@ def snp_allele_frequencies_advanced(
586583 frequency = np .compress (loc_variant , frequency , axis = 0 )
587584
588585 # Set up variant effect annotator.
589- ann = self ._snp_effect_annotator ()
586+ ann = self ._snp_effect_annotator
590587
591588 # Add effects to the dataframe.
592589 ann .get_effects (
@@ -832,7 +829,7 @@ def snp_genotype_allele_counts(
832829 df_snps = pd .concat ([df_snps , df_counts ], axis = 1 )
833830
834831 # Add effect annotations.
835- ann = self ._snp_effect_annotator ()
832+ ann = self ._snp_effect_annotator
836833 ann .get_effects (
837834 transcript = transcript , variants = df_snps , progress = self ._progress
838835 )
0 commit comments