Skip to content

Commit

Permalink
moi tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
MattWellie committed Nov 27, 2023
1 parent f98a88f commit 6f8972e
Show file tree
Hide file tree
Showing 12 changed files with 690 additions and 648 deletions.
2 changes: 1 addition & 1 deletion helpers/report_hunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from cpg_utils.config import get_config
from metamist.graphql import gql, query

from reanalysis.utils import get_logger
from reanalysis.static_values import get_logger

JINJA_TEMPLATE_DIR = Path(__file__).absolute().parent / 'templates'
PROJECT_QUERY = gql(
Expand Down
3 changes: 2 additions & 1 deletion reanalysis/hail_filter_sv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
ONE_INT,
MISSING_INT,
)
from reanalysis.utils import get_logger, read_json_from_path
from reanalysis.utils import read_json_from_path
from reanalysis.static_values import get_logger


def filter_matrix_by_af(
Expand Down
5 changes: 2 additions & 3 deletions reanalysis/interpretation_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@
seqr_loader,
)
from reanalysis.utils import (
FileTypes,
identify_file_type,
get_granular_date,
get_logger,
)
from reanalysis.models import FileTypes
from reanalysis.static_values import get_granular_date, get_logger

# region: CONSTANTS
# exact time that this run occurred
Expand Down
58 changes: 30 additions & 28 deletions reanalysis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

from enum import Enum
from pydantic import BaseModel, Field
from reanalysis.utils import get_granular_date

from reanalysis.static_values import get_granular_date

NON_HOM_CHROM = ['X', 'Y', 'MT', 'M']
CHROM_ORDER = list(map(str, range(1, 23))) + NON_HOM_CHROM


class VariantType(Enum):
"""
enumeration of permitted variant types
"""

SMALL = 'SMALL'
SV = 'SV'


class FileTypes(Enum):
"""
enumeration of permitted input file types
"""

HAIL_TABLE = '.ht'
MATRIX_TABLE = '.mt'
VCF = '.vcf'
VCF_GZ = '.vcf.gz'
VCF_BGZ = '.vcf.bgz'


class Coordinates(BaseModel):
"""
A representation of genomic coordinates
Expand Down Expand Up @@ -61,24 +81,13 @@ def __eq__(self, other) -> bool:
)


class VariantType(Enum):
"""
enumeration of permitted variant types
"""

SMALL = 'SMALL'
SV = 'SV'


class Variant(BaseModel):
"""
the abstracted representation of a variant from any source
todo move some more of the parsing logic into here as an init?
"""

coordinates: Coordinates = Field(repr=True)
info: dict[str, str | int | float] = Field(default_factory=dict)
categories: list[str] = Field(default_factory=list)
info: dict[str, str | int | float | list[str] | bool] = Field(default_factory=dict)
het_samples: set[str] = Field(default_factory=set, exclude=True)
hom_samples: set[str] = Field(default_factory=set, exclude=True)
boolean_categories: list[str] = Field(default_factory=list, exclude=True)
Expand Down Expand Up @@ -153,7 +162,9 @@ def sample_support_only(self, sample_id: str) -> bool:
Returns:
True if support only
"""
return self.has_support and not self.sample_categorised_check(sample_id)
return self.has_support and not (
self.category_non_support or self.sample_categorised_check(sample_id)
)

def category_values(self, sample: str) -> list[str]:
"""
Expand Down Expand Up @@ -227,8 +238,9 @@ def sample_category_check(self, sample_id: str, allow_support: bool = True) -> b
class SmallVariant(Variant):
depths: dict[str, int] = Field(default_factory=dict, exclude=True)
ab_ratios: dict[str, float] = Field(default_factory=dict, exclude=True)
transcript_consequences: list[dict[str, str]] = Field(default_factory=list)
var_type: str = VariantType.SMALL.value
transcript_consequences: list[dict[str, str | float | int]] = Field(
default_factory=list
)

def get_sample_flags(self, sample: str) -> list[str]:
"""
Expand Down Expand Up @@ -274,9 +286,6 @@ def check_ab_ratio(self, sample: str) -> list[str]:


class StructuralVariant(Variant):

var_type: str = VariantType.SV.value

def check_ab_ratio(self, *args, **kwargs) -> list[str]:
"""
dummy method for AB ratio checking - not implemented for SVs
Expand Down Expand Up @@ -314,14 +323,7 @@ class ReportVariant(BaseModel):
phenotypes: list[str] = Field(default_factory=list)
labels: list[str] = Field(default_factory=list)
first_seen: str = Field(default=get_granular_date())
independent: bool = False

@property
def is_independent(self):
"""
check if this variant acts independently
"""
return len(self.support_vars) == 0
independent: bool = Field(default=False)

def __eq__(self, other):
"""
Expand Down
Loading

0 comments on commit 6f8972e

Please sign in to comment.