GeneFamily#

class panorama.geneFamily.GeneFamily(family_id, name)#

Bases: GeneFamily

Represents a single gene family. It is a node in the pangenome graph and is aware of its genes and edges.

name#

The name of the gene family to be printed in output files.

Type:

str

_hmm#

The HMM associated with the gene family.

Type:

HMM, optional

profile#

The profile associated with the gene family.

Type:

optional

optimized_profile#

The optimized profile for the gene family.

Type:

optional

_units_getter#

A dictionary to retrieve system units.

Type:

dict

_systems_getter#

A dictionary to retrieve systems.

Type:

dict

_akin#

The akin families associated with other pangenomes.

Type:

Akin, optional

property HMM: HMM#

Gets the HMM associated with the GeneFamily.

Returns:

HMM – The HMM associated with the GeneFamily.

__delitem__(identifier)#

Remove the gene for the given name in the gene family

Parameters:

position – ID of the gene in the family

Raises:
  • TypeError – If the identifier is not instance string

  • KeyError – Gene with the given identifier does not exist in the contig

__eq__(other)#

Checks if two GeneFamily instances are equal based on their genes.

Parameters:

other (GeneFamily) – Another GeneFamily instance to compare.

Returns:

bool – True if the GeneFamily instances are equal, False otherwise.

Raises:

TypeError – If the other object is not a GeneFamily instance.

Return type:

bool

__getitem__(identifier)#

Get the gene for the given name

Parameters:

identifier (str) – ID of the gene in the gene family

Return type:

Gene

Returns:

Wanted gene

Raises:
  • TypeError – If the identifier is not instance string

  • KeyError – Gene with the given identifier does not exist in the contig

__hash__()#

Returns the hash of the GeneFamily instance.

Returns:

int – The hash value of the GeneFamily instance.

Return type:

int

__init__(family_id, name)#

Initializes a GeneFamily instance.

Parameters:
  • family_id (int) – The internal identifier of the gene family.

  • name (str) – The name of the gene family.

__len__()#

Get the number of genes in the family

Return type:

int

Returns:

The length of the list of genes

__ne__(other)#

Checks if two GeneFamily instances are not equal.

Parameters:

other (GeneFamily) – Another GeneFamily instance to compare.

Returns:

bool – True if the GeneFamily instances are not equal, False otherwise.

Return type:

bool

__repr__()#

Returns a string representation of the GeneFamily instance.

Returns:

str – The string representation of the GeneFamily instance.

Return type:

str

__setitem__(identifier, gene)#

Set gene to Gene Family

Parameters:
  • identifier (str) – ID of the gene

  • gene (Gene) – Gene object to add

Raises:
  • TypeError – If the gene is not instance Gene

  • TypeError – If the identifier is not instance string

  • ValueError – If a gene in getter already exists at the name

_getattr_from_ppanggolin(family)#

Copies attributes from a PPanGGOLiN GeneFamily instance to a PANORAMA GeneFamily instance.

Parameters:

family (GeneFamily) – A PPanGGOLiN GeneFamily instance.

add(gene)#

Add a gene to the gene family, and sets the gene’s :attr:family accordingly.

Parameters:

gene (Gene) – The gene to add

Raises:

TypeError – If the provided gene is of the wrong type

add_metadata(metadata, metadata_id=None)#

Add metadata to metadata getter

Parameters:
  • metadata (Metadata) – metadata value to add for the source

  • metadata_id (int) – metadata identifier

Raises:

AssertionError – Source or metadata is not with the correct type

Return type:

None

add_sequence(seq)#

Assigns a protein sequence to the gene family.

Parameters:

seq (str) – The sequence to add to the gene family

add_spot(spot)#

Add the given spot to the family

Parameters:

spot (Spot) – Spot belonging to the family

property akin: Akin#

Gets the akin families associated with other pangenomes.

Returns:

Akin – The akin families.

Raises:

KeyError – If no akin families are assigned.

contains_gene_id(identifier)#

Check if the family contains already a gene id

Parameters:

identifier – ID of the gene

Returns:

True if it contains False if it does not

Raises:

TypeError – If the identifier is not instance string

del_metadata_by_attribute(**kwargs)#

Remove a source from the feature

del_metadata_by_source(source)#

Remove a source from the feature

Parameters:

source (str) – Name of the source to delete

Raises:
  • AssertionError – Source is not with the correct type

  • KeyError – Source does not belong in the MetaFeature

duplication_ratio(exclude_fragment)#

Checks if the gene family is considered single copy based on the provided criteria.

Parameters:
  • dup_margin – The maximum allowed duplication margin for a gene family to be considered single copy.

  • exclude_fragment (bool) – A boolean indicating whether to exclude fragments when determining single copy families.

Return type:

bool

Returns:

A boolean indicating whether the gene family is single copy.

property edges: Generator[Edge, None, None]#

Returns all Edges that are linked to this gene family

Returns:

Edges of the gene family

formatted_metadata_dict()#

Format metadata by combining source and field values.

Given an object with metadata, this function creates a new dictionary where the keys are formatted as ‘source_field’.

Return type:

Dict[str, List[str]]

Returns:

A dictionary with formatted metadata.

formatted_metadata_dict_to_string(separator='|')#

Format metadata by combining source and field values.

Given an object with metadata, this function creates a new dictionary where the keys are formatted as ‘source_field’. In some cases, it is possible to have multiple values for the same field, in this situation, values are concatenated with the specified separator.

Parameters:

separator (str) – The separator used to join multiple values for the same field (default is ‘|’).

Return type:

Dict[str, str]

Returns:

A dictionary with formatted metadata.

property genes#

Return all the genes belonging to the family

Returns:

Generator of genes

get(identifier)#

Get a gene by its name

Parameters:

identifier (str) – ID of the gene

Return type:

Gene

Returns:

Wanted gene

Raises:

TypeError – If the identifier is not instance string

get_edge(target)#

Get the edge by the target gene family neighbor

Return type:

Edge

get_genes_per_org(org)#

Returns the genes belonging to the gene family in the given Organism

Parameters:

org (Organism) – Organism to look for

Return type:

Generator[Gene, None, None]

Returns:

A set of gene(s)

get_metadata(source, metadata_id=None)#

Get metadata from metadata getter by its source and identifier

Parameters:
  • source (str) – source of the metadata

  • metadata_id (int) – metadata identifier

Raises:

KeyError – No metadata with ID or source is found

Return type:

Metadata

get_metadata_by_attribute(**kwargs)#

Get metadata by one or more attribute

Return type:

Generator[Metadata, None, None]

Returns:

Metadata searched

get_metadata_by_source(source)#

Get all the metadata feature corresponding to the source

Parameters:

source (str) – Name of the source to get

Return type:

Optional[Dict[int, Metadata]]

Returns:

List of metadata corresponding to the source

Raises:

AssertionError – Source is not with the correct type

get_org_dict()#

Returns the organisms and the genes belonging to the gene family

Return type:

Dict[Organism, Set[Gene]]

Returns:

A dictionary of organism as key and set of genes as values

has_metadata()#

Does the feature has some metadata associated.

Return type:

bool

Returns:

True if it has metadata else False

property has_module: bool#

Check if the family is in a module

return True if it has a module else False

has_source(source)#

Check if the source is in the metadata feature

Parameters:

source (str) – name of the source

Return type:

bool

Returns:

True if the source is in the metadata feature else False

is_multigenic()#

Checks whether the GeneFamily is multigenic.

Returns:

bool – True if the GeneFamily is multigenic, False otherwise.

Return type:

bool

is_multigenic_in_org(organism)#

Checks whether the GeneFamily is multigenic in a specific organism.

Parameters:

organism (Organism) – The organism to check.

Returns:

bool – True if the GeneFamily is multigenic in the organism, False otherwise.

Return type:

bool

is_single_copy(dup_margin, exclude_fragment)#

Checks if the gene family is considered single copy based on the provided criteria.

Parameters:
  • dup_margin (float) – The maximum allowed duplication margin for a gene family to be considered single copy.

  • exclude_fragment (bool) – A boolean indicating whether to exclude fragments when determining single copy families.

Return type:

bool

Returns:

A boolean indicating whether the gene family is single copy.

max_metadata_by_source()#

Get the maximum number of metadata for one source

Return type:

Tuple[str, int]

Returns:

Name of the source with the maximum annotation and the number of metadata corresponding

property metadata: Generator[Metadata, None, None]#

Generate metadata in gene families

Returns:

Metadata from all sources

mk_bitarray(index, partition='all')#

Produces a bitarray representing the presence/absence of the family in the pangenome using the provided index The bitarray is stored in the bitarray attribute and is a gmpy2.xmpz type.

Parameters:
  • index (Dict[Organism, int]) – The index computed by ppanggolin.pangenome.Pangenome.getIndex()

  • partition (str) – partition used to compute bitarray

property module#

Return module belonging to the family

Returns:

panorama.region.Module – module belonging to the family

property named_partition: str#

Reads the partition attribute and returns a meaningful name

Returns:

The partition name of the gene family

Raises:

ValueError – If the gene family has no partition assigned

property neighbors: Generator[GeneFamily, None, None]#

Returns all the GeneFamilies that are linked with an edge

Returns:

Neighbors

property number_of_edges: int#

Get the number of edges for the current gene family

property number_of_genes: int#

Get the number of genes for the current gene family

property number_of_metadata: int#

Get the number of metadata associated to feature

property number_of_neighbors: int#

Get the number of neighbor for the current gene family

property number_of_organisms: int#

Get the number of organisms for the current gene family

property number_of_spots: int#

Get the number of spots for the current gene family

property organisms: Generator[Organism, None, None]#

Returns all the Organisms that have this gene family

Returns:

Organisms that have this gene family

property partition#
static recast(family)#

Recasts a PPanGGOLiN GeneFamily into a PANORAMA GeneFamily.

Parameters:

family (GeneFamily) – A PPanGGOLiN GeneFamily instance.

Returns:

GeneFamily – The recast PANORAMA GeneFamily instance.

Return type:

GeneFamily

remove(identifier)#

Remove a gene by its name

Parameters:

identifier – Name of the gene

Returns:

Wanted gene

Raises:

TypeError – If the identifier is not instance string

property representative: Gene#

Get the representative gene of the family

Returns:

The representative gene of the family

set_edge(target, edge)#

Set the edge between the gene family and another one

Parameters:
  • target (GeneFamily) – Neighbor family

  • edge (Edge) – Edge connecting families

set_module(module)#

Add the given module to the family

Parameters:

module (Module) – Module belonging to the family

property sources: Generator[str, None, None]#

Get all metadata source in gene family

Returns:

Metadata source

property spots: Generator[Spot, None, None]#

Return all the spots belonging to the family

Returns:

Generator of spots