Skip to content

Rename dimensions 'sample_x' and 'sample_y' in PC relate #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sgkit/stats/pc_relate.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def pc_relate(

:data:`sgkit.variables.pc_relate_phi_spec`: (S,S) ArrayLike
pairwise recent kinship coefficient matrix as float in [-0.5, 0.5].
The dimensions are named ``samples_0`` and ``samples_1``.

References
----------
Expand Down Expand Up @@ -173,5 +174,7 @@ def pc_relate(
phi = gramian(centered_af) / gramian(stddev)
# NOTE: phi is of shape (S x S), S = num samples
assert phi.shape == (call_g.shape[1],) * 2
new_ds = create_dataset({variables.pc_relate_phi: (("sample_x", "sample_y"), phi)})
new_ds = create_dataset(
{variables.pc_relate_phi: (("samples_0", "samples_1"), phi)}
)
return conditional_merge_datasets(ds, new_ds, merge)
4 changes: 2 additions & 2 deletions sgkit/tests/test_pc_relate.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_pc_relate__identical_sample_should_be_05() -> None:
g.call_genotype.loc[dict(samples=8)] = g.call_genotype.isel(samples=0)
phi = pc_relate(g)
assert phi.pc_relate_phi.shape == (n_samples, n_samples)
assert np.allclose(phi.pc_relate_phi.isel(sample_x=8, sample_y=0), 0.5, atol=0.1)
assert np.allclose(phi.pc_relate_phi.isel(samples_0=8, samples_1=0), 0.5, atol=0.1)


def test_pc_relate__parent_child_relationship() -> None:
Expand Down Expand Up @@ -164,7 +164,7 @@ def simulate_new_generation(ds: xr.Dataset) -> xr.Dataset:
ds["pc_relate_phi"]
.to_series()
.reset_index()
.pipe(lambda df: df.loc[df.sample_x >= df.sample_y]["pc_relate_phi"])
.pipe(lambda df: df.loc[df.samples_0 >= df.samples_1]["pc_relate_phi"])
.pipe(
pd.cut,
bins=[p for phi in [0, 0.25, 0.5] for p in [phi - 0.1, phi + 0.1]],
Expand Down