Skip to content

Commit

Permalink
support for subset of samples and individuals in a tree
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbin973 committed Nov 20, 2024
1 parent 81cbecf commit 7ca6452
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -8591,7 +8591,17 @@ def genetic_relatedness_vector(
nodes=nodes,
)
return out

def _expand_indices(self,
x: np.ndarray,
indices: np.ndarray
) -> np.ndarray:
y = np.zeros((self.num_samples, x.shape[1]))
y[indices] = x

return y


def _genetic_relatedness_vector_node(
self,
arr: np.ndarray,
Expand All @@ -8601,6 +8611,7 @@ def _genetic_relatedness_vector_node(
windows = None,
) -> np.ndarray:
x = arr - arr.mean(axis=0) if centre else arr
x = self._expand_indices(x, indices)
x = self.genetic_relatedness_vector(
W=x, windows=windows, mode=mode, centre=False, nodes=indices,
)[0]
Expand All @@ -8627,11 +8638,11 @@ def _genetic_relatedness_vector_individual(
ij[:, 0],
ij[:, 1],
)
x = (
arr - arr.mean(axis=0) if centre else arr
) # centering within index in rows
x = arr - arr.mean(axis=0) if centre else arr
x = x[sample_individuals]
x = self._expand_indices(x, samples)
x = self.genetic_relatedness_vector(
W=x[sample_individuals],
W=x,
windows=windows,
mode=mode,
centre=False,
Expand Down

0 comments on commit 7ca6452

Please sign in to comment.