View source: R/add_chemtable.R
| add_chemtable | R Documentation |
This function replaces add_chemtable and augment.table, converting wide-format chemical data into a normalized, long-format structure consisting of multiple related data frames following relational database design principles.
add_chemtable(
new.table,
data.list,
current.table = NULL,
reference = NULL,
species = NULL,
overwrite = FALSE,
sig.fig = 4,
clint.pvalue.threshold = 0.05,
allow.na = FALSE,
suppress.messages = FALSE,
type = "measured"
)
new.table |
Object of class data.frame containing one row per chemical, with each chemical minimally described by a CAS number. |
data.list |
This list identifies which properties are to be read from the table. Each item in the list should point to a column in the table new.table. Valid names in the list are: 'Compound', 'CAS', 'DTXSID', 'SMILES.desalt', 'Formula', 'Reference', 'Species', 'MW', 'logP', 'logPwa', 'logHenry', 'logWSol', 'logVP', 'MP', 'pKa_Donor', 'pKa_Accept', 'logMA', 'Clint', 'Clint.pValue', 'Funbound.plasma', 'Fabs', 'Fgut', 'Fhep', 'Rblood2plasma', 'Caco2.Pab', 'Foral'. |
current.table |
This is the list of data frames to which data are being added. If NULL, a new list is created. |
reference |
This is the reference for the data in the new table. This may be omitted if a column in data.list gives the reference value for each chemical. |
species |
This is the species for the data in the new table. This may be omitted if a column in data.list gives the species value for each chemical or if the data are not species-specific (e.g., MW). |
overwrite |
If TRUE then data in current.table will be replaced by any data in new.table that is for the same chemical and property. If FALSE (DEFAULT) then new data for the same chemical and property are ignored. Exceptions: 1) Funbound.plasma values of 0 (below limit of detection) are overwritten if new value is non-zero. 2) If Clint.pValue > clint.pvalue.threshold (default 0.05), Clint is overwritten and Clint.pValue is updated or deleted based on new data. |
sig.fig |
Sets the number of significant figures stored (defaults to 4) |
clint.pvalue.threshold |
P-value threshold for deciding whether to overwrite Clint (default 0.05). If existing Clint.pValue > this threshold and overwrite=TRUE, the Clint is replaced. (defaults to 0.05) |
allow.na |
If TRUE (default is FALSE) then NA values are written to the table, otherwise they are ignored. |
suppress.messages |
Whether or not the output messages are suppressed. |
type |
This is a character string indicating whether the data are "measured" or "predicted". This is used to populate the "type" column in the invitrotk table. Default is "measured". |
A list containing normalized data frames:
chemicals: One row per unique chemical with columns chem_id (PK), cichem, DTXSID, CASRN, Formula, SMILES.desalt
synonyms: Chemical name synonyms with columns synonym_text (normalized text), chem_id_fk (FK to chemicals)
chemprop: Physico-chemical properties with columns chem_id_fk (FK), property, value, units, ref_id_fk (FK)
refs: References with columns ref_id (PK), reference, pmid, doi
invitrotk: In vitro toxicokinetic data with columns chem_id_fk (FK), ref_id_fk (FK), parameter, type, value, units, species
John Wambaugh
library(httk)
num.chems <- length(get_cheminfo())
fake <- data.frame(Compound="Tester",
CASRN="222-11-7",
DTXSID="DTXSID111222",
MW=200,
logP=3.5,
pKa_Donor=" ",
pKa_Accept=" ",
Fup=0.1,
Clint=0.1,
Clint.pValue=0.001,stringsAsFactors=FALSE)
chem.physical_and_invitro.data <- add_chemtable(
fake,
current.table=chem.physical_and_invitro.data,
data.list=list(
Compound="Compound",
CAS="CASRN",
DTXSID="DTXSID",
MW="MW",
logP="logP",
pKa_Donor="pKa_Donor",
pKa_Accept="pKa_Accept",
Funbound.plasma="Fup",
Clint="Clint",
Clint.pValue="Clint.pValue"),
species="Human",
reference="Fake")
calc_css(chem.name="Tester")
load_sipes2017()
# We should have the ADMet Predicted chemicals from Sipes et al. (2017),
# this one is a good test since the logP is nearly 10!
calc_css(chem.cas="26040-51-7")
#Let's see how many chemicals we have now with the Sipes (2017) data loaded)=:
length(get_cheminfo())
#Now let's reset
reset_httk()
# We should be back to our original number:
num.chems == length(get_cheminfo())
# Now add chemicals A, B, and C:
my.new.data <- as.data.frame(c("A","B","C"),stringsAsFactors=FALSE)
my.new.data <- cbind(my.new.data,as.data.frame(c(
"111-11-2","222-22-0","333-33-5"),
stringsAsFactors=FALSE))
my.new.data <- cbind(my.new.data,as.data.frame(c("DTXSID1","DTXSID2","DTXSID3"),
stringsAsFactors=FALSE))
my.new.data <- cbind(my.new.data,as.data.frame(c(200,200,200)))
my.new.data <- cbind(my.new.data,as.data.frame(c(2,3,4)))
my.new.data <- cbind(my.new.data,as.data.frame(c(" ",2," ")))
my.new.data <- cbind(my.new.data,as.data.frame(c(" "," "," ")))
my.new.data <- cbind(my.new.data,as.data.frame(c(0.01,0.02,0.3)))
my.new.data <- cbind(my.new.data,as.data.frame(c(0,10,100)))
colnames(my.new.data) <- c("Name",
"CASRN",
"DTXSID",
"MW",
"LogP",
"pKa_Donor",
"pKa_Accept",
"Fup",
"CLint")
chem.physical_and_invitro.data <- add_chemtable(my.new.data,
current.table=
chem.physical_and_invitro.data,
data.list=list(
Compound="Name",
CAS="CASRN",
DTXSID="DTXSID",
MW="MW",
logP="LogP",
pKa_Donor="pKa_Donor",
pKa_Accept="pKa_Accept",
Funbound.plasma="Fup",
Clint="CLint"),
species="Human",
reference="MyPaper 2015")
parameterize_steadystate(chem.name="C")
calc_css(chem.name="B")
# Initialize a column describing proton donors ("acids")
my.new.data$pka.a <- NA
# set chemical C to an acid (pKa_donor = 5):
my.new.data[my.new.data$Name=="C","pka.a"] <- "5"
chem.physical_and_invitro.data <- add_chemtable(my.new.data,
current.table=
chem.physical_and_invitro.data,
data.list=list(
Compound="Name",
CAS="CASRN",
DTXSID="DTXSID",
pKa_Donor="pka.a"),
species="Human",
reference="MyPaper 2015")
# Note Rblood2plasma and hepatic bioavailability change (relative to above):
parameterize_steadystate(chem.name="C")
# Initialize a column describing proton acceptors ("bases")
my.new.data$pka.b <- NA
# set chemical B to a base with multiple pka's (pKa_accept = 7 and 8):
my.new.data[my.new.data$Name=="B","pka.b"] <- "7;8"
chem.physical_and_invitro.data <- add_chemtable(my.new.data,
current.table=
chem.physical_and_invitro.data,
data.list=list(
Compound="Name",
CAS="CASRN",
DTXSID="DTXSID",
pKa_Accept="pka.b"),
species="Human",
reference="MyPaper 2015")
# Note that average and max change (relative to above):
calc_css(chem.name="B")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.