Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^.travis.yml$
LICENSE.md
README_assets
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Package: DNAr
Type: Package
Title: Simulates chemical reaction networks constructed with DNA
Version: 0.9.6
Version: 0.9.7
Authors@R: c(person("Daniel", "Kneipp", email = "danielv@dcc.ufmg.br",
role = c("aut", "cre")),
role = c("aut")),
person("Marcos", "Guterres", email = "mguterres@yahoo.com",
role = c("aut")))
role = c("aut")),
person("Renan", "Marks", email = "renan.marks@ufms.br",
role = c("cre")))
Description: With this package you can simulate CRNs implemented with
DNA. Currently there is only one approach for CRN construction with
DNA, but the plan is to expand this to other approachs using the CRN
Expand All @@ -23,9 +25,8 @@ Imports:
reshape2 (>= 1.4.2),
RColorBrewer (>= 1.1.2),
assertthat (>= 0.2.0),
magrittr (>= 1.5),
Rdpack (>= 0.4.20)
RoxygenNote: 6.0.1
RoxygenNote: 7.3.3
RdMacros: Rdpack
Roxygen: list(markdown = TRUE)
Suggests: testthat
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export(save_dsd_script)
export(save_reactions_txt)
export(update_crn_4domain)
export(update_neuron_input_hje)
importFrom(Rdpack,reprompt)
importFrom(utils,capture.output)
importFrom(utils,read.csv)
importFrom(utils,write.csv)
12 changes: 11 additions & 1 deletion R/4domain_reactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#' \code{TRUE} if the reaction is supported, or \code{FALSE}
#' otherwise.
#'
#' @param reaction A string containing the text representing the reaction.
#'
#' @examples
#' DNAr:::check_reaction_4domain('A + B -> C') # Should return TRUE
#' DNAr:::check_reaction_4domain('2A -> B') # Should return TRUE
Expand All @@ -46,14 +48,22 @@ check_reaction_4domain <- function(reaction) {
#' The parameters of this function follows the same
#' semantics of \code{\link{react_4domain}()}.
#'
#' @param reactions A vector with the reactions of the CRN.
#' @param ki A vector defining the constant rate of each reaction
#' in \code{reactions}, in order.
#' @param qmax Maximum rate constant for the auxiliary reactions.
#' @param cmax Maximum initial concentration for the auxiliary species.
#'
#' @return \code{NULL} if no buffer modules were added. Otherwise
#' it returns a list with:
#' - `lambda_1` = lambda^{-1} value;
#' - `lambda_1` = lambda^\{-1\} value;
#' - `new_species` = vector with the new species added;
#' - `new_cis` = vector with the initial concentrations;
#' - `new_reactions` = vector with the new reactions;
#' - `new_ks` = constant rate of the new reactions.
#'
#' @importFrom Rdpack reprompt
#'
#' @references
#' - `[1]` \insertRef{soloveichik2010dna}{DNAr}
get_buff_modules <- function(reactions, ki, qmax, cmax) {
Expand Down
14 changes: 14 additions & 0 deletions R/analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ compare_behaviors_nrmse <- function(bhv_sim, bhv_obs, ignore_time_column = T) {
#' this functions returns the concentration of each species
#' at a specific point in time within the derivative.
#'
#' @param species A vector with the species of the reaction. The order of
#' this vector is important because it will define the
#' column order of the returned behavior.
#' @param ci A vector specifying the initial concentrations of the
#' \code{species} specified, in order.
#' @param reactions A vector with the reactions of the CRN. If a reaction has
#' has only reactants that are non in `species`, this
#' reaction will be treated as `0 -> products`. Furthermore,
#' this function treats a reaction `non_registered_species
#' + registered_species -> products` equally to
#' `registered_species -> products`, ignoring the species non
#' registered on the `species` vector.
#' @param ki A vector defining the constant rate of each reaction
#' in \code{reactions}, in order.
#' @param behavior The data returned by \code{\link{react}()}.
#' @param time_points A vector of indexes (representing multiple points in
#' time) used for access lines of `behavior`.
Expand Down
5 changes: 5 additions & 0 deletions R/crn_reactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#' This matrix has #lines = #reactions and #columns = #species and it
#' represents the stoichiometry of each species at each reaction.
#'
#' @param species A vector with the species of the reaction. The order of
#' this vector is important because it will define the
#' column order of the returned behavior.
#' @param reactions A vector with the reactions of the CRN.
#'
#' @return A list with the named indexes `prod` (stoichiometry matrix of the
#' products), `react` (stoichiometry matrix of reactants) and `M`
#' (the M matrix generate from the difference of theses two matrices).
Expand Down
26 changes: 23 additions & 3 deletions R/dsd.R
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,12 @@ get_dsd_def_str <- function(key, val) {
#'
#' If a reaction has 2 reactants and 1 product,
#' will be in the position 3,2. The formation reactions are in the
#' line 1, and the degradation reactions are in the column 1 ([[,1]]).
#' line 1, and the degradation reactions are in the column 1 (\[\[,1\]\]).
#'
#' The position [[1,1]] is filled with `NA` because it represents an
#' The position \[\[1,1\]\] is filled with `NA` because it represents an
#' invalid reaction (`0 -> 0`).
#'
#' @return The matrix of functions which can be accesses with [[i,j]]
#' @return The matrix of functions which can be accesses with \[\[i,j\]\]
dsd_4d_modules <- function() {
# Matrix with the module functions. The higher the row,the higher
# the number of products, The columns has the same relation with
Expand Down Expand Up @@ -1135,6 +1135,26 @@ dsd_4d_module_str <- function(reaction, species_domains, k_idx) {
#' the name of the file that will be exported and should be specified with
#' an extension, since there is no standard extension for DSD scripts.
#'
#' @param species A vector with the species of the reaction. The order of
#' this vector is important because it will define the
#' column order of the returned behavior. The species names
#' `L[0-9]*`, `H[0-9]*`, `W[0-9]*`, `O[0-9]*`,
#' `T[0-9]*`, `G[0-9]*`, `LS[0-9]*`, `HS[0-9]*`,
#' `WS[0-9]*` are not supported. For more information
#' about this, see the Section of **Known limitations**.
#' @param ci A vector specifying the initial concentrations of the
#' \code{species} specified, in order.
#' @param reactions A vector with the reactions of the CRN^*.
#' @param ki A vector defining the constant rate of each reaction
#' in \code{reactions}, in order.
#' @param qmax Maximum rate constant for the auxiliary reactions.
#' @param cmax Maximum initial concentration for the auxiliary species.
#' @param alpha,beta Rescaling parameters.
#' @param t A vector specifying the time interval. Each value
#' would be a specific time point.
#' @param filename The name of the file that will be exported and should be specified with
#' an extension, since there is no standard extension for DSD scripts.
#'
#' @export
save_dsd_script <- function(
species,
Expand Down
2 changes: 1 addition & 1 deletion R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fte_theme <- function() {

# Format the grid
ggplot2::theme(panel.grid.major = ggplot2::element_line(
color = color.grid.major, size = .25
color = color.grid.major, linewidth = .25
)) +
ggplot2::theme(panel.grid.minor = ggplot2::element_blank()) +
ggplot2::theme(axis.ticks = ggplot2::element_blank()) +
Expand Down
8 changes: 5 additions & 3 deletions R/neuron_hjelmfelt.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


#' Get a neuron based on Hjelmfelt A. et al. `[1]` approach
#'
#' This function returns a neuron based on the model described by
Expand All @@ -27,6 +26,8 @@
#'
#' @return A CRN representing the neuron.
#'
#' @importFrom Rdpack reprompt
#'
#' @export
#'
#' @references
Expand Down Expand Up @@ -195,7 +196,8 @@ update_neuron_input_hje <- function(neuron, bindings) {
#'
#' @param gate_name String specifying the gate name. Used for
#' identification purpose.
#' @param input_neuron_name A list of string. Each string specifies
#' @param input_neuron_names A list of string. Each string specifies a
#' neuron name.
#' @param output_neuron_name A string being the output neuron name
#' @param input_neuron_cis A vector of number representing the
#' initial concentration of each neuron
Expand Down Expand Up @@ -853,7 +855,7 @@ get_neuron_majority_gate <- function(
})

# Get the gate
gate <- DNAr:::get_neuron_generic_gate_hje(
gate <- get_neuron_generic_gate_hje(
gate_name = gate_name,
input_neuron_names = input_names,
output_neuron_name = output_name,
Expand Down
50 changes: 49 additions & 1 deletion R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#'
#' Given a reaction like 'A + B -> C', this function
#' returns 'A + B '.
#'
#' @param react_str A string representing the reaction
get_first_part <- function(react_str) {
return(sub('->.*', '', react_str))
}
Expand All @@ -28,6 +30,8 @@ get_first_part <- function(react_str) {
#'
#' Given a reaction like 'A + B -> C', this function
#' returns ' C'.
#'
#' @param react_str A string representing the reaction
get_second_part <- function(react_str) {
return(sub('.*->', '', react_str))
}
Expand All @@ -37,6 +41,8 @@ get_second_part <- function(react_str) {
#' Given a reaction, this functions checks if it is
#' a bimolecular reaction.
#'
#' @param react_str A string representing the reaction
#'
#' @examples
#' DNAr:::is_bimolecular('2A -> B') # Should return TRUE
#' DNAr:::is_bimolecular('A + B -> C') # Should return TRUE
Expand All @@ -51,6 +57,8 @@ is_bimolecular <- function(react_str) {
#' Given a reaction, this functions checks if it is
#' a unimolecular reaction.
#'
#' @param react_str A string representing the reaction
#'
#' @examples
#' DNAr:::is_bimolecular('2A -> B') # Should return FALSE
#' DNAr:::is_bimolecular('A + B -> C') # Should return FALSE
Expand Down Expand Up @@ -95,6 +103,8 @@ is_formation <- function(react_str) {
#' \code{\link{get_second_part}()} and then use this function with the second
#' part as the parameter.
#'
#' @param react_part A string containing part of the reaction
#'
#' @examples
#' sp <- DNAr:::get_second_part('A -> 0')
#' DNAr:::isempty_part(sp) # Should return TRUE
Expand All @@ -108,6 +118,9 @@ isempty_part <- function(react_part) {
#' With the reaction part 'A + B ', for instance, and \code{one_species}
#' begin equal to 'A', this function would return 1. On the case of '2A ' it
#' would return 2.
#'
#' @param one_species A string containing a species from reaction_part.
#' @param reaction_part Left or right part of a reaction.
get_onespecies_count <- function(one_species, reaction_part) {
m <- gregexpr(
paste('\\b[1-9]*', one_species, '\\b', sep = ''),
Expand All @@ -132,6 +145,9 @@ get_onespecies_count <- function(one_species, reaction_part) {
#' and right part of a reaction to get the stoichiometry of a species
#' in a reaction.
#'
#' @param one_species A string containing a species from reaction.
#' @param reaction A string representing the reaction.
#'
#' @return A list with \code{left_sto} being the stoichiometry of a
#' species in the left side of a reaction, and \code{right_sto} being
#' the same but for the right side of the reaction.
Expand All @@ -157,6 +173,8 @@ get_stoichiometry_onespecies <- function(one_species, reaction) {
#' This function is used when you want to know the count of molecules
#' in part of a reaction.
#'
#' @param reaction_part Left or right part of a reaction.
#'
#' @examples
#' DNAr:::get_stoichiometry_part('A + B ') # It should return 2
#' DNAr:::get_stoichiometry_part('2A ') # It should return 2
Expand All @@ -180,6 +198,8 @@ get_stoichiometry_part <- function(reaction_part) {
#' Use this function to get the stoichiometry of the left and
#' right part of a reaction.
#'
#' @param reaction A string representing the reaction
#'
#' @return a list with left_sto and right_sto being the stoichiometry
#' of the left and right part respectively.
#'
Expand All @@ -201,6 +221,8 @@ get_stoichiometry_all <- function(reaction) {
#' Use this function to get rid of the stoichiometry of a
#' species string.
#'
#' @param species A string containing the species from a reaction_part.
#'
#' @return The species string without the stoichiometry (number)
#' specifying the number of molecules
#'
Expand Down Expand Up @@ -260,6 +282,8 @@ get_species <- function(reaction_part) {
#' This function returns the reactants of a reactions,
#' removing their stoichiometry.
#'
#' @param reaction A string representing the reaction.
#'
#' @examples
#' DNAr:::get_reactants('A + B -> C') # Returns c('A', 'B')
#' DNAr:::get_reactants('2A -> B') # Returns c('A')
Expand All @@ -276,6 +300,8 @@ get_reactants <- function(reaction) {
#' 'A -> 0', '0' is returned as a species since it is considered
#' a special species.
#'
#' @param reaction A string representing the reaction.
#'
#' @examples
#' DNAr:::get_products('A + B -> C') # Returns c('C')
#' DNAr:::get_products('2A -> B + C') # Returns c('B', 'C')
Expand All @@ -293,6 +319,11 @@ get_products <- function(reaction) {
#' species indexes in \code{species} that are reactants
#' in \code{reaction}.
#'
#' @param species A vector with the species of the reaction. The order of
#' this vector is important because it will define the
#' column order of the returned behavior.
#' @param reaction A string representing the reaction.
#'
#' @return A vector filled with indexes specifying the
#' species that are in a reaction as a reactant.
#'
Expand Down Expand Up @@ -326,6 +357,23 @@ reactants_in_reaction <- function(species, reaction) {
#' - If there is no duplicate of species names on the `species` parameter.
#' The parameters of this function are the same of \code{\link{react}()}.
#'
#' @param species A vector with the species of the reaction. The order of
#' this vector is important because it will define the
#' column order of the returned behavior.
#' @param ci A vector specifying the initial concentrations of the
#' \code{species} specified, in order.
#' @param reactions A vector with the reactions of the CRN. If a reaction has
#' has only reactants that are non in `species`, this
#' reaction will be treated as `0 -> products`. Furthermore,
#' this function treats a reaction `non_registered_species
#' + registered_species -> products` equally to
#' `registered_species -> products`, ignoring the species non
#' registered on the `species` vector.
#' @param ki A vector defining the constant rate of each reaction
#' in \code{reactions}, in order.
#' @param t A vector specifying the time interval. Each value
#' would be a specific time point.
#'
#' @return The reactions after the preprocessing made by
#' `\link{check_fix_reaction}()` witch checks the reactions and fix
#' them when it is possible.
Expand All @@ -334,7 +382,7 @@ check_crn <- function(species, ci, reactions, ki, t) {
# This is a helper function to check the parameters
check_var <- function(vec, type_checker, err_msgs) {
# Check if the vec parameter is if the type vector
assertthat::assert_that(is.vector(species), msg = err_msg[[1]])
assertthat::assert_that(is.vector(species), msg = err_msgs[[1]])

# Check if all vector elements are of the correct type
# using the type_checker function
Expand Down
27 changes: 25 additions & 2 deletions man/analyze_behavior.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading