Skip to content

Commit

Permalink
Merge pull request #34 from timflutre/game_initialisation
Browse files Browse the repository at this point in the history
Game initialisation from the application
  • Loading branch information
timflutre authored Jun 13, 2024
2 parents d6e598b + 169c136 commit 235fa98
Show file tree
Hide file tree
Showing 40 changed files with 1,713 additions and 1,228 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

data:
R -e "rmarkdown::render('plantbreedgame_setup.Rmd')"
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,7 @@ The package can also be installed after cloning the git repository:
git clone [email protected]:timflutre/PlantBreedGame.git
```

2. Then, enter into the `PlantBreedGame` directory; inside, run the script `plantbreedgame_setup.Rmd` using [Rmarkdown](http://rmarkdown.rstudio.com/) to simulate the initial data set, this can be done with the command:

```sh
make data
```

> Or with R:
> ```sh
> R -e "rmarkdown::render('plantbreedgame_setup.Rmd')"
> ```
It also creates all the necessary files and database for the game to function, and initiate the game with two players, "test" (no password) and "admin" (password `1234`).
3. Finally, open a R session, and execute the following commands:
2. Finally, open a R session, and execute the following commands:

```
library(shiny)
Expand Down Expand Up @@ -95,18 +82,12 @@ Then, create a new directory for the application (let's call it `breeding-game`
mkdir /srv/shiny-server/breeding-game
```

and copy inside the content of our Shiny application you just downloaded:
and copy inside the content of the Shiny application you just downloaded:

```
cp -r ~/PlantBreedGame-master/* /srv/shiny-server/breeding-game
```

Generate the game data with:

```sh
R -e "rmarkdown::render('/srv/shiny-server/breeding-game/plantbreedgame_setup.Rmd')"
```

By default, the Shiny server runs as a unix user named `shiny`.
You hence need to create a unix group, named for instance `breeding`, to which the `shiny` user can be added (the Shiny server may need to be restarted for this to be taken into account).

Expand Down Expand Up @@ -214,8 +195,7 @@ or
git clone --depth=1 https://github.com/timflutre/PlantBreedGame.git
```

2. modify the file `PlantBreedGame/plantbreedgame_setup.Rmd`
3. move in the app code folder and build a new image:
2. move in the app code folder and build a new image:

```sh
cd PlantBreedGame
Expand All @@ -224,8 +204,23 @@ docker build -t customplantbreedgame ./

You can then run this image by using the same commands as above replacing `juliendiot/plantbreedgame` by `customplantbreedgame`


# Usage

## Game Initialisation

To start playing, the game need some specific data (eg. the genotypes and haplotypes of the initial population, a data-base...). This initialisation can be done through the game.

The first time you run the application, most of the game menus will show a message asking you to initialise the game. To do so you need to go to the `Admin` menue, and in `Game Initialisation` tab. There you will find a button that will start the game initialisation. Once the initialisation is completed (which takes about 2 minutes), the page will automatically reload and you will be able to connect and play the game.

The game initialisation will automatically create an `admin` breeder with the default password `1234`.

If the game have already been initialise, it is also possible to re-initialise it to start a new "fresh game". However in such case **all the data of the game will be lost**.

> NOTE: Currently the game do not let you choose the game initialisation parameters, in order to change them, you need to manually modify the file `plantbreedgame_setup.Rmd` befor proceding to the initialisation. In a near future, you will be able to set the intialisation parameters from the game.
## How to play

Once the application is installed and working, _please_ read the game rules (tab `How to play?`) and start by downloading the initial data set as well as example files showing how requests should be formatted (all files listed at the bottom of the tab `How to play?`).

Before making any request, such as phenotyping, you need to log in (tab `Identification`).
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
initialise-data = pkgs.writeShellApplication {
name = "initialise-data";
text = ''
rm -rf data
rm data.zip || echo "no data.zip file"
make data
'';
};
Expand Down
49 changes: 13 additions & 36 deletions global.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Copyright 2015,2016,2017,2018,2019 Institut National de la Recherche Agronomique

## and Montpellier SupAgro.
##
## This file is part of PlantBreedGame.
Expand All @@ -18,11 +19,14 @@
## <http://www.gnu.org/licenses/>.


source("src/dependencies.R", local = TRUE, encoding = "UTF-8")$value
source("src/dependencies.R", local = TRUE, encoding = "UTF-8")

source("src/fun/functions.R", local = TRUE, encoding = "UTF-8")$value
source("src/fun/func_time.R", local = TRUE, encoding = "UTF-8")$value
source("src/fun/func_id.R", local = TRUE, encoding = "UTF-8")$value
source("src/fun/functions.R", local = TRUE, encoding = "UTF-8")
source("src/fun/func_time.R", local = TRUE, encoding = "UTF-8")
source("src/fun/func_id.R", local = TRUE, encoding = "UTF-8")
source("./src/fun/module_constants.R", local = TRUE, encoding = "UTF-8")
source("./src/fun/module_breederList.R", local = TRUE, encoding = "UTF-8")
source("./src/fun/func_dbRequests.R", local = TRUE, encoding = "UTF-8")

## -------------------------------------------------------------------
## parameters
Expand All @@ -42,38 +46,11 @@ if (Sys.info()["sysname"] == "Windows") {
## -------------------------------------------------------------------
## variables

root.dir <- "data"
setup <- getBreedingGameSetup(root.dir)
checkDbFile(setup$dbname)
constants <- getBreedingGameConstants(setup$dbname)
if (is.null(constants$maxEvalInds)) {
constants$maxEvalInds <- 5
}


prices <- list(
"allofecundation" = constants$cost.allof * constants$cost.pheno.field,
"autofecundation" = constants$cost.autof * constants$cost.pheno.field,
"haplodiploidization" = constants$cost.haplodiplo * constants$cost.pheno.field,
"pheno-field" = constants$cost.pheno.field,
"pheno-patho" = constants$cost.pheno.patho * constants$cost.pheno.field,
"geno-hd" = constants$cost.geno.hd * constants$cost.pheno.field,
"geno-ld" = round(constants$cost.geno.ld * constants$cost.pheno.field, 2),
"geno-single-snp" = constants$cost.geno.single * constants$cost.pheno.field,
"register" = constants$cost.register * constants$cost.pheno.field
)

subset.snps <- list()
f <- paste0(setup$init.dir, "/snp_coords_hd.txt.gz")
subset.snps[["hd"]] <- rownames(read.table(f))
f <- paste0(setup$init.dir, "/snp_coords_ld.txt.gz")
subset.snps[["ld"]] <- rownames(read.table(f))
DATA_ROOT <- "data"
DATA_TRUTH <- file.path(DATA_ROOT, "truth")
DATA_SHARED <- file.path(DATA_ROOT, "shared")
DATA_INITIAL_DATA <- file.path(DATA_SHARED, "initial_data")
DATA_DB <- file.path(DATA_ROOT, "breeding-game.sqlite")

url.repo <- "https://github.com/timflutre/PlantBreedGame"
code.version <- getCodeVersion(url.repo)

stopifnot(all(c("admin", "test") %in% getBreederList(setup$dbname)))
stopifnot(all(
"game master" == getBreederStatus(setup$dbname, "admin"),
"tester" == getBreederStatus(setup$dbname, "test")
))
5 changes: 3 additions & 2 deletions plantbreedgame_setup.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ Set up directories:
```{r setup_dir}
root.dir <- file.path(getwd(), "data")
root.dir <- path.expand(root.dir)
if (!dir.exists(root.dir)) {
dir.create(root.dir)
if (dir.exists(root.dir)) {
stop(paste0("`data` directory (", root.dir, ") already exists. Please remove this directory before running this script."))
}
dir.create(root.dir)
truth.dir <- file.path(root.dir, "truth")
if (!dir.exists(truth.dir)) {
dir.create(truth.dir)
Expand Down
39 changes: 39 additions & 0 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,44 @@ shinyServer(function(input, output, session) {
getGameTime(setup)
})

values <- reactiveValues(
lastDBupdate = Sys.time()
)

gameInitialised <- function() {
(dir.exists(DATA_ROOT) &
dir.exists(DATA_TRUTH) &
dir.exists(DATA_SHARED) &
dir.exists(DATA_INITIAL_DATA) &
file.exists(DATA_DB))
}

observe({
if (!gameInitialised()) {
alert("Game is not initialised :-(")

# insertUI("#id_main_ui", where = "beforeBegin", {
# source("src/ui/ui_gameNotInitialised.R", local = TRUE, encoding = "UTF-8")$value
# })
# removeUI("#id_main_ui")

# insertUI("#pltmat_main_ui", where = "beforeBegin", {
# source("src/ui/ui_gameNotInitialised.R", local = TRUE, encoding = "UTF-8")$value
# })
# removeUI("#pltmat_main_ui")

# insertUI("#pheno_main_ui", where = "beforeBegin", {
# source("src/ui/ui_gameNotInitialised.R", local = TRUE, encoding = "UTF-8")$value
# })
# removeUI("#pheno_main_ui")

# insertUI("#geno_main_ui", where = "beforeBegin", {
# source("src/ui/ui_gameNotInitialised.R", local = TRUE, encoding = "UTF-8")$value
# })
# removeUI("#geno_main_ui")
}
})

source("src/server/server_information.R", local = TRUE, encoding = "UTF-8")$value
source("src/server/server_id.R", local = TRUE, encoding = "UTF-8")$value
source("src/server/server_plant_material.R", local = TRUE, encoding = "UTF-8")$value
Expand All @@ -40,4 +78,5 @@ shinyServer(function(input, output, session) {
source("src/server/server_theory.R", local = TRUE, encoding = "UTF-8")$value
source("src/server/server_admin.R", local = TRUE, encoding = "UTF-8")$value
source("src/server/server_about.R", local = TRUE, encoding = "UTF-8")$value
source("./src/server/server_constants.R", local = TRUE, encoding = "UTF-8")$value
})
45 changes: 24 additions & 21 deletions src/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@
## required packages available on the CRAN
## https://cran.r-project.org/
## R> install.packages("<package_name>")
library(shiny)
library(shinydashboard)
library(shinycssloaders)
library(shinyjs)
library(RSQLite)
library(MASS)
library(digest)
library(plotly)
library(DT)
library(igraph)
library(lubridate)
library(vistime)
library(tidyr)

## required packages NOT available on the CRAN
## R> devtools::install_github("timflutre/rutilstimflutre")
library(rutilstimflutre)
stopifnot(compareVersion(
"0.158.2",
as.character(packageVersion("rutilstimflutre"))
)
!= 1)
suppressPackageStartupMessages({
library(shiny)
library(shinydashboard)
library(shinycssloaders)
library(shinyjs)
library(RSQLite)
library(MASS)
library(digest)
library(plotly)
library(DT)
library(igraph)
library(lubridate)
library(vistime)
library(tidyr)

## required packages NOT available on the CRAN
## R> devtools::install_github("timflutre/rutilstimflutre")
library(rutilstimflutre)
stopifnot(compareVersion(
"0.158.2",
as.character(packageVersion("rutilstimflutre"))
)
!= 1)
})
Loading

0 comments on commit 235fa98

Please sign in to comment.