microbetag.build_mtg_cx2¶
- Aim:
Builds a microbetag-annotated network in a CX2 format, using the ndex2 (https://ndex2.readthedocs.io/) library.
Note
In case of the on-the-fly version, the annotated network is returned as a jsonifi-ed Flask Response. In the stand-alone version, the annotated network is saved (mtg-timestamp.cx2) and the user has to load it on Cytoscape to be able to visualize it and further exploit the MGG Cytoscape App (https://apps.cytoscape.org/apps/mgg) to parse and analyze the network.
Attributes¶
Functions¶
|
Updates a node's attributes by splitting taxonomy to the 7-levels scheme ( |
|
Initiates the nodes and edges of the network as dictionaries, in a ndex2-oriented format. |
|
Using the sequence mapping to their corresponding taxonomies objects, builds a dictionary with the |
|
Updates nodes with phenotypic traits. |
|
Updates nodes with FAPROTAX traits. |
|
Updates nodes with manta network cluster, assignment, and position data. |
|
Creates or updates an edge carrying pathway complementarities between a donor and a beneficiary node. |
|
Builds mapping objects to properly pass pathway/seed complementarities to their corresponding edges. |
|
|
|
Conceptually, the donor is the source, since a compound would be secreted from it |
|
|
|
Builds the microbetag annotated network in a CX2 format (https://cytoscape.org/cx/). |
|
Gets the df from the taxonomy.py returned when ran through the app.py and returns the equivalent |
|
|
|
Wrapper function for getting the various annotations previously made for a microbetag run |
Module Contents¶
- microbetag.build_mtg_cx2.__RANKS__ = ['domain', 'phylum', 'class', 'order', 'family', 'genus', 'species'][source]¶
- microbetag.build_mtg_cx2.taxonomy_levels_sa(node: Dict) None[source]¶
Updates a node’s attributes by splitting taxonomy to the 7-levels scheme (
__RANKS__) and giving their values to the corresponding ones. For stand-alone version.- Parameters:
node – A ndex2-oriented node’s dictionary; keys should be sequence ids
Note
Edits the node dictionary by adding a new key:value pair for each (of the 7) taxonomic level. Used only in the case of the stand-alone tool.
- microbetag.build_mtg_cx2.init_nodes_and_edges(edgelist: pandas.DataFrame, seq_id_to_taxonomy: Dict[str, str], onthefly=False, metadata=None, otf_seq_tax_df=None) Tuple[List[dict], List[str], List[dict]][source]¶
Initiates the nodes and edges of the network as dictionaries, in a ndex2-oriented format.
- Parameters:
edgelist – DataFrame containing ‘node_A’, ‘node_B’, and ‘microbetag::weight’.
seq_id_to_taxonomy – Mapping dictionary for sequence ids: taxonomy.
- Returns:
- A tuple containing:
nodes: A list of dictionaries with the nodes of the network
seq_ids_lst: A list with the sequence ids (of the abundance table) that are part of the network
edges: A list of dictionaries with the edges of the network
- Return type:
- microbetag.build_mtg_cx2.get_node_attributes(seq_id: str, seq_id_to_taxonomy: Dict, ncbi_ids_dict: Dict = None, metavars=None) Dict[source]¶
Using the sequence mapping to their corresponding taxonomies objects, builds a dictionary with the node’s taxonomy and mapped genomes (in case of on-the-fly) attributes, in a ndex2 and MGG-oriented way.
- Parameters:
seq_id – Sequence id of the node
seq_id_to_taxonomy – Dictionary with sequence ids keys and their corresponding taxonomies as value
config – Instance of the
Configclass
- Returns:
A dictionary with the a node’s attributes regarding the microbetag namespace of the MGG
- microbetag.build_mtg_cx2.update_with_phen_traits(nodes: List[dict], node_names: List[str], predictions_path: str, onthefly: bool) None[source]¶
Updates nodes with phenotypic traits.
- Parameters:
config – Configuration for loading phenotypic traits.
nodes (List[Dict]) – List of node dictionaries.
node_names (List[str]) – List of node names corresponding to node IDs.
Note
Like all functions applied in the nodes and edges, it does not return an object, it rather updates entries of the nodes dictionary.
Note
1. The node_names list is a mapping object where order is essential. It includes the sequence ids of the nodes present in the network, in the order they will be introduced in the ndex2 network constructor.
Initial phen_traits has the genome ids present in the phenotrex prediction files.
- microbetag.build_mtg_cx2.update_with_faprotax_traits(nodes: List[dict], node_names: List[str], fapr_tables, seq_col) None[source]¶
Updates nodes with FAPROTAX traits.
- Parameters:
config – Configuration for loading FAPROTAX traits.
nodes – List of node dictionaries.
node_names – List of node names corresponding to node IDs.
- microbetag.build_mtg_cx2.update_with_manta(nodes: List[dict], node_names: List[str], manta_net) Dict[source]¶
Updates nodes with manta network cluster, assignment, and position data.
- Returns:
A list of dictionaries representing the manta layout with node positions.
Note
Besides updating the entries of the nodes list, it also returns a ndex2.layout.
Attention
Currently, microbetag does not apply the manta layout returned. We could/should consider doing so by editing the ndex2 object.
- microbetag.build_mtg_cx2.pathway_complement_edge(edge_id: int, beneficiary: str, donor: str, complement: Dict, node_names: List[str], beneficiary_genome=None, donor_genome=None, update=False, cx_edges=None) Dict[source]¶
Creates or updates an edge carrying pathway complementarities between a donor and a beneficiary node.
Note
Conceptually, the donor is the source of the edge, since a compound would be secreted from it and drive to the beneficiary (target).
- Parameters:
edge_id (int) – ID of the edge
beneficiary (str) – The recipient of the complement. It is considered as the target of the edge in microbetag.
donor (str) – The source of the complement. It is considered as the donor of the edege.
complement (any) – The complement value.
node_names (list[str]) – List of node names to determine node indices.
interaction_type (str) – Type of interaction (e.g., “complementarity”).
interacting (str) – Descriptor of the interaction.
- Returns:
A dictionary with a pathway complementari edge representation.
- microbetag.build_mtg_cx2.get_compl_maps(config: microbetag.config.Config, genome_ids_in_nodes: List) Tuple[pandas.DataFrame, Dict[str, set]][source]¶
Builds mapping objects to properly pass pathway/seed complementarities to their corresponding edges.
- Parameters:
config
genomes_ids_in_nodes – A list of GC ids found in complementarities (pathCompls.json)
- Returns:
- nodes_in_compls: A pd.Series with the sequence ids of the nodes that participate
in pathway complementarity drive edges.
- node_to_gtdb: A dictionary with sequence ids as key and the set of their corresponding
GTDB representative as value{seq_id: {gtdb_ids}}
- Return type:
A tuple consisting of
- microbetag.build_mtg_cx2.pathway_complements(config: microbetag.config.Config, edgelist_df: pandas.DataFrame, node_names: List, cx_edges: Dict)[source]¶
- microbetag.build_mtg_cx2.seed_complement_edge(edge_id, beneficiary, donor, complement, competition, cooperation, node_names, ben_patric=None, donor_patric=None, update=False, cx_edges=None)[source]¶
Conceptually, the donor is the source, since a compound would be secreted from it and drive to the beneficiary (target). This holds for the scores as well - for node_A in scores, we consider its seeds. Thus, the A of the score should be the beneficiary, i.e. target
- microbetag.build_mtg_cx2.build_cx2(nodes: Dict[str, dict], edges: Dict[str, dict]) ndex2.cx2.CX2Network[source]¶
Builds the microbetag annotated network in a CX2 format (https://cytoscape.org/cx/).
To this end, the function exploits the ndex2 Python library (https://ndex2.readthedocs.io/) while the MGG Java app, needs to specify that the expected response from microbetag, is in CX2. – See CreateNetworkTask.java and the cytoscapeAPIURL.
- microbetag.build_mtg_cx2.load_otf_seq_map(df: pandas.DataFrame) Dict[source]¶
Gets the df from the taxonomy.py returned when ran through the app.py and returns the equivalent seqId_taxonomy of the stand-alone case.
- Parameters:
df
- Returns:
- A dictionary with sequence id (seqId) as key and the NCBI Taxonomy ids found along with their
corresponding taxonomic ranks and in case of genomes found those as well. Different NCBI Tax Ids and levels are split by ‘,’ while genomes of the same case, split by ‘;’
- Return type:
seq_map_dict
Example
- ‘ASV0005’: {‘ncbi_tax_id’: ‘411903,74426’, ‘ncbi_tax_level’: ‘mspecies,mspecies’,
‘gtdb_genomes’: [‘GCA_010509075.1’, ‘GCA_001404695.1’]}
- ‘ASV0021’: {‘ncbi_tax_id’: ‘1121308,1496’, ‘ncbi_tax_level’: ‘mspecies,mspecies’,
‘gtdb_genomes’: [“GCA_001077535.2’;’GCA_001077535.1”, ‘GCA_001299635.1’]}
- microbetag.build_mtg_cx2.mtg_annotate_network(config: microbetag.config.Config) ndex2.cx2.CX2Network[source]¶
Wrapper function for getting the various annotations previously made for a microbetag run and building a microbetag annotated network in a CX2 format.
- Parameters:
config – An instance of the microbetag configuration
Configclass.- Returns:
A
ndex2.cx2.CX2Network()object for the microbetag-annotated network in CX2 format.