dae.pedigrees package
Subpackages
- dae.pedigrees.tests package
- Submodules
- dae.pedigrees.tests.conftest module
- dae.pedigrees.tests.test_combine_families module
- dae.pedigrees.tests.test_disconnected_families module
- dae.pedigrees.tests.test_families_loader module
- dae.pedigrees.tests.test_family module
- dae.pedigrees.tests.test_family_role_builder module
- dae.pedigrees.tests.test_family_tags module
- dae.pedigrees.tests.test_family_tags_builder module
- dae.pedigrees.tests.test_interval_sandwich module
- dae.pedigrees.tests.test_layout module
- dae.pedigrees.tests.test_layout_loader module
- dae.pedigrees.tests.test_load_family_simple module
- dae.pedigrees.tests.test_pedigree_loading module
- dae.pedigrees.tests.test_pedigrees module
- Module contents
Submodules
dae.pedigrees.drawing module
Classes and helpers for drawing pedigrees into a PDF file.
dae.pedigrees.families_data module
- class dae.pedigrees.families_data.FamiliesData[source]
Bases:
Mapping
[str
,Family
]Defines class for handling families in a study.
- static combine(first: FamiliesData, second: FamiliesData, *, forced: bool = True) FamiliesData [source]
Combine families from two families data objects.
- copy() FamiliesData [source]
Build a copy of a families data object.
- static from_families(families: dict[str, Family]) FamiliesData [source]
Build families data from dictionary of families.
- static from_family_persons(family_persons: dict[str, list[Person]]) FamiliesData [source]
Build a families data object from persons grouped by family.
- static from_pedigree_df(ped_df: DataFrame) FamiliesData [source]
Build a families data object from a pedigree data frame.
- property ped_df: DataFrame
Build a pedigree dataframe from a families data.
- persons_with_roles(roles: list[Role] | None = None, family_ids: Iterable[str] | None = None) list[Person] [source]
Return list of persons matching the specified roles.
- dae.pedigrees.families_data.merge_families(l_fam: Family, r_fam: Family, *, forced: bool = True) Family [source]
Merge two families into one.
- dae.pedigrees.families_data.tag_families_data(families: FamiliesData) None [source]
dae.pedigrees.family module
Defines classes representing individuals and families.
- class dae.pedigrees.family.Family(family_id: str)[source]
Bases:
object
Defines class to represent a family.
- property members_ids: list[str]
- property samples_index: tuple[int | None, ...]
- property tag_labels: set[str]
- property trios: dict[str, tuple[str, str, str]]
Split family into list of trios - child, mom and dad.
- class dae.pedigrees.family.FamilyTag(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
Enumeration of all available family tags.
- AFFECTED_DAD = 7
- AFFECTED_MOM = 8
- AFFECTED_PRB = 9
- AFFECTED_SIB = 10
- CONTROL = 6
- FEMALE_PRB = 16
- MALE_PRB = 15
- MISSING_DAD = 18
- MISSING_MOM = 17
- MULTIPLEX = 5
- NUCLEAR = 1
- QUAD = 2
- SIMPLEX = 4
- TRIO = 3
- UNAFFECTED_DAD = 11
- UNAFFECTED_MOM = 12
- UNAFFECTED_PRB = 13
- UNAFFECTED_SIB = 14
- property label: str
- class dae.pedigrees.family.Person(**attributes: Any)[source]
Bases:
object
Class to represent an individual.
- property family_bin: int | None
- property generated: bool
- property layout: str | None
- property member_index: int
- property missing: bool
- property not_sequenced: bool
- property sample_index: int | None
dae.pedigrees.family_role_builder module
Family members’ roles with respect to the proband.
dae.pedigrees.family_tag_builder module
Helper class for tagging families.
- class dae.pedigrees.family_tag_builder.FamilyTagsBuilder[source]
Bases:
object
Class used ot apply all tags to a family.
- TAGS: dict[FamilyTag, Callable[[Family], bool]] = {FamilyTag.NUCLEAR: <function tag_nuclear_family>, FamilyTag.QUAD: <function tag_quad_family>, FamilyTag.TRIO: <function tag_trio_family>, FamilyTag.SIMPLEX: <function tag_simplex_family>, FamilyTag.MULTIPLEX: <function tag_multiplex_family>, FamilyTag.CONTROL: <function tag_control_family>, FamilyTag.AFFECTED_DAD: <function tag_affected_dad_family>, FamilyTag.AFFECTED_MOM: <function tag_affected_mom_family>, FamilyTag.AFFECTED_PRB: <function tag_affected_prb_family>, FamilyTag.AFFECTED_SIB: <function tag_affected_sib_family>, FamilyTag.UNAFFECTED_DAD: <function tag_unaffected_dad_family>, FamilyTag.UNAFFECTED_MOM: <function tag_unaffected_mom_family>, FamilyTag.UNAFFECTED_PRB: <function tag_unaffected_prb_family>, FamilyTag.UNAFFECTED_SIB: <function tag_unaffected_sib_family>, FamilyTag.MALE_PRB: <function tag_male_prb_family>, FamilyTag.FEMALE_PRB: <function tag_female_prb_family>, FamilyTag.MISSING_MOM: <function tag_missing_mom_family>, FamilyTag.MISSING_DAD: <function tag_missing_dad_family>}
- dae.pedigrees.family_tag_builder.check_family_tags_query(family: Family, or_mode: bool, include_tags: set[FamilyTag], exclude_tags: set[FamilyTag]) bool [source]
Check if a family passes specified filters.
- dae.pedigrees.family_tag_builder.check_nuclear_family(family: Family) bool [source]
Check if the family is a nuclear family.
- dae.pedigrees.family_tag_builder.tag_affected_dad_family(family: Family) bool [source]
Set affected dad family tag to the family.
- dae.pedigrees.family_tag_builder.tag_affected_mom_family(family: Family) bool [source]
Set affected mom family tag to the family.
- dae.pedigrees.family_tag_builder.tag_affected_prb_family(family: Family) bool [source]
Set affected proband family tag to the family.
- dae.pedigrees.family_tag_builder.tag_affected_sib_family(family: Family) bool [source]
Set affected sibling family tag to the family.
- dae.pedigrees.family_tag_builder.tag_control_family(family: Family) bool [source]
Set control family tag to the family.
- dae.pedigrees.family_tag_builder.tag_female_prb_family(family: Family) bool [source]
Set female proband family tag to the family.
- dae.pedigrees.family_tag_builder.tag_male_prb_family(family: Family) bool [source]
Set male proband family tag to the family.
- dae.pedigrees.family_tag_builder.tag_missing_dad_family(family: Family) bool [source]
Set missing dad family tag to the family.
- dae.pedigrees.family_tag_builder.tag_missing_mom_family(family: Family) bool [source]
Set missing mom family tag to the family.
- dae.pedigrees.family_tag_builder.tag_multiplex_family(family: Family) bool [source]
Set multiplex family tag to the family.
- dae.pedigrees.family_tag_builder.tag_nuclear_family(family: Family) bool [source]
Set nuclear family tag to the family.
- dae.pedigrees.family_tag_builder.tag_quad_family(family: Family) bool [source]
Set quad family tag to the family.
- dae.pedigrees.family_tag_builder.tag_simplex_family(family: Family) bool [source]
Set simplex family tag to the family.
- dae.pedigrees.family_tag_builder.tag_trio_family(family: Family) bool [source]
Set trio family tag to the family.
- dae.pedigrees.family_tag_builder.tag_unaffected_dad_family(family: Family) bool [source]
Set unaffected dad family tag to the family.
- dae.pedigrees.family_tag_builder.tag_unaffected_mom_family(family: Family) bool [source]
Set unaffected mom family tag to the family.
- dae.pedigrees.family_tag_builder.tag_unaffected_prb_family(family: Family) bool [source]
Set unaffected proband family tag to the family.
dae.pedigrees.generate_families_cache module
- dae.pedigrees.generate_families_cache.main(argv: list[str] | None = None, gpf_instance: GPFInstance | None = None) None [source]
Command line tool to create genotype groups families cache.
dae.pedigrees.layout module
Classes and helper functions to represent pedigree layout.
- class dae.pedigrees.layout.IndividualWithCoordinates(individual: Individual, x: float = 0.0, y: float = 0.0, size: float = 21.0)[source]
Bases:
object
Class to represent individuals with specified coordinates.
- SIZE = 21.0
- property x_center: float
- property y_center: float
- class dae.pedigrees.layout.Layout(intervals: list[IntervalForVertex] | None = None)[source]
Bases:
object
Represents a layout of a connected component of a family.
- class BBox(min_x, min_y, max_x, max_y)
Bases:
tuple
- max_x
Alias for field number 2
- max_y
Alias for field number 3
- min_x
Alias for field number 0
- min_y
Alias for field number 1
- static from_family(family: Family, add_missing_members: bool = True) list[Layout] [source]
Generate layout for each connected component of a family.
- static from_family_layout(family: Family) Layout | None [source]
Construct layout for each connected component using layout data.
- property id_to_position: dict[str, IndividualWithCoordinates]
- property individuals_by_rank: dict[str, int]
Return a dictionary mapping individual person IDs to their rank.
The rank is determined by the order of individuals in the _individuals_by_rank list. The higher the rank, the higher the position in the list.
- Returns:
A dictionary mapping individual person IDs to their rank.
dae.pedigrees.loader module
Loader for pedigree files.
- class dae.pedigrees.loader.FamiliesLoader(families_filename: str | Path | TextIO, **params: Any)[source]
Bases:
CLILoader
Pedigree files loader.
- static build_families_data_from_pedigree(ped_df: DataFrame, pedigree_params: dict[str, Any] | None = None) FamiliesData [source]
Build a families data object from a pedigree data frame.
- static flexible_pedigree_read(pedigree_filepath: str | Path | TextIO, *, ped_sep: str = '\t', ped_no_header: bool = False, ped_no_role: bool = False, ped_family: str | int = 'familyId', ped_person: str | int = 'personId', ped_mom: str | int = 'momId', ped_dad: str | int = 'dadId', ped_sex: str | int = 'sex', ped_status: str | int = 'status', ped_role: str | int = 'role', ped_proband: str | int = 'proband', ped_layout: str | int = 'layout', ped_generated: str | int = 'generated', ped_not_sequenced: str | int = 'not_sequenced', ped_sample_id: str | int = 'sample_id', enums_as_values: bool = False, **kwargs: Any) DataFrame [source]
Read a pedigree from file.
- load() FamiliesData [source]
- static load_pedigree_file(pedigree_filename: str | Path | TextIO, pedigree_params: dict[str, Any] | None = None) FamiliesData [source]
Load a pedigree files and return FamiliesData object.
- static load_simple_families_file(infile: str | Path | TextIO, ped_sep: str = '\t') FamiliesData [source]
Load a pedigree from a DAE simple family format file.
- classmethod parse_cli_arguments(argv: Namespace, *, use_defaults: bool = False) tuple[list[str], dict[str, Any]] [source]
Parse cli arguments.
- static save_families(families: FamiliesData, filename: str | Path | TextIO) None [source]
- static save_pedigree(families: FamiliesData, filename: str | Path | TextIO) None [source]
Save FamiliesData object into a pedigree file.
- static to_tsv(families: FamiliesData) str [source]
Convert a FamiliesData object into a TSV string.
dae.pedigrees.pedigrees module
- class dae.pedigrees.pedigrees.FamilyConnections(family: Family, id_to_individual: dict[str, Individual], id_to_mating_unit: dict[str, MatingUnit])[source]
Bases:
object
Representation of connections between family members.
- create_sandwich_instance() SandwichInstance [source]
Generate an Interval Graph Sandwich problem instance.
Based on https://academic.oup.com/bioinformatics/article-pdf/17/2/174/442086/170174.pdf Slightly modified to support people with multiple mates. :return: SandwichInstance
- classmethod from_family(family: Family, add_missing_members: bool = True) FamilyConnections | None [source]
Build family connections object from a family.
- get_individual(person_id: str) Individual | None [source]
- get_individuals() set[Individual] [source]
- get_individuals_with_rank(rank: int) set[Individual] [source]
- get_mating_units() set[MatingUnit] [source]
- get_sibship_units() set[SibshipUnit] [source]
- static is_valid_family(family: dict[str, MatingUnit]) bool [source]
Check if a family is valid.
- class dae.pedigrees.pedigrees.Individual(mating_units: list[MatingUnit] | None = None, member: Person | None = None, parents: MatingUnit | None = None, rank: int = -3673473456)[source]
Bases:
IndividualGroup
Represents an individual and all connected members.
- NO_RANK = -3673473456
- add_rank(rank: int) None [source]
Calculate and set generation rank for each individual in a group.
- are_mates(other_individual: Individual) bool [source]
- are_siblings(other_individual: Individual) bool [source]
- children_set() set[Individual] [source]
Return set of children in the group.
- individual_set() set[Individual] [source]
Return set of individuals in the group.
- class dae.pedigrees.pedigrees.IndividualGroup[source]
Bases:
ABC
Group of individuals connected to an individual.
- abstract children_set() set[Individual] [source]
Return set of children in the group.
- abstract individual_set() set[Individual] [source]
Return set of individuals in the group.
- class dae.pedigrees.pedigrees.Interval(left: float = 0.0, right: float = 1.0)[source]
Bases:
object
Represents an interval between two points on a number line.
- intersection(other: IntervalForVertex) Interval | None [source]
Compute the intersection of this interval with another interval.
- Args:
- other (IntervalForVertex): The other interval to compute the
intersection with.
- Returns:
- Optional[Interval]: The intersection interval if it exists,
None otherwise.
- class dae.pedigrees.pedigrees.IntervalForVertex(vertex: IndividualGroup, left: float = 0.0, right: float = 1.0)[source]
Bases:
Interval
Represents an interval associated with a vertex in a pedigree.
- class dae.pedigrees.pedigrees.MatingUnit(mother: Individual, father: Individual, children: SibshipUnit | None = None)[source]
Bases:
IndividualGroup
Gropu of individuals connected in a mating unit.
- children_set() set[Individual] [source]
Return set of children in the group.
- individual_set() set[Individual] [source]
Return set of individuals in the group.
- other_parent(this_parent: Individual) Individual [source]
- class dae.pedigrees.pedigrees.Realization(graph: Graph, forbidden_graph: Graph, intervals: list[IntervalForVertex] | None = None, domain: list[IndividualGroup] | None = None, max_width: int = 3, _cached_active_vertices: set[IndividualGroup] | None = None, _cached_maximal_set: set[IndividualGroup] | None = None, _graph_neighbors_cache: dict[IndividualGroup, set[IndividualGroup]] | None = None, _cached_dangling_set: set[IndividualGroup] | None = None, _cached_vertex_degree: dict[IndividualGroup, int] | None = None)[source]
Bases:
object
Represents a realization in a pedigree graph.
- Attributes:
graph (nx.Graph): The graph representing the pedigree. forbidden_graph (nx.Graph): The graph representing forbidden edges
in the pedigree.
- intervals (Optional[list[IntervalForVertex]]): The intervals for each
vertex in the pedigree.
domain (Optional[list[IndividualGroup]]): The domain of the pedigree. max_width (int): The maximum width of the pedigree. _cached_active_vertices (Optional[set[IndividualGroup]]): Cached set of
active vertices.
- _cached_maximal_set (Optional[set[IndividualGroup]]): Cached set of
maximal vertices.
- _graph_neighbors_cache (
Optional[dict[IndividualGroup, set[IndividualGroup]]]): Cached neighbors of each vertex.
- _cached_dangling_set (Optional[set[IndividualGroup]]): Cached set of
dangling vertices.
- _cached_vertex_degree (Optional[dict[IndividualGroup, int]]): Cached
degree of each vertex.
- can_extend(new_vertex: IndividualGroup) bool [source]
Determine whether a new vertex can be added to the pedigree.
- Args:
new_vertex (IndividualGroup): The new vertex to be added.
- Returns:
bool: True if the new vertex can be added, False otherwise.
- copy() Realization [source]
- dangling(vertex: IndividualGroup) set[IndividualGroup] [source]
- dangling_set() set[IndividualGroup] [source]
Return a set of the dangling vertices in the pedigree graph.
Dangling vertices are vertices that have no outgoing edges.
- Returns:
set[IndividualGroup]: A set of IndividualGroup objects representing the dangling vertices.
- degree(vertex: IndividualGroup) int [source]
Calculate the degree of a vertex in the pedigree.
- Parameters:
vertex (IndividualGroup): The vertex for which to calculate the degree.
- Returns:
int: The degree of the vertex.
- extend(vertex: IndividualGroup) bool [source]
- force_extend(vertex: IndividualGroup) None [source]
Extend the pedigree by adding a new vertex.
Parameters: - vertex (IndividualGroup): The vertex to be added to the pedigree.
Returns: - None
- get_active_vertex_edges(vertex: IndividualGroup) set[IndividualGroup] [source]
- get_active_vertices() set[IndividualGroup] [source]
Return a set of active vertices in the domain.
- Returns:
set[IndividualGroup]: A set of active vertices.
- get_interval(vertex: IndividualGroup) IntervalForVertex [source]
- get_maximal_set() set[IndividualGroup] [source]
Return the maximal set of IndividualGroup objects in the domain.
If the maximal set has already been computed, it is returned from the cache. Otherwise, the maximal set is computed by iterating over the domain and checking if each IndividualGroup is maximal. The computed maximal set is then stored in the cache for future use.
- Returns:
set[IndividualGroup]: The maximal set of IndividualGroup objects.
- is_active_vertex(vertex: IndividualGroup) bool [source]
- class dae.pedigrees.pedigrees.SandwichInstance(vertices: set[IndividualGroup], required_graph: Graph, forbidden_graph: Graph)[source]
Bases:
object
Represent a sandwich instance representing the pedigree.
- Attributes:
- vertices (set[IndividualGroup]): The set of vertices in the sandwich
instance.
- required_graph (nx.Graph): The required graph representing the
connections between vertices.
- forbidden_graph (nx.Graph): The forbidden graph representing the
forbidden connections between vertices.
- static from_sets(all_vertices: set[IndividualGroup], required_set: set[tuple[IndividualGroup, IndividualGroup]], forbidden_set: set[tuple[IndividualGroup, IndividualGroup]]) SandwichInstance [source]
Create a SandwichInstance object.
- Args:
- all_vertices (set[IndividualGroup]): Set of all vertices in the
graph.
- required_set (set[tuple[IndividualGroup, IndividualGroup]]): Set
of required edges.
- forbidden_set (set[tuple[IndividualGroup, IndividualGroup]]): Set
of forbidden edges.
- Returns:
SandwichInstance: The created SandwichInstance object.
- class dae.pedigrees.pedigrees.SandwichSolver[source]
Bases:
object
A class that provides methods for solving sandwich instances.
Methods: - solve(sandwich_instance: SandwichInstance):
Solves the given sandwich instance and returns a list of intervals for each vertex, or None if no solution is found.
- try_solve(sandwich_instance: SandwichInstance)
Tries to solve the given sandwich instance and returns a list of intervals for each vertex, or None if no solution is found.
- static solve(sandwich_instance: SandwichInstance) list[IntervalForVertex] | None [source]
Solve the sandwich instance.
- Args:
sandwich_instance (SandwichInstance): The sandwich instance to solve.
- Returns:
Optional[list[IntervalForVertex]]: A list of intervals for each vertex if a solution is found, otherwise an empty list.
- static try_solve(sandwich_instance: SandwichInstance) list[IntervalForVertex] | None [source]
Try to solve the sandwich instance by finding a realization.
Searchs for realization that satisfies the given constraints.
- Args:
sandwich_instance (SandwichInstance): The sandwich instance to be solved.
- Returns:
Optional[list[IntervalForVertex]]: A list of intervals for each vertex if a solution is found,otherwise None.
- class dae.pedigrees.pedigrees.SibshipUnit(individuals: Iterable[Individual] | None = None)[source]
Bases:
IndividualGroup
Group of individuals connected as siblings.
- individual_set() set[Individual] [source]
Return set of individuals in the group.
dae.pedigrees.testing module
Defines tools usefull for testing families.
- dae.pedigrees.testing.build_families_data(content: str) FamiliesData [source]