Skip to content

Commit 68179d2

Browse files
authored
Merge pull request #29 from sbslee/0.8.0-dev
0.8.0 dev
2 parents 1b0ec72 + cd8bda7 commit 68179d2

13 files changed

Lines changed: 870 additions & 22 deletions

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
*********
33

4+
0.8.0 (2021-11-20)
5+
------------------
6+
7+
* Update :meth:`api.core.sort_alleles` method to also sort alleles by name for genes that do not use the star allele nomenclature (e.g. the DPYD gene).
8+
* Add new method :meth:`api.core.is_legit_allele`.
9+
* Update :meth:`api.core.predict_phenotype` method to first check if the two alleles are legit.
10+
* Add new genes: ABCB1, CYP1A1, CYP1B1, CYP4A11, CYP4A22, CYP4B1, CYP17A1, CYP19A1, G6PD, IFNL3, POR, PTGIS, SLCO1B3, SULT1A1, TBXAS1, UGT1A4, XPC.
11+
412
0.7.0 (2021-10-23)
513
------------------
614

README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ For getting help on the CLI:
185185
estimate-phase-beagle
186186
Estimate haplotype phase of observed variants with the Beagle program.
187187
filter-samples Filter Archive file for specified samples.
188-
import-read-depth Import read depth data for target gene.
188+
import-read-depth Import read depth data for the target gene.
189189
import-variants Import variant data for the target gene.
190190
plot-bam-copy-number
191191
Plot copy number profile from CovFrame[CopyNumber].
@@ -232,6 +232,13 @@ For getting help on a specific submodule (e.g. utils):
232232
>>> from pypgx.api import utils
233233
>>> help(utils)
234234
235+
For getting help on a specific method (e.g. predict_phenotype):
236+
237+
.. code:: python3
238+
239+
>>> import pypgx
240+
>>> help(pypgx.predict_phenotype)
241+
235242
CLI examples
236243
============
237244

docs/cli.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ For getting help on the CLI:
3636
estimate-phase-beagle
3737
Estimate haplotype phase of observed variants with the Beagle program.
3838
filter-samples Filter Archive file for specified samples.
39-
import-read-depth Import read depth data for target gene.
39+
import-read-depth Import read depth data for the target gene.
4040
import-variants Import variant data for the target gene.
4141
plot-bam-copy-number
4242
Plot copy number profile from CovFrame[CopyNumber].
@@ -768,7 +768,7 @@ train-cnv-caller
768768
Train a CNV caller for the target gene.
769769
770770
This command will return a SVM-based multiclass classifier that makes CNV
771-
calls using the one-vs-rest stategy.
771+
calls using the one-vs-rest strategy.
772772
773773
Positional arguments:
774774
copy-number Archive file with the semantic type

docs/create.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@
211211
>>> from pypgx.api import utils
212212
>>> help(utils)
213213
214+
For getting help on a specific method (e.g. predict_phenotype):
215+
216+
.. code:: python3
217+
218+
>>> import pypgx
219+
>>> help(pypgx.predict_phenotype)
220+
214221
CLI examples
215222
============
216223

pypgx/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
collapse_alleles,
44
has_phenotype,
55
has_score,
6+
is_legit_allele,
67
is_target_gene,
78
get_default_allele,
89
get_function,

pypgx/api/core.py

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414

1515
FUNCTION_ORDER = [
1616
'No Function',
17+
'Severely Decreased Function',
1718
'Decreased Function',
1819
'Possible Decreased Function',
1920
'Increased Function',
2021
'Possible Increased Function',
22+
'Class I (Deficient with CNSHA)',
23+
'Class II (Deficient)',
24+
'Class III (Deficient)',
2125
'Uncertain Function',
2226
'Unknown Function',
2327
'Normal Function',
28+
'Class IV (Normal)',
2429
]
2530

2631
class AlleleNotFoundError(Exception):
@@ -202,6 +207,24 @@ def has_score(gene):
202207

203208
return gene in df[df.PhenotypeMethod == 'Score'].Gene.unique()
204209

210+
def is_legit_allele(gene, allele):
211+
"""
212+
Return True if specified allele exists in the allele table.
213+
214+
Parameters
215+
----------
216+
gene : str
217+
Target gene.
218+
allele : str
219+
Allele to be tested.
220+
221+
Returns
222+
-------
223+
bool
224+
True if the allele is legit.
225+
"""
226+
return allele in list_alleles(gene)
227+
205228
def is_target_gene(gene):
206229
"""
207230
Return True if specified gene is one of the target genes.
@@ -465,7 +488,7 @@ def get_score(gene, allele):
465488
df = df[(df.Gene == gene) & (df.StarAllele == allele)]
466489

467490
if df.empty:
468-
raise AlleleNotFoundError(gene + allele)
491+
raise AlleleNotFoundError(gene, allele)
469492

470493
return df.ActivityScore.values[0]
471494

@@ -960,6 +983,10 @@ def one_row(r, score):
960983
elif phenotype_method == 'Diplotype':
961984
df = load_diplotype_table()
962985
df = df[df.Gene == gene]
986+
if not is_legit_allele(gene, a):
987+
raise AlleleNotFoundError(gene, a)
988+
if not is_legit_allele(gene, b):
989+
raise AlleleNotFoundError(gene, b)
963990
l = [f'{a}/{b}', f'{b}/{a}']
964991
i = df.Diplotype.isin(l)
965992
try:
@@ -1095,7 +1122,7 @@ def sort_alleles(
10951122
10961123
>>> alleles = ['*1', '*2', '*4', '*10']
10971124
1098-
We can sort them by their prioirty with ``method='priority'``:
1125+
We can sort the alleles by their prioirty with ``method='priority'``:
10991126
11001127
>>> import pypgx
11011128
>>> alleles = pypgx.sort_alleles(alleles, by='priority', gene='CYP2D6', assembly='GRCh37')
@@ -1107,8 +1134,17 @@ def sort_alleles(
11071134
>>> alleles = pypgx.sort_alleles(alleles, by='name')
11081135
>>> alleles
11091136
['*1', '*2', '*4', '*10']
1137+
1138+
Note that we can also sort alleles by name for genes that do not use the
1139+
star allele nomenclature (e.g. the *DPYD* gene):
1140+
1141+
>>> alleles = ['c.557A>G', 'c.2194G>A (*6)', 'c.496A>G', 'Reference', 'c.1627A>G (*5)']
1142+
>>> pypgx.sort_alleles(alleles, by='name')
1143+
['Reference', 'c.496A>G', 'c.557A>G', 'c.1627A>G (*5)', 'c.2194G>A (*6)']
11101144
"""
11111145
def func1(allele):
1146+
if gene is None:
1147+
raise ValueError('Gene is required when sorting by priority')
11121148
if not is_target_gene(gene):
11131149
raise NotTargetGeneError(gene)
11141150
function = get_function(gene, allele)
@@ -1122,13 +1158,18 @@ def func1(allele):
11221158
return (a, b, c, d)
11231159

11241160
def func2(allele):
1161+
n = 99999
11251162
cn = 1
1126-
if '*' not in allele:
1127-
n = 999
1163+
if allele == 'Reference':
1164+
n = 0
1165+
elif 'c.' in allele: # For the DPYD gene
1166+
n = int(''.join([x for x in allele.split('>')[0] if x.isdigit()]))
1167+
elif '*' not in allele:
1168+
pass
11281169
else:
11291170
_ = allele.split('+')[0].split('x')[0].replace('*', '')
11301171
if not _[0].isdigit():
1131-
n = 999
1172+
pass
11321173
else:
11331174
n = int(''.join([x for x in _ if x.isdigit()]))
11341175
if 'x' in allele.split('+')[0]:

0 commit comments

Comments
 (0)