44import allel # type: ignore
55
66from numpydoc_decorator import doc
7- from ..util import check_types , _karyotype_tags_n_alt
7+ from ..util import check_types
88from . import base_params
99from typing import Optional
1010
1111from .snp_data import AnophelesSnpData
1212from .karyotype_params import inversion_param
1313
1414
15- class AnophelesKaryotypeData (AnophelesSnpData ):
15+ def _karyotype_tags_n_alt (gt , alts , inversion_alts ):
16+ # could be Numba'd for speed but was already quick (not many inversion tag snps)
17+ n_sites = gt .shape [0 ]
18+ n_samples = gt .shape [1 ]
19+
20+ # create empty array
21+ inv_n_alt = np .empty ((n_sites , n_samples ), dtype = np .int8 )
22+
23+ # for every site
24+ for i in range (n_sites ):
25+ # find the index of the correct tag snp allele
26+ tagsnp_index = np .where (alts [i ] == inversion_alts [i ])[0 ]
27+
28+ for j in range (n_samples ):
29+ # count alleles which == tag snp allele and store
30+ n_tag_alleles = np .sum (gt [i , j ] == tagsnp_index [0 ])
31+ inv_n_alt [i , j ] = n_tag_alleles
32+
33+ return inv_n_alt
34+
35+
36+ class AnophelesKaryotypeAnalysis (AnophelesSnpData ):
1637 def __init__ (
1738 self ,
1839 inversion_tag_path : Optional [str ] = None ,
@@ -23,13 +44,11 @@ def __init__(
2344 # to the superclass constructor.
2445 super ().__init__ (** kwargs )
2546
26- # If provided, this analysis version will override the
27- # default value provided in the release configuration.
2847 self ._inversion_tag_path = inversion_tag_path
2948
3049 @check_types
3150 @doc (
32- summary = "Load tag SNPs for a given inversion in Ag ." ,
51+ summary = "Load tag SNPs for a given inversion." ,
3352 )
3453 def load_inversion_tags (self , inversion : inversion_param ) -> pd .DataFrame :
3554 # needs to be modified depending on where we are hosting
0 commit comments