Module phc.easy.omics.options.genomic_expression

Expand source code
from enum import Enum
from typing import List, Optional, Union
from pydantic import Field, constr

from phc.easy.abstract.paging_api_item import PagingApiOptions
from phc.easy.omics.options.common import GenomicVariantInclude

MAPPINGS = {
    "variant_set_ids": "rnaQuantificationSetIds",
    "outlier_std_dev": "outlierStdDev",
    "in_ckb": "drugAssociations",
    "order_by": "orderBy",
}


class GenomicExpressionOptions(PagingApiOptions):
    """Options to pass to `/v1/genomics/expressions`"""

    variant_set_ids: List[str] = Field(..., min_length=1)
    include: List[GenomicVariantInclude] = []
    gene: List[str] = []
    expression: Optional[str] = Field(None, pattern=r"^(\d+(\.\d+)?-\d+(\.\d+)?|[><]=\s?\d+(\.\d+)?|\d+(\.\d+)?:(lte|gte))$")
    order_by: Optional[str] = Field(None, pattern=r"^expression(:desc)?$")
    in_ckb: Optional[bool] = None
    # TODO: Fill out allowed options for this parameter
    outlier_std_dev: Optional[str] = None

    @staticmethod
    def transform(key, value):
        if key == "expression" and value is not None:
            value = GenomicExpressionOptions.transform_expression(value)

        if isinstance(value, list):
            value = ",".join(
                [elem if isinstance(elem, str) else str(elem) for elem in value]
            )
        elif isinstance(value, bool):
            value = "true" if value else None

        return (MAPPINGS.get(key, key), value)

    @staticmethod
    def transform_expression(value: str):
        value = value.replace(" ", "")

        if ">=" in value:
            return value.replace(">=", "") + ":gte"

        if "<=" in value:
            return value.replace("<=", "") + ":lte"

        return value

Classes

class GenomicExpressionOptions (**data: Any)

Options to pass to /v1/genomics/expressions

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class GenomicExpressionOptions(PagingApiOptions):
    """Options to pass to `/v1/genomics/expressions`"""

    variant_set_ids: List[str] = Field(..., min_length=1)
    include: List[GenomicVariantInclude] = []
    gene: List[str] = []
    expression: Optional[str] = Field(None, pattern=r"^(\d+(\.\d+)?-\d+(\.\d+)?|[><]=\s?\d+(\.\d+)?|\d+(\.\d+)?:(lte|gte))$")
    order_by: Optional[str] = Field(None, pattern=r"^expression(:desc)?$")
    in_ckb: Optional[bool] = None
    # TODO: Fill out allowed options for this parameter
    outlier_std_dev: Optional[str] = None

    @staticmethod
    def transform(key, value):
        if key == "expression" and value is not None:
            value = GenomicExpressionOptions.transform_expression(value)

        if isinstance(value, list):
            value = ",".join(
                [elem if isinstance(elem, str) else str(elem) for elem in value]
            )
        elif isinstance(value, bool):
            value = "true" if value else None

        return (MAPPINGS.get(key, key), value)

    @staticmethod
    def transform_expression(value: str):
        value = value.replace(" ", "")

        if ">=" in value:
            return value.replace(">=", "") + ":gte"

        if "<=" in value:
            return value.replace("<=", "") + ":lte"

        return value

Ancestors

Class variables

var expression : Optional[str]
var gene : List[str]
var in_ckb : Optional[bool]
var include : List[GenomicVariantInclude]
var model_config
var order_by : Optional[str]
var outlier_std_dev : Optional[str]
var variant_set_ids : List[str]

Static methods

def transform(key, value)
Expand source code
@staticmethod
def transform(key, value):
    if key == "expression" and value is not None:
        value = GenomicExpressionOptions.transform_expression(value)

    if isinstance(value, list):
        value = ",".join(
            [elem if isinstance(elem, str) else str(elem) for elem in value]
        )
    elif isinstance(value, bool):
        value = "true" if value else None

    return (MAPPINGS.get(key, key), value)
def transform_expression(value: str)
Expand source code
@staticmethod
def transform_expression(value: str):
    value = value.replace(" ", "")

    if ">=" in value:
        return value.replace(">=", "") + ":gte"

    if "<=" in value:
        return value.replace("<=", "") + ":lte"

    return value

Methods

def model_dump(self)

Inherited from: PagingApiOptions.model_dump