Commit 2054450f authored by mariefbourdon's avatar mariefbourdon
Browse files

modif mark_prop chi

parent 716a1393
This diff is collapsed.
{
"activeTab" : 6
"activeTab" : 1
}
\ No newline at end of file
{
"left" : {
"panelheight" : 1271,
"splitterpos" : 533,
"topwindowstate" : "NORMAL",
"windowheight" : 1309
"panelheight" : 583,
"splitterpos" : 244,
"topwindowstate" : "MAXIMIZE",
"windowheight" : 621
},
"right" : {
"panelheight" : 1271,
"splitterpos" : 804,
"splitterpos" : 803,
"topwindowstate" : "NORMAL",
"windowheight" : 1309
}
......
{
"TabSet1" : 3,
"TabSet1" : 0,
"TabSet2" : 4,
"TabZoom" : {
}
......
{
"cursorPosition" : "16,28",
"scrollLine" : "0"
"cursorPosition" : "70,29",
"scrollLine" : "40"
}
\ No newline at end of file
{
}
\ No newline at end of file
{
"cursorPosition" : "135,15",
"last_setup_crc32" : "",
"scrollLine" : "111"
"cursorPosition" : "114,53",
"last_setup_crc32" : "E69463565bfca283",
"scrollLine" : "110"
}
\ No newline at end of file
......@@ -22,3 +22,4 @@
~%2Fstuart_package%2Fstuart%2Fdoc%2FstuaRt.R="65312719"
~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.R="EBD625D2"
~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.Rmd="D602FFE4"
~%2Fstuart_package%2Fstuart_old%2FR%2Fmark_prop.R="63BDD9CA"
......@@ -5,10 +5,10 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "1203844341",
"hash" : "0",
"id" : "1656F55",
"lastKnownWriteTime" : 1622640147,
"last_content_update" : 1622640147,
"lastKnownWriteTime" : 1623060553,
"last_content_update" : 1623060553,
"path" : "~/Documents/PhD/stuart_R/stuart/R/geno_strains.R",
"project_path" : "R/geno_strains.R",
"properties" : {
......
......@@ -5,20 +5,20 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "3094972460",
"hash" : "0",
"id" : "42D37312",
"lastKnownWriteTime" : 1623061718,
"last_content_update" : 1623061718577,
"lastKnownWriteTime" : 1623086204,
"last_content_update" : 1623086204670,
"path" : "~/Documents/PhD/stuart_R/stuart/R/mark_prop.R",
"project_path" : "R/mark_prop.R",
"properties" : {
"cursorPosition" : "16,28",
"scrollLine" : "0"
"cursorPosition" : "70,29",
"scrollLine" : "40"
},
"read_only" : false,
"read_only_alternatives" : [
],
"relative_order" : 9,
"relative_order" : 2,
"source_on_save" : false,
"source_window" : "",
"type" : "r_source"
......
......@@ -14,10 +14,9 @@
#### mark_prop ####
## excludes markers depending on proportions of homo/hetorozygous
## to modify with chisq.test
mark_prop <- function(tab,cross,homo=NA,hetero=NA,na=0.5){
mark_prop <- function(tab,cross,homo=NA,hetero=NA,pval=NA,na=0.5){
#calculate total number of individuals genotyped for each marker
tab <- tab %>% mutate(n_geno = tab %>% select(n_HM1,n_HM2,n_HT) %>% rowSums(na.rm=TRUE))
tab <- tab %>% mutate(n_geno = (n_HM1 + n_HM2 + n_HT))
#calculate proportion of each genotype
tab <- tab %>% mutate(p_HM1 = n_HM1/n_geno)
......@@ -25,27 +24,50 @@ mark_prop <- function(tab,cross,homo=NA,hetero=NA,na=0.5){
tab <- tab %>% mutate(p_HT = n_HT/n_geno)
tab <- tab %>% mutate(p_NA = n_NA/(n_geno+n_NA))
#stock colnames to join
names <- colnames(tab)
#stop if cross != "F2" or "N2"
if(!cross %in% c("F2","N2")){
stop("Cross must be F2 or N2")
}
#stop if no value for "homo" for F2 cross
if(cross=="F2" & (is.na(homo)==TRUE | is.na(hetero)==TRUE)){
stop("Arguments homo and hetero must be specified for F2 crosses")
#stop of homo&hetero or pval not specified
if((is.na(homo)==TRUE | is.na(hetero)==TRUE) & is.na(pval)==TRUE){
stop("Arguments homo and hetero or argument pval must be specified")
}
#stop if no value for "homo" and "hetero" for N2 cross
if(cross=="N2" & (is.na(homo)==TRUE | is.na(hetero)==TRUE)){
stop("Arguments homo and hetero must be specified for N2 crosses")
#stop with prop of na
tab <- tab %>%
mutate(exclude_prop=case_when(p_NA > na ~ 1,
T ~ 0))
#stop with prop of homo/hetero
if(is.na(pval)==TRUE){
tab <- tab %>%
mutate(exclude_prop=case_when(p_NA > na ~ 1,
cross=="F2" & (p_HM1 < homo | p_HM2 < homo | p_HT < hetero) ~ 1,
cross=="N2" & (p_HM1 < homo | p_HT < hetero) ~ 1,
T ~ exclude_prop
))
}
#exclude markers according to proportion of na
tab <- tab %>% mutate(exclude_prop=case_when(p_NA > na ~ 1, #exclude markers according to proportion of na
cross=="F2" & (p_HM1 < homo | p_HM2 < homo | p_HT < hetero) ~ 1, #exclude markers according to proportion of homozygous individuals for F2 cross
cross=="N2" & (p_HM1 < homo | p_HT < hetero) ~ 1, #exclude markers according to proportion of homozygous and heterozygous individuals for N2 cross
T ~ 0))
#stop with pval chisq.test
## NEED TO ADD THIS FILTER IF CROSS = N2
if(is.na(pval)==FALSE){
tab <- tab %>% filter(p_NA != 1) %>% rowwise() %>%
mutate(.,chi_pval = tibble(n_HM1,n_HM2,n_HT) %>%
chisq.test(p=c(0.25,0.25,0.5)) %>% .$p.value) %>%
full_join(.,tab,by=names)
tab <- tab %>% mutate(exclude_prop=case_when(chi_pval < pval ~ 1,
T ~ exclude_prop))
}
tab <- tab %>% select(-c(p_HM1,p_HM2,p_HT,p_NA,n_geno))
tab <- tab %>% select(names)
return(tab)
}
......@@ -5,7 +5,7 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "1139135974",
"hash" : "0",
"id" : "45D91D58",
"lastKnownWriteTime" : 1622648301,
"last_content_update" : 1622648301329,
......@@ -18,7 +18,7 @@
"read_only" : false,
"read_only_alternatives" : [
],
"relative_order" : 11,
"relative_order" : 9,
"source_on_save" : false,
"source_window" : "",
"type" : "r_source"
......
......@@ -5,10 +5,10 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "1762622592",
"hash" : "0",
"id" : "65C9B72B",
"lastKnownWriteTime" : 1622642120,
"last_content_update" : 1622642120783,
"lastKnownWriteTime" : 1623060553,
"last_content_update" : 1623060553,
"path" : "~/Documents/PhD/stuart_R/stuart/R/tab_mark.R",
"project_path" : "R/tab_mark.R",
"properties" : {
......
{
"collab_server" : "",
"contents" : "",
"created" : 1623083300385.000,
"dirty" : false,
"encoding" : "",
"folds" : "",
"hash" : "0",
"id" : "6DCC955A",
"lastKnownWriteTime" : 140320379993736,
"last_content_update" : 1623083300385,
"path" : null,
"project_path" : null,
"properties" : {
"cacheKey" : "FFFA47E6",
"caption" : "test_tab",
"contentUrl" : "grid_resource/gridviewer.html?env=&obj=test_tab&cache_key=FFFA47E6",
"displayedObservations" : "20",
"environment" : "",
"expression" : "test_tab",
"object" : "test_tab",
"preview" : "0",
"totalObservations" : "20",
"variables" : "9"
},
"read_only" : false,
"read_only_alternatives" : [
],
"relative_order" : 12,
"source_on_save" : false,
"source_window" : "",
"type" : "r_dataframe"
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "143869640",
"hash" : "0",
"id" : "76AC3EC",
"lastKnownWriteTime" : 1623060553,
"last_content_update" : 1623060553,
......@@ -18,7 +18,7 @@
"read_only" : false,
"read_only_alternatives" : [
],
"relative_order" : 7,
"relative_order" : 6,
"source_on_save" : false,
"source_window" : "",
"type" : "r_source"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment