-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplifying and unifying dispatch a good bit across packages #24
- Loading branch information
1 parent
c86157e
commit 1700044
Showing
10 changed files
with
213 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
from .core import * | ||
from .core import ( | ||
GeneticDataset, | ||
GenotypeAlleleCountDataset, | ||
GenotypeCallDataset, | ||
GenotypeCountDataset, | ||
GenotypeDosageDataset, | ||
GenotypeProbabilityDataset | ||
) | ||
|
||
from .config import config | ||
|
||
from . import io | ||
from .io import ( | ||
from .io.core import ( | ||
read_plink, | ||
write_zarr | ||
) | ||
from .config import config | ||
|
||
from . import stats | ||
from .stats.core import ( | ||
ld_matrix | ||
) | ||
|
||
from . import method | ||
from .method.core import ( | ||
ld_prune | ||
) | ||
|
||
from . import graph | ||
from .graph.core import ( | ||
maximal_independent_set | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from .core import * | ||
|
||
from . import numba_backend | ||
|
||
# TODO: Add when ready | ||
# try: | ||
# from . import networkx_backend | ||
# except ImportError: | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Graph API""" | ||
from ..dispatch import register_function | ||
|
||
|
||
DOMAIN = 'graph' | ||
|
||
|
||
@register_function(DOMAIN) | ||
def maximal_independent_set(df): | ||
"""Maximal Independent Set""" | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from lib.io.core import * | ||
from .core import * | ||
|
||
# Choose the backends to register | ||
import lib.io.pysnptools_backend | ||
try: | ||
from . import pysnptools_backend | ||
except ImportError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .core import * | ||
|
||
try: | ||
from .ld_prune import dask_backend | ||
except ImportError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from ..dispatch import register_function | ||
from xarray import Dataset | ||
from typing import Optional | ||
|
||
DOMAIN = 'method' | ||
|
||
@register_function(DOMAIN) | ||
def ld_prune( | ||
ldm: 'DataFrame', | ||
use_cmp: bool = True | ||
): | ||
"""LD Prune | ||
Prune variants within a dataset using a sparse LD matrix to find a | ||
maximally independent set (MIS). | ||
Note: This result is not a true MIS if `use_cmp` is True and was based on MAF scores | ||
(or anything else) provided during pair-wise LD matrix evaluation, or if those scores | ||
were not all identical (it is otherwise). | ||
Parameters | ||
---------- | ||
ldm : DataFrame | ||
LD matrix from `ld_matrix` | ||
use_cmp : bool | ||
Whether or not to use precomputed score-based comparisons | ||
TODO: wire this up in MIS | ||
Returns | ||
------- | ||
array | ||
Array with indexes of rows that should be removed | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .core import * | ||
|
||
try: | ||
from .ld_matrix import dask_backend | ||
except ImportError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from ..dispatch import register_function | ||
from xarray import Dataset | ||
from typing import Optional | ||
|
||
DOMAIN = 'stats' | ||
|
||
@register_function(DOMAIN) | ||
def ld_matrix( | ||
ds: Dataset, | ||
window: int = 1_000_000, | ||
threshold: float = 0.2, | ||
step: Optional[int] = None, | ||
groups='contig', | ||
positions='pos', | ||
scores=None, | ||
**kwargs | ||
): | ||
"""Compute Sparse LD Matrix (for tall-skinny matrices only at the moment) | ||
This method works by first computing all overlapping variant ranges | ||
and then breaking up necessary pariwise comparisons into approximately | ||
equal sized chunks (along dimension 0). These chunks are exactly equal | ||
in size when windows are of fixed size but vary based on variant density | ||
when using base pair ranges. For each pair of variants in a window, | ||
R2 is calculated and only those exceeding the provided threshold are returned. | ||
Parameters | ||
---------- | ||
window : int | ||
Size of window for LD comparisons (between rows). This is either in base pairs | ||
if `positions` is not None or is a fixed window size otherwise. By default this | ||
is 1,000,000 (1,000 kbp) | ||
threshold : float | ||
R2 threshold below which no variant pairs will be returned. This should almost | ||
always be something at least slightly above 0 to avoid the large density very | ||
near zero LD present in most datasets. Defaults to 0.2 | ||
step : optional | ||
Fixed step size to move each window by. Has no effect when `positions` is provided | ||
and must be provided when base pair ranges are not being used. | ||
groups : str or array-like, optional | ||
Name of field to use to represent disconnected components (typically contigs). Will | ||
be used directly if provided as an array and otherwise fetched from | ||
`ds` if given as a variable name. | ||
positions : str or array-like, optional | ||
Name of field to use to represent base pair positions. Will | ||
be used directly if provided as an array and otherwise fetched from | ||
`ds` if given as a variable name. | ||
scores : [type], optional | ||
Name of field to use to prioritize variant selection (e.g. MAF). Will | ||
be used directly if provided as an array and otherwise fetched from | ||
`ds` if given as a variable name. | ||
return_intervals : bool | ||
Whether or not to also return the variant interval calculations (which can be | ||
useful for analyzing variant density), by default False | ||
**kwargs | ||
Backend-specific options | ||
Returns | ||
------- | ||
DataFrame or (DataFrame, (DataFrame, DataFrame)) | ||
Upper triangle (including diagonal) of LD matrix as COO in dataframe. Fields: | ||
`i`: Row (variant) index 1 | ||
`j`: Row (variant) index 2 | ||
`value`: R2 value | ||
`cmp`: If scores are provided, this is 1, 0, or -1 indicating whether or not | ||
i > j (1), i < j (-1), or i == j (0) | ||
When `return_intervals` is True, the second tuple contains the results from | ||
`axis_intervals` | ||
""" | ||
pass |