Skip to content

Commit f87e0da

Browse files
committed
Addressing comments
1 parent 6649eca commit f87e0da

File tree

7 files changed

+35
-52
lines changed

7 files changed

+35
-52
lines changed

malariagen_data/anoph/karyotype.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,36 @@
44
import allel # type: ignore
55

66
from numpydoc_decorator import doc
7-
from ..util import check_types, _karyotype_tags_n_alt
7+
from ..util import check_types
88
from . import base_params
99
from typing import Optional
1010

1111
from .snp_data import AnophelesSnpData
1212
from .karyotype_params import inversion_param
1313

1414

15-
class AnophelesKaryotypeData(AnophelesSnpData):
15+
def _karyotype_tags_n_alt(gt, alts, inversion_alts):
16+
# could be Numba'd for speed but was already quick (not many inversion tag snps)
17+
n_sites = gt.shape[0]
18+
n_samples = gt.shape[1]
19+
20+
# create empty array
21+
inv_n_alt = np.empty((n_sites, n_samples), dtype=np.int8)
22+
23+
# for every site
24+
for i in range(n_sites):
25+
# find the index of the correct tag snp allele
26+
tagsnp_index = np.where(alts[i] == inversion_alts[i])[0]
27+
28+
for j in range(n_samples):
29+
# count alleles which == tag snp allele and store
30+
n_tag_alleles = np.sum(gt[i, j] == tagsnp_index[0])
31+
inv_n_alt[i, j] = n_tag_alleles
32+
33+
return inv_n_alt
34+
35+
36+
class AnophelesKaryotypeAnalysis(AnophelesSnpData):
1637
def __init__(
1738
self,
1839
inversion_tag_path: Optional[str] = None,
@@ -23,13 +44,11 @@ def __init__(
2344
# to the superclass constructor.
2445
super().__init__(**kwargs)
2546

26-
# If provided, this analysis version will override the
27-
# default value provided in the release configuration.
2847
self._inversion_tag_path = inversion_tag_path
2948

3049
@check_types
3150
@doc(
32-
summary="Load tag SNPs for a given inversion in Ag.",
51+
summary="Load tag SNPs for a given inversion.",
3352
)
3453
def load_inversion_tags(self, inversion: inversion_param) -> pd.DataFrame:
3554
# needs to be modified depending on where we are hosting
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Parameter definitions for karyotype analysis functions."""
22

3-
from typing import Literal
43

54
from typing_extensions import Annotated, TypeAlias
65

76
inversion_param: TypeAlias = Annotated[
8-
Literal["2La", "2Rb", "2Rc_gam", "2Rc_col", "2Rd", "2Rj"],
7+
str,
98
"Name of inversion to infer karyotype for.",
109
]

malariagen_data/anopheles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
plotly_params,
3030
xpehh_params,
3131
)
32-
from .anoph.karyotype import AnophelesKaryotypeData
32+
from .anoph.karyotype import AnophelesKaryotypeAnalysis
3333
from .anoph.aim_data import AnophelesAimData
3434
from .anoph.base import AnophelesBase
3535
from .anoph.cnv_data import AnophelesCnvData
@@ -95,7 +95,7 @@ class AnophelesDataResource(
9595
AnophelesPca,
9696
PlinkConverter,
9797
AnophelesIgv,
98-
AnophelesKaryotypeData,
98+
AnophelesKaryotypeAnalysis,
9999
AnophelesAimData,
100100
AnophelesHapData,
101101
AnophelesSnpData,

malariagen_data/util.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,27 +1591,6 @@ def distributed_client():
15911591
return client
15921592

15931593

1594-
def _karyotype_tags_n_alt(gt, alts, inversion_alts):
1595-
# could be Numba'd for speed but was already quick (not many inversion tag snps)
1596-
n_sites = gt.shape[0]
1597-
n_samples = gt.shape[1]
1598-
1599-
# create empty array
1600-
inv_n_alt = np.empty((n_sites, n_samples), dtype=np.int8)
1601-
1602-
# for every site
1603-
for i in range(n_sites):
1604-
# find the index of the correct tag snp allele
1605-
tagsnp_index = np.where(alts[i] == inversion_alts[i])[0]
1606-
1607-
for j in range(n_samples):
1608-
# count alleles which == tag snp allele and store
1609-
n_tag_alleles = np.sum(gt[i, j] == tagsnp_index[0])
1610-
inv_n_alt[i, j] = n_tag_alleles
1611-
1612-
return inv_n_alt
1613-
1614-
16151594
def prep_samples_for_cohort_grouping(*, df_samples, area_by, period_by):
16161595
# Take a copy, as we will modify the dataframe.
16171596
df_samples = df_samples.copy()

notebooks/karyotype.ipynb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,6 @@
359359
"source": [
360360
"ag3.plot_pca_coords(pca_df_2rc_col, color=\"karyotype_2Rc_col\", symbol=\"country\", width=600, height=500)"
361361
]
362-
},
363-
{
364-
"cell_type": "code",
365-
"execution_count": null,
366-
"id": "d6fb7237-bb4e-490e-9ae0-33a52d4fa650",
367-
"metadata": {},
368-
"outputs": [],
369-
"source": []
370362
}
371363
],
372364
"metadata": {
@@ -391,7 +383,7 @@
391383
"name": "python",
392384
"nbconvert_exporter": "python",
393385
"pygments_lexer": "ipython3",
394-
"version": "3.10.12"
386+
"version": "3.10.11"
395387
}
396388
},
397389
"nbformat": 4,

tests/integration/test_af1.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,9 @@ def test_locate_region(region_raw):
8484
def test_karyotyping(inversion):
8585
af1 = setup_af1()
8686

87-
if inversion == "X_x":
88-
with pytest.raises(TypeError):
89-
af1.karyotype(
90-
inversion=inversion, sample_sets="AG1000G-GH", sample_query=None
91-
)
92-
else:
93-
with pytest.raises(FileNotFoundError):
94-
af1.karyotype(
95-
inversion=inversion,
96-
sample_sets="1229-VO-GH-DADZIE-VMF00095",
97-
sample_query=None,
98-
)
87+
with pytest.raises(FileNotFoundError):
88+
af1.karyotype(
89+
inversion=inversion,
90+
sample_sets="1229-VO-GH-DADZIE-VMF00095",
91+
sample_query=None,
92+
)

tests/integration/test_ag3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_karyotyping(inversion):
167167
ag3 = setup_ag3(cohorts_analysis="20230516")
168168

169169
if inversion == "X_x":
170-
with pytest.raises(TypeError):
170+
with pytest.raises(ValueError):
171171
ag3.karyotype(
172172
inversion=inversion, sample_sets="AG1000G-GH", sample_query=None
173173
)

0 commit comments

Comments
 (0)