Skip to content

Commit 08c2d5f

Browse files
Merge pull request #174 from hyanwong/document-sd-haplotypes
Include docs for SampleData.haplotypes()
2 parents bf8bc5d + f630262 commit 08c2d5f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

tsinfer/formats.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,13 +1180,11 @@ def finalise(self):
11801180
def genotypes(self, inference_sites=None):
11811181
"""
11821182
Returns an iterator over the (site_id, genotypes) pairs.
1183-
If ``inference_sites`` is ``None``, return genotypes for all sites.
1184-
If ``inference_sites`` is ``True``, return only genotypes at sites that have
1185-
been marked for inference; if ``False``, return only genotypes at sites
1186-
that are not marked for inference.
11871183
1188-
:param bool inference_sites: Control the sites that we return genotypes
1189-
for.
1184+
:param bool inference_sites: Control the sites for which genotypes are returned.
1185+
If ``None``, return genotypes for all sites; if ``True``, return only
1186+
genotypes at sites that have been marked for inference; if ``False``, return
1187+
only genotypes at sites that are not marked for inference.
11901188
"""
11911189
inference = self.sites_inference[:]
11921190
for j, a in enumerate(chunk_iterator(self.sites_genotypes)):
@@ -1198,13 +1196,10 @@ def variants(self, inference_sites=None):
11981196
Returns an iterator over the Variant objects. This is equivalent to
11991197
the TreeSequence.variants iterator.
12001198
1201-
If ``inference_sites`` is ``None``, return variants for all sites.
1202-
If ``inference_sites`` is ``True``, return only variants at sites that have
1203-
been marked for inference; if ``False``, return only genotypes at sites
1204-
that are not marked for inference.
1205-
1206-
:param bool inference_sites: Control the sites that we return variants
1207-
for.
1199+
:param bool inference_sites: Control the sites for which variants are returned.
1200+
If ``None``, return genotypes for all sites; if ``True``, return only
1201+
genotypes at sites that have been marked for inference; if ``False``, return
1202+
only genotypes at sites that are not marked for inference.
12081203
"""
12091204
position = self.sites_position[:]
12101205
alleles = self.sites_alleles[:]
@@ -1236,6 +1231,20 @@ def __all_haplotypes(self, inference_sites=None):
12361231
yield j, a[selection]
12371232

12381233
def haplotypes(self, samples=None, inference_sites=None):
1234+
"""
1235+
Returns an iterator over the (sample_id, haplotype) pairs.
1236+
1237+
:param list samples: The sample IDs for which haplotypes are returned. If
1238+
``None``, return haplotypes for all sample nodes, otherwise this may be a
1239+
numpy array (or array-like) object (converted to dtype=np.int32).
1240+
:param bool inference_sites: Control the sites included in each haplotype. If
1241+
``inference_sites`` is ``None``, each returned haplotype includes all sampled
1242+
sites and is thus of length ``num_sites``. Otherwise, if ``inference_sites``
1243+
is ``True`` each haplotype includes only sites that have been marked for
1244+
inference, if ``False``, only sites that are not marked for inference: in
1245+
both cases the haplotype arrays may thus be less than ``num_sites`` long.
1246+
1247+
"""
12391248
if samples is None:
12401249
samples = np.arange(self.num_samples)
12411250
else:

0 commit comments

Comments
 (0)