Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
danymukesha committed Feb 23, 2024
1 parent 4365cb2 commit 3b68842
Show file tree
Hide file tree
Showing 33 changed files with 299 additions and 169 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Package: BioGA
Title: Bioinformatics Genetic Algorithm (BioGA)
Version: 0.99.0
Authors@R:
person("Dany", "Mukesha", , "[email protected]", role = c("aut", "cre"),
person("Dany", "Mukesha", , "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0009-0001-9514-751X"))
Description: Genetic algorithm are a class of optimization algorithms
inspired by the process of natural selection and genetics. This
Expand All @@ -17,7 +18,8 @@ BugReports: https://github.com/danymukesha/BioGA/issues
Imports:
ggplot2,
graphics,
Rcpp
Rcpp,
sessioninfo
Suggests:
knitr,
rmarkdown
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ importFrom(Rcpp,
evalCpp,
sourceCpp)
import(ggplot2,
graphics)
graphics,
sessioninfo)
useDynLib(BioGA, .registration = TRUE)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# BioGA 0.99.0

* Added a `NEWS.md` file to track changes to the package.
1 change: 1 addition & 0 deletions R/BioGA-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
## usethis namespace: start
#' @import biocViews
#' @importFrom ggplot2 ggplot aes geom_line coord_flip
#' @import sessioninfo
## usethis namespace: end
NULL
42 changes: 28 additions & 14 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

#' Function to perform crossover between selected individuals
#'
#' @param selected_parents Numeric matrix representing the selected individuals.
#' @param selected_parents Numeric matrix representing the selected
#' individuals.
#' @param offspring_size Number of offspring to generate.
#' @return Numeric matrix representing the offspring.
#' @examples
#' # example of usage
#' genomic_data <- matrix(rnorm(100), nrow = 10, ncol = 10)
#' population <- BioGA::initialize_population_cpp(genomic_data, population_size = 5)
#' population <- BioGA::initialize_population_cpp(genomic_data,
#' population_size = 5)
#' fitness <- BioGA::evaluate_fitness_cpp(genomic_data, population)
#' selected_parents <- BioGA::selection_cpp(population, fitness, num_parents = 2)
#' selected_parents <- BioGA::selection_cpp(population, fitness,
#' num_parents = 2)
#' BioGA::crossover_cpp(selected_parents, offspring_size = 2)
#' @export
crossover_cpp <- function(selected_parents, offspring_size) {
Expand All @@ -20,13 +23,16 @@ crossover_cpp <- function(selected_parents, offspring_size) {

#' Function to evaluate fitness using genomic data
#'
#' @param genomic_data Numeric matrix of genomic data where rows represent genes/features and columns represent samples.
#' @param population Numeric matrix representing the population of individuals.
#' @param genomic_data Numeric matrix of genomic data where rows represent
#' genes/features and columns represent samples.
#' @param population Numeric matrix representing the population of
#' individuals.
#' @return Numeric vector of fitness scores for each individual.
#' @examples
#' # example of usage
#' genomic_data <- matrix(rnorm(100), nrow = 10, ncol = 10)
#' population <- BioGA::initialize_population_cpp(genomic_data, population_size = 5)
#' population <- BioGA::initialize_population_cpp(genomic_data,
#' population_size = 5)
#' BioGA::evaluate_fitness_cpp(genomic_data, population)
#' @export
evaluate_fitness_cpp <- function(genomic_data, population) {
Expand All @@ -35,7 +41,8 @@ evaluate_fitness_cpp <- function(genomic_data, population) {

#' Function to initialize the population from genomic data
#'
#' @param genomic_data Numeric matrix of genomic data where rows represent genes/features and columns represent samples.
#' @param genomic_data Numeric matrix of genomic data where rows represent
#' genes/features and columns represent samples.
#' @param population_size Number of individuals in the population.
#' @return Numeric matrix representing the initialized population.
#' @examples
Expand All @@ -55,9 +62,11 @@ initialize_population_cpp <- function(genomic_data, population_size) {
#' @examples
#' # example of usage
#' genomic_data <- matrix(rnorm(100), nrow = 10, ncol = 10)
#' population <- BioGA::initialize_population_cpp(genomic_data, population_size = 5)
#' population <- BioGA::initialize_population_cpp(genomic_data,
#' population_size = 5)
#' fitness <- BioGA::evaluate_fitness_cpp(genomic_data, population)
#' selected_parents <- BioGA::selection_cpp(population, fitness, num_parents = 2)
#' selected_parents <- BioGA::selection_cpp(population,
#' fitness, num_parents = 2)
#' offspring <- BioGA::crossover_cpp(selected_parents, offspring_size = 2)
#' BioGA::mutation_cpp(offspring, mutation_rate = 0)
#' @export
Expand All @@ -68,16 +77,19 @@ mutation_cpp <- function(offspring, mutation_rate) {
#' Function to replace non-selected individuals in the population
#'
#' Replace non-selected individuals in the population
#' @param population Numeric matrix representing the population of individuals.
#' @param population Numeric matrix representing the population of
#' individuals.
#' @param offspring Numeric matrix representing the offspring.
#' @param num_to_replace Number of individuals to replace.
#' @return Numeric matrix representing the updated population.
#' @examples
#' # example of usage
#' genomic_data <- matrix(rnorm(100), nrow = 10, ncol = 10)
#' population <- BioGA::initialize_population_cpp(genomic_data, population_size = 5)
#' population <- BioGA::initialize_population_cpp(genomic_data,
#' population_size = 5)
#' fitness <- BioGA::evaluate_fitness_cpp(genomic_data, population)
#' selected_parents <- BioGA::selection_cpp(population, fitness, num_parents = 2)
#' selected_parents <- BioGA::selection_cpp(population, fitness,
#' num_parents = 2)
#' offspring <- BioGA::crossover_cpp(selected_parents, offspring_size = 2)
#' mutated_offspring <- BioGA::mutation_cpp(offspring, mutation_rate = 0)
#' BioGA::replacement_cpp(population, mutated_offspring, num_to_replace = 1)
Expand All @@ -88,14 +100,16 @@ replacement_cpp <- function(population, offspring, num_to_replace) {

#' Function to select individuals based on fitness scores
#'
#' @param population Numeric matrix representing the population of individuals.
#' @param population Numeric matrix representing the population of
#' individuals.
#' @param fitness Numeric vector of fitness scores for each individual.
#' @param num_parents Number of individuals to select.
#' @return Numeric matrix representing the selected individuals.
#' @examples
#' # example of usage
#' genomic_data <- matrix(rnorm(100), nrow = 10, ncol = 10)
#' population <- BioGA::initialize_population_cpp(genomic_data, population_size = 5)
#' population <- BioGA::initialize_population_cpp(genomic_data,
#' population_size = 5)
#' fitness <- BioGA::evaluate_fitness_cpp(genomic_data, population)
#' BioGA::selection_cpp(population, fitness, num_parents = 2)
#' @export
Expand Down
4 changes: 3 additions & 1 deletion R/plot_fitness_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ plot_fitness_history <- function(fitness_history) {
fitness_values <- unlist(fitness_history)

# Create generation index
generations <- rep(seq_along(fitness_history), vapply(fitness_history, length, integer(1)))
generations <-
rep(seq_along(fitness_history),
vapply(fitness_history, length, integer(1)))

# Create data frame
df <- data.frame(Generation = generations, Fitness = fitness_values)
Expand Down
11 changes: 8 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ knitr::opts_chunk$set(
)
```

# BioGA <a href="https://danymukesha.github.io/BioGA/"><img src="man/figures/logo.png" align="right" height="139" alt="BioGA website" /></a>

The `BioGA` package provides a set of functions for genetic algorithm optimization tailored for analyzing high throughput genomic data. These functions are implemented in C++ for improved speed and efficiency, with an easy-to-use interface for use within R.
# BioGA
<a href="https://danymukesha.github.io/BioGA/"><img src="man/figures/logo.png"
align="right" height="139" alt="BioGA website" /></a>

The `BioGA` package provides a set of functions for genetic algorithm
optimization tailored for analyzing high throughput genomic data.
These functions are implemented in C++ for improved speed and efficiency,
with an easy-to-use interface for use within R.

## Installation

Expand Down
42 changes: 23 additions & 19 deletions docs/articles/Overview.html

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

Binary file modified docs/articles/Overview_files/figure-html/unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3b68842

Please sign in to comment.