microbetag.db¶
- Aim:
Establishing connection and query on microbetagDB. Useful for the API and the on-the-fly version of microbetag, more specifically for the phenotrex-based phenotypic traits and the pathway complementarity steps.
Notes
Needs a hidden file called .env_dev.json with the database credentials.
Attributes¶
Classes¶
Functions¶
|
Establish a database connection and perform an action |
|
Executes a query using a connection from the connection pool. |
|
Initiates a connection pool. |
|
Removes duplicates of a genome that has entries both as GCA and GCF in the db. |
Switches GCA prefic of a genome accession id to GCF and vice-versa. |
|
|
Get the genome IDs corresponding to a given NCBI Taxonomy ID from the microbetagDB. |
|
|
|
Gets a list of GC accession ids and returns a dictionary where the GC ids are the keys |
|
|
|
On the fly way to get pathway complementarities. Builds the pathCompls.json and |
|
|
|
Gets 2 gc accession ids and returns a query for their pathway complementarities |
|
|
|
|
|
|
|
Gets thes actual complement using its unique complementId and builds its KEGG url. |
|
|
|
Takes as input the complements list between two genomes and |
Module Contents¶
- microbetag.db.execute(phrase: str) list[tuple][source]¶
Establish a database connection and perform an action
- microbetag.db.execute_in_a_pool(cursor: mysql.connector, query: str)[source]¶
Executes a query using a connection from the connection pool.
- microbetag.db.init_connection_pool() mysql.connector.pooling.MySQLConnectionPool[source]¶
Initiates a connection pool. A pool opens a number of connections and handles thread safety when providing connections to requesters. For more see: https://dev.mysql.com/doc/connector-python/en/connector-python-connection-pooling.html
- microbetag.db.gc_unify(gc_list)[source]¶
Removes duplicates of a genome that has entries both as GCA and GCF in the db.
- microbetag.db.alt_genome_prefix(gc)[source]¶
Switches GCA prefic of a genome accession id to GCF and vice-versa.
- microbetag.db.get_genomes_for_ncbi_tax_id(ncbi_tax_id: int)[source]¶
Get the genome IDs corresponding to a given NCBI Taxonomy ID from the microbetagDB.
Example: 1281578
- microbetag.db.patric_from_gc_list(gc_accession_list: list)[source]¶
Gets a list of GC accession ids and returns a dictionary where the GC ids are the keys and their corresponding PATRIC ids are the values.
[“GCA_003184265.1”]
- microbetag.db.update_for_patric(module_nonseeds_pkl, gc_to_patric)[source]¶
- Parameters:
module_nonseeds_pkl – path to nonseeds KEGG MODULE related pickle file
gc_to_patric – a dictionary with GTDB representative genomes as key and their corresponding PATRIC id as value.
- class microbetag.db.GetPhenotrexTraits(config=None)[source]¶
- get_phen_traits()[source]¶
Returns predictions for a list of genomes
repr_genomes_present, config.predictions_path
- microbetag.db.get_path_compls_otf(config)[source]¶
On the fly way to get pathway complementarities. Builds the pathCompls.json and the pathway_complements_extended.json files.
The first file, in the stand-alone version lools like this: {“bin_101”: {
“bin_101”: [], “bin_151”: [[“md:M00019”, [“K00826”], [“K01652”, “K01653”, “K00053”, “K01687”, “K00826”],
},..
} where the elements regarding the complement and the alternative are actually lists, and not strings, while the latter: {“bin_101”: {
“bin_101”: [], “bin_151”: {“0”: [“M00019”, “Valine/isoleucine biosynthesis”, “Branched-chain amino acid metabolism”,
“K00826”, “K01652;K01653;K00053;K01687;K00826”, “https://…]
}
}
To build those files for the on-the-fly version (otf), this function makes use of the config.otf_seq_tax_df attribute of the config, as returned by the taxonomy.py script.
It creates a list of tuples with the NCBI Taxonomy Ids of found related taxa (in the edgelist) and using their corresponding GTDB representative genomes gets their complements.
- Parameters:
config – Insance of the microbetat’g config class but as edited in the app.py script where the otf_seq_tax_df attribute is added
- Returns:
- A pd.DataFrame with nodes names, NCBI Taxonomy ids and GTDB representative genomes for those
edges of the network that were both mapped to at least a GTDB genome.
- Return type:
mspecies_map_df
- microbetag.db.get_path_compls_for_ncbi_ids(relative_genomes: Dict[str, Set[str]], pairs_of_interest: Set[Tuple[str, str]]) dict[source]¶
- Parameters:
relative_genomes – A dictionary {“1260918”: {“GCF_002102185.1”}, “1819566”: {“GCF_009711525.1”}}
pairs_of_interest={ ("1260918", "1819566")
- microbetag.db.query_for_getting_compl_ids(beneficiary='GCA_003184265.1', donor='GCA_000015645.1')[source]¶
Gets 2 gc accession ids and returns a query for their pathway complementarities
- microbetag.db.get_coloured_complements(pairs_to_compl_ids: Dict[Tuple[str, str], dict[Tuple[str, str], list[str]]])[source]¶
Gets thes actual complement using its unique complementId and builds its KEGG url.
- Parameters:
pairs_to_compl_ids – {(‘1260918’, ‘1819566’): {(‘GCA_002102185.1’, ‘GCA_009711525.1’): [‘180131’, ..’]}}
- Returns:
[]
- Return type:
pairs_complements
- microbetag.db.build_kegg_urls(genome_pair_compls)[source]¶
Takes as input the complements list between two genomes and build urls to colorify the related to the module kegg map based on the KO terms of the beneficiary (pink) and those it gets from the donor (green).
Notes
Some modules do not belong to any map, e.g. https://www.kegg.jp/module/M00705. In these cases, we will have a N/A value in the url.