data(thermo)
# an inorganic example: sulfur species
basis("CHNOS+")
basis("pH",5)
species(c("H2S","S2-2","S3-2","S2O3-2","S2O4-2","S3O6-2",
"S5O6-2","S2O6-2","HSO3-","SO2","HSO4-"))
# to minimize the standard deviations of the loga of the species
target <- "sd"
# this one gives logfO2=-27.8
f1 <- findit(list(O2=c(-50,-15)),target,T=325,P=350,n=3)
# this one gives logfO2=-30.0 pH=9.38
f2 <- findit(list(O2=c(-50,-15),pH=c(0,14)),target,T=325,P=350,res=16,n=4)
# an organic example:
# find chemical activities where metastable activities of
# selected proteins in P. ubique have high correlation
# with a lognormal distribution (i.e., maximize r of q-q plot)
f <- system.file("extdata/HTCC1062.faa",package="CHNOSZ")
# search for three groups of proteins
myg <- c("ribosomal","nucle","membrane")
g <- lapply(myg,function(x) grep.file(f,x))
# note that some proteins match more than one search term
uug <- unique(unlist(g))
# read their amino acid compositions from the file
p <- read.fasta(f,uug)
# add these proteins to thermo$protein
ip <- add.protein(p)
# load a predefined set of uncharged basis species
# (speeds things up as we won't model protein ionization)
basis("CHNOS")
# make colors for the diagram
rgbargs <- lapply(1:3,function(x) as.numeric(uug %in% g[[x]]))
col <- do.call(rgb,c(rgbargs,list(alpha=0.5)))
# get point symbols (use 1,2,4 and their sums)
pch <- colSums(t(list2array(rgbargs)) * c(1,2,4))
# plot 1: calculated logarithms of chemical activity
# as a function of logfO2 ... a bundle of curves near logfO2 = -77
a <- affinity(O2=c(-90,-50),iprotein=ip)
d <- diagram(a,logact=0,col=col)
# plot 2: q-q correlation coefficient
# it shows lognormal distribution favored near logfO2 = -73.6
r <- revisit(d,"qqr")
# plot 3: q-q at a single value of logfO2
basis("O2",-73.6)
a <- affinity(iprotein=ip)
d <- diagram(a,logact=0,do.plot=FALSE)
qqr3 <- revisit(d,"qqr",pch=pch)$H
legend("topleft",pch=c(1,2,4),legend=myg)
# plot 4: findit... maximize qqr as a function of O2-H2O-NH3-CO2
# it shows an optimum at low logaH2O, logaNH3
f1 <- findit(list(O2=c(-90,-70),H2O=c(-30,0),CO2=c(-20,10),NH3=c(-15,0)),
"qqr",iprotein=ip,n=8)
# plot 5: q-q plot at the final loga O2, H2O, CO2, NH3
# higher correlation coefficient than plot 3
a <- affinity(iprotein=ip)
d <- diagram(a,logact=0,do.plot=FALSE)
qqr5 <- revisit(d,"qqr",pch=pch)$H
legend("topleft",pch=c(1,2,4),legend=myg)
# plot 6: trajectory of O2, H2O, CO2, NH3, and the
# q-q correlation coefficient in the search
plot(f1,mar=c(2,5,1,1),mgp=c(4,1,0))
Run the code above in your browser using DataLab