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. Ifpyham.abstractgene.HOGreturn self, thepyham.abstractgene.HOGis already top level. Ifpyham.abstractgene.Genereturn self, thepyham.abstractgene.Geneis a singleton.- Returns:
return
pyham.abstractgene.HOG.
- search_ancestor_hog_in_ancestral_genome(ancestral_genome)[source]¶
Get the
HOGrelated to the queryAncestralGenomefrom which thisAbstractGeneis descendant otherwise return None. In addition, it returns a boolean whether a duplication occurs in between the twoAbstractGene.- Args:
ancestral_genome (
pyham.genome.AncestralGenome): Ancestral genome of interest.- Returns:
return
pyham.abstractgene.HOGor None andbool
- 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 idgene_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.
- 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.ExtantGenomegiven 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 (listofpyham.abstractgene.AbstractGene): A list of direct descendants AbstractGene.hogvis (pyham.IHAM):pyham.IHAMobject of this HOG.duplications (listofpyham.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.AbstractGeneand 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:
- Returns:
pyham.abstractgene.HOGif found otherwise None.
- get_all_descendant_genes()[source]¶
Get all
Genepresent in this HOG.- Returns:
list of
pyham.abstractgene.Gene
- get_all_descendant_genes_clustered_by_species()[source]¶
Get all
pyham.abstractgene.Genepresent in this HOG clustered by speciespyham.genomeExtantGenome.- Returns:
Dictionary of
pyham.genome.ExtantGenomemap their list ofpyham.abstractgene.Gene.
- get_all_descendant_hog_levels()[source]¶
Get all
pyham.genome.Genomepresent in this HOG hierarchy.- Returns:
List of
pyham.genome.Genome.
- get_all_descendant_hogs()[source]¶
Get all
pyham.abstractgene.HOGpresent in this HOG hierarchy.- Returns:
Dictionary of
pyham.genomeExtantGenomemap their list ofpyham.abstractgene.Gene.
- get_hog_vis(newick_str)[source]¶
Lazy getter of the
pyham.abstractgene.HOGIHAM.- Args:
newick_str (
str): newick species tree used by the create_iHam.- Returns:
pyham.IHAMof 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/Genehere 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.
- remove_child(child_to_remove)[source]¶
Remove from the children attribute a given
AbstractGeneand 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.AncestralGenomegiven as parameter as genome attribute.- Attributes:
- genome (
pyham.genome.AncestralGenome): Ancestral genome to be set as genome.
- to_ete_tree()[source]¶
Convert this
HOGand its nested sub-HOGs into anete4.Tree.Each nested
HOGbecomes an internal node named after its hog_id (also stored as the “hog_id” prop), and each terminalGenebecomes 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