Skip to content

Instantly share code, notes, and snippets.

@juanchiem
Forked from agustin-alesso/get_genotypes.R
Last active April 10, 2022 13:14
Show Gist options
  • Save juanchiem/68da029c181d310596ba5e81e2909e47 to your computer and use it in GitHub Desktop.
Save juanchiem/68da029c181d310596ba5e81e2909e47 to your computer and use it in GitHub Desktop.
find genotypes that are repeatead in selected environments
pacman::p_load(tidyverse)
# Fake data
full_grid <- expand_grid(
gen = paste0("G", 1:3),
loc = paste0("L", 1:3),
season = paste0("S", 1:4)
) %>%
mutate(env = paste(loc, season))
replications(~ gen * env, full_grid)
# Generate inbalance
red_grid <- sample_frac(full_grid, size = 0.8)
replications(~ gen * env, red_grid)
# Get available seasons
seasons <- red_grid %>%
distinct(season) %>%
pull %>%
sort
seasons
# Get last Nth seasons
last_nseasons <- tail(seasons, 1)
last_nseasons
# Get distinct environments within selected seasons
envs <- red_grid %>%
filter(season %in% last_nseasons) %>%
distinct(env) %>%
pull
envs
# Get genotypes that were present in all of those the environments
red_grid %>%
filter(env %in% envs) %>%
count(gen) %>%
filter(n == n_distinct(envs)) %>%
distinct(gen) %>%
pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment