Skip to content

Commit f08cd85

Browse files
committed
changing depth per haplotype such that the same individual has the same coverage for all its chromosomes
1 parent 1d9d891 commit f08cd85

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

simGL/simGL.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ def incorporate_monomorphic(gm, pos, start, end):
3737
gm2[pos.astype(int)] = gm
3838
return gm2
3939

40-
def depth_per_haplotype(rng, mean_depth, std_depth, n_hap):
40+
def depth_per_haplotype(rng, mean_depth, std_depth, n_hap, ploidy):
4141
if isinstance(mean_depth, np.ndarray):
4242
return mean_depth
4343
else:
44-
dp = np.full((n_hap, ), 0.0)
44+
dp = np.full((n_hap//ploidy, ), 0.0)
4545
while (dp <= 0).sum():
4646
n = (dp <= 0).sum()
4747
dp[dp <= 0] = rng.normal(loc = mean_depth, scale = std_depth, size=n)
48-
return dp
48+
return dp.repeat(ploidy)
4949

5050
def refalt_int_encoding(gm, ref, alt):
5151
refalt_str = np.array([ref, alt])
@@ -122,7 +122,7 @@ def sim_allelereadcounts(gm, mean_depth, e, ploidy, seed = None, std_depth = Non
122122
err = np.array([[1-e, e/3, e/3, e/3], [e/3, 1-e, e/3, e/3], [e/3, e/3, 1-e, e/3], [e/3, e/3, e/3, 1-e]])
123123
rng = np.random.default_rng(seed)
124124
#1. Depths (DP) per haplotype (h)
125-
DPh = depth_per_haplotype(rng, mean_depth, std_depth, gm.shape[1])
125+
DPh = depth_per_haplotype(rng, mean_depth, std_depth, gm.shape[1], ploidy)
126126
#2. Sample depths (DP) per site per haplotype
127127
DP = rng.poisson(DPh, size=gm.shape)
128128
#3. Sample correct and error reads per SNP per haplotype (Rh)

0 commit comments

Comments
 (0)