Region#
- class panorama.region.Region(name)#
Bases:
RegionRepresents a region in a pangenome.
- Parameters:
name (
str) – The name of the region.
- __delitem__(position)#
Remove the gene at the given position
- Parameters:
position – Position of the gene
- Raises:
KeyError – Gene at the given position does not exist
- __eq__(other)#
Test whether two Region objects have the same gene families
- Parameters:
other (
Region) – Another region to test equality of regions- Return type:
bool- Returns:
Equal or not
- Raises:
TypeError – Try to compare a region with another type object
- __getitem__(position)#
Get the gene at the given position
- Parameters:
position (
int) – Position of the gene- Return type:
Gene- Returns:
Gene in the Region at the given position
- Raises:
KeyError – Gene at the given position does not exist
- __hash__()#
Create a hash value for the region
- Return type:
int
- __init__(name)#
Constructor method.
- Parameters:
name (
str) – The name of the region.
- __len__()#
Get the number of genes in the region
- Return type:
int
- __repr__()#
Region representation
- Return type:
str
- __setitem__(position, gene)#
Set a gene by is position in the region
- Parameters:
position (
int) – Position of the gene in the contiggene (
Gene) – Gene to add in the region
- Raises:
TypeError – If the gene is not an instance of Gene.
ValueError – If the organism or contig of the gene is different from the region.
KeyError – If another gene already exists at the specified position.
ValueError – If the position of the gene does not match the provided position.
- add(gene)#
Add a gene to the region
- Parameters:
gene (
Gene) – Gene to add
- add_metadata(metadata, metadata_id=None)#
Add metadata to metadata getter
- Parameters:
metadata (
Metadata) – metadata value to add for the sourcemetadata_id (
int) – metadata identifier
- Raises:
AssertionError – Source or metadata is not with the correct type
- Return type:
None
- property contig: Contig#
Get the starter contig link to RGP
- Returns:
Contig corresponding to the region
- property coordinates: List[Tuple[int]]#
Return the coordinates of the region :return: coordinates of the region
- 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]#
Get the gene families in the RGP
- Returns:
Gene families
- 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: Generator[Gene, None, None]#
Generate the gene as they are ordered in contigs
- Returns:
Genes in the region
- get(position)#
Get a gene by its position
- Parameters:
position (
int) – Position of the gene in the contig- Return type:
Gene- Returns:
Wanted gene
- Raises:
TypeError – Position is not an integer
- get_bordering_genes(n, multigenics, return_only_persistents=True)#
Get the bordered genes in the region. Find the n persistent and single copy gene bordering the region. If return_only_persistents is False, the method return all genes included between the n single copy and persistent genes.
- Parameters:
n – Number of genes to get
multigenics – pangenome graph multigenic persistent families
return_only_persistents – return only non multgenic persistent genes identify as the region. If False return all genes included between the borders made of n persistent and single copy genes around the region.
- Returns:
A list of bordering genes in start and stop position
- get_metadata(source, metadata_id=None)#
Get metadata from metadata getter by its source and identifier
- Parameters:
source (
str) – source of the metadatametadata_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_ordered_genes()#
Get ordered genes of the region, taking into account the circularity of contigs.
- Return type:
List[Gene]- Returns:
A list of genes ordered by their positions in the region.
- 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
- id_counter = 0#
- identify_rgp_last_and_first_genes()#
Identify first and last genes of the rgp by taking into account the circularity of contigs.
Set the attributes _starter: first gene of the region and _stopper: last gene of the region and _coordinates
- property is_contig_border: bool#
Indicates if the region is bordering a contig
- Returns:
True if bordering else False
- Raises:
AssertionError – No genes in the regions, it’s not expected
- property is_whole_contig: bool#
Indicates if the region is an entire contig
- Returns:
True if whole contig else False
- property length#
Get the length of the region
- Returns:
Size of the region
- 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
- property modules: Set[Module]#
Get the modules of gene families in the RGP
- Returns:
Modules found in families of the RGP
- property number_of_families: int#
Get the number of different gene families in the region
- Returns:
Number of families
- property number_of_metadata: int#
Get the number of metadata associated to feature
- property organism: Organism#
Get the Organism link to RGP
- Returns:
Organism corresponding to the region
- property overlaps_contig_edge: bool#
- remove(position)#
Remove a gene by its position
- Parameters:
position – Position of the gene in the contig
- Raises:
TypeError – Position is not an integer
- property sources: Generator[str, None, None]#
Get all metadata source in gene family
- Returns:
Metadata source
- property spot: Spot | None#
- property start: int#
Get the starter start link to RGP
- Returns:
start position in the contig of the first gene of the RGP
- property starter: Gene#
Return first gene of the region. If this gene is not identified, it does that first. :return: first gene of the region
- property stop: int#
Get the stopper stop link to RGP
- Returns:
start position in the contig of the last gene of the RGP
- property stopper: Gene#
Return last gene of the region. If this gene is not identified, it does that first. :return: last gene of the region
- string_coordinates()#
Return a string representation of the coordinates
- Return type:
str