[CHNOSZ-commits] r728 - in pkg/CHNOSZ: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 20 04:29:42 CEST 2022


Author: jedick
Date: 2022-06-20 04:29:42 +0200 (Mon, 20 Jun 2022)
New Revision: 728

Added:
   pkg/CHNOSZ/R/rank_affinity.R
   pkg/CHNOSZ/man/rank_affinity.Rd
Removed:
   pkg/CHNOSZ/R/affinity_rank.R
   pkg/CHNOSZ/man/affinity_rank.Rd
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/NAMESPACE
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/man/diagram.Rd
   pkg/CHNOSZ/man/extdata.Rd
Log:
Rename affinity_rank() to rank_affinity()


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/DESCRIPTION	2022-06-20 02:29:42 UTC (rev 728)
@@ -1,6 +1,6 @@
-Date: 2022-06-08
+Date: 2022-06-20
 Package: CHNOSZ
-Version: 1.9.9-20
+Version: 1.9.9-21
 Title: Thermodynamic Calculations and Diagrams for Geochemistry
 Authors at R: c(
     person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),

Modified: pkg/CHNOSZ/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/NAMESPACE	2022-06-20 02:29:42 UTC (rev 728)
@@ -58,7 +58,7 @@
 # added 20220324
   "logB_to_OBIGT",
 # added 20220416
-  "affinity_rank"
+  "rank_affinity"
 )
 
 # Load shared objects

Deleted: pkg/CHNOSZ/R/affinity_rank.R
===================================================================
--- pkg/CHNOSZ/R/affinity_rank.R	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/R/affinity_rank.R	2022-06-20 02:29:42 UTC (rev 728)
@@ -1,27 +0,0 @@
-# Calculate normalized sum of ranking of affinities for species in designated groups
-# 20220416 jmd first version
-
-affinity_rank <- function(aout, groups) {
-  # Put the affinities into matrix form
-  amat <- sapply(aout$values, as.numeric)
-  # Calculate ranks
-  # https://stackoverflow.com/questions/1412775/pmax-parallel-maximum-equivalent-for-rank-in-r
-  arank <- apply(amat, 1, rank)
-  # Get the normalized ranks for each group
-  grank <- sapply(groups, function(group) {
-    # Sum the ranks for this group and divide by number of species in the group
-    if(inherits(group, "logical")) n <- sum(group)
-    if(inherits(group, "integer")) n <- length(group)
-    colSums(arank[group, ]) / n
-  })
-  # Restore dims
-  dims <- dim(aout$values[[1]])
-  glist <- apply(grank, 2, "dim<-", dims, simplify = FALSE)
-  aout$values <- glist
-  # Rename species to group names (for use by diagram())
-  aout$species <- aout$species[1:length(groups), ]
-  aout$species$name <- names(groups)
-  # "Sign" the object with our function name
-  aout$fun <- "affinity_rank"
-  aout
-}

Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/R/diagram.R	2022-06-20 02:29:42 UTC (rev 728)
@@ -44,15 +44,15 @@
   ## Check that eout is a valid object
   efun <- eout$fun
   if(length(efun)==0) efun <- ""
-  if(!(efun %in% c("affinity", "affinity_rank", "equilibrate") | grepl("solubilit", efun)))
-    stop("'eout' is not the output from one of these functions: affinity, affinity_rank, equilibrate, or solubility")
+  if(!(efun %in% c("affinity", "rank_affinity", "equilibrate") | grepl("solubilit", efun)))
+    stop("'eout' is not the output from one of these functions: affinity, rank_affinity, equilibrate, or solubility")
   # For solubilities(), default type is loga.balance 20210303
   if(grepl("solubilities", efun) & missing(type)) type <- "loga.balance"
-  # Check balance argument for affinity_rank() 20220416
-  if(efun == "affinity_rank") {
+  # Check balance argument for rank_affinity() 20220416
+  if(efun == "rank_affinity") {
     if(!identical(balance, 1)) {
-      if(!is.null(balance)) stop("balance = 1 or NULL is required for plotting output of affinity_rank()")
-      if(is.null(balance)) message("diagram: setting balance = 1 for plotting output of affinity_rank()")
+      if(!is.null(balance)) stop("balance = 1 or NULL is required for plotting output of rank_affinity()")
+      if(is.null(balance)) message("diagram: setting balance = 1 for plotting output of rank_affinity()")
       balance <- 1
     }
   }
@@ -124,8 +124,8 @@
     })
     names(plotvals) <- names(eout$values)
     plotvar <- eout$property
-    if(efun == "affinity_rank") {
-      plotvar <- "affinity_rank"
+    if(efun == "rank_affinity") {
+      plotvar <- "rank_affinity"
       message(paste("diagram: plotting average affinity ranking for", length(plotvals), "groups"))
     } else if(plotvar=="A") {
       # we change 'A' to 'A/(2.303RT)' so the axis label is made correctly
@@ -203,7 +203,7 @@
   ## identify predominant species
   predominant <- NA
   H2O.predominant <- NULL
-  if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)", "affinity_rank") & type!="saturation") {
+  if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)", "rank_affinity") & type!="saturation") {
     pv <- plotvals
     # some additional steps for affinity values, but not for equilibrated activities
     if(eout.is.aout) {
@@ -352,7 +352,7 @@
         if(missing(xlab)) xlab <- axis.label(eout$vars[1], basis=eout$basis, molality=molality)
         if(missing(ylab)) {
           ylab <- axis.label(plotvar, units="", molality=molality)
-          if(plotvar == "affinity_rank") ylab <- "Average affinity ranking"
+          if(plotvar == "rank_affinity") ylab <- "Average affinity ranking"
           # use ppb, ppm, ppt (or log ppb etc.) for converted values of solubility 20190526
           if(grepl("solubility.", eout$fun, fixed=TRUE)) {
             ylab <- strsplit(eout$fun, ".", fixed=TRUE)[[1]][2]

Copied: pkg/CHNOSZ/R/rank_affinity.R (from rev 727, pkg/CHNOSZ/R/affinity_rank.R)
===================================================================
--- pkg/CHNOSZ/R/rank_affinity.R	                        (rev 0)
+++ pkg/CHNOSZ/R/rank_affinity.R	2022-06-20 02:29:42 UTC (rev 728)
@@ -0,0 +1,27 @@
+# Calculate normalized sum of ranking of affinities for species in designated groups
+# 20220416 jmd first version
+
+rank_affinity <- function(aout, groups) {
+  # Put the affinities into matrix form
+  amat <- sapply(aout$values, as.numeric)
+  # Calculate ranks
+  # https://stackoverflow.com/questions/1412775/pmax-parallel-maximum-equivalent-for-rank-in-r
+  arank <- apply(amat, 1, rank)
+  # Get the normalized ranks for each group
+  grank <- sapply(groups, function(group) {
+    # Sum the ranks for this group and divide by number of species in the group
+    if(inherits(group, "logical")) n <- sum(group)
+    if(inherits(group, "integer")) n <- length(group)
+    colSums(arank[group, ]) / n
+  })
+  # Restore dims
+  dims <- dim(aout$values[[1]])
+  glist <- apply(grank, 2, "dim<-", dims, simplify = FALSE)
+  aout$values <- glist
+  # Rename species to group names (for use by diagram())
+  aout$species <- aout$species[1:length(groups), ]
+  aout$species$name <- names(groups)
+  # "Sign" the object with our function name
+  aout$fun <- "rank_affinity"
+  aout
+}

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2022-06-20 02:29:42 UTC (rev 728)
@@ -10,7 +10,7 @@
 \newcommand{\s}{\ifelse{latex}{\eqn{_{#1}}}{\ifelse{html}{\out{<sub>#1</sub>}}{#1}}}
 \newcommand{\S}{\ifelse{latex}{\eqn{^{#1}}}{\ifelse{html}{\out{<sup>#1</sup>}}{^#1}}}
 
-\section{Changes in CHNOSZ version 1.9.9-19 (2022-06-04)}{
+\section{Changes in CHNOSZ version 1.9.9-21 (2022-06-08)}{
 
   \subsection{MAJOR CHANGE}{
     \itemize{
@@ -68,7 +68,7 @@
       \item Add a check to \code{add.protein()} that all new protein IDs
       (protein name + organism name) are unique.
 
-      \item Add function \code{affinity_rank()} to calculate (sums of ranks of
+      \item Add function \code{rank_affinity()} to calculate (sums of ranks of
       affinities for species in designated groups) normalized by number of
       species in each group. The output of the new function can be used by
       \code{diagram()}.

Deleted: pkg/CHNOSZ/man/affinity_rank.Rd
===================================================================
--- pkg/CHNOSZ/man/affinity_rank.Rd	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/man/affinity_rank.Rd	2022-06-20 02:29:42 UTC (rev 728)
@@ -1,52 +0,0 @@
-\encoding{UTF-8}
-\name{affinity_rank}
-\alias{affinity_rank}
-\title{Normalized Sums of Ranks of Chemical Affinities}
-\description{
-Affinity ranking for groups of species.
-}
-
-\usage{
-  affinity_rank(aout, groups)
-}
-
-\arguments{
-  \item{aout}{list, output of \code{\link{affinity}}}
-  \item{groups}{named list of indices (integer or numeric) for species in each group}
-}
-
-\details{
-The following calculations are applied to each set of conditions (i.e., grid point if \code{\link{affinity}} was called with two variables).
-The \code{\link{rank}}s of affinities for all species are first computed.
-Then, the ranks for the species in each group are summed and divided by the number of species in that group (this is the normalization step).
-}
-
-\value{
-The normalized sum of ranks are inserted into the \code{values} element of \code{aout}, and the names of the groups are inserted into the \code{species} element.
-The result can be used by \code{\link{diagram}} to show the groups with the highest normalized sum of ranks.
-}
-
-\note{
-The reaction coefficients in the \code{species} element of the returned value of \code{aout} are not valid.
-Because balancing on a basis species (i.e., dividing by its reaction coefficient) would be incorrect, \code{diagram} enforces \code{balance = 1} so that that the normalized sums of ranks are used as-is.
-}
-
-\examples{
-\dontshow{reset()}# Compare Rubisco proteins from three domains
-datfile <- system.file("extdata/cpetc/rubisco.csv", package = "CHNOSZ")
-fastafile <- system.file("extdata/protein/rubisco.fasta", package = "CHNOSZ")
-dat <- read.csv(datfile)
-aa <- read.fasta(fastafile)
-groups <- sapply(c("A", "B", "E"), "==", dat$domain, simplify = FALSE)
-names(groups) <- c("Archaea", "Bacteria", "Eukaryota")
-ip <- add.protein(aa, as.residue = TRUE)
-basis("QEC")
-aout <- affinity(O2 = c(-74, -66, 100), H2O = c(-4, 4, 100), iprotein = ip)
-arank <- affinity_rank(aout, groups = groups)
-nspecies <- sapply(groups, sum)
-names <- paste0(names(groups), " (", nspecies, ")")
-diagram(arank, fill = "terrain", font = 2, names = names, format.names = FALSE)
-title("Average affinity ranking of Rubisco proteins")
-}
-
-\concept{Extended workflow}

Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/man/diagram.Rd	2022-06-20 02:29:42 UTC (rev 728)
@@ -93,7 +93,7 @@
 \details{
 
 This function displays diagrams representing either chemical affinities or equilibrium chemical activities of species.
-The first argument is the output from \code{\link{affinity}}, \code{\link{affinity_rank}}, \code{\link{equilibrate}}, or \code{\link{solubility}}.
+The first argument is the output from \code{\link{affinity}}, \code{\link{rank_affinity}}, \code{\link{equilibrate}}, or \code{\link{solubility}}.
 0-D diagrams, at a single point, are shown as \code{\link{barplot}}s.
 1-D diagrams, for a single variable on the x-axis, are plotted as lines.
 2-D diagrams, for two variables, are plotted as predominance fields.

Modified: pkg/CHNOSZ/man/extdata.Rd
===================================================================
--- pkg/CHNOSZ/man/extdata.Rd	2022-06-08 13:58:00 UTC (rev 727)
+++ pkg/CHNOSZ/man/extdata.Rd	2022-06-20 02:29:42 UTC (rev 728)
@@ -30,7 +30,7 @@
     \item \code{HWM96_V.csv}, \code{HW97_Cp.csv} Apparent molar volumes and heat capacities of \CH4, \CO2, \H2S, and \NH3 in dilute aqueous solutions reported by Hnědkovský et al., 1996 and Hnědkovský and Wood, 1997. Units are Kelvin, MPa, J/K/mol, and cm3/mol. See \code{demo("AD")} for examples that use these files.
     \item \code{SC10_Rainbow.csv} Values of temperature (\degC), pH and logarithms of activity of \CO2, \H2, \NH4plus, \H2S and \CH4 for mixing of seawater and hydrothermal fluid at Rainbow field (Mid-Atlantic Ridge), taken from Shock and Canovas, 2010. See the vignette \viglink{anintro} for an example that uses this file.
     \item \code{SS98_Fig5a.csv}, \code{SS98_Fig5b.csv} Values of logarithm of fugacity of \O2 and pH as a function of temperature for mixing of seawater and hydrothermal fluid, digitized from Figs. 5a and b of Shock and Schulte, 1998. See the vignette \viglink{anintro} for an example that uses this file.
-    \item \code{rubisco.csv} UniProt IDs for Rubisco, ranges of optimal growth temperature of organisms, domain and name of organisms, and URL of reference for growth temperature, from Dick, 2014. See \code{\link{affinity_rank}} and the vignette \viglink{anintro} for examples that use this file.
+    \item \code{rubisco.csv} UniProt IDs for Rubisco, ranges of optimal growth temperature of organisms, domain and name of organisms, and URL of reference for growth temperature, from Dick, 2014. See \code{\link{rank_affinity}} and the vignette \viglink{anintro} for examples that use this file.
     \item \code{bluered.txt} Blue - light grey - red color palette, computed using \CRANpkg{colorspace}\code{::diverge_hcl(1000,} \code{c = 100, l = c(50, 90), power = 1)}. This is used by \code{\link{ZC.col}}.
     \item \code{AD03_Fig1?.csv} Experimental data points digitized from Figure 1 of Akinfiev and Diamond, 2003, used in \code{demo("AD")}.
     \item \code{TKSS14_Fig2.csv} Experimental data points digitized from Figure 2 of Tutolo et al., 2014, used in \code{demo("aluminum")}.

Copied: pkg/CHNOSZ/man/rank_affinity.Rd (from rev 727, pkg/CHNOSZ/man/affinity_rank.Rd)
===================================================================
--- pkg/CHNOSZ/man/rank_affinity.Rd	                        (rev 0)
+++ pkg/CHNOSZ/man/rank_affinity.Rd	2022-06-20 02:29:42 UTC (rev 728)
@@ -0,0 +1,52 @@
+\encoding{UTF-8}
+\name{rank_affinity}
+\alias{rank_affinity}
+\title{Normalized Sums of Ranks of Chemical Affinities}
+\description{
+Affinity ranking for groups of species.
+}
+
+\usage{
+  rank_affinity(aout, groups)
+}
+
+\arguments{
+  \item{aout}{list, output of \code{\link{affinity}}}
+  \item{groups}{named list of indices (integer or numeric) for species in each group}
+}
+
+\details{
+The following calculations are applied to each set of conditions (i.e., grid point if \code{\link{affinity}} was called with two variables).
+The \code{\link{rank}}s of affinities for all species are first computed.
+Then, the ranks for the species in each group are summed and divided by the number of species in that group (this is the normalization step).
+}
+
+\value{
+The normalized sum of ranks are inserted into the \code{values} element of \code{aout}, and the names of the groups are inserted into the \code{species} element.
+The result can be used by \code{\link{diagram}} to show the groups with the highest normalized sum of ranks.
+}
+
+\note{
+The reaction coefficients in the \code{species} element of the returned value of \code{aout} are not valid.
+Because balancing on a basis species (i.e., dividing by its reaction coefficient) would be incorrect, \code{diagram} enforces \code{balance = 1} so that that the normalized sums of ranks are used as-is.
+}
+
+\examples{
+\dontshow{reset()}# Compare Rubisco proteins from three domains
+datfile <- system.file("extdata/cpetc/rubisco.csv", package = "CHNOSZ")
+fastafile <- system.file("extdata/protein/rubisco.fasta", package = "CHNOSZ")
+dat <- read.csv(datfile)
+aa <- read.fasta(fastafile)
+groups <- sapply(c("A", "B", "E"), "==", dat$domain, simplify = FALSE)
+names(groups) <- c("Archaea", "Bacteria", "Eukaryota")
+ip <- add.protein(aa, as.residue = TRUE)
+basis("QEC")
+aout <- affinity(O2 = c(-74, -66, 100), H2O = c(-4, 4, 100), iprotein = ip)
+arank <- rank_affinity(aout, groups = groups)
+nspecies <- sapply(groups, sum)
+names <- paste0(names(groups), " (", nspecies, ")")
+diagram(arank, fill = "terrain", font = 2, names = names, format.names = FALSE)
+title("Average affinity ranking of Rubisco proteins")
+}
+
+\concept{Extended workflow}



More information about the CHNOSZ-commits mailing list