Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "serve" command (#24) #35

Merged
merged 8 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading