admix-kit 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- admix/__init__.py +17 -0
- admix/_logging.py +3 -0
- admix/ancestry/__init__.py +4 -0
- admix/ancestry/_local.py +107 -0
- admix/ancestry/_wrapper.py +48 -0
- admix/assoc/__init__.py +657 -0
- admix/assoc/_fast.py +118 -0
- admix/cli/__init__.py +43 -0
- admix/cli/_assoc.py +132 -0
- admix/cli/_ext.py +360 -0
- admix/cli/_genet_cor.py +620 -0
- admix/cli/_geno.py +442 -0
- admix/cli/_lanc.py +175 -0
- admix/cli/_plot.py +109 -0
- admix/cli/_simulate.py +182 -0
- admix/cli/_utils.py +318 -0
- admix/data/__init__.py +38 -0
- admix/data/_geno.py +699 -0
- admix/data/_lanc.py +817 -0
- admix/data/_misc.py +41 -0
- admix/data/_stats.py +236 -0
- admix/data/_utils.py +413 -0
- admix/dataset/__init__.py +12 -0
- admix/dataset/_dataset.py +373 -0
- admix/dataset/_index.py +141 -0
- admix/dataset/_load.py +433 -0
- admix/dataset/_utils.py +107 -0
- admix/estimate/__init__.py +5 -0
- admix/estimate/_admix_gen_cor.py +113 -0
- admix/estimate/_genetic_cor.py +120 -0
- admix/estimate/_utils.py +42 -0
- admix/estimate/_var_component.py +313 -0
- admix/io/__init__.py +10 -0
- admix/io/_read.py +413 -0
- admix/io/_write.py +138 -0
- admix/plot/__init__.py +14 -0
- admix/plot/_plot.py +625 -0
- admix/predict/__init__.py +27 -0
- admix/predict/_utils.py +1 -0
- admix/simulate/__init__.py +15 -0
- admix/simulate/_geno.py +290 -0
- admix/simulate/_lanc.py +135 -0
- admix/simulate/_pheno.py +454 -0
- admix/tools/__init__.py +19 -0
- admix/tools/_standalone.py +486 -0
- admix/tools/_utils.py +249 -0
- admix/tools/gcta.py +289 -0
- admix/tools/liftover.py +85 -0
- admix/tools/plink.py +136 -0
- admix/tools/plink2.py +556 -0
- admix/utils.py +47 -0
- admix/version.py +1 -0
- admix_kit-0.1.4.dist-info/METADATA +83 -0
- admix_kit-0.1.4.dist-info/RECORD +57 -0
- admix_kit-0.1.4.dist-info/WHEEL +5 -0
- admix_kit-0.1.4.dist-info/entry_points.txt +2 -0
- admix_kit-0.1.4.dist-info/top_level.txt +1 -0
admix/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from ._logging import logger
|
|
2
|
+
from .dataset import Dataset
|
|
3
|
+
from . import data, dataset, simulate, ancestry, plot, assoc, estimate, tools, io, cli
|
|
4
|
+
from .version import __version__
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"data",
|
|
8
|
+
"simulate",
|
|
9
|
+
"ancestry",
|
|
10
|
+
"plot",
|
|
11
|
+
"assoc",
|
|
12
|
+
"estimate",
|
|
13
|
+
"tools",
|
|
14
|
+
"io",
|
|
15
|
+
"cli",
|
|
16
|
+
"Dataset",
|
|
17
|
+
]
|
admix/_logging.py
ADDED
admix/ancestry/_local.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from typing import List
|
|
3
|
+
import admix
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
This will be the interface to call various local ancestry inference methods
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def lanc_single_chrom(
|
|
11
|
+
sample_dset: admix.Dataset,
|
|
12
|
+
ref_dsets: List[admix.Dataset],
|
|
13
|
+
method="lampld",
|
|
14
|
+
n_proto=6,
|
|
15
|
+
window_size=300,
|
|
16
|
+
):
|
|
17
|
+
"""Local ancestry inference for data sets of single chromosome
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
sample_dset : admix.Dataset
|
|
22
|
+
dataset of the sample to be inferred
|
|
23
|
+
ref_dsets : List[admix.Dataset]
|
|
24
|
+
dataset of the reference panel
|
|
25
|
+
method : str, optional
|
|
26
|
+
method used to perform local ancestry inference, by default "lampld"
|
|
27
|
+
n_proto : int, optional
|
|
28
|
+
number of prototypes used in lampld, by default 6
|
|
29
|
+
window_size : int, optional
|
|
30
|
+
"""
|
|
31
|
+
from pylampld import LampLD
|
|
32
|
+
|
|
33
|
+
assert method in ["lampld"]
|
|
34
|
+
assert len(sample_dset.snp.CHROM.unique()), "Datasets are not of single chromosome"
|
|
35
|
+
assert admix.dataset.is_aligned(
|
|
36
|
+
[sample_dset, *ref_dsets]
|
|
37
|
+
), "Datasets are not aligned"
|
|
38
|
+
|
|
39
|
+
n_anc = len(ref_dsets)
|
|
40
|
+
n_snp = sample_dset.n_snp
|
|
41
|
+
|
|
42
|
+
model = LampLD(n_snp=n_snp, n_anc=n_anc, n_proto=n_proto, window_size=window_size)
|
|
43
|
+
ref_list = [
|
|
44
|
+
np.vstack(
|
|
45
|
+
[
|
|
46
|
+
dset.geno[:, :, 0].T,
|
|
47
|
+
dset.geno[:, :, 1].T,
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
for dset in ref_dsets
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
model.set_pos(sample_dset.snp.POS.values)
|
|
54
|
+
model.fit(ref_list)
|
|
55
|
+
|
|
56
|
+
est = np.dstack(
|
|
57
|
+
[
|
|
58
|
+
model.infer_lanc(sample_dset.geno[:, :, 0].T.compute()),
|
|
59
|
+
model.infer_lanc(sample_dset.geno[:, :, 1].T.compute()),
|
|
60
|
+
]
|
|
61
|
+
)
|
|
62
|
+
return np.swapaxes(est.astype(np.int8), 0, 1)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def lanc(
|
|
66
|
+
sample_dset: admix.Dataset,
|
|
67
|
+
ref_dsets: List[admix.Dataset],
|
|
68
|
+
method="lampld",
|
|
69
|
+
n_proto=6,
|
|
70
|
+
window_size=300,
|
|
71
|
+
) -> np.ndarray:
|
|
72
|
+
"""Local ancestry inference
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
----------
|
|
76
|
+
sample_dset : admix.Dataset
|
|
77
|
+
dataset of the sample to be inferred
|
|
78
|
+
ref_dsets : List[admix.Dataset]
|
|
79
|
+
dataset of the reference panel
|
|
80
|
+
method : str, optional
|
|
81
|
+
method used to perform local ancestry inference, by default "lampld"
|
|
82
|
+
n_proto : int, optional
|
|
83
|
+
number of prototypes used in lampld, by default 6
|
|
84
|
+
window_size : int, optional
|
|
85
|
+
window size used in local ancestry inference, by default 100
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
np.ndarray
|
|
90
|
+
Estimated local ancestries
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
assert method in ["lampld"]
|
|
94
|
+
chrom_list = sample_dset.snp.CHROM.unique()
|
|
95
|
+
lanc = []
|
|
96
|
+
for chrom in chrom_list:
|
|
97
|
+
chrom_sample_dset = sample_dset[(sample_dset.snp.CHROM == chrom).values]
|
|
98
|
+
chrom_ref_dsets = [dset[(dset.snp.CHROM == chrom).values] for dset in ref_dsets]
|
|
99
|
+
chrom_lanc = lanc_single_chrom(
|
|
100
|
+
chrom_sample_dset,
|
|
101
|
+
chrom_ref_dsets,
|
|
102
|
+
method=method,
|
|
103
|
+
n_proto=n_proto,
|
|
104
|
+
window_size=window_size,
|
|
105
|
+
)
|
|
106
|
+
lanc.append(chrom_lanc)
|
|
107
|
+
return np.concatenate(lanc, axis=0)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import tempfile
|
|
4
|
+
from os.path import join
|
|
5
|
+
import subprocess
|
|
6
|
+
from ..io import read_digit_mat, write_digit_mat
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def lampld_wrapper(
|
|
10
|
+
ref_hap_list,
|
|
11
|
+
sample_hap,
|
|
12
|
+
snp_pos,
|
|
13
|
+
window_size=300,
|
|
14
|
+
n_proto=6,
|
|
15
|
+
bin_dir="/u/project/pasaniuc/kangchen/admix-tools/cache/LAMPLD-v1.3/bin/",
|
|
16
|
+
):
|
|
17
|
+
tmp = tempfile.TemporaryDirectory()
|
|
18
|
+
tmp_dir = tmp.name
|
|
19
|
+
|
|
20
|
+
assert len(ref_hap_list) in [2, 3], "Currently only support 2-way / 3-way ancestry"
|
|
21
|
+
for ref_i in range(len(ref_hap_list)):
|
|
22
|
+
write_digit_mat(join(tmp_dir, f"ref{ref_i}.hap"), ref_hap_list[ref_i])
|
|
23
|
+
write_digit_mat(join(tmp_dir, "sample.hap"), sample_hap)
|
|
24
|
+
np.savetxt(join(tmp_dir, "pos.txt"), snp_pos, fmt="%s")
|
|
25
|
+
|
|
26
|
+
if len(ref_hap_list) == 2:
|
|
27
|
+
bin_path = join(bin_dir, "haplanc2way")
|
|
28
|
+
elif len(ref_hap_list) == 3:
|
|
29
|
+
bin_path = join(bin_dir, "haplanc")
|
|
30
|
+
else:
|
|
31
|
+
raise NotImplementedError
|
|
32
|
+
cmd = " ".join(
|
|
33
|
+
[
|
|
34
|
+
bin_path,
|
|
35
|
+
str(window_size),
|
|
36
|
+
str(n_proto),
|
|
37
|
+
join(tmp_dir, "pos.txt"),
|
|
38
|
+
*[join(tmp_dir, f"ref{ref_i}.hap") for ref_i in range(len(ref_hap_list))],
|
|
39
|
+
join(tmp_dir, "sample.hap"),
|
|
40
|
+
join(tmp_dir, "out.txt"),
|
|
41
|
+
str(1),
|
|
42
|
+
]
|
|
43
|
+
)
|
|
44
|
+
print(cmd)
|
|
45
|
+
subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
|
46
|
+
infer_lanc = read_digit_mat(join(tmp_dir, "out.txt"))
|
|
47
|
+
tmp.cleanup()
|
|
48
|
+
return infer_lanc
|