Skip to content

Commit

Permalink
Merge pull request #134 from CAST-genomics/feat/actions
Browse files Browse the repository at this point in the history
dep: remove myst-parser
  • Loading branch information
aryarm authored Nov 3, 2022
2 parents 9eabfce + 23a8f44 commit 58d171c
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 235 deletions.
1 change: 1 addition & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version: 2

sphinx:
configuration: docs/conf.py
fail_on_warning: true

python:
version: 3.7
Expand Down
5 changes: 1 addition & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"sphinx_rtd_theme",
"numpydoc",
"sphinx_click",
"myst_parser",
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -48,8 +47,6 @@
# -- Extension configuration -------------------------------------------------
autosummary_generate = True
numpydoc_show_class_members = False
# allow for both rst and md syntax
source_suffix = [".rst"]

# -- Options for HTML output -------------------------------------------------

Expand All @@ -61,4 +58,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_static_path = []
2 changes: 1 addition & 1 deletion docs/formats/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Example model.dat file
Simulating 40 samples for 6 generations in this case implies the first generation has population freqs ``Admixed=0, CEU=0.2, YRI=0.8`` and the remaining 2-6 generations have population frequency ``Admixed=1, CEU=0, YRI=0``

Example pulse event model.dat file
----------------------
----------------------------------

.. code-block::
Expand Down
10 changes: 10 additions & 0 deletions haptools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try:
from importlib.metadata import version, PackageNotFoundError
except ImportError:
# handles py3.7, since importlib.metadata was introduced in py3.8
from importlib_metadata import version, PackageNotFoundError

try:
__version__ = version(__name__)
except PackageNotFoundError:
__version__ = "unknown"
12 changes: 5 additions & 7 deletions haptools/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/usr/bin/env python

from __future__ import annotations
import re
import sys
import time
import click
from pathlib import Path
from haptools.data.haplotypes import Haplotypes
from haptools import data
import tempfile

# AVOID IMPORTING ANYTHING HERE
import click

# AVOID IMPORTING ANYTHING ABOVE
# any imports we put here will make it slower to use the command line client
# a basic "haptools --help" should be quick and require very few imports, for example

Expand Down Expand Up @@ -180,6 +176,8 @@ def simgenotype(
"""
Simulate admixed genomes under a pre-defined model.
"""
import re
import time
from .sim_genotype import (
output_vcf,
simulate_gt,
Expand Down
22 changes: 14 additions & 8 deletions haptools/data/breakpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _find_blocks(
problem_position = positions[indices >= len(blocks)][0]
raise ValueError(
f"Position {problem_position} exceeds the range of the provided "
"haplotype blocks."
"breakpoint blocks."
)
return indices

Expand Down Expand Up @@ -298,6 +298,13 @@ def population_array(
for strand_num in range(len(samp_blocks)):
blocks = samp_blocks[strand_num]
chrom_block = blocks[blocks["chrom"] == chrom]
if not len(chrom_block):
samp_id = tuple(data.keys())[samp_idx]
raise ValueError(
f"Chromosome {chrom} in the genotypes is absent in the "
f"breakpoints for sample {samp_id}_{strand_num+1}. Check "
"that your 'chr' prefixes match!"
)
# TODO: raise an exception if the end positions in chrom_block
# aren't sorted
# Now try to figure out the right population labels using binary
Expand All @@ -307,14 +314,13 @@ def population_array(
self._find_blocks(chrom_block["bp"], positions)
]
except ValueError as e:
diff = gts_chroms.difference(blocks["chrom"])
if str(e).startswith("Position ") and len(diff):
samp_id = tuple(data.keys())[samp_idx]
samp_id = tuple(data.keys())[samp_idx]
if str(e).startswith("Position "):
raise ValueError(
f"Chromosomes {diff} in the genotypes are absent in "
f"the breakpoints for sample {samp_id}_{strand_num+1}."
" Check that your 'chr' prefixes match!"
)
f"The breakpoints for chromosome {chrom} in sample"
f" {samp_id}_{strand_num+1} do not specify an ancestry"
" for one of the requested variants."
) from e
else:
raise e
return arr
Expand Down
4 changes: 2 additions & 2 deletions haptools/data/genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ def __init__(self, fname: Path | str, log: Logger = None, chunk_size: int = None
import pgenlib
except ImportError:
raise ImportError(
"We cannot read PGEN files without the pgenlib library. Please "
"reinstall haptools with the 'files' extra requirement via\n"
f"We cannot read PGEN files without the pgenlib library. Please "
f"reinstall haptools with the 'files' extra requirement via\n"
f"pip install haptools[files]"
)

Expand Down
23 changes: 23 additions & 0 deletions haptools/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations
import logging


def getLogger(name: str = None):
"""
Retrieve a Logger object
Parameters
----------
name : str, optional
The name of the logging object
"""
if name is None:
pass

log = logging.getLogger("haptools " + name)
db_time = "|%(asctime)s" if verbosity == "DEBUG" else ""
logging.basicConfig(
format="[%(levelname)8s" + db_time + "] %(message)s (%(filename)s:%(lineno)s)",
level=verbosity,
datefmt="%H:%M:%S",
)
Loading

0 comments on commit 58d171c

Please sign in to comment.