Skip to content

Commit d78b045

Browse files
Rename encode_alignments to encode_alleles
1 parent 239f081 commit d78b045

File tree

8 files changed

+15
-16
lines changed

8 files changed

+15
-16
lines changed

docs/alignments_analysis.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ The drawback of this is that it's not as easy to inspect and debug, and we must
146146
always be aware of the translation required.
147147

148148
Sc2ts provides some utilities for doing this. The easiest way to get the string
149-
values is to use {func}`decode_alignment` function:
149+
values is to use {func}`decode_alleles` function:
150150

151151
```{code-cell}
152-
a = sc2ts.decode_alignment(ds.alignment["SRR11597146"])
152+
a = sc2ts.decode_alleles(ds.alignment["SRR11597146"])
153153
a
154154
```
155155
This is a numpy string array, which can still be processed quite efficiently.
@@ -179,7 +179,6 @@ easily and handled correctly by downstream utilities.
179179
:::{warning}
180180
It is important to take this into account when translating the integer encoded data into
181181
strings, because -1 is interpreted as the last element of the list in Python. Please
182-
use the {func}`decode_alignment` function
183-
182+
use the {func}`decode_alleles` function to avoid this tripwire.
184183
:::
185184

docs/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ notebooks.
3535
```{eval-rst}
3636
.. autosummary::
3737
Dataset
38-
decode_alignment
38+
decode_alleles
3939
mask_ambiguous
4040
mask_flanking_deletions
4141
```
@@ -44,7 +44,7 @@ notebooks.
4444
.. autoclass:: Dataset
4545
:members:
4646
47-
.. autofunction:: decode_alignment
47+
.. autofunction:: decode_alleles
4848
4949
.. autofunction:: mask_ambiguous
5050

sc2ts/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def import_alignments(dataset, fastas, initialise, progress, verbose):
157157
position=1,
158158
)
159159
for k, v in a_bar:
160-
alignments[k] = jit.encode_alignment(v)
160+
alignments[k] = jit.encode_alleles(v)
161161
sc2ts.Dataset.append_alignments(dataset, alignments)
162162

163163

sc2ts/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def write_fasta(self, out, sample_id=None):
414414

415415
for sid in sample_id:
416416
h = self.alignment[sid]
417-
a = decode_alignment(h)
417+
a = decode_alleles(h)
418418
print(f">{sid}", file=out)
419419
# FIXME this is probably a terrible way to write a large numpy string to
420420
# a file

sc2ts/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,10 @@ def make_tsb(ts, num_alleles, mirror_coordinates=False):
12271227
ts = tree_ops.insert_vestigial_root_edge(ts)
12281228

12291229
# Convert arrays for numba compatibility
1230-
ancestral_state = jit.encode_alignment(
1230+
ancestral_state = jit.encode_alleles(
12311231
np.asarray(ts.sites_ancestral_state, dtype="U1")
12321232
)
1233-
derived_state = jit.encode_alignment(
1233+
derived_state = jit.encode_alleles(
12341234
np.asarray(ts.mutations_derived_state, dtype="U1")
12351235
)
12361236

sc2ts/jit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def count(ts):
203203

204204
# FIXME make cache optional.
205205
@numba.njit(cache=True)
206-
def encode_alignment(h):
206+
def encode_alleles(h):
207207
# Just so numba knows this is a constant string.
208208
alleles = "ACGT-RYSWKMBDHV."
209209
n = h.shape[0]

tests/sc2ts_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def encoded_alignments(path):
4747
fr = data_import.FastaReader(path)
4848
alignments = {}
4949
for k, v in fr.items():
50-
alignments[k] = jit.encode_alignment(v[1:])
50+
alignments[k] = jit.encode_alleles(v[1:])
5151
return alignments
5252

5353

tests/test_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,14 @@ class TestEncodeAlignment:
550550
)
551551
def test_examples(self, hap, expected):
552552
h = np.array(list(hap), dtype="U1")
553-
a = jit.encode_alignment(h)
553+
a = jit.encode_alleles(h)
554554
nt.assert_array_equal(a, expected)
555555

556556
@pytest.mark.parametrize("hap", "acgtXZxz")
557557
def test_other_error(self, hap):
558558
h = np.array(list(hap), dtype="U1")
559559
with pytest.raises(ValueError, match="not recognised"):
560-
jit.encode_alignment(h)
560+
jit.encode_alleles(h)
561561

562562

563563
class TestDecodeAlleles:
@@ -609,6 +609,6 @@ class TestMaskFlankingDeletions:
609609
],
610610
)
611611
def test_examples(self, nucs, expected):
612-
a = jit.encode_alignment(np.array(list(nucs), dtype="U1"))
613-
b = jit.encode_alignment(np.array(list(expected), dtype="U1"))
612+
a = jit.encode_alleles(np.array(list(nucs), dtype="U1"))
613+
b = jit.encode_alleles(np.array(list(expected), dtype="U1"))
614614
nt.assert_array_equal(sc2ts.mask_flanking_deletions(a), b)

0 commit comments

Comments
 (0)