Ham

ham is the main object oh Ham. It contains all the information and functions required to performs and HOGs analysis.


class pyham.ham.Ham(tree_file=None, hog_file=None, type_hog_file='orthoxml', filter_object=None, use_internal_name=False, orthoXML_as_string=False, tree_format='newick_string', phyloxml_internal_name_tag='taxonomy_scientific_name', phyloxml_leaf_name_tag='taxonomy_scientific_name', use_data_from=None, query_database=None, species_resolve_mode=None, with_parser_progress=False, fail_fast=False, id_schema='auto')[source]
Attributes:
tree_file (str): Path to the file that contained the taxonomy information.
hog_file (str): Path to the file that contained the HOGs information.
hog_file_type (str): File type of the hog_file. Can be “orthoxml or “hdf5”. Defaults to “orthoxml”.
top_level_hogs (dict): Dictionary that map hog unique id with its list of related pyham.abstractgene.HOG.
extant_gene_map (dict): Dictionary that map gene unique id with its list of related pyham.abstractgene.Gene.
external_id_mapper (dict): Dictionary that map a gene external id with its list of related pyham.abstractgene.HOG or pyham.abstractGene.gene.
HOGMaps (dict): Dictionary that map a frozenset of a pair of genomes to its pyham.mapper.HOGsMap.
filter_obj (pyham.pyham.ParserFilter): ParserFilter used during the instanciation of Ham. Defaults to None.
taxonomy: (pyham.mapper.Taxonomy): pyham.pyham.Taxonomy build and used by pyham.pyham.Ham instance.
orthoXML_as_string (Bool) If set to true, hog_file is a string of an orthoxml file. Defaults to False.
Args:
tree_file (str): Path to the file that contained the taxonomy information.
hog_file (str): Path to the file that contained the HOGs information.
type_hog_file (str, optional): File type of the hog_file. Can be “orthoxml or “hdf5”. Defaults to “orthoxml”.
filter_object (pyham.pyham.ParserFilter, optional): pyham.pyham.ParserFilter used during the instantiation of pyham.pyham.Ham. Defaults to None.
use_internal_name (Boolean, optional): Set to decide to use or not the internal naming of the given taxonomy. This should be set to False when support values are provided in the newick. Defaults to False.
tree_format (str): type of inputted tree file. Defaults to newick_string. Can be ‘newick’, ‘phyloxml, ‘newick_string’.
phyloxml_leaf_name_tag (str) tag to use in the phyloxml to name the extant species (leaves). Defaults tag is taxonomy.scientific_name to populate species names. available options: ‘clade_name’, ‘taxonomy_scientific_name’, ‘taxonomy_code’. Beware than missing species names will stop pyham working.
phyloxml_internal_name_tag (str) tag to use in the phyloxml to name the ancestral species (internal nodes). Defaults will use taxonomy.scientific_name to populate species names. available options: ‘clade_name’, ‘taxonomy_scientific_name’, ‘taxonomy_code’. Beware than missing species names will stop pyham working.
use_data_from (str) if specified, use data from a remote databaseto populate pyHam. Defaults to None. Options: ‘oma’.
query_database (str) if use_data_from is specified, use this as a query to fetch the orthoxml and tree information for the related query hog (gene family). For ‘oma’, this correspond to the oma gene id (e.g. ‘HUMAN12’ or ‘CHIMP1435’).
with_parser_progress (:bool:, optional) whether to show progress bar when parsing the XML file. In a terminal, log messages emitted during parsing can garble the bar; to interleave them cleanly, wrap the call in tqdm.contrib.logging.logging_redirect_tqdm().
fail_fast (Boolean, optional) if a HOG’s claimed taxonomic level (TaxRange/taxid) conflicts with the given species tree, raise pyham.abstractgene.TaxonomicConflictError immediately at the first conflict found. If False (default), keep parsing and collect every conflict found across the whole file, raising a single combined error (with all conflicts available via its conflicts attribute) once parsing completes.
id_schema (str, optional) the HOG id scheme used by the orthoxml file, one of ‘LOFT’, ‘LOFT_TAXID’, ‘GENERIC’ (see pyham.id_formats), used to synthesize ids for HOG levels the species tree implies but the file doesn’t explicitly encode. Defaults to ‘auto’, which samples the first few families of the file to detect the scheme automatically. The resolved value is available afterwards as self.id_schema.
compare_genomes_lateral(genome1, genome2)[source]

Function to compute a pyham.mapper.MapLateral based on the 2 given genomes. The genome order doesn’t matter.

Attributes:
genome1 (pyham.genome.Genome): First pyham.genome.Genome to compare.
genome2 (pyham.genome.Genome): Second pyham.genome.Genome to compare.
Returns:
Raises:
TypeError: if genome1 and genome2 are not pyham.genome.Genome.
compare_genomes_vertically(genome1, genome2)[source]

Function to compute a MapVertical based on the 2 given genomes. The genome order doesn’t matter.

Attributes:
genome1 (pyham.genome.Genome): First pyham.genome.Genome to compare.
genome2 (pyham.genome.Genome): Second pyham.genome.Genome to compare.
Returns:
Raises:
TypeError: if genome1 and genome2 are not pyham.genome.Genome.
create_iHam(hog, outfile=None)[source]

Function to compute a pyham.IHAM.

If an outfile is specified, export the pyham.IHAM as html file.

Attributes:
hog (pyham.abstractgene.HOG): HOG use as template for the pyham.IHAM.
outfile (str, optional): Path to the IHAM html file.
Returns:
create_tree_profile(hog=None, outfile=None, as_html=True, export_with_histogram=True)[source]

Function to compute a pyham.TreeProfile.

If no hog are given the tree profile will be created for the whole Ham setup (all internal nodes with all HOGs). Otherwise, the tree profile is build for the specific hog given.

If an outfile is specified, export the create_tree_profile as image into file.

Attributes:
hog (pyham.abstractgene.HOG, optional): HOG use as template for the create_tree_profile.
outfile (str, optional): Path to the create_tree_profile output image file. valid extensions are .SVG, .PDF, .PNG.
export_with_histogram (Bool, optional): If True, export image with histogram at each internal node otherwise display internal node information as text.
as_html (Bool, optional): If true, the tree profile will be exported as html file containing an interactive viewer to handle tree profile information.
Returns:
get_ancestral_genome_by_mrca_of_genome_set(genome_set)[source]

Get the pyham.genome.AncestralGenome corresponding to the MRCA of query genomes.

Args:

genome_set (set): Set of pyham.genome.AncestralGenome.

Returns:

pyham.genome.AncestralGenome or raise KeyError

get_ancestral_genome_by_name(name)[source]

Get the pyham.genome.AncestralGenome corresponding of the query name.

Args:

name (str): Name of the pyham.genome.AncestralGenome.

Returns:

pyham.genome.AncestralGenome or raise KeyError

get_ancestral_genome_by_taxon(taxon)[source]

Get the pyham.genome.AncestralGenome corresponding of the query taxon.

Args:

taxon (str): treeNode object of the pyham.taxonomy.Taxonomy.tree object.

Returns:

pyham.genome.AncestralGenome or raise KeyError

get_dict_extant_genes()[source]

Get a dictionary that map all unique gene id with their related pyham.abstractgene.Gene.

Returns:

a dictionary mapping unique gene Id (str) with pyham.abstractgene.Gene.

get_dict_top_level_hogs()[source]

Get a dictionary that map all top level hog id with their related pyham.abstractgene.HOG.

Returns:

a dictionary mapping hog Id (str) with pyham.abstractgene.HOG.

get_extant_genome_by_name(name)[source]

Get the pyham.genome.ExtantGenome that match the query name.

Args:

name (str): Name of the pyham.genome.ExtantGenome.

Returns:

pyham.genome.ExtantGenome or raise KeyError

get_gene_by_id(gene_unique_id)[source]

Get the pyham.abstractgene.Gene that match the query unique gene Id.

Args:
gene_unique_id (str or int): Unique gene Id.
Returns:

pyham.abstractgene.Gene

Raises:

KeyError is not pyham.abstractgene.Gene match the id.

get_genes_by_external_id(external_gene_id)[source]

Get the list of pyham.abstractgene.Gene that match the query external gene Id.

Args:

external_gene_id (str or int): External gene Id.

Returns:

a list of pyham.abstractgene.Gene

Raises:

KeyError if no pyham.abstractgene.Gene match id.

get_hog_by_gene(gene)[source]

Get the top level HOG that contain the query pyham.abstractgene.Gene. If the pyham.abstractgene.Gene is a singleton it will return itself.

Args:

gene (pyham.abstractgene.Gene): pyham.abstractgene.Gene object.

Returns:

pyham.abstractgene.HOG

Raises:

KeyError is gene is not a pyham.abstractgene.Gene.

get_hog_by_id(hog_id)[source]

Get the top level HOG that match the hog id query.

Args:

hog_id (str or int): Top level HOG id.

Returns:

pyham.abstractgene.HOG

Raises:

KeyError if id match no pyham.abstractgene.HOG.

get_list_ancestral_genomes()[source]

Get the list of all pyham.genome.AncestralGenome created during the parsing.

Returns:

a list of pyham.genome.AncestralGenome.

get_list_extant_genes()[source]

Get the list of all pyham.abstractgene.Gene.

Returns:

a list of pyham.abstractgene.Gene.

get_list_extant_genomes()[source]

Get the list of all pyham.genome.ExtantGenome created during the parsing.

Returns:

a list of pyham.genome.ExtantGenome.

get_list_top_level_hogs()[source]

Get the list of all the top level pyham.abstractgene.HOG.

Returns:

a list of pyham.abstractgene.HOG.

get_taxon_by_name(name)[source]

Get the ete3.TreeNode object of the pyham.taxonomy.Taxonomy.tree corresponding of the query name.

Args:

name (str): Name of the treeNode.

Returns:

ete3.TreeNode or raise KeyError