Module#

class panorama.region.Module(module_id, families=None)#

Bases: Module

Represents a module in a pangenome.

Parameters:
  • module_id (int) – The identifier of the module.

  • families (set) – The set of families that define the module.

__delitem__(name)#

Remove the gene family for the given name in the module

Parameters:

name – Name of the gene family

Raises:

KeyError – Family with the given name does not exist in the module

__eq__(other)#

Test whether two Module objects have the same gene families

Parameters:

other (Module) – Another module to test equality

Return type:

bool

Returns:

Equal or not

Raises:

TypeError – Try to compare a module with another type object

__getitem__(name)#

Get the gene family for the given name in the module

Parameters:

name – Name of the gene family

Return type:

GeneFamily

Returns:

Gene family with the given name

Raises:

KeyError – Family with the given name does not exist in the module

__hash__()#

Create a hash value for the module

Return type:

int

__init__(module_id, families=None)#

Constructor method.

Parameters:
  • module_id (int) – The identifier of the module.

  • families (set) – The set of families that define the module. Defaults to None.

__len__()#

Get the number of families in the module

Return type:

int

__repr__()#

Module representation

Return type:

str

__setitem__(name, family)#

Set a gene family in the module

Parameters:
  • name (str) – Name of the family

  • family (GeneFamily) – Gene family belonging to the module

Raises:
  • TypeError – Family is not instance GeneFamily

  • KeyError – Another family with the same name already exists in the module

__str__()#

String representation of the module

Return type:

str

add(family)#

Add a family to the module. Alias more readable for setitem

Parameters:

family (GeneFamily) – Region to add in the spot

Raises:

TypeError – Region is not an instance Region

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_unit(unit)#

Add a system to the module.

Parameters:

unit (System) – The system to add to the module.

Raises:
  • Exception – If a system with the same ID but different name or

  • gene families is already associated with the module.

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

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

Generator of the family in the module

Returns:

Families belonging to the module

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 gene_families: Generator[GeneFamily, None, None]#

Get the set of gene families that define the module.

Returns:

GeneFamily – The set of gene families.

get(name)#

Get a family by its name. Alias more readable for getitem

Parameters:

name (str) – Name of the family

Return type:

GeneFamily

Returns:

Wanted family

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_unit(identifier)#

Get a unit associated with the module.

Parameters:

identifier (int) – The identifier of the unit.

Returns:

System – The unit with the given identifier.

Raises:

KeyError – If the unit is not associated with the module.

has_metadata()#

Does the feature has some metadata associated.

Return type:

bool

Returns:

True if it has metadata 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

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 families in the organism using the provided index The bitarray is stored in the bitarray attribute and is a gmpy2.xmpz type.

Parameters:
  • partition (str) – filter module by partition

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

property number_of_metadata: int#

Get the number of metadata associated to feature

property number_of_organisms#

Get the number of organisms that contain the module.

Returns:

int – The number of organisms.

property organisms#

Get the set of organisms that contain the module.

Returns:

set – The set of organisms.

remove(name)#

Remove a family by its name. Alias more readable for delitem

Parameters:

name (str) – Name of the family

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

Get all metadata source in gene family

Returns:

Metadata source

property systems#

Generator of the systems associated with the module.

Yields:

System – The next system associated with the module.

property units#

Generator of the systems associated with the module.

Yields:

Generator[SystemUnit] – The next system associated with the module.