|
1 | | -from collections import Counter |
2 | 1 | from typing import Optional, Tuple, Dict, Mapping |
3 | 2 |
|
4 | 3 | import allel # type: ignore |
|
7 | 6 | import bokeh.plotting |
8 | 7 |
|
9 | 8 | from .hap_data import AnophelesHapData |
10 | | -from ..util import hash_columns, check_types, CacheMiss |
| 9 | +from ..util import check_types, CacheMiss, haplotype_frequencies |
11 | 10 | from . import base_params |
12 | 11 | from . import h12_params, gplt_params, hap_params |
13 | 12 |
|
@@ -515,21 +514,11 @@ def plot_h12_gwss( |
515 | 514 | return fig |
516 | 515 |
|
517 | 516 |
|
518 | | -def haplotype_frequencies(h): |
519 | | - """Compute haplotype frequencies, returning a dictionary that maps |
520 | | - haplotype hash values to frequencies.""" |
521 | | - n = h.shape[1] |
522 | | - hashes = hash_columns(np.asarray(h)) |
523 | | - counts = Counter(hashes) |
524 | | - freqs = {key: count / n for key, count in counts.items()} |
525 | | - return freqs |
526 | | - |
527 | | - |
528 | 517 | def garud_h12(ht): |
529 | 518 | """Compute Garud's H12.""" |
530 | 519 |
|
531 | 520 | # Compute haplotype frequencies. |
532 | | - frq_counter = haplotype_frequencies(ht) |
| 521 | + frq_counter, _, _ = haplotype_frequencies(ht) |
533 | 522 |
|
534 | 523 | # Convert to array of sorted frequencies. |
535 | 524 | f = np.sort(np.fromiter(frq_counter.values(), dtype=float))[::-1] |
|
0 commit comments