Genes

AbstractGene is an abstract class representing extant or ancestral genes.

class pyham.abstractgene.AbstractGene(arose_by_duplication=False, **kwargs)[source]

AbstractGene is an abstract class representing extant or ancestral genes. An AbstractGene is defined by an unique id, the genome it belongs to and its parent AbstractGene.

Attributes:
parent (pyham.abstractgene.HOG): Direct parent HOG this gene is descendant to. For and only for top level HOG, parent attribute is set to None.
genome (pyham.genome.Genome): Related Genome object.
arose_by_duplication: pyham.abstractgene.DuplicationNode if this AbstractGene arose by a duplication from its parent otherwise False.
Attributes:
arose_by_duplication (Bool): True if this AbstractGene arose by a duplication from its parent.
** kwargs: dictionary of attribute and value required to create the: obj:pyham.abstractgene.AbstractGene.
get_at_level(genome)[source]

Get for the query HOG, the ancestor or children AbstractGene in the genome of interest

Args:

genome (pyham.genome.Genome): Genome of interest.

Returns:

list of pyham.abstractgene.AbstractGene.

Raises:

TypeError: if genome is not a Genome. KeyError: If no HOG matches the query genome or it return itself.

get_top_level_hog()[source]

Get the related top level pyham.abstractgene.HOG. If pyham.abstractgene.HOG return self, the pyham.abstractgene.HOG is already top level. If pyham.abstractgene.Gene return self, the pyham.abstractgene.Gene is a singleton.

Returns:

return pyham.abstractgene.HOG.

abstractmethod is_singleton()[source]

Return true if singletons otherwise false

search_ancestor_hog_in_ancestral_genome(ancestral_genome)[source]

Get the HOG related to the query AncestralGenome from which this AbstractGene is descendant otherwise return None. In addition, it returns a boolean whether a duplication occurs in between the two AbstractGene.

Args:

ancestral_genome (pyham.genome.AncestralGenome): Ancestral genome of interest.

Returns:

return pyham.abstractgene.HOG or None and bool

abstractmethod set_genome(genome)[source]

Set the genome attribute using the given Genome.


class pyham.abstractgene.Gene(id, geneId=None, protId=None, transcriptId=None, **kwargs)[source]

Gene class for extant genes (inherit from AbstractGene).

Attributes:
unique_id internal unique id
gene_id id used to mapped to external ids.
prot_id id used to mapped to external ids.
transcript_id id used to mapped to external ids.
Attributes:
arose_by_duplication (Bool): True if this AbstractGene arose by a duplication from its parent.
** kwargs: dictionary of attribute and value required to create the: obj:pyham.abstractgene.AbstractGene.
get_dict_xref()[source]

Get the dictionary of cross references.

Returns:

Dictionary of external id tag map with their value.

is_singleton()[source]

Return true if singletons otherwise false

set_LOFT(loft_id)[source]

Set the LOFT identifier for the gene.

In case the ID has already been set, a ValueError is raised. It is assumed that a gene can only have one LOFT identifier.

set_genome(genome)[source]

This method set pyham.genome.ExtantGenome given as parameter as genome attribute.

Attributes:

genome (pyham.genome.ExtantGenome): Extant genome to be set as genome.

Raises:

TypeError: If genome is not pyham.genome.ExtantGenome. EvolutionaryConceptError: If we try to add more than one genome.


class pyham.abstractgene.HOG(id=None, **kwargs)[source]

HOG class represents ancestral genes. An AbstractGene is defined the genome it belongs to and its child/parent AbstractGene. Only top level HOG doesn’t have parent attribute (set to None).

Attributes:
hog_id (str): hog id. Defaults is None.
children (list of pyham.abstractgene.AbstractGene): A list of direct descendants AbstractGene.
hogvis (pyham.IHAM): pyham.IHAM object of this HOG.
duplications (list of pyham.abstractgene.DuplicationNode): list of all duplication node child of this HOG.
Attributes:
arose_by_duplication (Bool): True if this AbstractGene arose by a duplication from its parent.
** kwargs: dictionary of attribute and value required to create the: obj:pyham.abstractgene.AbstractGene.
add_child(child_to_add)[source]

Add in the children attribute a given pyham.abstractgene.AbstractGene and update parent attribute in child AbstractGene.

Attributes:

child_to_add (pyham.abstractgene.AbstractGene): add_child to add.

find_by_id(hog_id: str, taxid: int = None)[source]

Recursive function to find a HOG by its id and optionally its taxid.

Args:
hog_id (str): HOG id to be found.
taxid (optional, int): taxid of the genome of the HOG to be found.
Returns:

pyham.abstractgene.HOG if found otherwise None.

get_all_descendant_genes()[source]

Get all Gene present in this HOG.

Returns:

list of pyham.abstractgene.Gene

get_all_descendant_genes_clustered_by_species()[source]

Get all pyham.abstractgene.Gene present in this HOG clustered by species pyham.genomeExtantGenome.

Returns:

Dictionary of pyham.genome.ExtantGenome map their list of pyham.abstractgene.Gene.

get_all_descendant_hog_levels()[source]

Get all pyham.genome.Genome present in this HOG hierarchy.

Returns:

List of pyham.genome.Genome.

get_all_descendant_hogs()[source]

Get all pyham.abstractgene.HOG present in this HOG hierarchy.

Returns:

Dictionary of pyham.genomeExtantGenome map their list of pyham.abstractgene.Gene.

get_hog_vis(newick_str)[source]

Lazy getter of the pyham.abstractgene.HOG IHAM.

Args:

newick_str (str): newick species tree used by the create_iHam.

Returns:

pyham.IHAM of this HOG.

get_number_losses()[source]

Compute the number of implied gene losses within this HOG’s hierarchy, following the Dollo parsimony principle: once a gene lineage is lost it cannot be regained, so a whole clade lacking any representative under this HOG is explained by a single loss event placed on the branch leading to that clade, rather than one loss per missing descendant leaf.

For every ancestral level in this HOG’s subtree (starting at self), each immediate child taxon in the species tree that has no matching child HOG/Gene here contributes one loss; that clade is not explored further since it is already fully accounted for by this single event.

Returns:

int: number of implied Dollo loss events in this HOG’s subtree.

is_singleton()[source]

Return true if singletons otherwise false

remove_child(child_to_remove)[source]

Remove from the children attribute a given AbstractGene and update parent attribute in child AbstractGene.

Attributes:

child_to_add (AbstractGene): add_child to add.

score(score_id, value=None)[source]

Get or set a score attribute for this HOG.

If no value is passed, the stored value is returned or a KeyError is raised if this score has not been stored.

Attributes:

score_id (ExtantGenome): score to be set or returned. value (optional): A numeric value for the score of this HOG. score_id (ExtantGenome): score to be set or returned.

Raises:

KeyError: if score_id is unknown and accessed.

set_genome(genome)[source]

This method set pyham.genome.AncestralGenome given as parameter as genome attribute.

Attributes:
genome (pyham.genome.AncestralGenome): Ancestral genome to be set as genome.
to_ete_tree()[source]

Convert this HOG and its nested sub-HOGs into an ete4.Tree.

Each nested HOG becomes an internal node named after its hog_id (also stored as the “hog_id” prop), and each terminal Gene becomes a leaf named after its external gene id (geneId, protId or transcriptId, in that order of preference, falling back to its internal unique_id), with all available external ids attached as leaf props.

Returns:

ete4.Tree: tree representation of this HOG hierarchy, rooted at self.

visit(elem, function_extant_gene=None, function_postfix=None, function_prefix=None)[source]

Recursive function to traverse the HOG nested children hierarchy.

An arbitrary object “elem” is return at each visit() and is pass/returned from each recursive state function calls.

There is tree recursive state functions:

  • function_extant_gene: Function called at each ExtantGene child. Its take as argument the child ExtantGene and the “elem” and return processed “elem”.

  • function_postfix: Function called after each HOG child visit(). Its take as argument the child HOG and the “elem” and return processed “elem”.

  • function_prefix: First function called that take as argument the current HOG and the “elem” and return processed “elem”.

Attributes:
elem (arbitrary object): object that is pass through visit recursive and recursive state functions calls.
function_extant_gene (callback function): Callback function for ExtantGenes (leaves).
function_postfix (callback function): Callback function for after child visit current HOG.
function_prefix (callback function): Callback function for current HOG.
Returns:

return arbitrary