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" : { "left" : {
"panelheight" : 1271, "panelheight" : 583,
"splitterpos" : 533, "splitterpos" : 244,
"topwindowstate" : "NORMAL", "topwindowstate" : "MAXIMIZE",
"windowheight" : 1309 "windowheight" : 621
}, },
"right" : { "right" : {
"panelheight" : 1271, "panelheight" : 1271,
"splitterpos" : 804, "splitterpos" : 803,
"topwindowstate" : "NORMAL", "topwindowstate" : "NORMAL",
"windowheight" : 1309 "windowheight" : 1309
} }
......
{ {
"TabSet1" : 3, "TabSet1" : 0,
"TabSet2" : 4, "TabSet2" : 4,
"TabZoom" : { "TabZoom" : {
} }
......
{ {
"cursorPosition" : "16,28", "cursorPosition" : "70,29",
"scrollLine" : "0" "scrollLine" : "40"
} }
\ No newline at end of file
{
}
\ No newline at end of file
{ {
"cursorPosition" : "135,15", "cursorPosition" : "114,53",
"last_setup_crc32" : "", "last_setup_crc32" : "E69463565bfca283",
"scrollLine" : "111" "scrollLine" : "110"
} }
\ No newline at end of file
...@@ -22,3 +22,4 @@ ...@@ -22,3 +22,4 @@
~%2Fstuart_package%2Fstuart%2Fdoc%2FstuaRt.R="65312719" ~%2Fstuart_package%2Fstuart%2Fdoc%2FstuaRt.R="65312719"
~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.R="EBD625D2" ~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.R="EBD625D2"
~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.Rmd="D602FFE4" ~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.Rmd="D602FFE4"
~%2Fstuart_package%2Fstuart_old%2FR%2Fmark_prop.R="63BDD9CA"
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
"dirty" : false, "dirty" : false,
"encoding" : "UTF-8", "encoding" : "UTF-8",
"folds" : "", "folds" : "",
"hash" : "1203844341", "hash" : "0",
"id" : "1656F55", "id" : "1656F55",
"lastKnownWriteTime" : 1622640147, "lastKnownWriteTime" : 1623060553,
"last_content_update" : 1622640147, "last_content_update" : 1623060553,
"path" : "~/Documents/PhD/stuart_R/stuart/R/geno_strains.R", "path" : "~/Documents/PhD/stuart_R/stuart/R/geno_strains.R",
"project_path" : "R/geno_strains.R", "project_path" : "R/geno_strains.R",
"properties" : { "properties" : {
......
...@@ -5,20 +5,20 @@ ...@@ -5,20 +5,20 @@
"dirty" : false, "dirty" : false,
"encoding" : "UTF-8", "encoding" : "UTF-8",
"folds" : "", "folds" : "",
"hash" : "3094972460", "hash" : "0",
"id" : "42D37312", "id" : "42D37312",
"lastKnownWriteTime" : 1623061718, "lastKnownWriteTime" : 1623086204,
"last_content_update" : 1623061718577, "last_content_update" : 1623086204670,
"path" : "~/Documents/PhD/stuart_R/stuart/R/mark_prop.R", "path" : "~/Documents/PhD/stuart_R/stuart/R/mark_prop.R",
"project_path" : "R/mark_prop.R", "project_path" : "R/mark_prop.R",
"properties" : { "properties" : {
"cursorPosition" : "16,28", "cursorPosition" : "70,29",
"scrollLine" : "0" "scrollLine" : "40"
}, },
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 9, "relative_order" : 2,
"source_on_save" : false, "source_on_save" : false,
"source_window" : "", "source_window" : "",
"type" : "r_source" "type" : "r_source"
......
...@@ -14,10 +14,9 @@ ...@@ -14,10 +14,9 @@
#### mark_prop #### #### mark_prop ####
## excludes markers depending on proportions of homo/hetorozygous ## excludes markers depending on proportions of homo/hetorozygous
## to modify with chisq.test mark_prop <- function(tab,cross,homo=NA,hetero=NA,pval=NA,na=0.5){
mark_prop <- function(tab,cross,homo=NA,hetero=NA,na=0.5){
#calculate total number of individuals genotyped for each marker #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 #calculate proportion of each genotype
tab <- tab %>% mutate(p_HM1 = n_HM1/n_geno) 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){ ...@@ -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_HT = n_HT/n_geno)
tab <- tab %>% mutate(p_NA = n_NA/(n_geno+n_NA)) tab <- tab %>% mutate(p_NA = n_NA/(n_geno+n_NA))
#stock colnames to join
names <- colnames(tab)
#stop if cross != "F2" or "N2" #stop if cross != "F2" or "N2"
if(!cross %in% c("F2","N2")){ if(!cross %in% c("F2","N2")){
stop("Cross must be F2 or N2") stop("Cross must be F2 or N2")
} }
#stop if no value for "homo" for F2 cross #stop of homo&hetero or pval not specified
if(cross=="F2" & (is.na(homo)==TRUE | is.na(hetero)==TRUE)){ if((is.na(homo)==TRUE | is.na(hetero)==TRUE) & is.na(pval)==TRUE){
stop("Arguments homo and hetero must be specified for F2 crosses") 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 #stop with pval chisq.test
tab <- tab %>% mutate(exclude_prop=case_when(p_NA > na ~ 1, #exclude markers according to proportion of na ## NEED TO ADD THIS FILTER IF CROSS = N2
cross=="F2" & (p_HM1 < homo | p_HM2 < homo | p_HT < hetero) ~ 1, #exclude markers according to proportion of homozygous individuals for F2 cross if(is.na(pval)==FALSE){
cross=="N2" & (p_HM1 < homo | p_HT < hetero) ~ 1, #exclude markers according to proportion of homozygous and heterozygous individuals for N2 cross
T ~ 0)) 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) return(tab)
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"dirty" : false, "dirty" : false,
"encoding" : "UTF-8", "encoding" : "UTF-8",
"folds" : "", "folds" : "",
"hash" : "1139135974", "hash" : "0",
"id" : "45D91D58", "id" : "45D91D58",
"lastKnownWriteTime" : 1622648301, "lastKnownWriteTime" : 1622648301,
"last_content_update" : 1622648301329, "last_content_update" : 1622648301329,
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 11, "relative_order" : 9,
"source_on_save" : false, "source_on_save" : false,
"source_window" : "", "source_window" : "",
"type" : "r_source" "type" : "r_source"
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
"dirty" : false, "dirty" : false,
"encoding" : "UTF-8", "encoding" : "UTF-8",
"folds" : "", "folds" : "",
"hash" : "1762622592", "hash" : "0",
"id" : "65C9B72B", "id" : "65C9B72B",
"lastKnownWriteTime" : 1622642120, "lastKnownWriteTime" : 1623060553,
"last_content_update" : 1622642120783, "last_content_update" : 1623060553,
"path" : "~/Documents/PhD/stuart_R/stuart/R/tab_mark.R", "path" : "~/Documents/PhD/stuart_R/stuart/R/tab_mark.R",
"project_path" : "R/tab_mark.R", "project_path" : "R/tab_mark.R",
"properties" : { "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 @@ ...@@ -5,7 +5,7 @@
"dirty" : false, "dirty" : false,
"encoding" : "UTF-8", "encoding" : "UTF-8",
"folds" : "", "folds" : "",
"hash" : "143869640", "hash" : "0",
"id" : "76AC3EC", "id" : "76AC3EC",
"lastKnownWriteTime" : 1623060553, "lastKnownWriteTime" : 1623060553,
"last_content_update" : 1623060553, "last_content_update" : 1623060553,
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 7, "relative_order" : 6,
"source_on_save" : false, "source_on_save" : false,
"source_window" : "", "source_window" : "",
"type" : "r_source" "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