Skip to content

Commit

Permalink
feat: add "serve" command (#24) (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jan 5, 2024
1 parent 7b322ba commit 56f7078
Show file tree
Hide file tree
Showing 9 changed files with 668 additions and 50 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.PHONY: default
default:

.PHONY: format
format: black isort

.PHONY: black
black:
black -l 100 .
Expand Down
44 changes: 44 additions & 0 deletions chew/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import typing

import click
from logzero import logger

from chew import __version__, compare, fingerprint, plot_compare, plot_var_het, stats

try:
import dash # noqa

have_dash_installed = True
except ImportError:
have_dash_installed = False


@click.group()
@click.version_option(__version__)
Expand Down Expand Up @@ -171,3 +179,39 @@ def cli_plot_var_het(
stats_out=stats_out,
)
plot_var_het.run(config)


if have_dash_installed:

@cli.command("serve", help="Run report server") # type: ignore[attr-defined]
@click.option(
"--annos-tsv",
default=None,
required=False,
help="Optional TSV file with further annotations",
)
@click.option("--strip-suffix", default="", help="Suffix to strip from sample names")
@click.argument("cohort_ped")
@click.argument("fingerprints", nargs=-1)
@click.pass_context
def cli_serve(
ctx: click.Context,
annos_tsv: typing.Optional[str],
strip_suffix: str,
cohort_ped: str,
fingerprints: typing.List[str],
):
if not fingerprints:
logger.warn("No fingerprints given!")
return

from chew import serve

config = serve.Config(
verbosity=2 if ctx.obj["verbose"] else 1,
strip_suffix=strip_suffix,
cohort_ped=cohort_ped,
fingerprints=fingerprints,
annos_tsv=annos_tsv,
)
serve.run(config)
50 changes: 50 additions & 0 deletions chew/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Commonly used code"""

import enum
import gzip
import os
import typing
Expand Down Expand Up @@ -67,6 +68,55 @@
}


class Sex(enum.Enum):
UNKNOWN = "unknown"
MALE = "male"
FEMALE = "female"


PED_SEX_MAP = {
"0": Sex.UNKNOWN,
"1": Sex.MALE,
"2": Sex.FEMALE,
}


class DiseaseState(enum.Enum):
UNKNOWN = "unknown"
UNAFFECTED = "affected"
AFFECTED = "unaffected"


PED_DISEASE_MAP = {
"0": DiseaseState.UNKNOWN,
"1": DiseaseState.UNAFFECTED,
"2": DiseaseState.AFFECTED,
}


@attrs.frozen
class PedigreeMember:
family_name: str
name: str
father: str
mother: str
sex: Sex
disease_state: DiseaseState


def pedigree_member_from_tsv(arr: typing.List[str]) -> PedigreeMember:
if len(arr) < 6:
raise Exception("TSV array must have at least 6 fields")
return PedigreeMember(
family_name=arr[0],
name=arr[1],
father=arr[2],
mother=arr[3],
sex=PED_SEX_MAP.get(arr[4], Sex.UNKNOWN),
disease_state=PED_DISEASE_MAP.get(arr[5], DiseaseState.UNKNOWN),
)


@attrs.frozen
class Site:
chrom: str
Expand Down
Loading

0 comments on commit 56f7078

Please sign in to comment.