core¶
The data model and the metagenomics pipeline. core holds the record types that move
between modules (feeds, experiments, reactions, metabolites), the database interface, and
the Metagenomics class that implements every pipeline step.
from adtoolbox import configs, core
db = core.Database(config=configs.Database(database_dir="./database"))
mg = core.Metagenomics(configs.Metagenomics("./run", database_dir="./database"))
Record types¶
Lightweight dataclasses that are serializable to and from the on-disk databases.
Feed¶
Feed
dataclass
¶
Feed(
name: str,
carbohydrates: float,
lipids: float,
proteins: float,
tss: float,
si: float,
xi: float,
reference: str = "",
)
The Feed class is used to store the feed information, and later use it in the e_adm model. all the entered numbers must in percentages. Carbohudrates, lipids, and proteins and si must sum up to 100, and they form the total dissolved solids. Carbohydrates, lipids, proteins, and xi must sum up to 100, and they form the total suspended solids.
IMPORTANT: It is assumed that lipid, proteins and carbohydrates have the same fraction in soluble and insoluble fractions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A unique name for the feed. |
required |
carbohydrates
|
float
|
percentage of carbohydrates in the feed. |
required |
lipids
|
float
|
percentage of lipids in the feed. |
required |
proteins
|
float
|
percentage of proteins in the feed. |
required |
tss
|
float
|
percentage of total COD in the form of suspended solids. |
required |
si
|
float
|
percentage of percentage of soluble inorganics in the TDS. |
required |
xi
|
float
|
percentage of percentage of insoluble inorganics in the TSS. |
required |
reference
|
str
|
A reference for the feed data. Defaults to ''. |
''
|
Examples:
>>> feed=Feed(name="Test",carbohydrates=25,lipids=25,proteins=25,si=25,xi=25,tss=70)
>>> assert feed.ch_tss==feed.lip_tss==feed.prot_tss==feed.xi_tss==0.25
to_dict
¶
Experiment¶
Experiment
dataclass
¶
Experiment(
name: str,
time: list[float],
variables: list[str],
data: list[list[float]],
feed: Feed,
initial_concentrations: dict[str, float] = dict(),
base_parameters: dict[str, float] = dict(),
constants: list[str] = tuple(),
reference: str = "",
model_name: str = "e_adm",
)
This class creates an interface for the experimental data to be used in different places in ADToolbox. First you should give each experiment a name. Time must be a list of time points in days, and there must be a time 0 point assinged to each experiment. variables must be a list of integers that represent the variables that are the index of the ADM species that we have concentration data for. data must be a list of lists. Each list in the list must be a list of concentrations for each species at each time point. IMPORTANT: The order of the species in the data list must match the order of the species in the variables list. if there are specific initial concentrations for the ADM species, they can be passed as a dictionary to the initial_concentrations argument. reference is an optional argument that can be used to provide a reference for the experimental data. If using the database module to query for Experiment objects you can query by name or reference or model_type. So, having a descriptive reference can be useful for querying as well. default model name is "e_adm". This can be changed by passing a different model name to the model_name argument. This also helps with querying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A unique name for the experiment. |
required |
time
|
list
|
A list of time points in days. |
required |
variables
|
list
|
A list of strings that represent the species that are in the used model (most commonly ADM) that we have concentration data for. |
required |
data
|
list
|
A list of lists. Each list in the list must be a list of concentrations for each species at each time point. |
required |
feed
|
Feed
|
An instance of feed class |
required |
initial_concentrations
|
dict
|
A dictionary of initial concentrations for the ADM species. Defaults to {}. |
dict()
|
base_parameters
|
dict
|
A dictionary of base parameters for the model. Defaults to {}. |
dict()
|
constants
|
list
|
A list of strings that represent the species that are in the used model (most commonly ADM) that are held constant during the simulations. Their value will come from the initial_concentrations. Defaults to []. |
tuple()
|
reference
|
str
|
A reference for the experimental data. Defaults to ''. |
''
|
model_name
|
str
|
The name of the model that the experimental data is for. Defaults to "e_adm". |
'e_adm'
|
Examples:
>>> import json
>>> with open(configs.Database().adm_parameters["species"],"r") as f:
... species=json.load(f)
>>> feed=Feed(name="Test",carbohydrates=25,lipids=25,proteins=25,si=25,xi=25,tss=70)
>>> exp=Experiment(name="Test",time=[0,1,2],variables=["S_su","S_aa"],data=[[1,2,3],[4,5,6]],feed=Feed,reference="Test reference")
initial_concentrations
class-attribute
instance-attribute
¶
base_parameters
class-attribute
instance-attribute
¶
validate
¶
Source code in adtoolbox/core.py
to_dict
¶
Source code in adtoolbox/core.py
MetagenomicsStudy¶
MetagenomicsStudy
dataclass
¶
MetagenomicsStudy(
name: str,
study_type: str,
microbiome: str,
sample_accession: str,
comments: str,
study_accession: str,
)
This class is used to communicate between the metagenomics studies database and the ADM model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the metagenomics study. Its okay if it is not unique. |
required |
study_type
|
str
|
The type of the metagenomics study. It can be "amplicon" or "WGS". |
required |
microbiome
|
str
|
The microbiome that the metagenomics study is about. |
required |
sample_accession
|
str
|
The SRA sample accession number of the metagenomics study. This must be unique. |
required |
comments
|
str
|
Any comments that you want to add to the metagenomics study. |
required |
study_accession
|
str
|
The SRA study accession number of the metagenomics study. |
required |
Examples:
>>> study=MetagenomicsStudy(name="Test",study_type="WGS",microbiome="test_microbiome",sample_accession="test_accession",comments="test_comments",study_accession="test_study_accession")
>>> assert study.name=="Test"
to_dict
¶
Reaction¶
Reaction
¶
This class provides a simple interface between information about biochemical reactions and multiple functionalities of ADToolbox. In order to instantiate a reaction object, you need to pass a dictionary of the reaction information. This dictionary must include 'name','stoichiometry' keys. This follows the format of the seed database. stoichiometry must be formatted like seed database. The seed database format is as follows: stoichiometry: '-1:cpd00079:0:0:"D-glucose-6-phosphate";1:cpd00072:0:0:"D-fructose-6-phosphate"'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the reaction information. This follows the format of the seed database. |
required |
Examples:
>>> A={"name":'D-glucose-6-phosphate aldose-ketose-isomerase',"stoichiometry":'-1:cpd00079:0:0:"D-glucose-6-phosphate";1:cpd00072:0:0:"D-fructose-6-phosphate"'}
>>> a=Reaction(A)
>>> print(a)
D-glucose-6-phosphate aldose-ketose-isomerase
stoichiometry
property
¶
Returns the stoichiometry of the reaction by the seed id of the compounds as key and the stoichiometric coefficient as value. Examples: >>> A={"name":'D-glucose-6-phosphate aldose-ketose-isomerase',"stoichiometry":'-1:cpd00079:0:0:"D-glucose-6-phosphate";1:cpd00072:0:0:"D-fructose-6-phosphate"'} >>> a=Reaction(A) >>> a.stoichiometry=={'cpd00079': -1, 'cpd00072': 1} True
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
self
|
Reaction
|
An instance of the Reaction. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The stoichiometry of the reaction |
Metabolite¶
Metabolite
¶
This class provides a simple interface between information about metabolites and multiple functionalities of ADToolbox. In order to instantiate a metabolite object, you need to pass a dictionary of the metabolite information. This dictionary must include 'name','mass','formula' keys. This follows the format of the seed database. formula must be formatted like seed database. The seed database format is as follows: formula: 'C6H12O6' Possibly the main advantage of instantiating a metabolite object is that it provides a COD attribute that can be used to convert the concentration of the metabolite from g/l to gCOD/l. This is useful for comparing the experimental data with the model outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the metabolite information. This follows the format of the seed database. |
required |
Examples:
Source code in adtoolbox/core.py
cod_calc
¶
Calculates the conversion rates for g/l -> gCOD/l In some cases we would like to add extra atoms for COD calculations For example, model seed biochemistry database only uses acetate instead of acetic acid. The 1 hydrogen difference changes the COD conversion rate. For this reason we can add extra atoms to the formula to calculate the COD conversion rate without changing anything else.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
add_h
|
float
|
The number of extra hydrogen atoms to add to the formula for COD calculation. |
0
|
add_c
|
float
|
The number of extra carbon atoms to add to the formula for COD calculation. |
0
|
add_o
|
float
|
The number of extra oxygen atoms to add to the formula for COD calculation. |
0
|
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
self
|
Metabolite
|
An instance of the Metabolite class: Note |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
COD conversion from g/l to gCOD/l |
Source code in adtoolbox/core.py
Databases¶
SeedDB¶
Interface to the ModelSEED reaction and compound databases, including EC-number lookups.
SeedDB
¶
This class is designed to interact with seed database. The main advantage of using this class is that it can be used to instantiate a reaction and metabolite object, and it provides extra functionalities that rely on information in the seed database. For example, If there is a chemical formula assigned to a metabolite in the seed database, then the informattion about the COD of that metabolite can be computed using the chemical formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SeedDB
|
An instance of the SeedDB class in the configs module. This class contains the information about the seed database. |
required |
Examples:
>>> seed_db=SeedDB(configs.Database())
>>> assert seed_db.compound_db==configs.Database().compound_db
>>> assert seed_db.reaction_db==configs.Database().reaction_db
Source code in adtoolbox/core.py
instantiate_rxns
¶
This method is used to instantiate reaction objects from the seed database. in order to instantiate a reaction object, you need to pass the seed identifier for that reaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed_id
|
str
|
The seed identifier for the reaction. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Reaction |
Reaction
|
An instance of the Reaction class. |
Required Configs
- config.reaction_db
Examples:
>>> db_conf=configs.Database()
>>> seed_db=SeedDB(db_conf)
>>> rxn=seed_db.instantiate_rxns("rxn00558")
>>> assert rxn.data["name"]=="D-glucose-6-phosphate aldose-ketose-isomerase"
Source code in adtoolbox/core.py
instantiate_metabs
¶
This method is used to instantiate metabolite objects from the seed database. In order to instantiate a metabolite object, you need to pass the seed identifier for that metabolite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed_id
|
str
|
The seed identifier for the metabolite. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Metabolite |
Metabolite
|
An instance of the Metabolite class. |
Required Configs
- config.compound_db
Examples:
>>> seed_db=SeedDB(configs.Database())
>>> metab=seed_db.instantiate_metabs("cpd01024")
>>> assert metab.cod==4.0
Source code in adtoolbox/core.py
get_seed_rxn_from_ec
¶
This method is used to get the seed reaction identifiers for a given EC number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ec_number
|
str
|
The EC number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of seed reaction identifiers. |
Required Configs
- config.reaction_db
Examples:
>>> seed_db=SeedDB(config=configs.Database())
>>> seed_rxn_list=seed_db.get_seed_rxn_from_ec("1.1.1.1")
>>> assert len(seed_rxn_list)>0
Source code in adtoolbox/core.py
Database¶
Create, download, query, and extend every local ADToolbox database. There are two ways to get a working database directory: download the prebuilt files, or build the protein database yourself from reaction metadata.
flowchart TB
A["download_all_databases<br>or an individual download_* method"] --> DIR["database directory"]
B["initialize_protein_db"] --> C["add_proteins_from_ecnumbers_to_protein_db"]
C --> D["build_protein_db_from_reactions_db"]
D --> DIR
DIR --> MM["build_mmseqs_database"]
The download_* methods each fetch one database; download_all_databases calls every one
of them in turn.
Database
¶
This class is designed to supply any data requirement for ADToolbox. All functionalisties for saving, loading, and querying data are implemented here. ADToolbox in general contains the following databases:
-
The seed reaction database
-
The seed compound database
-
ADToolbox's Feed database
-
ADToolbox's Metagenomics studies database
-
ADToolbox's Experimental data database
-
ADToolbox's Protein database
-
ADToolbox's Reaction database
-
GTDB-tk database for bacterial and archaeal 16s rRNA sequences
-
ADM and e_adm model parameters
This class is instantiated with a configs.Database object. This object contains the paths to all the databases that ADToolbox uses. Please refer to the documentation of each method for more information on the required configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Database
|
A configs.Database object. Defaults to configs.Database(). |
None
|
Examples:
>>> db=Database(config=configs.Database())
>>> assert type(db)==Database and type(db.config)==configs.Database
Source code in adtoolbox/core.py
initialize_protein_db
¶
This function intializes ADToolbox's protein database by creating an empty fasta file. Be careful, this will overwrite any existing file with the same name. Logically, this needs method needs config.protein_db to be defined.
Required Configs
- config.protein_db¶
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==False # This is just to make sure that the following lines create the file
>>> db=Database(config=configs.Database(protein_db=os.path.join(Main_Dir,"protein_test_db.fasta"))) # point to a test non-existing file
>>> db.initialize_protein_db() # initialize the protein database
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==True # check if the file is created
>>> os.remove(os.path.join(Main_Dir,"protein_test_db.fasta")) # remove the file to clean up
Source code in adtoolbox/core.py
initialize_reaction_db
¶
This function intializes ADToolbox's reaction database by creating an empty tsv file. Be careful, this will overwrite any existing file with the same name.
Required Configs
- config.reaction_db
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"reaction_test_db.tsv"))==False
>>> db=Database(config=configs.Database(reaction_db=os.path.join(Main_Dir,"reaction_test_db.tsv")))
>>> db.initialize_reaction_db()
>>> assert pd.read_table(os.path.join(Main_Dir,"reaction_test_db.tsv"),delimiter="\t").shape[0]==0
>>> assert set(pd.read_csv(os.path.join(Main_Dir,"reaction_test_db.tsv"),delimiter="\t").columns)==set(["ec_numbers","seed_ids","reaction_names","adm1_reaction","e_adm_reactions","pathways"])
>>> os.remove(os.path.join(Main_Dir,"reaction_test_db.tsv"))
Source code in adtoolbox/core.py
initialize_feed_db
¶
This function intializes ADToolbox's Feed database by creating an empty tsv file. Be careful, this will overwrite any existing file with the same name.
Required Configs
- config.feed_db
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==False
>>> db=Database(config=configs.Database(feed_db=os.path.join(Main_Dir,"feed_test_db.tsv")))
>>> db.initialize_feed_db()
>>> assert pd.read_table(os.path.join(Main_Dir,"feed_test_db.tsv"),delimiter='\t').shape[0]==0
>>> assert set(pd.read_table(os.path.join(Main_Dir,"feed_test_db.tsv"),delimiter='\t').columns)==set(["name","carbohydrates","lipids","proteins","tss","si","xi","reference"])
>>> os.remove(os.path.join(Main_Dir,"feed_test_db.tsv"))
Source code in adtoolbox/core.py
initialize_metagenomics_studies_db
¶
This function intializes ADToolbox's Metagenomics studies database by creating an empty tsv file. Be careful, this will overwrite any existing file with the same name.
Required Configs
- config.metagenomics_studies_db
Examples:
>>> import os
>>> local_dir={'metagenomics_studies':os.path.join(Main_Dir,"test","metagenomics_test_db.tsv")}
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> db.initialize_metagenomics_studies_db()
>>> assert pd.read_table(local_dir['metagenomics_studies'],delimiter="\t").shape[0]==0
>>> assert set(pd.read_table(local_dir['metagenomics_studies'],delimiter="\t").columns)==set(["name","study_type","microbiome","sample_accession","comments","study_accession"])
>>> os.remove(local_dir['metagenomics_studies'])
Source code in adtoolbox/core.py
initialize_experimental_data_db
¶
This function intializes ADToolbox's experimental data database by creating an empty json file. Be careful, this will overwrite any existing file with the same name.
Required Configs
- config.experimental_data_db
Examples:
>>> import os,json
>>> local_dir={'experimental_data_db':os.path.join(Main_Dir,"test","experiments_test_db.json")}
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> db.initialize_experimental_data_db()
>>> assert pd.read_json(local_dir['experimental_data_db']).shape[0]==0
>>> with open(local_dir['experimental_data_db'],"r") as f:
... assert json.load(f)==[]
>>> os.remove(local_dir['experimental_data_db'])
Source code in adtoolbox/core.py
filter_seed_from_ec
¶
This function takes a list of EC numbers and filters the seed database to find the seed reactions that have the EC numbers in their EC number list. This will help to trim the large seed database to a smaller one that only contains the reactions that are relevant to the AD process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ec_list
|
list[str]
|
A list of EC numbers. |
required |
save
|
bool
|
Whether to save the filtered seed database or not. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
A tuple containing the filtered seed reaction database and the seed compound database, respectively. |
Required Configs:
- config.reaction_db
--------
- config.compound_db
--------
- config.local_reaction_db
--------
- config.local_compound_db
--------
Examples:
>>> db=Database()
>>> seed_rxn_db,seed_compound_db=db.filter_seed_from_ec(["1.1.1.1","1.1.1.2"])
>>> assert len(seed_rxn_db)>0 and len(seed_compound_db)>0
>>> assert pd.read_json(configs.Database().reaction_db).shape[0]>pd.DataFrame(seed_rxn_db).shape[0]
Source code in adtoolbox/core.py
get_protein_seqs_from_uniprot
¶
This function takes a uniprot id and fetches the protein sequence from Uniprot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uniprot_id
|
str
|
The uniprot id of the protein. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The protein sequence. |
Examples:
>>> db=Database()
>>> seq=db.get_protein_seqs_from_uniprot("P0A9P0")
>>> assert type(seq)==str and len(seq)>0
Source code in adtoolbox/core.py
proteins_from_ec
¶
This function returns a dictionary of protein sequences for a given EC number. The keys are the uniprot ids and ec number compatible with ADToolbox protein database and the values are the protein sequences. Since ADToolbox deals with microbial process, only bacterial and archaeal proteins are considered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ec_number
|
str
|
The EC number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary of protein sequences. |
Examples:
>>> db=Database()
>>> protein_seqs=db.proteins_from_ec("1.1.1.1")
>>> assert len(protein_seqs)>0
>>> assert list(protein_seqs.keys())[0].split("|")[1]=="1.1.1.1"
Source code in adtoolbox/core.py
build_protein_db_from_reactions_db
¶
This function builds the protein database from the reaction database. It takes the reaction database and finds the protein sequences for each EC number in the reaction database. Then it saves the protein sequences in a fasta file.
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==False
>>> assert os.path.exists(os.path.join(Main_Dir,"reaction_test_db.tsv"))==False
>>> db=Database(config=configs.Database(protein_db=os.path.join(Main_Dir,"protein_test_db.fasta"),reaction_db=os.path.join(Main_Dir,"reaction_test_db.tsv")))
>>> reaction_db=pd.DataFrame(columns=["EC_Numbers","Seed Ids","Reaction Names","ADM1_Reaction","e_adm_Reactions","Pathways"])
>>> reaction_db.loc[0,"EC_Numbers"]="1.1.1.1"
>>> reaction_db.to_csv(os.path.join(Main_Dir,"reaction_test_db.tsv"),index=False,sep="\t")
>>> db.build_protein_db_from_reactions_db()
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==True
>>> assert os.path.exists(os.path.join(Main_Dir,"reaction_test_db.tsv"))==True
>>> assert os.path.getsize(os.path.join(Main_Dir,"protein_test_db.fasta"))>0
>>> os.remove(os.path.join(Main_Dir,"protein_test_db.fasta"))
>>> os.remove(os.path.join(Main_Dir,"reaction_test_db.tsv"))
Source code in adtoolbox/core.py
add_protein_to_protein_db
¶
This funciton adds a protein sequence to the protein database. It takes a uniprot id and an EC number it is assigned to and adds the corresponding protein sequence to the protein database.
Required Configs
- config.protein_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protein_id
|
str
|
The uniprot id of the protein. |
required |
header_tail
|
str
|
A text to append to the header of the entry in the database. In ADToolbox it is better to use ec number for compatibility with downstream functions. |
required |
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==False
>>> db=Database(config=configs.Database(protein_db=os.path.join(Main_Dir,"protein_test_db.fasta")))
>>> db.add_protein_to_protein_db("P0A9P0","1.2.3.4")
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==True
>>> assert os.path.getsize(os.path.join(Main_Dir,"protein_test_db.fasta"))>0
>>> import utils
>>> assert len(utils.fasta_to_dict(os.path.join(Main_Dir,"protein_test_db.fasta")))>0
>>> os.remove(os.path.join(Main_Dir,"protein_test_db.fasta"))
Source code in adtoolbox/core.py
add_proteins_from_ecnumbers_to_protein_db
¶
This function adds protein sequences to the protein database from a list of EC numbers. It takes a list of EC numbers and finds the protein sequences for each EC number in the list. Then it saves the protein sequences in a fasta file.
Required Configs
- config.protein_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ec_numbers
|
list
|
A list of EC numbers. |
required |
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==False
>>> db=Database(config=configs.Database(protein_db=os.path.join(Main_Dir,"protein_test_db.fasta")))
>>> db.add_proteins_from_ecnumbers_to_protein_db(["1.1.1.1","1.1.1.2"])
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==True
>>> import utils
>>> assert len(utils.fasta_to_dict(os.path.join(Main_Dir,"protein_test_db.fasta")))>0
>>> os.remove(os.path.join(Main_Dir,"protein_test_db.fasta"))
Source code in adtoolbox/core.py
add_feed_to_feed_db
¶
This function adds a feed to the feed database. It takes the feed name and the feed composition and adds them to the feed database.
Required Configs
- config.feed_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
Feed
|
An instance of the Feed class. |
required |
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==False
>>> db=Database(config=configs.Database(feed_db=os.path.join(Main_Dir,"feed_test_db.tsv")))
>>> feed=Feed(name="test_feed",carbohydrates=10,lipids=20,proteins=30,tss=80,si=10,xi=30,reference="test")
>>> db.add_feed_to_feed_db(feed)
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==True
>>> assert pd.read_table(os.path.join(Main_Dir,"feed_test_db.tsv"),delimiter="\t").shape[0]>0
>>> os.remove(os.path.join(Main_Dir,"feed_test_db.tsv"))
Source code in adtoolbox/core.py
remove_feed_from_feed_db
¶
This function removes studyes that contain the query in the given column, field name, from the feed database.
Required Configs
- config.feed_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the column to query. |
required |
query
|
str
|
The query string. |
required |
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==False
>>> db=Database(config=configs.Database(feed_db=os.path.join(Main_Dir,"feed_test_db.tsv")))
>>> feed=Feed(name="test_feed",carbohydrates=10,lipids=20,proteins=30,tss=80,si=10,xi=30,reference="test")
>>> db.add_feed_to_feed_db(feed)
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==True
>>> assert pd.read_table(os.path.join(Main_Dir,"feed_test_db.tsv"),delimiter="\t").shape[0]>0
>>> db.remove_feed_from_feed_db("name","test_feed")
>>> assert pd.read_table(os.path.join(Main_Dir,"feed_test_db.tsv"),delimiter="\t").shape[0]==0
>>> os.remove(os.path.join(Main_Dir,"feed_test_db.tsv"))
Source code in adtoolbox/core.py
get_feed_from_feed_db
¶
This function returns a feed from the feed database. It takes the query string and the column name to query and returns the feed that contains the query string in the given column.
Required Configs
- config.feed_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the column to query. |
required |
query
|
str
|
The query string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Feed |
list[Feed]
|
An instance of the Feed class. |
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==False
>>> db=Database(config=configs.Database(feed_db=os.path.join(Main_Dir,"feed_test_db.tsv")))
>>> feed=Feed(name="test_feed",carbohydrates=10,lipids=20,proteins=30,tss=80,si=10,xi=30,reference="test")
>>> db.add_feed_to_feed_db(feed)
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==True
>>> assert pd.read_table(os.path.join(Main_Dir,"feed_test_db.tsv"),delimiter="\t").shape[0]>0
>>> feed=db.get_feed_from_feed_db("name","test_feed")
>>> assert feed[0].name=="test_feed"
>>> os.remove(os.path.join(Main_Dir,"feed_test_db.tsv"))
Source code in adtoolbox/core.py
add_metagenomics_study_to_metagenomics_studies_db
¶
This function adds a metagenomics study to the metagenomics studies database. It takes a metagenomics study and adds it to the metagenomics studies database.
Required Configs
- config.metagenomics_studies_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metagenomics_study
|
MetagenomicsStudy
|
An instance of the MetagenomicsStudy class. |
required |
Examples:
>>> import os
>>> local_dir={'metagenomics_studies':os.path.join(Main_Dir,"test","metagenomics_test_db.tsv")}
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> metagenomics_study=MetagenomicsStudy(name="test_study",study_type="metagenomics",microbiome="anaerobic digester",sample_accession="test",comments="test",study_accession="test")
>>> db.add_metagenomics_study_to_metagenomics_studies_db(metagenomics_study)
>>> assert os.path.exists(local_dir['metagenomics_studies'])==True
>>> assert pd.read_table(local_dir['metagenomics_studies'],delimiter="\t").shape[0]>0
>>> os.remove(local_dir['metagenomics_studies'])
Source code in adtoolbox/core.py
remove_metagenomics_study_from_metagenomics_studies_db
¶
This function removes studies that contain the query in the given column, field name, from the metagenomics studies database.
Required Configs
- config.metagenomics_studies_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the column to query. |
required |
query
|
str
|
The query string. |
required |
Examples:
>>> import os,json
>>> local_dir={'metagenomics_studies':os.path.join(Main_Dir,"test","metagenomics_test_db.json")}
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> metagenomics_study=MetagenomicsStudy(name="test_study",study_type="metagenomics",microbiome="anaerobic digester",sample_accession="test",comments="test",study_accession="test")
>>> db.add_metagenomics_study_to_metagenomics_studies_db(metagenomics_study)
>>> assert os.path.exists(local_dir['metagenomics_studies'])==True
>>> assert pd.read_table(local_dir['metagenomics_studies'],delimiter="\t").shape[0]>0
>>> db.remove_metagenomics_study_from_metagenomics_studies_db("name","test_study")
>>> assert pd.read_table(local_dir['metagenomics_studies'],delimiter="\t").shape[0]==0
>>> os.remove(local_dir['metagenomics_studies'])
Source code in adtoolbox/core.py
get_metagenomics_study_from_metagenomics_studies_db
¶
get_metagenomics_study_from_metagenomics_studies_db(
field_name: str, query: str
) -> list[MetagenomicsStudy]
This function returns a metagenomics study from the metagenomics studies database. It takes the query string and the column name to query and returns the metagenomics study that contains the query string in the given column.
Required Configs
- config.metagenomics_studies_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the column to query. |
required |
query
|
str
|
The query string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MetagenomicsStudy |
list[MetagenomicsStudy]
|
An instance of the MetagenomicsStudy class. |
Examples:
>>> import os
>>> local_dir={'metagenomics_studies':os.path.join(Main_Dir,"test","metagenomics_test_db.tsv")}
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> metagenomics_study=MetagenomicsStudy(name="test_study",study_type="metagenomics",microbiome="anaerobic digester",sample_accession="test",comments="test",study_accession="test")
>>> db.add_metagenomics_study_to_metagenomics_studies_db(metagenomics_study)
>>> assert os.path.exists(local_dir['metagenomics_studies'])==True
>>> assert pd.read_table(local_dir['metagenomics_studies'],delimiter="\t").shape[0]>0
>>> metagenomics_study=db.get_metagenomics_study_from_metagenomics_studies_db("name","test_study")
>>> assert metagenomics_study[0].name=="test_study"
>>> os.remove(local_dir['metagenomics_studies'])
Source code in adtoolbox/core.py
add_experiment_to_experiments_db
¶
This function adds an experiment to the experiments database. It takes an experiment and adds it to the experiments database.
Required Configs
- config.experimental_data_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment
|
Experiment
|
An instance of the Experiment class. |
required |
Examples:
>>> import os,json
>>> local_dir={'experimental_data_db':os.path.join(Main_Dir,"test","experiments_test_db.json")}
>>> if os.path.exists(local_dir['experimental_data_db']):
... os.remove(local_dir['experimental_data_db'])
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> feed=Feed(name="test_feed",carbohydrates=10,lipids=20,proteins=30,tss=80,si=10,xi=30,reference="test")
>>> experiment = Experiment(name="test2_study",initial_concentrations={}, time=[0, 1, 2], variables=["S_bu","S_ac"], data=[[1, 2, 3], [4, 5, 6]],feed=feed,reference="test")
>>> db.add_experiment_to_experiments_db(experiment,force=True)
>>> assert os.path.exists(local_dir['experimental_data_db'])==True
>>> assert os.path.getsize(local_dir['experimental_data_db'])>0
>>> os.remove(local_dir['experimental_data_db'])
Source code in adtoolbox/core.py
remove_experiment_from_experiments_db
¶
This function removes experiments that contain the query in the given column, field name, from the experiments database.
Required Configs
- config.experimental_data_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the column to query. |
required |
query
|
str
|
The query string. |
required |
Examples:
>>> import os,json
>>> local_dir={'experimental_data_db':os.path.join(Main_Dir,"test","experiments_test_db.json")}
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> feed=Feed(name="test_feed",carbohydrates=10,lipids=20,proteins=30,tss=80,si=10,xi=30,reference="test")
>>> experiment = Experiment(name="test2_study",initial_concentrations={}, time=[0, 1, 2], variables=["S_bu","S_ac"], data=[[1, 2, 3], [4, 5, 6]],feed=feed,reference="test")
>>> db.add_experiment_to_experiments_db(experiment,force=True)
>>> assert os.path.exists(local_dir['experimental_data_db'])==True
>>> assert os.path.getsize(local_dir['experimental_data_db'])>0
>>> db.remove_experiment_from_experiments_db("name","test2_study")
>>> assert pd.read_json(local_dir['experimental_data_db']).shape[0]==0
>>> os.remove(local_dir['experimental_data_db'])
Source code in adtoolbox/core.py
get_experiment_from_experiments_db
¶
This function returns an experiment from the experiments database. It takes the query string and the column name to query and returns the experiment that contains the query string in the given column.
Required Configs
- config.experimental_data_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the column to query. |
required |
query
|
str
|
The query string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Experiment |
list[Experiment]
|
An instance of the Experiment class. |
Examples:
>>> import os,json
>>> local_dir={'experimental_data_db':os.path.join(Main_Dir,"test","experiments_test_db.json")}
>>> db=Database(config=configs.Database(studies_local=local_dir))
>>> feed=Feed(name="test_feed",carbohydrates=10,lipids=20,proteins=30,tss=80,si=10,xi=30,reference="test")
>>> experiment = Experiment(name="test2_study",initial_concentrations={}, time=[0, 1, 2], variables=["S_bu","S_ac"], data=[[1, 2, 3], [4, 5, 6]],feed=feed,reference="test")
>>> db.add_experiment_to_experiments_db(experiment,force=True)
>>> assert os.path.exists(local_dir['experimental_data_db'])==True
>>> assert os.path.getsize(local_dir['experimental_data_db'])>0
>>> experiment=db.get_experiment_from_experiments_db("name","test2_study")
>>> assert experiment[0].name=="test2_study"
>>> os.remove(local_dir['experimental_data_db'])
Source code in adtoolbox/core.py
build_mmseqs_database
¶
Builds an indexed mmseqs database from the ADToolbox's fasta protein database.
Required Configs
- config.protein_db
- config.adtoolbox_singularity
- config.adtoolbox_docker
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
str
|
The container to run the script with. Defaults to "None". |
'None'
|
Returns: str: The script to build the mmseqs database.
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==False
>>> db=Database(config=configs.Database(protein_db=os.path.join(Main_Dir,"protein_test_db.fasta")))
>>> db.add_protein_to_protein_db("P0A9P0","x,x,x,x")
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==True
>>> assert os.path.getsize(os.path.join(Main_Dir,"protein_test_db.fasta"))>0
>>> script=db.build_mmseqs_database()
>>> assert script=="mmseqs createdb "+str(os.path.join(Main_Dir,"protein_test_db.fasta"))+" "+str(db.config.protein_db_mmseqs)
>>> os.remove(os.path.join(Main_Dir,"protein_test_db.fasta"))
Source code in adtoolbox/core.py
download_adm_parameters
¶
Downloads the parameters needed for running ADM models in ADToolbox.
Required Configs
- config.adm_parameters_base_dir
- config.adm_parameters_urls
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"adm_parameters_test"))==False
>>> E_ADM_LOCAL={"model_parameters":os.path.join(Main_Dir, "test","ADM_Parameters","e_adm_model_parameters.json"), "base_parameters":os.path.join(Main_Dir, "test","ADM_Parameters","e_adm_base_parameters.json"), "initial_conditions":os.path.join(Main_Dir, "test","ADM_Parameters","e_adm_initial_conditions.json"), "inlet_conditions":os.path.join(Main_Dir, "test","ADM_Parameters","e_adm_inlet_conditions.json"), "reactions":os.path.join(Main_Dir, "test","ADM_Parameters","e_adm_reactions.json"), "species":os.path.join(Main_Dir, "test","ADM_Parameters","e_adm_species.json")}
>>> db=Database(config=configs.Database(adm_parameters=E_ADM_LOCAL))
>>> db.download_adm_parameters(verbose=False)
>>> assert os.path.exists(os.path.join(Main_Dir,"test"))==True
>>> assert len(os.listdir(os.path.join(Main_Dir,"test")))>0
>>> os.system("rm -r "+os.path.join(Main_Dir,"test"))
0
Args:
verbose (bool, optional): Whether to print the progress or not. Defaults to True.
Source code in adtoolbox/core.py
download_seed_databases
¶
This function will download the seed databases, both compound and reaction databases.
Required Configs
- config.seed_rxn_url
- config.seed_compound_url
- config.reaction_db
- config.compound_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print the progress or not. Defaults to True. |
True
|
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"seed_compound.json"))==False
>>> db=Database(config=configs.Database(reaction_db=os.path.join(Main_Dir,"seed_rxn.json"),compound_db=os.path.join(Main_Dir,"seed_compound.json")))
>>> db.download_seed_databases(verbose=False)
>>> assert os.path.exists(os.path.join(Main_Dir,"seed_rxn.json"))==True
>>> assert os.path.exists(os.path.join(Main_Dir,"seed_compound.json"))==True
>>> os.remove(os.path.join(Main_Dir,"seed_rxn.json"))
>>> os.remove(os.path.join(Main_Dir,"seed_compound.json"))
Source code in adtoolbox/core.py
download_protein_database
¶
Downloads the prebuilt protein database from the remote repository.
Required Configs
- config.protein_db_url
- config.protein_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print the progress or not. Defaults to True. |
True
|
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==False
>>> db=Database(config=configs.Database(protein_db=os.path.join(Main_Dir,"protein_test_db.fasta")))
>>> db.download_protein_database(verbose=False)
>>> assert os.path.exists(os.path.join(Main_Dir,"protein_test_db.fasta"))==True
>>> assert os.path.getsize(os.path.join(Main_Dir,"protein_test_db.fasta"))>0
>>> os.remove(os.path.join(Main_Dir,"protein_test_db.fasta"))
Source code in adtoolbox/core.py
download_reaction_database
¶
This function will download the reaction database from the remote repository.
Required Configs
- config.adtoolbox_rxn_db_url
- config.csv_reaction_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print the progress or not. Defaults to True. |
True
|
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"reaction_test_db.csv"))==False
>>> db=Database(config=configs.Database(csv_reaction_db=os.path.join(Main_Dir,"reaction_test_db.csv")))
>>> db.download_reaction_database(verbose=False)
>>> assert os.path.exists(os.path.join(Main_Dir,"reaction_test_db.csv"))==True
>>> assert os.path.getsize(os.path.join(Main_Dir,"reaction_test_db.csv"))>0
>>> os.remove(os.path.join(Main_Dir,"reaction_test_db.csv"))
Source code in adtoolbox/core.py
download_feed_database
¶
This function will download the feed database from the remote repository.
Required Configs
- config.feed_db_url
- config.feed_db
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print the progress or not. Defaults to True. |
True
|
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==False
>>> db=Database(config=configs.Database(feed_db=os.path.join(Main_Dir,"feed_test_db.tsv")))
>>> db.download_feed_database(verbose=False)
>>> assert os.path.exists(os.path.join(Main_Dir,"feed_test_db.tsv"))==True
>>> assert os.path.getsize(os.path.join(Main_Dir,"feed_test_db.tsv"))>0
>>> os.remove(os.path.join(Main_Dir,"feed_test_db.tsv"))
Source code in adtoolbox/core.py
download_studies_database
¶
This function will download the required files for studies functionality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print the progress or not. Defaults to True. |
True
|
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"studies_test_db.tsv"))==False
>>> STUDIES_LOCAL={"metagenomics_studies":os.path.join(Main_Dir,"Database","test","Studies","metagenomics_studies.tsv"), "experimental_data_db":os.path.join(Main_Dir,"Database","test","Studies","experimental_data_references.json")}
>>> db=Database(config=configs.Database(studies_local=STUDIES_LOCAL))
>>> db.download_studies_database(verbose=False)
>>> assert os.path.exists(STUDIES_LOCAL['metagenomics_studies'])==True
>>> assert os.path.getsize(STUDIES_LOCAL['metagenomics_studies'])>0
>>> os.remove(STUDIES_LOCAL['metagenomics_studies'])
Source code in adtoolbox/core.py
download_amplicon_to_genome_db
¶
This function will automatically download the GTDB-tk database for genome assignment.
Required Configs
- config.amplicon_to_genome_db
- config.amplicon_to_genome_urls
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print the progress or not. Defaults to True. |
True
|
Examples:
>>> import os
>>> assert os.path.exists(os.path.join(Main_Dir,"amplicon_to_genome_test_db"))==False
>>> db=Database(config=configs.Database(amplicon_to_genome_db=os.path.join(Main_Dir,"amplicon_to_genome_test_db")))
>>> db.download_amplicon_to_genome_db(verbose=False)
>>> assert os.path.exists(os.path.join(Main_Dir,"amplicon_to_genome_test_db"))==True
>>> assert len(os.listdir(os.path.join(Main_Dir,"amplicon_to_genome_test_db")))>0
>>> os.system("rm -r "+os.path.join(Main_Dir,"amplicon_to_genome_test_db"))
0
Source code in adtoolbox/core.py
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 | |
download_all_databases
¶
This function will download all the required databases for all the functionalities of ADToolbox. NOTE: each method that this function calls is individually tested so it is skipped from testing!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print the progress or not. Defaults to True. |
True
|
Required Configs
- config.adm_parameters_base_dir
- config.adm_parameters_urls
- config.seed_rxn_url
- config.seed_compound_url
- config.reaction_db
- config.compound_db
- config.protein_db_url
- config.protein_db
- config.adtoolbox_rxn_db_url
- config.csv_reaction_db
- config.feed_db_url
- config.feed_db
- config.amplicon_to_genome_db
- config.amplicon_to_genome_urls
- config.studies_db
- config.studies_urls
Examples:
>>> import os
>>> db=Database(config=configs.Database())
>>> db.download_all_databases(verbose=False)
Source code in adtoolbox/core.py
Metagenomics¶
Everything from SRA download through read preprocessing, alignment, and COD allocation, for two assays: an amplicon route (DADA2 denoising → GTDB mapping → genome protein alignment) and a shotgun route (MMseqs2 translated search of reads straight against the protein database).
batch_sample_to_cod is the entry point the CLI uses; it drives sample_to_cod per
sample — whose mode selects the amplicon or shotgun path — which in turn calls the
individual run_*_step methods. Any of those three levels can be used directly.
flowchart LR
B["batch_sample_to_cod<br>manifest of samples"] --> S["sample_to_cod<br>one sample"]
S --> R1["run_sra_download_step"]
S --> R2["run_trim_reads_step"]
S --> R3["run_build_amplicon_features_step"]
S --> R4["run_gtdb_alignment_step"]
S --> R5["run_genome_alignment_step"]
S --> R6["run_short_read_alignment_step"]
See the pipeline guide for the artifact chain these produce and for execution profiles.
Metagenomics
¶
This is the main class for Metagenomics functionality of ADToolbox. This class contains all the methods required for metagenomics analysis that ADToolbox offers.
In order to instntiate an object from this class, you need to provide a metagenomics configs object from the configs module : configs.Metagenomics. Information for inputs and of each method is then obtained from the corresponding configs object. The following example shows how to instantiate an object from this class using the default configs object:
Examples:
>>> from adtoolbox import core, configs
>>> config=configs.Metagenomics() ### This uses default arguments. Refer to configs module for more information.
>>> metagenomics=core.Metagenomics(config)
>>> assert type(metagenomics)==core.Metagenomics
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Metagenomics
|
A metagenomics configs object from configs module. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in adtoolbox/core.py
find_top_taxa
¶
This function needs three amplicon outputs: 1. feature table: This is the abundance of each feature in each sample (TSV). 2. taxonomy table: This is the taxonomy of each feature (TSV). 3. rep seqs: This is the representative sequence of each feature (fasta). It then finds the top k features or features that form specific percentile of the community of the sample.
Required Configs:
config.feature_table_dir: The path to the feature table tsv file.
---------
config.taxonomy_table_dir: The path to the taxonomy table tsv file.
---------
config.rep_seq_fasta: The path to the representative sequence fasta file.
---------
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_name
|
str
|
The name of the sample. |
required |
treshold
|
(int, float)
|
The threshold for the top k or the percentile. |
required |
mode
|
str
|
Whether to find the top k features or features that form specific percentile of the community of the sample. Defaults to 'top_k'. Options: 'top_k', 'percentile'. |
'top_k'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary of the top k features and their taxonomy. |
Source code in adtoolbox/core.py
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 | |
align_to_gtdb
¶
align_to_gtdb(
query_dir: str, output_dir: str, container: str = "None", image: str | None = None
) -> tuple[str]
This function takes the representative sequences of the top k features and generates the script to align these feature sequences to gtdb using VSEARCH. If you intend to run this you either need to have VSEARCH installed or run it with a container option. You can use either the docker or singularity as container options. Otherwise you can use None and run it with the assumption that VSEARCH is installed. If you only want the script and not to run it, set run to False.
Required Configs:
---------
config.gtdb_dir_fasta: The path to the gtdb fasta database.
---------
config.vsearch_similarity: The similarity threshold for the alignment to be used by VSEARCH.
---------
config.vsearch_threads: The number of threads to be used by VSEARCH.
---------
config.adtoolbox_docker: The name of the docker image to be used by ADToolbox (Only if using Docker as container).
---------
config.adtoolbox_singularity: The name of the singularity image to be used by ADToolbox (Only if using Singularity as container).
---------
Examples: >>> import os >>> query_dir=os.path.join(Main_Dir,"test","query.fa") >>> output_dir=os.path.join(Main_Dir,"test") >>> conf=configs.Metagenomics(vsearch_similarity=0.8) >>> conf.gtdb_dir_fasta=(os.path.join(Main_Dir,"db.fa")) >>> obj = Metagenomics(conf) >>> assert obj.align_to_gtdb(query_dir, output_dir, container="docker")[0] == f'docker run -v {output_dir}:{output_dir} -v {conf.gtdb_dir_fasta}:{conf.gtdb_dir_fasta} -v {query_dir}:{query_dir} parsaghadermazi/adtoolbox:x86 vsearch --top_hits_only --blast6out {output_dir}/matches.blast --usearch_global {query_dir} --db {conf.gtdb_dir_fasta} --id {conf.vsearch_similarity} --threads 4 --alnout {output_dir}/Alignments --top_hits_only\n'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
str
|
The container to use. Defaults to "None". |
'None'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
tuple[str]
|
The script that is supposed to be running later. |
Source code in adtoolbox/core.py
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 | |
get_genomes_from_gtdb_alignment
¶
This function takes the alignment file generated from the align_to_gtdb function and generates the the genome information using the GTDB-Tk. In the outputted dictionary, the keys are feature ids and the values are the representative genomes.
Examples:
>>> import os
>>> alignments=["0034e3d0368ec41aeb7f346b434f8d46","GB_GCA_937889405.1~CALAPC010000121.1","100.0","253","0","0" ,"1","253", "1","1009", "-1","0"]
>>> hit="\t".join(alignments)
>>> output= os.path.join(Main_Dir,"test","matches.blast")
>>> with open(output,"w") as f:
... f.write(hit)
101
>>> obj=Metagenomics(configs.Metagenomics())
>>> obj.get_genomes_from_gtdb_alignment(output)
{'0034e3d0368ec41aeb7f346b434f8d46': 'GCA_937889405.1'}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alignment_dir
|
str
|
The path to the alignment file generated by align_to_gtdb. |
required |
Source code in adtoolbox/core.py
download_genome
¶
This function downloads the genomes from NCBI using the refseq/genbank identifiers. Note that this function uses rsync to download the genomes.
Required Configs
config.genomes_base_dir: The path to the base directory where the genomes will be saved.¶
config.adtoolbox_docker: The name of the docker image to be used by ADToolbox (Only if using Docker as container).¶
config.adtoolbox_singularity: The name of the singularity image to be used by ADToolbox (Only if using Singularity as container).¶
Examples: >>> import os >>> genome_identifier="GCA_937889405.1" >>> output=os.path.join(Main_Dir,"test") >>> obj = Metagenomics(configs.Metagenomics()) >>> assert obj.download_genome(identifier=genome_identifier,output_dir= output)[0] == 'rsync -avz --progress rsync://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/937/889/405 '+output
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The identifier for the genome. It can be either refseq or genbank. |
required |
output_dir
|
str
|
The directory where the genome should be downloaded. |
required |
container
|
str
|
The container to use. Defaults to "None". You may select from "None", "docker", "singularity". |
'None'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The bash script that is used to download the genomes or to be used to download the genomes. |
Source code in adtoolbox/core.py
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 | |
download_genomes
¶
download_genomes(
identifiers: Iterable[str],
output_dir: str | PathLike,
work_dir: str | PathLike,
*,
max_workers: int = 10,
container: str = "None",
image: str | None = None
) -> tuple[str]
Build one NCBI Datasets command for a batch of assembly accessions.
Source code in adtoolbox/core.py
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 | |
async_genome_downloader
¶
extract_genome_info
¶
extract_genome_info(
base_dir: str,
endpattern: str = "genomic.fna.gz",
filters: dict = {"INCLUDE": [], "EXCLUDE": ["cds", "rna"]},
) -> dict[str, str]
This function extracts the genome information from the genomes base directory. The output is a dictionary where the keys are the genome IDs and the values are the paths to the genome files.
Required Configs
None
Args: base_dir (str): The path to the base directory where the genomes are saved. endpattern (str, optional): The end pattern of the genome files. Defaults to "genomic.fna.gz". filters (dict, optional): The filters to be applied to the genome files. This filter must be a dictionary with two keys: INCLUDE and EXCLUDE. The values of these keys must be lists of strings. Defaults to {"INCLUDE":[],"EXCLUDE":["cds","rna"]}. This defult is compatible with the genomes downloaded from NCBI i.e. only change this if you are providing your own genomes with different file name conventions. Returns: dict[str,str]: A dictionary containing the address of the genomes that are downloaded or to be downloaded.
Source code in adtoolbox/core.py
extract_genome_info_df
¶
extract_genome_info_df(
base_dir: str, endpattern: str = "genomic.fna.gz", filters: dict | None = None
) -> pl.DataFrame
Source code in adtoolbox/core.py
align_genome_to_protein_db
¶
align_genome_to_protein_db(
address: str,
outdir: str,
name: str,
container: str = "None",
image: str | None = None,
tmp_dir: str | PathLike | None = None,
) -> tuple[str, str]
This is a function that will align a genome to the Protein Database of the ADToolbox using mmseqs2. If you want to save the scripts, set save to True. Note that the alignment tables will be saved in any case. Note that this function uses mmseqs2 to align the genomes to the protein database. So, to run this function without any container you need to have mmseqs2 installed on your system. However, if you want to run this function with a container, you need to have the container installed on your system. You may select from "None", "docker", "singularity".
Requires
config.protein_db: The address of the protein database of the ADToolbox.¶
config.adtoolbox_docker: The name of the docker image to be used by ADToolbox (Only if using Docker as container).¶
config.adtoolbox_singularity: The name of the singularity image to be used by ADToolbox (Only if using Singularity as container).¶
Example: >>> import os >>> output=os.path.join(Main_Dir,"test") >>> address=os.path.join(Main_Dir,"test","genome_sequence.fa") >>> obj = Metagenomics(configs.Metagenomics()) >>> name="test_align" >>> assert obj.align_genome_to_protein_db(address=address,outdir=output,name=name,container="docker")[0].split(" ")==['docker', 'run', '', '-v', address+':'+address, '-v', configs.Database().protein_db+':'+configs.Database().protein_db, '-v', output+':'+output, 'parsaghadermazi/adtoolbox:x86', '', 'mmseqs', 'easy-search', address, configs.Database().protein_db, output+'/Alignment_Results_mmseq_test_align.tsv', 'tmpfiles', '--format-mode', '4', '\n\n']
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The address of the genome to be aligned. |
required |
outdir
|
str
|
The output directory where the alignment files will be saved. |
required |
name
|
str
|
The name of the genome. |
required |
container
|
str
|
The container to use. Defaults to "None". You may select from "None", "docker", "singularity". |
'None'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A dictionary containing the alignment files. |
str |
str
|
The bash script that is used to align the genomes or to be used to align the genomes. |
Source code in adtoolbox/core.py
2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 | |
align_short_reads_to_protein_db
¶
align_short_reads_to_protein_db(
query_seq: str | PathLike | Iterable[str | PathLike],
alignment_file_name: str,
container: str = "None",
image: str | None = None,
output_dir: str | PathLike | None = None,
threads: int = 1,
search_type: int = 2,
sensitivity: float | None = None,
keep_work: bool = False,
) -> tuple[str, str]
Prepare one MMseqs translated-search task for shotgun reads.
One or two FASTQ/FASTA inputs are accepted. All MMseqs query, result,
and temporary databases are kept below output_dir instead of next
to the source reads. A prebuilt protein_db_mmseqs is reused when
available; otherwise the configured protein FASTA is converted inside
this task's private working directory.
Source code in adtoolbox/core.py
2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 | |
extract_ec_from_alignment
¶
This function extracts the number of times an EC number is found in the alignment file when aligned to ADToolbox protein database.
Required Configs
config.e_value: The e-value threshold for the filtering the alignment table.¶
config.bit_score: The bit score threshold for the filtering the alignment table.¶
config.ec_counts_from_alignment: The address of the json file that the results will be saved in.¶
Example
import os output = os.path.join(Main_Dir, "test", "mmseqs_alignments.tsv") alignments = ["CP001673.1", "Q8YNF9|1.4.4.2", "0.566", "2859", "414", "0", "1021521", "1024379", "27", "982", "0.000E+00", "1109"] headers = ["query", "target", "fident", "alnlen", "mismatch", "gapopen", "qstart", "qend ", "tstart", "tend", "evalue", "bits"] hit = "\t".join(alignments) headers_tab = "\t".join(headers) combine = headers_tab + "\n" + hit with open(output, "w") as f: ... f.write(combine) 161 obj = Metagenomics(configs.Metagenomics()) obj.extract_ec_from_alignment(output)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alignment_file
|
str
|
The address of the alignment file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, int]
|
A dictionary of EC numbers and their counts. |
Source code in adtoolbox/core.py
get_cod_from_ec_counts
¶
This function takes a json file that comtains ec counts and converts it to ADM microbial agents counts. Required Configs: config.adm_mapping : A dictionary that maps ADM reactions to ADM microbial agents. --------- config.csv_reaction_db : The address of the reaction database of ADToolbox. --------- config.adm_cod_from_ec : The address of the json file that the results will be saved in. --------- Example: >>> import os >>> output = os.path.join(Main_Dir, "test", "cod_from_ec_counts") >>> alignments = ["CP001673.1", "Q8YNF9|1.4.4.2", "0.566", "2859", "414", "0", "1021521", "1024379", "27", "982", "0.000E+00", "1109"] >>> headers = ["query", "target", "fident", "alnlen", "mismatch", "gapopen", "qstart", "qend ", "tstart", "tend", "evalue", "bits"] >>> hit = "\t".join(alignments) >>> headers_tab = "\t".join(headers) >>> combine = headers_tab + "\n" + hit >>> with open(output, "w") as f: ... f.write(combine) 161 >>> obj = Metagenomics(configs.Metagenomics()) >>> obj.get_cod_from_ec_counts(output) [('ADM_microbe_1', 161), ('ADM_microbe_2', 0), ('ADM_microbe_3', 0)]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ec_counts
|
dict
|
A dictionary containing the counts for each ec number. |
required |
Returns: dict: A dictionary containing the ADM microbial agents counts.
Source code in adtoolbox/core.py
cod_from_ec_counts
¶
Source code in adtoolbox/core.py
cod_from_alignment
¶
detect_amplicon_primers
¶
detect_amplicon_primers(
read_1: str | PathLike,
read_2: str | PathLike | None = None,
*,
catalog: str | PathLike | None = None,
reads_to_check: int = 10000,
max_offset: int = 12,
max_error_rate: float = 0.15,
minimum_fraction: float = 0.8
) -> dict
Conservatively select a known primer pair from read starts.
Source code in adtoolbox/core.py
trim_amplicon_reads
¶
trim_amplicon_reads(
*,
read_1: str | PathLike,
read_2: str | PathLike | None,
output_dir: str | PathLike,
sample_name: str,
forward_primer: str | None = None,
reverse_primer: str | None = None,
adapter_1: str | None = None,
adapter_2: str | None = None,
minimum_length: int = 100,
quality_cutoff: str | int | None = None,
quality_trim: str = "none",
quality_window_size: int = 4,
quality_mean: int | None = None,
min_reads_for_denoising: int = 1,
allow_single_end_fallback: bool = True,
threads: int = 1,
container: str = "None",
image: str | None = None
) -> tuple[str, dict[str, str | None]]
Source code in adtoolbox/core.py
3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 | |
build_amplicon_features
¶
build_amplicon_features(
*,
read_1: str | PathLike,
read_2: str | PathLike | None,
read_layout: str | PathLike | None = None,
read_selection: str | PathLike | None = None,
primer_detection_read_1: str | PathLike | None = None,
primer_detection_read_2: str | PathLike | None = None,
output_dir: str | PathLike,
sample_name: str,
identity: float = 0.97,
maxee: float = 1.0,
minimum_length: int = 100,
min_unique_size: int = 2,
chimera_filter: bool = True,
denoiser: str = "vsearch",
forward_primer: str | None = None,
reverse_primer: str | None = None,
primer_mode: str = "none",
primer_catalog: str | PathLike | None = None,
primer_detection_reads: int = 10000,
primer_max_offset: int = 12,
primer_max_error_rate: float = 0.15,
primer_min_fraction: float = 0.8,
cutadapt_error_rate: float = 0.15,
discard_untrimmed: bool = True,
dada2_min_overlap: int = 12,
threads: int = 1,
container: str = "None",
image: str | None = None
) -> tuple[str, dict[str, str]]
Source code in adtoolbox/core.py
3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 | |
run_trim_reads_step
¶
run_trim_reads_step(
*,
sample_name: str,
output_dir: str | PathLike,
read_1: str | PathLike,
read_2: str | PathLike | None = None,
step_output_dir: str | PathLike | None = None,
forward_primer: str | None = None,
reverse_primer: str | None = None,
adapter_1: str | None = None,
adapter_2: str | None = None,
minimum_length: int = 100,
quality_cutoff: str | int | None = None,
enable_single_end_fallback: bool = True,
container: str = "None",
execute: bool = False,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None,
dependencies: Iterable[dict] | None = None
) -> dict
Prepare or run the amplicon read trimming step for one sample.
Source code in adtoolbox/core.py
4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 | |
run_sra_download_step
¶
run_sra_download_step(
*,
sample_name: str,
output_dir: str | PathLike,
accession: str,
sra_dir: str | PathLike | None = None,
paired: bool = True,
container: str = "None",
execute: bool = False,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None,
dependencies: Iterable[dict] | None = None
) -> dict
Prepare or run an SRA download step for one sample.
Source code in adtoolbox/core.py
run_build_amplicon_features_step
¶
run_build_amplicon_features_step(
*,
sample_name: str,
output_dir: str | PathLike,
read_1: str | PathLike,
read_2: str | PathLike | None = None,
read_layout: str | PathLike | None = None,
read_selection: str | PathLike | None = None,
primer_detection_read_1: str | PathLike | None = None,
primer_detection_read_2: str | PathLike | None = None,
step_output_dir: str | PathLike | None = None,
forward_primer: str | None = None,
reverse_primer: str | None = None,
identity: float = 0.97,
maxee: float = 1.0,
minimum_length: int = 100,
min_unique_size: int = 2,
chimera_filter: bool = True,
container: str = "None",
execute: bool = False,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None,
dependencies: Iterable[dict] | None = None
) -> dict
Prepare or run the configured amplicon feature-table step for one sample.
Source code in adtoolbox/core.py
4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 | |
run_short_read_alignment_step
¶
run_short_read_alignment_step(
*,
sample_name: str,
output_dir: str | PathLike,
reads: str | PathLike | Iterable[str | PathLike],
step_output_dir: str | PathLike | None = None,
container: str = "None",
execute: bool = False,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None,
dependencies: Iterable[dict] | None = None
) -> dict
Prepare or run the MMseqs shotgun-read alignment step.
Source code in adtoolbox/core.py
run_gtdb_alignment_step
¶
run_gtdb_alignment_step(
*,
sample_name: str,
output_dir: str | PathLike,
query_fasta: str | PathLike,
container: str = "None",
execute: bool = False,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None
) -> dict
Prepare or run the VSEARCH representative-sequence to GTDB step.
Source code in adtoolbox/core.py
run_genome_alignment_step
¶
run_genome_alignment_step(
*,
sample_name: str,
output_dir: str | PathLike,
genome_name: str,
genome_file: str | PathLike,
alignment_dir: str | PathLike | None = None,
container: str = "None",
execute: bool = False,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None
) -> dict
Prepare or run one genome-to-protein-database MMseqs alignment step.
Source code in adtoolbox/core.py
preprocess_amplicon_sample
¶
preprocess_amplicon_sample(
*,
sample_name: str,
output_dir: str | PathLike,
read_1: str | PathLike,
read_2: str | PathLike | None = None,
forward_primer: str | None = None,
reverse_primer: str | None = None,
adapter_1: str | None = None,
adapter_2: str | None = None,
minimum_length: int = 100,
quality_cutoff: str | int | None = None,
quality_maxee: float = 1.0,
identity: float = 0.97,
min_unique_size: int = 2,
chimera_filter: bool = True,
container: str = "None",
execute: bool = False,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None,
dependencies: Iterable[dict] | None = None
) -> dict
Source code in adtoolbox/core.py
4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 | |
aggregate_genome_cod
¶
aggregate_genome_cod(
genome_cods: dict[str, dict[str, float]],
genome_abundances: dict[str, float],
normalize: bool = True,
) -> dict[str, float]
Source code in adtoolbox/core.py
sample_to_cod
¶
sample_to_cod(
sample_name: str,
output_dir: str | PathLike,
*,
mode: str,
alignment_file: str | PathLike | None = None,
reads: str | PathLike | Iterable[str | PathLike] | None = None,
read_1: str | PathLike | None = None,
read_2: str | PathLike | None = None,
genome_abundances: str | PathLike | dict[str, float] | None = None,
genome_alignments: str | PathLike | dict[str, str] | None = None,
genomes_dir: str | PathLike | None = None,
feature_table: str | PathLike | None = None,
rep_seqs: str | PathLike | None = None,
gtdb_matches: str | PathLike | None = None,
force_gtdb_alignment: bool = False,
forward_primer: str | None = None,
reverse_primer: str | None = None,
adapter_1: str | None = None,
adapter_2: str | None = None,
minimum_length: int = 100,
quality_cutoff: str | int | None = None,
quality_maxee: float = 1.0,
identity: float = 0.97,
min_unique_size: int = 2,
chimera_filter: bool = True,
top_k: int = -1,
container: str = "None",
execute: bool = False,
normalize: bool = True,
verbose: bool = True,
execution_profile: str | PathLike | dict | None = None,
dependencies: Iterable[dict] | None = None
) -> dict
Run one metagenomics-to-eADM-COD pipeline for a single sample.
The method writes tall CSV tables for table-shaped artifacts,
plus provenance.json and pipeline.log under output_dir.
Source code in adtoolbox/core.py
4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 | |
batch_sample_to_cod
¶
batch_sample_to_cod(
*,
manifest: str | PathLike,
output_dir: str | PathLike,
assay: str = "amplicon",
input_type: str | None = None,
sra_dir: str | PathLike | None = None,
stage: str = "all",
amplicon_to_genome_db: str | PathLike | None = None,
genome_alignments: str | PathLike | dict[str, str] | None = None,
genomes_dir: str | PathLike | None = None,
gtdb_matches_dir: str | PathLike | None = None,
forward_primer: str | None = None,
reverse_primer: str | None = None,
adapter_1: str | None = None,
adapter_2: str | None = None,
minimum_length: int = 100,
quality_cutoff: str | int | None = None,
quality_maxee: float = 1.0,
identity: float = 0.97,
min_unique_size: int = 2,
chimera_filter: bool = True,
top_k: int = -1,
container: str = "None",
execute: bool = False,
normalize: bool = True,
verbose: bool = True,
sample_workers: int = 4,
execution_profile: str | PathLike | dict | None = None
) -> dict
Run a manifest-driven batch of amplicon or shotgun samples.
Manifest rows may provide either an SRA accession or FASTQ paths
in read_1/read_2. The stage argument can be download,
preprocess, cod, or all.
Source code in adtoolbox/core.py
5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 | |
calculate_group_abundances
¶
calculate_group_abundances(
elements_feature_abundances: dict[str, dict], rel_abund: dict[str, dict]
) -> dict[str, dict[str, float]]
This method is defined to calculate the features for each sample given: 1) The relative abundances of the genomes in each sample: - In this dictionary the keys are the sample names and the values are dictionaries where the keys are the genome names and the values are the relative abundances of the genomes in the sample. 2) The relative abundances of the elements in each genome. - In this dictionary the keys are the genome names and the values are dictionaries where the keys are the element names and the values are the relative abundances of the elements in the genome.
Required Configs
None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements_feature_abundances
|
dict[str, dict]
|
A dictionary containing the relative abundances of the elements in each genome. |
required |
rel_abund
|
dict[str, dict]
|
A dictionary containing the relative abundances of the genomes in each sample. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float]]
|
dict[str,dict[str,float]]: A dictionary containing the relative abundances of the elements in each sample. |
Source code in adtoolbox/core.py
extract_relative_abundances
¶
extract_relative_abundances(
feature_table_dir: str, sample_names: Union[list[str], None] = None, top_k: int = -1
) -> dict
This method extracts the relative abundances of the features in each sample from a TSV feature table. VSEARCH OTU tables and exported BIOM-style TSV tables are both supported. NOTE: The final feature abundances sum to 1 for each sample. Required Configs: None Args: feature_table_dir (str): The path to the feature table. sample_names (Union[list[str],None], optional): The list of sample names. to be considered. If None, all the samples will be considered. Defaults to None. top_k (int, optional): The number of top features to be used. If -1, all the features will be used. Defaults to -1.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the relative abundances of the features in each sample. |
Source code in adtoolbox/core.py
assign_ec_to_genome
¶
This function takes an alignment file and assigns the EC numbers to the genomes based on the alignment file, and the e-adm groupings of the EC numbers. The output is a dictionary where the keys e-adm reactions and the values are the EC numbers, that are found in the genome and are grouped under the e-adm reaction.
Example
import os output = os.path.join(Main_Dir, "test", "ec_to_genome") alignments = ["CP001673.1", "Q8YNF9|1.4.4.2", "0.566", "2859", "414", "0", "1021521", "1024379", "27", "982", "0.000E+00", "1109"] headers = ["query", "target", "fident", "alnlen", "mismatch", "gapopen", "qstart", "qend ", "tstart", "tend", "evalue", "bits"] hit = "\t".join(alignments) headers_tab = "\t".join(headers) combine = headers_tab + "\n" + hit with open(output, "w") as f: ... f.write(combine) 161 obj = Metagenomics(configs.Metagenomics()) obj.assign_ec_to_genome(output)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alignment_file
|
str
|
The address of the alignment file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the e-adm reactions and the EC numbers that are found in the genome and are grouped under the e-adm reaction. |
Source code in adtoolbox/core.py
6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 | |
seqs_from_sra
¶
seqs_from_sra(
accession: str, target_dir: str, container: str = "None", **kwargs
) -> tuple[str, dict]
This method downloads the fastq files from the SRA database using the accession number (ONLY SAMPLE ACCESSION AND NOT PROJECT ACCESSION) of the project or run. The method uses the fasterq-dump tool to download the fastq files. This method also extracts the sample metadata from the SRA database for future use.
NOTE In order for this method to work without any container, you need to have the SRA toolkit installed on your system or¶
at least have prefetch and fasterq-dump installed on your system. For more information on how to install the SRA toolkit, please refer to the following link: https://github.com/ncbi/sra-tools.
Any additional keyword
Required Configs
None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accession
|
str
|
The accession number of the SRA project or run |
required |
target_dir
|
str
|
The directory where the fastq files will be downloaded |
required |
container
|
str
|
The containerization tool that will be used to run the bash scripts. Defaults to "None". Options are "None","docker","singularity" |
'None'
|
Returns:
| Name | Type | Description |
|---|---|---|
prefetch_script |
str
|
The bash script that will be used to download the SRA files in python string format |
sample_metadata |
dict
|
A dictionary that contains the sample metadata |
Source code in adtoolbox/core.py
merge_paired_sequences
¶
merge_paired_sequences(
read_1: str, read_2: str, outputfile: str, container: str = "None", **kwargs
) -> tuple[str]
This method merges the paired end reads using the fastp tool. Note that any additional keyword arguments will be passed to the fastp tool.
Required Configs:
None
Args:
read_1 (str): The directory of the forward reads file.
read_2 (str): The directory of the reverse reads file.
outputfile (str): The directory of the output file.
container (str, optional): The containerization tool that will be used to run the bash scripts. Defaults to "None". Options are "None","docker","singularity".
Returns:
| Name | Type | Description |
|---|---|---|
str |
tuple[str]
|
The bash script that will be used to merge the paired end reads in python string format |
Source code in adtoolbox/core.py
Annotation¶
Annotation
¶
Source code in adtoolbox/core.py
annotate_with_metacyc
¶
" This function annotates the genomes with the metabolic pathways using the metabolic pathways database. Required Configs: None Args: alignment_file (str): The path to the alignment file. Returns: dict: A dictionary containing the metabolic pathways and their coverage in based on the input alignment file.
Source code in adtoolbox/core.py
Pipeline execution¶
Task bookkeeping and Slurm submission used by the batch pipeline.
PipelineTask¶
PipelineTask
dataclass
¶
PipelineTask(
sample_name: str,
step_name: str,
backend: str,
command: str,
status: str,
dependencies: list[str] = list(),
sbatch: str | None = None,
job_id: str | None = None,
submission: str | None = None,
)
dependencies
class-attribute
instance-attribute
¶
PipelineTaskManager¶
PipelineTaskManager
¶
PipelineTaskManager(
*,
sample_name: str,
output_dir: str | PathLike,
execution_profile: dict,
logger: Logger
)
Small execution manager for local and Slurm pipeline tasks.
Source code in adtoolbox/core.py
record
¶
Source code in adtoolbox/core.py
parse_slurm_job_id
staticmethod
¶
wait_for_slurm_capacity
¶
Source code in adtoolbox/core.py
submit_slurm_job
¶
submit_slurm_job(
*,
sbatch_path: str | PathLike,
task: PipelineTask,
job_name_prefix: str,
attempt: int
) -> tuple[str, str | None]
Source code in adtoolbox/core.py
submit_slurm_job_with_retries
¶
submit_slurm_job_with_retries(
*,
sbatch_path: str | PathLike,
task: PipelineTask,
job_name_prefix: str,
max_retries: int,
retry_delay_seconds: int
) -> dict
Submit a fresh Slurm job for every task attempt.
Source code in adtoolbox/core.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |