Commit d5572d89 authored by Marie Bourdon's avatar Marie Bourdon
Browse files

modif names tab_mark

parent c62185f3
{
"debugBreakpointsState" : {
"breakpoints" : [
]
}
}
\ No newline at end of file
{ {
"activeTab" : 2 "activeTab" : 0
} }
\ No newline at end of file
{ {
"left" : { "left" : {
"panelheight" : 689, "panelheight" : 1271,
"splitterpos" : 290, "splitterpos" : 533,
"topwindowstate" : "NORMAL", "topwindowstate" : "NORMAL",
"windowheight" : 727 "windowheight" : 1309
}, },
"right" : { "right" : {
"panelheight" : 689, "panelheight" : 1271,
"splitterpos" : 436, "splitterpos" : 804,
"topwindowstate" : "NORMAL", "topwindowstate" : "NORMAL",
"windowheight" : 727 "windowheight" : 1309
} }
} }
\ No newline at end of file
{ {
"TabSet1" : 3, "TabSet1" : 3,
"TabSet2" : 3, "TabSet2" : 4,
"TabZoom" : { "TabZoom" : {
} }
} }
\ No newline at end of file
build-last-errors="[]" build-last-errors="[]"
build-last-errors-base-dir="~/stuart_package/stuart/" build-last-errors-base-dir="~/stuart_package/stuart/"
build-last-outputs="[{\"output\":\"==> R CMD INSTALL --no-multiarch --with-keep.source stuart\\n\\n\",\"type\":0},{\"output\":\"* installing to library ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library’\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"* installing *source* package ‘stuart’ ...\\n\",\"type\":1},{\"output\":\"** using staged installation\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** R\\n\",\"type\":1},{\"output\":\"** data\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** moving datasets to lazyload DB\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** inst\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** byte-compile and prepare package for lazy loading\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** help\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** installing help indices\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** building package indices\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** installing vignettes\\n\",\"type\":1},{\"output\":\"** testing if installed package can be loaded from temporary location\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** testing if installed package can be loaded from final location\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** testing if installed package keeps a record of temporary installation path\\n\",\"type\":1},{\"output\":\"* DONE (stuart)\\n\",\"type\":1},{\"output\":\"\",\"type\":1}]" build-last-outputs="[{\"output\":\"==> R CMD INSTALL --no-multiarch --with-keep.source stuart\\n\\n\",\"type\":0},{\"output\":\"* installing to library ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library’\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"* installing *source* package ‘stuart’ ...\\n\",\"type\":1},{\"output\":\"** using staged installation\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** R\\n\",\"type\":1},{\"output\":\"** data\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** moving datasets to lazyload DB\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** inst\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** byte-compile and prepare package for lazy loading\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** help\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** installing help indices\\n\",\"type\":1},{\"output\":\"** building package indices\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** installing vignettes\\n\",\"type\":1},{\"output\":\"** testing if installed package can be loaded from temporary location\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** testing if installed package can be loaded from final location\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** testing if installed package keeps a record of temporary installation path\\n\",\"type\":1},{\"output\":\"* DONE (stuart)\\n\",\"type\":1},{\"output\":\"\",\"type\":1}]"
compile_pdf_state="{\"errors\":[],\"output\":\"\",\"running\":false,\"tab_visible\":false,\"target_file\":\"\"}" compile_pdf_state="{\"errors\":[],\"output\":\"\",\"running\":false,\"tab_visible\":false,\"target_file\":\"\"}"
files.monitored-path="" files.monitored-path=""
find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":true,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOff\":[],\"matchOn\":[]},\"running\":false}" find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":true,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOff\":[],\"matchOn\":[]},\"running\":false}"
......
/private/var/folders/dn/j71yz2tn5_gdffs8fqxhddrr0000gn/T/Rtmp3VMULh/preview-1ced414f7aab.dir/stuaRt.html
/private/var/folders/dn/j71yz2tn5_gdffs8fqxhddrr0000gn/T/Rtmp3VMULh/preview-1ced48fe920c.dir/stuaRt.html
/private/var/folders/dn/j71yz2tn5_gdffs8fqxhddrr0000gn/T/RtmpNme5vw/preview-4c4321234d03.dir/stuaRt.html
{
"cursorPosition" : "8,12",
"scrollLine" : "0"
}
\ No newline at end of file
{ {
"cursorPosition" : "38,30", "cursorPosition" : "43,27",
"scrollLine" : "25", "scrollLine" : "29",
"source_window_id" : "" "source_window_id" : ""
} }
\ No newline at end of file
{ {
"cursorPosition" : "34,0", "cursorPosition" : "22,39",
"scrollLine" : "21" "scrollLine" : "7"
} }
\ No newline at end of file
{ {
"cursorPosition" : "78,3", "cursorPosition" : "89,0",
"last_setup_crc32" : "39B546A65bfca283", "last_setup_crc32" : "39B546A65bfca283",
"scrollLine" : "63" "scrollLine" : "74"
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
~%2Fstuart_package%2Fstuart%2FR%2Fmark_match.R="75F49619" ~%2Fstuart_package%2Fstuart%2FR%2Fmark_match.R="75F49619"
~%2Fstuart_package%2Fstuart%2FR%2Fmark_poly.R="3A328548" ~%2Fstuart_package%2Fstuart%2FR%2Fmark_poly.R="3A328548"
~%2Fstuart_package%2Fstuart%2FR%2Fmark_prop.R="A609F054" ~%2Fstuart_package%2Fstuart%2FR%2Fmark_prop.R="A609F054"
~%2Fstuart_package%2Fstuart%2FR%2Fstuart_tab-data.R="7411866"
~%2Fstuart_package%2Fstuart%2FR%2Ftab_mark.R="7FA3B215" ~%2Fstuart_package%2Fstuart%2FR%2Ftab_mark.R="7FA3B215"
~%2Fstuart_package%2Fstuart%2FR%2Fwrite_rqtl.R="5B8691C7" ~%2Fstuart_package%2Fstuart%2FR%2Fwrite_rqtl.R="5B8691C7"
~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.R="EBD625D2" ~%2Fstuart_package%2Fstuart%2Fvignettes%2FstuaRt.R="EBD625D2"
......
{ {
"collab_server" : "", "collab_server" : "",
"contents" : "", "contents" : "",
"created" : 1622636127574.000, "created" : 1622641774018.000,
"dirty" : false, "dirty" : false,
"encoding" : "UTF-8", "encoding" : "UTF-8",
"folds" : "", "folds" : "",
"hash" : "0", "hash" : "1203844341",
"id" : "907DF1D3", "id" : "1656F55",
"lastKnownWriteTime" : 1622640147, "lastKnownWriteTime" : 1622640147,
"last_content_update" : 1622640147854, "last_content_update" : 1622640147,
"path" : "~/stuart_package/stuart/R/geno_strains.R", "path" : "~/stuart_package/stuart/R/geno_strains.R",
"project_path" : "R/geno_strains.R", "project_path" : "R/geno_strains.R",
"properties" : { "properties" : {
"cursorPosition" : "34,0", "cursorPosition" : "22,39",
"scrollLine" : "21" "scrollLine" : "7"
}, },
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 2, "relative_order" : 4,
"source_on_save" : false, "source_on_save" : false,
"source_window" : "", "source_window" : "",
"type" : "r_source" "type" : "r_source"
......
#' @title Create haplotype for a new mouse strain into a reference dataframe
#'
#' @description This functions adds columns for parental strains used in the cross in the annotation data frame, from the genotype data frame in which one or several animal of the parental strains were genotyped.
#' If several animals of one strain were genotyped, a consensus is created from these animals.
#' The consensus is created as follow : if the indivuals carry the same allele, this allele is kept, otherwise, the allele is noted as "N". If individuals show residual heterozygosity, it is encoded as "H".
#' @param ref data frame with the reference genotypes of mouse lines
#' @param geno data frame with the genotyping results for your cross from miniMUGA array
#' @param par1 first parental strain used in the cross, the name must be written as in the geno data frame
#' @param par2 second parental strain used in the cross, the name must be written as in the geno data frame
#' @param name1 name of the first parental strain to use as the column name in the ref data frame
#' @param name2 name of the second parental strain to use as the column name in the ref data frame
#'
#' @import dplyr
#' @import tidyr
#'
#' @export
#'
geno_strains <- function(ref,geno,par1,par2,name1,name2){
#rename df columns
geno <- geno %>% rename("marker"=1,
"id"=2,
"allele_1"=3,
"allele_2"=4)
#recode genotypes from 2 alleles to 1
geno <- geno %>% mutate_all(as.character)
geno <- geno %>% filter(id %in% c(par1,par2))
geno <- geno %>% mutate(Geno=case_when(allele_1 == "-" | allele_2 == "-" ~ "N",
allele_1 == allele_2 ~ allele_1,
allele_1 %in% c("A","T","G","C") & allele_2 %in% c("A","T","G","C") ~ "H"))
geno <- geno %>% select(marker,id,Geno) %>% pivot_wider(names_from = id, values_from = Geno)
#create consensus
if(length(par1)!=1){
geno <- geno %>% mutate(parent1 = ifelse(!!sym(par1[1])==!!sym(par1[2]),!!sym(par1[1]),"N"))
} else {
geno <- geno %>% rename(parent1=!!sym(par1[1]))
}
if(length(par2)!=1){
geno <- geno %>% mutate(parent2 = ifelse(!!sym(par2[1])==!!sym(par2[2]),!!sym(par2[1]),"N"))
} else {
geno <- geno %>% rename(parent2=!!sym(par2[1]))
}
geno <- geno %>% select(marker,parent1,parent2)
colnames(geno) <- c("marker",name1,name2)
#merge with ref file
ref <- full_join(ref,geno,by=c("marker"="marker"))
return(ref)
}
{
"collab_server" : "",
"contents" : "",
"created" : 1622641680399.000,
"dirty" : false,
"encoding" : "",
"folds" : "",
"hash" : "0",
"id" : "17AE345",
"lastKnownWriteTime" : 140481884136632,
"last_content_update" : 1622641680399,
"path" : null,
"project_path" : null,
"properties" : {
"cacheKey" : "E58FACDB",
"caption" : "stuart_tab",
"contentUrl" : "grid_resource/gridviewer.html?env=&obj=stuart_tab&cache_key=E58FACDB",
"displayedObservations" : 11125,
"environment" : "",
"expression" : "stuart_tab",
"object" : "stuart_tab",
"preview" : 0,
"totalObservations" : 11125,
"variables" : 7
},
"read_only" : false,
"read_only_alternatives" : [
],
"relative_order" : 2,
"source_on_save" : false,
"source_window" : "",
"type" : "r_dataframe"
}
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 7, "relative_order" : 9,
"source_on_save" : false, "source_on_save" : false,
"source_window" : "", "source_window" : "",
"type" : "r_source" "type" : "r_source"
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 9, "relative_order" : 11,
"source_on_save" : false, "source_on_save" : false,
"source_window" : "", "source_window" : "",
"type" : "r_source" "type" : "r_source"
......
...@@ -5,21 +5,21 @@ ...@@ -5,21 +5,21 @@
"dirty" : false, "dirty" : false,
"encoding" : "UTF-8", "encoding" : "UTF-8",
"folds" : "", "folds" : "",
"hash" : "1306976036", "hash" : "1762622592",
"id" : "65C9B72B", "id" : "65C9B72B",
"lastKnownWriteTime" : 1622462353, "lastKnownWriteTime" : 1622642120,
"last_content_update" : 1622462353, "last_content_update" : 1622642120783,
"path" : "~/stuart_package/stuart/R/tab_mark.R", "path" : "~/stuart_package/stuart/R/tab_mark.R",
"project_path" : "R/tab_mark.R", "project_path" : "R/tab_mark.R",
"properties" : { "properties" : {
"cursorPosition" : "38,30", "cursorPosition" : "43,27",
"scrollLine" : "25", "scrollLine" : "29",
"source_window_id" : "" "source_window_id" : ""
}, },
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 3, "relative_order" : 5,
"source_on_save" : false, "source_on_save" : false,
"source_window" : "", "source_window" : "",
"type" : "r_source" "type" : "r_source"
......
...@@ -12,8 +12,14 @@ ...@@ -12,8 +12,14 @@
#### tab_mark function #### #### tab_mark function ####
## create table with markers and counts ## create table with markers and counts
tab_mark <- function(geno){ tab_mark <- function(geno){
#rename df columns
geno <- geno %>% rename("marker"=1,
"id"=2,
"allele_1"=3,
"allele_2"=4)
#create geno column in geno df #create geno column in geno df
geno <- geno %>% unite(Geno,c("Allele1...Forward","Allele2...Forward"),sep="",remove=FALSE) geno <- geno %>% unite(Geno,c("allele_1","allele_2"),sep="",remove=FALSE)
#recode genotypes to have all heterozygous encoded the same way (ex: only "AT", no "TA") #recode genotypes to have all heterozygous encoded the same way (ex: only "AT", no "TA")
geno <- geno %>% mutate(Geno=recode(Geno, geno <- geno %>% mutate(Geno=recode(Geno,
...@@ -26,9 +32,9 @@ tab_mark <- function(geno){ ...@@ -26,9 +32,9 @@ tab_mark <- function(geno){
#create df with counts for each genotype #create df with counts for each genotype
df_count <- tibble(SNP.Name = as.character(unique(geno$SNP.Name)), df_count <- tibble(marker = as.character(unique(geno$marker)),
Allele_1 = NA, allele_1 = NA,
Allele_2 = NA, allele_2 = NA,
n_HM1 = NA, n_HM1 = NA,
n_HM2 = NA, n_HM2 = NA,
n_HT = NA, n_HT = NA,
...@@ -36,11 +42,11 @@ tab_mark <- function(geno){ ...@@ -36,11 +42,11 @@ tab_mark <- function(geno){
## loop to count genotype ## loop to count genotype
for(i in df_count$SNP.Name){ for(i in df_count$marker){
#extract alleles for each marker #extract alleles for each marker
Alleles <- geno %>% filter(SNP.Name==i) %>% Alleles <- geno %>% filter(marker==i) %>%
select(c(SNP.Name,Sample.ID,Geno,Allele1...Forward,Allele2...Forward)) %>% select(c(marker,id,Geno,allele_1,allele_2)) %>%
pivot_longer(c(Allele1...Forward,Allele2...Forward),names_to="Allele_name",values_to="Allele") %>% pivot_longer(c(allele_1,allele_2),names_to="Allele_name",values_to="Allele") %>%
distinct(Allele) %>% filter(Allele != "-") distinct(Allele) %>% filter(Allele != "-")
Alleles <- as.factor(paste(Alleles$Allele)) Alleles <- as.factor(paste(Alleles$Allele))
...@@ -52,19 +58,19 @@ tab_mark <- function(geno){ ...@@ -52,19 +58,19 @@ tab_mark <- function(geno){
if(all(rapportools::is.empty(Alleles))==FALSE){ if(all(rapportools::is.empty(Alleles))==FALSE){
#add alleles to df_count #add alleles to df_count
df_count <- df_count %>% mutate(Allele_1 = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(allele_1 = ifelse(marker == i,
paste(Alleles[1]), Allele_1)) paste(Alleles[1]), allele_1))
#count for homozygous for allele 1 #count for homozygous for allele 1
n1 <- geno %>% filter(SNP.Name==i) %>% n1 <- geno %>% filter(marker==i) %>%
filter(Geno == paste(Alleles[1],Alleles[1],sep="")) %>% filter(Geno == paste(Alleles[1],Alleles[1],sep="")) %>%
summarise(n=n()) summarise(n=n())
#add count for homozygous for allele 1 to df_count #add count for homozygous for allele 1 to df_count
df_count <- df_count %>% mutate(n_HM1 = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(n_HM1 = ifelse(marker == i,
n1$n, n_HM1)) n1$n, n_HM1))
...@@ -72,55 +78,55 @@ tab_mark <- function(geno){ ...@@ -72,55 +78,55 @@ tab_mark <- function(geno){
#if marker not polymorphic #if marker not polymorphic
if(is.na(Alleles[2])==TRUE){ if(is.na(Alleles[2])==TRUE){
#NA as Allele_2 #NA as allele_2
df_count <- df_count %>% mutate(Allele_2 = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(allele_2 = ifelse(marker == i,
NA, Allele_2)) NA, allele_2))
#NA as n_HM2 #NA as n_HM2
df_count <- df_count %>% mutate(n_HM2 = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(n_HM2 = ifelse(marker == i,
NA, n_HM2)) NA, n_HM2))
#NA as n_HT #NA as n_HT
df_count <- df_count %>% mutate(n_HT = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(n_HT = ifelse(marker == i,
NA, n_HT)) NA, n_HT))
} else { } else {
#add alleles to df_count #add alleles to df_count
df_count <- df_count %>% mutate(Allele_2 = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(allele_2 = ifelse(marker == i,
paste(Alleles[2]), Allele_2)) paste(Alleles[2]), allele_2))
#count for homozygous for allele 2 #count for homozygous for allele 2
n2 <- geno %>% filter(SNP.Name==i) %>% n2 <- geno %>% filter(marker==i) %>%
filter(Geno == paste(Alleles[2],Alleles[2],sep="")) %>% filter(Geno == paste(Alleles[2],Alleles[2],sep="")) %>%
summarise(n=n()) summarise(n=n())
#add count for homozygous for allele 1 to df_count #add count for homozygous for allele 1 to df_count
df_count <- df_count %>% mutate(n_HM2 = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(n_HM2 = ifelse(marker == i,
n2$n, n_HM2)) n2$n, n_HM2))
#count for heterozygous #count for heterozygous
n3 <- geno %>% filter(SNP.Name==i) %>% n3 <- geno %>% filter(marker==i) %>%
filter(Geno == paste(Alleles[1],Alleles[2],sep="")) %>% filter(Geno == paste(Alleles[1],Alleles[2],sep="")) %>%
summarise(n=n()) summarise(n=n())
#add count for homozygous for allele 1 to df_count #add count for homozygous for allele 1 to df_count
df_count <- df_count %>% mutate(n_HT = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(n_HT = ifelse(marker == i,
n3$n, n_HT)) n3$n, n_HT))
} }
#count for NA #count for NA
n4 <- geno %>% filter(SNP.Name==i) %>% n4 <- geno %>% filter(marker==i) %>%
filter(Geno == "--" | filter(Geno == "--" |
Geno == paste(Alleles[1],"-",sep="") | Geno == paste(Alleles[2],"-",sep="") | Geno == paste(Alleles[1],"-",sep="") | Geno == paste(Alleles[2],"-",sep="") |
Geno == paste("-",Alleles[1],sep="") | Geno == paste("-",Alleles[2],sep="")) %>% Geno == paste("-",Alleles[1],sep="") | Geno == paste("-",Alleles[2],sep="")) %>%
summarise(n=n()) summarise(n=n())
#add count for NA to df_count #add count for NA to df_count
df_count <- df_count %>% mutate(n_NA = ifelse(SNP.Name == i, df_count <- df_count %>% mutate(n_NA = ifelse(marker == i,
n4$n, n_NA)) n4$n, n_NA))
} }
#change class of counts as numeric : #change class of counts as numeric :
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"read_only" : false, "read_only" : false,
"read_only_alternatives" : [ "read_only_alternatives" : [
], ],
"relative_order" : 5, "relative_order" : 7,
"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