class PoreCContactRecord(_BaseModel): read_name: constr(min_length=1, strip_whitespace=True) read_length: conint(ge=1) read_idx: conint(ge=0, strict=True) contact_is_direct: bool = False contact_is_cis: bool = False contact_read_distance: int = 0 contact_genome_distance: int = 0 contact_fragment_adjacent: bool = False contact_fragment_distance: conint(ge=0, strict=True) haplotype_pair_type: HaplotypePairType = HaplotypePairType.null align1_align_idx: conint(ge=0, strict=True) align1_chrom: constr(min_length=1, strip_whitespace=True) align1_start: conint(ge=0) align1_end: conint(ge=0) align1_strand: STRAND_DTYPE align1_mapping_quality: conint(ge=0, le=255) align1_align_score: conint(ge=0) align1_align_base_qscore: conint(ge=0) align1_phase_set: int = 0 align1_phase_qual: int = 0 align1_haplotype: conint(ge=-1) = -1 align1_fragment_id: conint(ge=0) = 0 align1_fragment_start: conint(ge=0) = 0 align1_fragment_end: conint(ge=0) = 0 align2_align_idx: conint(ge=0, strict=True) align2_chrom: constr(min_length=1, strip_whitespace=True) align2_start: conint(ge=0) align2_end: conint(ge=0) align2_strand: STRAND_DTYPE align2_mapping_quality: conint(ge=0, le=255) align2_align_score: conint(ge=0) align2_align_base_qscore: conint(ge=0) align2_phase_set: int = 0 align1_phase_qual: int = 0 align2_haplotype: conint(ge=-1) = -1 align2_fragment_id: conint(ge=0) = 0 align2_fragment_start: conint(ge=0) = 0 align2_fragment_end: conint(ge=0) = 0 class Config: use_enum_values = True fields = dict( read_name=dict(description="The original read name", dtype="str"), read_length=dict(description="The length of the read in bases", dtype=READ_COORD_DTYPE), read_idx=dict(description="Unique integer ID of the read", dtype=READ_IDX_DTYPE), contact_is_direct=dict( description= "There are no intervening assigned restriction fragments on the read", dtype="bool"), contact_is_cis=dict( description= "Both alignments come from the same chromsome/contig", dtype="bool"), contact_read_distance=dict( description= ("The distance between the end of the left alignment and the start of the right " "alignment on the read"), dtype=READ_DISTANCE_DTYPE, ), contact_genome_distance=dict( description= ("The distance between the end of the left alignment and the start of the right alignment " "(valid for cis contacts only)"), dtype=GENOMIC_DISTANCE_DTYPE, ), contact_fragment_adjacent=dict( description= ("A boolean to indicate if the contact is between the same or adjacent fragments", ), dtype="bool", ), contact_fragment_distance=dict( description= ("The distance between the midpoints of the assigned fragments (valid for cis contacts only)" ), dtype=GENOMIC_DISTANCE_DTYPE, ), haplotype_pair_type=dict( description= ("A categorical variable describing the relationship between the haplotypes assigned to each of the " "alignments in a contact", ), dtype="category", ), align1_align_idx=dict( description="Unique integer ID of the first aligned segment", dtype=ALIGN_IDX_DTYPE), align1_chrom=dict( description= "The chromosome/contig of the first aligned segment", dtype="category"), align1_start=dict( description= "The zero-based start position on the genome of the alignment", dtype=GENOMIC_COORD_DTYPE), align1_end=dict( description="The end position on the genome of the alignment", dtype=GENOMIC_COORD_DTYPE), align1_strand=dict(description="The alignment strand", dtype="bool"), align1_mapping_quality=dict( description="The mapping quality as calculated by the aligner", dtype=MQ_DTYPE), align1_align_score=dict( description="The alignment score as calculated by the aligner", dtype=ALIGN_SCORE_DTYPE), align1_align_base_qscore=dict( description= "The mean read base score for the aligned segment (rounded to the nearest integer).", dtype=ALIGN_SCORE_DTYPE, ), align1_phase_set=dict( description= "The ID of the phase set, often this is the start position of the phase block", dtype=PHASE_SET_DTYPE, ), align1_phase_qual=dict( description= "The phred-scaled quality score of the haplotype assignment", dtype=MQ_DTYPE), align1_haplotype=dict( description= ("The id of the haplotype within this block, usually set to 1 or 2. " "A value of -1 means that this alignment is unphased"), dtype=HAPLOTYPE_IDX_DTYPE, ), align1_fragment_id=dict( description= "The UID of the restriction fragment assigned to this alignment", dtype=FRAG_IDX_DTYPE), align1_fragment_start=dict( description= "The start point on the genome of this restriction fragment", dtype=GENOMIC_COORD_DTYPE), align1_fragment_end=dict( description= "The end point on the genome of this restriction fragment", dtype=GENOMIC_COORD_DTYPE), align2_align_idx=dict( description="Unique integer ID of the first aligned segment", dtype=ALIGN_IDX_DTYPE), align2_chrom=dict( description= "The chromosome/contig of the first aligned segment", dtype="category"), align2_start=dict( description= "The zero-based start position on the genome of the alignment", dtype=GENOMIC_COORD_DTYPE), align2_end=dict( description="The end position on the genome of the alignment", dtype=GENOMIC_COORD_DTYPE), align2_strand=dict(description="The alignment strand", dtype="bool"), align2_mapping_quality=dict( description="The mapping quality as calculated by the aligner", dtype=MQ_DTYPE), align2_align_score=dict( description="The alignment score as calculated by the aligner", dtype=ALIGN_SCORE_DTYPE), align2_align_base_qscore=dict( description= "The mean read base score for the aligned segment (rounded to the nearest integer).", dtype=ALIGN_SCORE_DTYPE, ), align2_phase_set=dict( description= "The ID of the phase set, often this is the start position of the phase block", dtype=PHASE_SET_DTYPE, ), align2_phase_qual=dict( description= "The phred-scaled quality score of the haplotype assignment", dtype=MQ_DTYPE), align2_haplotype=dict( description= ("The id of the haplotype within this block, usually set to 1 or 2. " "A value of -1 means that this alignment is unphased"), dtype=HAPLOTYPE_IDX_DTYPE, ), align2_fragment_id=dict( description= "The UID of the restriction fragment assigned to this alignment", dtype=FRAG_IDX_DTYPE), align2_fragment_start=dict( description= "The start point on the genome of this restriction fragment", dtype=GENOMIC_COORD_DTYPE), align2_fragment_end=dict( description= "The end point on the genome of this restriction fragment", dtype=GENOMIC_COORD_DTYPE), ) @classmethod def from_pore_c_align_pair(cls, read_name: str, read_length: int, read_idx: int, align1, align2): contact_read_distance = align2.read_start - align1.read_end contact_is_direct = align2.pos_on_read - align1.pos_on_read == 1 if align1.fragment_id > align2.fragment_id: align1, align2 = align2, align1 contact_is_cis = align1.chrom == align2.chrom if contact_is_cis: contact_genome_distance = align2.start - align1.end contact_fragment_distance = align2.fragment_midpoint - align1.fragment_midpoint contact_fragment_adjacent = abs(align2.fragment_id - align1.fragment_id) <= 1 else: contact_genome_distance = 0 contact_fragment_distance = 0 contact_fragment_adjacent = False haplotype_pair_type = HaplotypePairType.null if not contact_is_cis: haplotype_pair_type = HaplotypePairType.trans elif align1.haplotype == -1 and align2.haplotype == -1: haplotype_pair_type = HaplotypePairType.unphased elif align1.haplotype == -1 or align2.haplotype == -1: haplotype_pair_type = HaplotypePairType.semi_phased elif align1.phase_set != align2.phase_set: haplotype_pair_type = HaplotypePairType.phased_sets_differ elif align1.haplotype == align2.haplotype: haplotype_pair_type = HaplotypePairType.phased_h_cis else: haplotype_pair_type = HaplotypePairType.phased_h_trans return cls( read_name=read_name, read_length=read_length, read_idx=read_idx, contact_is_direct=contact_is_direct, contact_is_cis=contact_is_cis, contact_read_distance=contact_read_distance, contact_genome_distance=contact_genome_distance, contact_fragment_adjacent=contact_fragment_adjacent, contact_fragment_distance=contact_fragment_distance, haplotype_pair_type=haplotype_pair_type, align1_align_idx=align1.align_idx, align1_chrom=align1.chrom, align1_start=align1.start, align1_end=align1.end, align1_strand=align1.strand, align1_mapping_quality=align1.mapping_quality, align1_align_score=align1.align_score, align1_align_base_qscore=align1.align_base_qscore, align1_phase_set=align1.phase_set, align1_phase_qual=align1.phase_qual, align1_haplotype=align1.haplotype, align1_fragment_id=align1.fragment_id, align1_fragment_start=align1.fragment_start, align1_fragment_end=align1.fragment_end, align2_align_idx=align2.align_idx, align2_chrom=align2.chrom, align2_start=align2.start, align2_end=align2.end, align2_strand=align2.strand, align2_mapping_quality=align2.mapping_quality, align2_align_score=align2.align_score, align2_align_base_qscore=align2.align_base_qscore, align2_phase_set=align2.phase_set, align2_phase_qual=align2.phase_qual, align2_haplotype=align2.haplotype, align2_fragment_id=align2.fragment_id, align2_fragment_start=align2.fragment_start, align2_fragment_end=align2.fragment_end, )
class DAG(IOBase): """A Directed Acyclic Graph containing a list of tasks.""" type: constr(regex='^DAG$') = 'DAG' name: str = Field( ..., description='A unique name for this dag.' ) inputs: List[DAGInputs] = Field( None, description='Inputs for the DAG.' ) fail_fast: bool = Field( True, description='Stop scheduling new steps, as soon as it detects that one of the' ' DAG nodes is failed. Default is True.' ) tasks: List[DAGTask] = Field( ..., description='Tasks are a list of DAG steps' ) outputs: List[DAGOutputs] = Field( None, description='Outputs of the DAG that can be used by other DAGs.' ) @staticmethod def find_task_return( tasks: List[DAGTask], reference: Union[ TaskReference, TaskFileReference, TaskFolderReference, TaskPathReference] ) -> Union[TaskReturn, TaskPathReturn]: """Find a task output within the DAG from a reference Arguments: tasks {List[DAGTask]} -- A list of DAG Tasks reference {Union[TaskReference, TaskFileReference, TaskFolderReference, TaskPathReference]} -- A reference to a DAG Task output Raises: ValueError: The task name cannot be found. ValueError: The task return reference cannot be found. Returns: Union[TaskReturn, TaskPathReturn] -- A task output parameter or artifact """ filtered_tasks = [x for x in tasks if x.name == reference.name] if not filtered_tasks: raise ValueError(f'Task with name "{reference.name}" not found.') task = filtered_tasks[0] if isinstance(reference, TaskReference): if task.loop is not None: raise ValueError( 'Cannot refer to outputs from a looped task.' 'You must perform your own aggregation and then refer to ' 'a hard coded folder path.' ) out = [ret for ret in task.returns if ret.name == reference.variable] if not out: raise ValueError( f'Failed to find referenced variable name "{reference.variable}" in ' f'"{task.name}" task.' ) return out[0] @validator('tasks') def check_unique_names(cls, v): """Check that all tasks have unique names.""" names = [task.name for task in v] duplicates = find_dup_items(names) if len(duplicates) != 0: raise ValueError(f'Duplicate names: {duplicates}') return v @validator('tasks') def check_dependencies(cls, v): """Check that all task dependencies exist.""" task_names = [task.name for task in v] exceptions = [] err_msg = 'DAG Task "{name}" has unresolved dependency: "{dep}"\n' for task in v: if task.needs is None: continue for dep in task.needs: if dep not in task_names: exceptions.append(err_msg.format(name=task.name, dep=dep)) if exceptions: raise ValueError(''.join(exceptions)) return v @validator('tasks') def check_references(cls, v, values): """Check that input and output references exist.""" dag_inputs = values.get('inputs', []) dag_input_names = set(d.name for d in dag_inputs) exceptions = [] for task in v: if task.arguments is None: continue # Check DAG input references for arg in task.argument_by_ref_source('dag'): if arg.from_.variable not in dag_input_names: exceptions.append( f'Invalid input reference variable: "{arg.from_.variable}" ' f'in task "{task.name}"' ) # Check DAG task inputs for arg in task.argument_by_ref_source('task'): try: cls.find_task_return(tasks=v, reference=arg.from_) except ValueError as error: exceptions.append(f'tasks.{task.name}.{arg.name}: %s' % error) if exceptions: raise ValueError('\n '.join(exceptions)) return v @validator('tasks', each_item=True) def check_template_name(cls, v, values): """Check that a task name does not refer to itself in a template.""" name = values.get('name') plugin = v.template.split('/')[0] assert plugin != name, \ ValueError('Task cannot refer to its own DAG as a template.') return v @validator('tasks') def sort_list(cls, v): """Sort the list of tasks by name""" v.sort(key=lambda x: x.name) return v @root_validator def check_dag_outputs(cls, values): """Check DAG outputs refer to existing Task outputs. It can't be a normal validator because of the order in which the inputs get assigned in Pydantic when a class is a subclass from another. """ if 'tasks' not in values or 'outputs' not in values: # another validation has failed return values tasks = values['tasks'] outputs = values['outputs'] exceptions = [] for out in outputs: if isinstance(out.from_, TaskReference): try: cls.find_task_return(tasks=tasks, reference=out.from_) except ValueError as error: exceptions.append(f'outputs.{out.name}: %s' % error) elif isinstance(out.from_, (FolderReference, FileReference)): # the validation will be checked when the Pydantic model is being loaded pass if exceptions: raise ValueError(' \n'.join(exceptions)) return values def get_task(self, name): """Get task by name. Arguments: name {str} -- The name of a task Raises: ValueError: The task name does not exist Returns: DAGTask -- A DAG Task """ task = [t for t in self.tasks if t.name == name] if not task: raise ValueError(f'Invalid task name: {name}') return task[0] @property def templates(self) -> Set[str]: """A list of unique templates referred to in the DAG. Returns: List[str] -- A list of task name """ return set([task.template for task in self.tasks])
class PlayerHandedness(BaseModel): code: constr(max_length=1) description: str
from typing import Optional, Union from uuid import UUID from pydantic import AnyUrl, BaseModel, Extra, Field, constr from .services import PROPERTY_KEY_RE NodeID = UUID # Pydantic does not support exporting a jsonschema with Dict keys being something else than a str # this is a regex for having uuids of type: 8-4-4-4-12 digits UUID_REGEX = ( r"^[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}$" ) NodeID_AsDictKey = constr(regex=UUID_REGEX) class PortLink(BaseModel): node_uuid: NodeID = Field( ..., description="The node to get the port output from", example=["da5068e0-8a8d-4fb9-9516-56e5ddaef15b"], alias="nodeUuid", ) output: str = Field( ..., description="The port key in the node given by nodeUuid", regex=PROPERTY_KEY_RE, example=["out_2"], )
class UserInDB(IDModelMixin, DateTimeModelMixin, UserBase): password: constr(min_length=7, max_length=100) salt: str
class MemberOfOrganization(OscalBaseModel): __root__: constr( regex='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$' )
class MoreStringsModel(BaseModel): str_regex: constr(regex=r'^xxx\d{3}$') = ... str_min_length: constr(min_length=5) = ... str_curtailed: constr(curtail_length=5) = ... str_email: EmailStr = ... name_email: NameEmail = ...
class UserUpdate(CoreModel): email: Optional[EmailStr] username: Optional[constr(min_length=3, regex="[a-zA-Z0-9_-]+$")]
class Metadata(BaseModel): title: constr(min_length=1) text: constr(min_length=1) class Config: extra = Extra.forbid
__root__: List[FileLocation] class FileLocationEnveloped(BaseModel): data: FileLocation error: Any class FileLocationArrayEnveloped(BaseModel): data: FileLocationArray error: Any # /locations/{location_id}/datasets DatCoreId = constr(regex=r"^N:dataset:" + UUID_RE) class DatasetMetaData(BaseModel): dataset_id: Union[UUID, DatCoreId] display_name: str class Config: schema_extra = { "examples": [ # simcore dataset { "dataset_id": "74a84992-8c99-47de-b88a-311c068055ea", "display_name": "api", }, {
class ReferenceDois(BaseModel): doi: constr(min_length=1) in_text: StrictBool
class Todo(BaseModel): name : str description : Optional[constr(max_length = 100)] priority : str created_at : datetime
class Model(pydantic.BaseModel): field: pydantic.constr(max_length=100)
from rastervision.pytorch_learner.utils import ( color_to_triple, validate_albumentation_transform) from rastervision.pytorch_learner.utils import MinMaxNormalize default_augmentors = ['RandomRotate90', 'HorizontalFlip', 'VerticalFlip'] augmentors = [ 'Blur', 'RandomRotate90', 'HorizontalFlip', 'VerticalFlip', 'GaussianBlur', 'GaussNoise', 'RGBShift', 'ToGray' ] if TYPE_CHECKING: from rastervision.pytorch_learner.learner import Learner # noqa # types Proportion = confloat(ge=0, le=1) NonEmptyStr = constr(strip_whitespace=True, min_length=1) NonNegInt = conint(ge=0) class Backbone(Enum): alexnet = 'alexnet' densenet121 = 'densenet121' densenet169 = 'densenet169' densenet201 = 'densenet201' densenet161 = 'densenet161' googlenet = 'googlenet' inception_v3 = 'inception_v3' mnasnet0_5 = 'mnasnet0_5' mnasnet0_75 = 'mnasnet0_75' mnasnet1_0 = 'mnasnet1_0' mnasnet1_3 = 'mnasnet1_3'
class ConStringModel(BaseModel): v: constr(max_length=10) = 'foobar'
class UserCreate(CoreModel): email: EmailStr password: constr(min_length=7, max_length=100) username: constr(min_length=3, regex="[a-zA-Z0-9_-]+$")
class _ItemBase(pydantic.BaseModel): title: constr(min_length=1) description: constr(min_length=1)
class UserPasswordUpdate(CoreModel): password: constr(min_length=7, max_length=100) salt: str
class Permission(BaseModel): name: constr(max_length=100) id: constr(max_length=100) class Config: orm_mode = True
class MSSQLDataSource(ToucanDataSource): query: constr(min_length=1)
class WindowConstructionShadeAbridged(IDdEnergyBaseModel): """Construction for window objects with an included shade layer.""" type: constr(regex='^WindowConstructionShadeAbridged$') = \ 'WindowConstructionShadeAbridged' window_construction: WindowConstructionAbridged = Field( ..., description='A WindowConstructionAbridged object that serves as the ' '"switched off" version of the construction (aka. the "bare construction"). ' 'The shade_material and shade_location will be used to modify this ' 'starting construction.') shade_material: str = Field( ..., min_length=1, max_length=100, description='Identifier of a An EnergyWindowMaterialShade or an ' 'EnergyWindowMaterialBlind that serves as the shading layer for this ' 'construction. This can also be an EnergyWindowMaterialGlazing, which ' 'will indicate that the WindowConstruction has a dynamically-controlled ' 'glass pane like an electrochromic window assembly.') shade_location: ShadeLocation = Field( ShadeLocation.interior, description= 'Text to indicate where in the window assembly the shade_material ' 'is located. Note that the WindowConstruction must have at least one gas ' 'gap to use the "Between" option. Also note that, for a WindowConstruction ' 'with more than one gas gap, the "Between" option defalts to using the ' 'inner gap as this is the only option that EnergyPlus supports.') control_type: ControlType = Field( ControlType.always_on, description= 'Text to indicate how the shading device is controlled, which ' 'determines when the shading is “on” or “off.”') setpoint: float = Field( None, description='A number that corresponds to the specified control_type. ' 'This can be a value in (W/m2), (C) or (W) depending upon the control type.' 'Note that this value cannot be None for any control type except "AlwaysOn."' ) schedule: str = Field( None, min_length=1, max_length=100, description= 'An optional schedule identifier to be applied on top of the ' 'control_type. If None, the control_type will govern all behavior of ' 'the construction.') @root_validator def check_setpoint_exists(cls, values): "Ensure the setpoint exists if control_type isn't AlwaysOn." control_type = values.get('control_type') setpoint = values.get('setpoint') if control_type != 'AlwaysOn': assert setpoint is not None, 'Control setpoint cannot ' \ 'be None for control type "{}"'.format(control_type) return values
class ActivityUuid(OscalBaseModel): __root__: constr( regex='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$' )
class RoomEnergyPropertiesAbridged(NoExtraBaseModel): type: constr(regex='^RoomEnergyPropertiesAbridged$') = \ 'RoomEnergyPropertiesAbridged' construction_set: str = Field( default=None, min_length=1, max_length=100, description='Identifier of a ConstructionSet to specify all default ' 'constructions for the Faces, Apertures, and Doors of the Room. If ' 'None, the Room will use the Model global_construction_set.') program_type: str = Field( default=None, min_length=1, max_length=100, description= 'Identifier of a ProgramType to specify all default schedules ' 'and loads for the Room. If None, the Room will have no loads or setpoints.' ) hvac: str = Field( default=None, min_length=1, max_length=100, description= 'An optional identifier of a HVAC system (such as an IdealAirSystem)' ' that specifies how the Room is conditioned. If None, it will be assumed ' 'that the Room is not conditioned.') people: PeopleAbridged = Field( default=None, description='People object to describe the occupancy of the Room.') lighting: LightingAbridged = Field( default=None, description= 'Lighting object to describe the lighting usage of the Room.') electric_equipment: ElectricEquipmentAbridged = Field( default=None, description= 'ElectricEquipment object to describe the electric equipment usage.') gas_equipment: GasEquipmentAbridged = Field( default=None, description='GasEquipment object to describe the gas equipment usage.') service_hot_water: ServiceHotWaterAbridged = Field( default=None, description='ServiceHotWater object to describe the hot water usage.') infiltration: InfiltrationAbridged = Field( default=None, description= 'Infiltration object to to describe the outdoor air leakage.') ventilation: VentilationAbridged = Field( default=None, description= 'Ventilation object for the minimum outdoor air requirement.') setpoint: SetpointAbridged = Field( default=None, description='Setpoint object for the temperature setpoints of the Room.' ) daylighting_control: DaylightingControl = Field( default=None, description= 'An optional DaylightingControl object to dictate the dimming ' 'of lights. If None, the lighting will respond only to the schedule and ' 'not the daylight conditions within the room.') window_vent_control: VentilationControlAbridged = Field( default=None, description= 'An optional VentilationControl object to dictate the opening ' 'of windows. If None, the windows will never open.')
class ValidateAssignmentModel(BaseModel): a: int = 2 b: constr(min_length=1) class Config: validate_assignment = True
class ModelEnergyProperties(NoExtraBaseModel): type: constr(regex='^ModelEnergyProperties$') = \ 'ModelEnergyProperties' construction_sets: List[Union[ ConstructionSetAbridged, ConstructionSet]] = Field( default=None, description='List of all unique ConstructionSets in the Model.') constructions: List[Union[ OpaqueConstructionAbridged, WindowConstructionAbridged, WindowConstructionShadeAbridged, AirBoundaryConstructionAbridged, OpaqueConstruction, WindowConstruction, WindowConstructionShade, AirBoundaryConstruction, ShadeConstruction]] = Field( default=None, description= 'A list of all unique constructions in the model. This includes ' 'constructions across all Faces, Apertures, Doors, Shades, Room ' 'ConstructionSets, and the global_construction_set.') materials: List[ Union[EnergyMaterial, EnergyMaterialNoMass, EnergyWindowMaterialGas, EnergyWindowMaterialGasCustom, EnergyWindowMaterialGasMixture, EnergyWindowMaterialSimpleGlazSys, EnergyWindowMaterialBlind, EnergyWindowMaterialGlazing, EnergyWindowMaterialShade]] = Field( default=None, description= 'A list of all unique materials in the model. This includes ' 'materials needed to make the Model constructions.') hvacs: List[ Union[IdealAirSystemAbridged, VAV, PVAV, PSZ, PTAC, ForcedAirFurnace, FCUwithDOASAbridged, WSHPwithDOASAbridged, VRFwithDOASAbridged, FCU, WSHP, VRF, Baseboard, EvaporativeCooler, Residential, WindowAC, GasUnitHeater]] = Field( default=None, description='List of all unique HVAC systems in the Model.') program_types: List[Union[ProgramTypeAbridged, ProgramType]] = Field( default=None, description='List of all unique ProgramTypes in the Model.') schedules: List[Union[ ScheduleRulesetAbridged, ScheduleFixedIntervalAbridged, ScheduleRuleset, ScheduleFixedInterval]] = Field( default=None, description= 'A list of all unique schedules in the model. This includes ' 'schedules across all HVAC systems, ProgramTypes, Rooms, and Shades.' ) schedule_type_limits: List[ScheduleTypeLimit] = Field( default=None, description='A list of all unique ScheduleTypeLimits in the model. This ' 'all ScheduleTypeLimits needed to make the Model schedules.') ventilation_simulation_control: VentilationSimulationControl = Field( default=None, description='An optional parameter to define the global parameters for ' 'a ventilation cooling.')
class AlignmentRecord(_BaseModel): """An alignment derived from a BAM file""" read_idx: conint(ge=0, strict=True) align_idx: conint(ge=0, strict=True) align_type: AlignmentType chrom: constr(min_length=1, strip_whitespace=True) start: conint(ge=0) end: conint(ge=0) strand: STRAND_DTYPE read_name: constr(min_length=1, strip_whitespace=True) read_length: conint(ge=1) read_start: conint(ge=0) read_end: conint(ge=0) mapping_quality: conint(ge=0, le=255) align_score: conint(ge=0) align_base_qscore: conint(ge=0) phase_set: int = 0 phase_qual: conint(ge=0) = 0 haplotype: conint(ge=-1) = -1 class Config: use_enum_values = True fields = dict( read_idx=dict(description="Unique integer ID of the read", dtype=READ_IDX_DTYPE), align_idx=dict( description="Unique integer ID of the aligned segment", dtype=ALIGN_IDX_DTYPE), align_type=dict(description="The type of alignment", dtype="category"), chrom=dict( description="The chromosome/contig the read is aligned to", dtype="category"), start=dict( description= "The zero-based start position on the genome of the alignment", dtype=GENOMIC_COORD_DTYPE), end=dict( description="The end position on the genome of the alignment", dtype=GENOMIC_COORD_DTYPE), strand=dict(description="The alignment strand", dtype="bool"), read_name=dict(description="The original read name", dtype="str"), read_length=dict(description="The length of the read in bases", dtype=READ_COORD_DTYPE), read_start=dict( description="The start coordinate on the read (0-based)", dtype=READ_COORD_DTYPE), read_end=dict( description="The end coordinate on the read (0-based)", dtype=READ_COORD_DTYPE), mapping_quality=dict( description="The mapping quality as calculated by the aligner", dtype=MQ_DTYPE), align_score=dict( description="The alignment score as calculated by the aligner", dtype=ALIGN_SCORE_DTYPE), align_base_qscore=dict( description= "The mean read base score for the aligned segment (rounded to the nearest integer).", dtype=ALIGN_SCORE_DTYPE, ), phase_set=dict( description= "The ID of the phase set, often this is the start position of the phase block", dtype=PHASE_SET_DTYPE, ), phase_qual=dict( description= "The phred-scaled quality score of the haplotype assignment", dtype=MQ_DTYPE), haplotype=dict( description= ("The id of the haplotype within this block, usually set to 1 or 2. " "A value of -1 means that this alignment is unphased"), dtype=HAPLOTYPE_IDX_DTYPE, ), ) @classmethod def from_aligned_segment(cls, align: pysam.AlignedSegment) -> "AlignmentRecord": """Extract information from a pysam Aligned segment""" read_name, read_idx, align_idx = align.query_name.split(":") read_idx, align_idx = int(read_idx), int(align_idx) if align.is_unmapped: align_cat = "unmapped" chrom, start, end, align_score = "NULL", 0, 0, 0 read_length = align.query_length quals = align.query_qualities # TODO: handle this more gracefully if quals is None: align_base_qscore = 0 else: align_base_qscore = mean_qscore(np.array( align.query_qualities)) else: chrom, start, end = (align.reference_name, align.reference_start, align.reference_end) read_length = align.infer_read_length() align_score = align.get_tag("AS") align_base_qscore = mean_qscore( np.array(align.query_alignment_qualities)) if align.is_secondary: align_cat = "secondary" elif align.is_supplementary: align_cat = "supplementary" else: align_cat = "primary" optional = {} for key, tag in [("haplotype", "HP"), ("phase_set", "PS"), ("phase_qual", "PC")]: if align.has_tag(tag): optional[key] = int(align.get_tag(tag)) return cls( read_idx=read_idx, align_idx=align_idx, align_type=align_cat, chrom=chrom, start=start, end=end, strand=not align.is_reverse, read_name=read_name, read_length=read_length, read_start=align.query_alignment_start, read_end=align.query_alignment_end, mapping_quality=align.mapq, align_score=align_score, align_base_qscore=np.rint(align_base_qscore), **optional, ) @classmethod def to_dataframe(cls, aligns: List, chrom_order: List[str] = None): columns = [a[0] for a in aligns[0]] if chrom_order: overrides = { "chrom": pd.CategoricalDtype(chrom_order, ordered=True) } else: overrides = {} dtype = cls.pandas_dtype(overrides=overrides) df = pd.DataFrame([a.to_tuple() for a in aligns], columns=columns) df = df.astype(dtype) return df @staticmethod def update_dataframe_with_haplotypes(align_df, haplotype_df): if len(haplotype_df) == 0: logger.info( "Aligment haplotypes dataframe is empty, haplotypes won't be added." ) return align_df haplotype_df = (haplotype_df.join(haplotype_df["#readname"].str.split( ":", expand=True).rename({ 0: "read_name", 1: "read_idx", 2: "align_idx" }, axis=1)).rename(columns={ "phaseset": "phase_set" }).replace( dict( haplotype={ "none": -1, "H1": 1, "H2": 2 }, phase_set={"none": 0}, )).astype({ "read_idx": READ_IDX_DTYPE, "align_idx": ALIGN_IDX_DTYPE, "haplotype": HAPLOTYPE_IDX_DTYPE, "phase_set": PHASE_SET_DTYPE, }).set_index(["read_idx", "align_idx"])) col_order = list(align_df.columns) align_df = align_df.set_index(["read_idx", "align_idx"]) align_df["haplotype"] = -1 align_df["phase_set"] = 0 align_df["phase_qual"] = 0 align_df.update(haplotype_df[["haplotype", "phase_set"]], overwrite=True, errors="ignore") align_df = align_df.reset_index()[col_order].astype({ "haplotype": HAPLOTYPE_IDX_DTYPE, "phase_set": PHASE_SET_DTYPE }) return align_df
class DAGGenericInputAlias(GenericInput): """Base class for DAG Alias inputs. This class adds a handler to input to handle the process of loading the input from different graphical interfaces. """ type: constr(regex='^DAGGenericInputAlias$') = 'DAGGenericInputAlias' platform: List[str] = Field( ..., description= 'Name of the client platform (e.g. Grasshopper, Revit, etc). The ' 'value can be any strings as long as it has been agreed between client-side ' 'developer and author of the recipe.') handler: List[IOAliasHandler] = Field( ..., description= 'List of process actions to process the input or output value.') default: str = Field(None, description='Default value for generic input.') # see: https://github.com/ladybug-tools/queenbee/issues/172 required: bool = Field( False, description= 'A field to indicate if this input is required. This input needs to ' 'be set explicitly even when a default value is provided.') spec: Dict = Field( None, description= 'An optional JSON Schema specification to validate the input value. ' 'You can use validate_spec method to validate a value against the spec.' ) def validate_spec(self, value): """Validate an input value against specification. Use this for validating workflow inputs against a recipe. """ if self.spec: spec = dict(self.spec) json_schema_validator(value, spec) return value @validator('default') def validate_default_refs(cls, v, values): """Validate referenced variables in the command""" try: type_ = values['type'] except KeyError: raise ValueError(f'Input with missing type: {cls.__name__}') if type_ != cls.__name__ or not isinstance(v, (str, bytes)): # this is a check to ensure the default value only gets validated againt the # correct class type. See spec validation for more information return v ref_var = get_ref_variable(v) add_info = [] for ref in ref_var: add_info.append(validate_inputs_outputs_var_format(ref)) if add_info: raise ValueError('\n'.join(add_info)) return v @validator('spec') def validate_default_value(cls, v, values): """Validate default value against spec if provided.""" try: type_ = values['type'] except KeyError: raise ValueError(f'Input with missing type: {cls.__name__}') if type_ != cls.__name__: # this is a check to ensure the default value only gets validated againt the # correct class type. The reason we need to do this is that Pydantic doesn't # support discriminators (https://github.com/samuelcolvin/pydantic/issues/619). # As a result in case of checking for Union it checks every possible item # from the start until it finds one. For inputs it causes this check to fail # on a string before it gets to the integer class for an integer input. return v try: default = values['default'] except KeyError: # spec is not set return v if v is not None and default is not None: json_schema_validator(default, v) return v @validator('platform', always=True) def create_empty_platform_list(cls, v): return [] if v is None else v @validator('handler', always=True) def check_duplicate_platform_name(cls, v, values): v = [] if v is None else v languages = [h.language for h in v] dup_lang = find_dup_items(languages) if dup_lang: raise ValueError( f'Duplicate use of language(s) found in alias handlers for ' f'{values["platform"]}: {dup_lang}. Each language can only be used once ' 'in each platform.') return v
class PoreCConcatemerRecord(_BaseModel): read_name: constr(min_length=1, strip_whitespace=True) read_length: conint(ge=1) read_idx: conint(ge=0, strict=True) read_order: conint(ge=0, strict=True) num_fragments: conint(ge=0, strict=True) total_contacts: conint(ge=0, strict=True) total_cis_contacts: conint(ge=0, strict=True) total_trans_contacts: conint(ge=0, strict=True) total_short_range_cis_contacts: conint(ge=0, strict=True) total_long_range_cis_contacts: conint(ge=0, strict=True) direct_contacts: conint(ge=0, strict=True) direct_cis_contacts: conint(ge=0, strict=True) direct_trans_contacts: conint(ge=0, strict=True) direct_short_range_cis_contacts: conint(ge=0, strict=True) direct_long_range_cis_contacts: conint(ge=0, strict=True) indirect_contacts: conint(ge=0, strict=True) indirect_cis_contacts: conint(ge=0, strict=True) indirect_trans_contacts: conint(ge=0, strict=True) indirect_short_range_cis_contacts: conint(ge=0, strict=True) indirect_long_range_cis_contacts: conint(ge=0, strict=True) haplotype_phased_h_cis: conint(ge=0, strict=True) haplotype_phased_h_trans: conint(ge=0, strict=True) haplotype_phased_sets_differ: conint(ge=0, strict=True) haplotype_semi_phased: conint(ge=0, strict=True) haplotype_unphased: conint(ge=0, strict=True) max_indirect_contact_genome_distance: conint(ge=0, strict=True) max_direct_contact_genome_distance: conint(ge=0, strict=True) max_indirect_contact_fragment_distance: conint(ge=0, strict=True) max_direct_contact_fragment_distance: conint(ge=0, strict=True) class Config: use_enum_values = True fields = dict( read_name=dict(description="The original read name", dtype="str"), read_length=dict(description="The length of the read in bases", dtype=READ_COORD_DTYPE), read_idx=dict(description="Unique integer ID of the read", dtype=READ_IDX_DTYPE), read_order=dict(description="The number of monomers for this read", dtype="uint32"), total_contacts=dict( description= "The total (direct + indirect) number of contacts for this read", dtype="uint32"), direct_contacts=dict( description= "The total number direct (adjacent on read) contacts for this read", dtype="uint32"), indirect_contacts=dict( description= "The total number indirect (non-adjacent on read) contacts for this read", dtype="uint32"), total_cis_contacts=dict( description= "The total number of cis-contacts (direct + indirect) for this read", dtype="uint32"), total_trans_contacts=dict( description= "The total number of trans-contacts (direct + indirect) for this read", dtype="uint32"), direct_cis_contacts=dict( description="The number of direct cis-contacts for this read", dtype="uint32"), direct_trans_contacts=dict( description="The number of direct trans-contacts for this read", dtype="uint32"), indirect_cis_contacts=dict( description="The number of indirect cis-contacts for this read", dtype="uint32"), indirect_trans_contacts=dict( description= "The number of indirect trans-contacts for this read", dtype="uint32"), total_short_range_cis_contacts=dict( description= f"The total number of cis contacts < {SHORT_RANGE_CUTOFF} bases apart for this read", dtype="uint32", ), total_long_range_cis_contacts=dict( description= f"The total number of cis contacts >= {SHORT_RANGE_CUTOFF} bases apart for this read", dtype="uint32", ), direct_short_range_cis_contacts=dict( description= f"The number of direct cis contacts < {SHORT_RANGE_CUTOFF} bases apart for this read", dtype="uint32", ), direct_long_range_cis_contacts=dict( description= f"The number of direct cis contacts >= {SHORT_RANGE_CUTOFF} bases apart for this read", dtype="uint32", ), indirect_short_range_cis_contacts=dict( description= f"The number of indirect cis contacts < {SHORT_RANGE_CUTOFF} bases apart for this read", dtype="uint32", ), indirect_long_range_cis_contacts=dict( description= f"The number of indirect cis contacts >= {SHORT_RANGE_CUTOFF} bases apart for this read", dtype="uint32", ), haplotype_unphased=dict( description= "The number of cis contacts where both members of the pair are unphased", dtype="uint32"), haplotype_semi_phased=dict( description= "The number of cis contacts where one member of the pair is unphased", dtype="uint32"), haplotype_phased_sets_differ=dict( description= ("The number of cis contacts where both members of the pair are phased but the phase sets differ" ), dtype="uint32", ), haplotype_phased_h_trans=dict( description= ("The number of cis contacts where both members of the pair are phased, are part of the same phase " "group, but the haplotypes differ"), dtype="uint32", ), haplotype_phased_h_cis=dict( description= ("The number of cis contacts where both members of the pair are phased, are part of the same phase " "group, and the haplotypes agree"), dtype="uint32", ), max_direct_contact_fragment_distance=dict( description= ("The longest distance between fragment midpoints for all direct contacts", ), dtype=GENOMIC_DISTANCE_DTYPE, ), max_indirect_contact_fragment_distance=dict( description= ("The longest distance between fragment midpoints for all indirect contacts", ), dtype=GENOMIC_DISTANCE_DTYPE, ), max_direct_contact_genome_distance=dict( description= ("The longest distance between alignment endpoints for all direct contacts", ), dtype=GENOMIC_DISTANCE_DTYPE, ), max_indirect_contact_genome_distance=dict( description= ("The longest distance between alignment endpoints for all indirect contacts", ), dtype=GENOMIC_DISTANCE_DTYPE, ), num_fragments=dict( description= ("The number of unique restriction fragments represented in the concatemer" ), dtype="uint32", ), )
"""Validate query configuration parameters.""" # Standard Library from typing import List # Third Party from pydantic import Field, StrictStr, StrictBool, constr # Project from hyperglass.constants import SUPPORTED_QUERY_TYPES # Local from ..main import HyperglassModel ASPathMode = constr(regex=r"asplain|asdot") CommunityInput = constr(regex=r"(input|select)") class BgpCommunityPattern(HyperglassModel): """Validation model for bgp_community regex patterns.""" decimal: StrictStr = Field( r"^[0-9]{1,10}$", title="Decimal Community", description= "Regular expression pattern for validating decimal type BGP Community strings.", ) extended_as: StrictStr = Field( r"^([0-9]{0,5})\:([0-9]{1,5})$", title="Extended AS Community", description=
"""**keepluggable** contains reusable code that stores files and images.""" from pydantic import BaseModel, conint, constr AtLeastOneChar: constr = constr(min_length=1, strip_whitespace=True) ZeroOrMore: conint = conint(gt=-1) class Pydantic(BaseModel): """Base class for our validation models.""" class Config: """Controls the behaviour of pydantic.""" anystr_strip_whitespace = True min_anystr_length = 1
constr, validator, root_validator, ) from pydantic.color import Color # Project from hyperglass.constants import DNS_OVER_HTTPS, FUNC_COLOR_MAP # Local from ..main import HyperglassModel from .opengraph import OpenGraph DEFAULT_IMAGES = Path(__file__).parent.parent.parent / "images" Percentage = constr(regex=r"^([1-9][0-9]?|100)\%$") TitleMode = constr(regex=("logo_only|text_only|logo_title|logo_subtitle|all")) ColorMode = constr(regex=r"light|dark") DOHProvider = constr(regex="|".join(DNS_OVER_HTTPS.keys())) Title = constr(max_length=32) class Analytics(HyperglassModel): """Validation model for Google Analytics.""" enable: StrictBool = False id: Optional[StrictStr] @validator("id") def validate_id(cls, value, values): """Ensure ID is set if analytics is enabled.