Wed Apr  5 23:41:21 2017: arg parsing for read_dnms.r
Wed Apr  5 23:41:21 2017: arg parsing for read_dnms.r

carjed/smaug-genetics,carjed/smaug-genetics,carjed/smaug-genetics,carjed/smaug-genetics
#!/usr/bin/Rscript

##############################################################################
# Standalone script for
##############################################################################
# Change to 1 if running as standalone process during
# generation of validation data
write <- FALSE

args <- commandArgs(TRUE)
write <- as.logical(args[1])

cat(write, "\n")

require(dplyr)

parentdir <- "/net/bipolar/jedidiah/mutation"

# Read DNMs
gonl_dnms <- read.table(paste0(parentdir,
		"/reference_data/DNMs/GoNL_DNMs.txt"),
	header=T, stringsAsFactors=F)
gonl_dnms <- gonl_dnms[,1:5]
names(gonl_dnms) <- c("ID", "CHR", "POS", "REF", "ALT")

itmi_dnms <- read.table(paste0(parentdir,
		"/reference_data/DNMs/goldmann_2016_dnms.txt"),
	header=T, stringsAsFactors=F)
itmi_dnms$ID <- "goldmann"
itmi_dnms <- itmi_dnms[,c(7,1,2,4,5)]
names(itmi_dnms) <- c("ID", "CHR", "POS", "REF", "ALT")
itmi_dnms$CHR <- gsub("chr", "", itmi_dnms$CHR)

dnms_full <- rbind(gonl_dnms, itmi_dnms)
dnms_full$CAT <- paste(dnms_full$REF, dnms_full$ALT, sep="")

dnms_full$Category[dnms_full$CAT=="AC" | dnms_full$CAT=="TG"] <- "AT_CG"
dnms_full$Category[dnms_full$CAT=="AG" | dnms_full$CAT=="TC"] <- "AT_GC"
dnms_full$Category[dnms_full$CAT=="AT" | dnms_full$CAT=="TA"] <- "AT_TA"
dnms_full$Category[dnms_full$CAT=="GA" | dnms_full$CAT=="CT"] <- "GC_AT"
dnms_full$Category[dnms_full$CAT=="GC" | dnms_full$CAT=="CG"] <- "GC_CG"
dnms_full$Category[dnms_full$CAT=="GT" | dnms_full$CAT=="CA"] <- "GC_TA"

dnms_full <- dnms_full %>%
  dplyr::select(ID, CHR, POS, Category) %>%
  arrange(CHR, POS)

if(write){
  categs <- c("AT_CG", "AT_GC", "AT_TA", "GC_AT", "GC_CG", "GC_TA")
  for(i in 1:6){
    cat <- categs[i]
    outdat <- dnms_full %>%
      filter(Category==cat)

    outfile <- paste0(parentdir, "/reference_data/DNMs/GoNL_", cat, ".txt")
    write.table(outdat, outfile, col.names=F, row.names=F, sep="\t", quote=F)

    annocmd <- paste0("bash ", parentdir,
      "/smaug-genetics/data_mgmt/process_dnms/annotate_dnms.sh ", cat)
    system(annocmd)
  }
}

#!/usr/bin/Rscript

##############################################################################
# Standalone script for
##############################################################################
# Change to 1 if running as standalone process during
# generation of validation data
write <- FALSE

args <- commandArgs(TRUE)
write <- as.double(args[1])

cat(write, "\n")

require(dplyr)

parentdir <- "/net/bipolar/jedidiah/mutation"

# Read DNMs
gonl_dnms <- read.table(paste0(parentdir,
		"/reference_data/DNMs/GoNL_DNMs.txt"),
	header=T, stringsAsFactors=F)
gonl_dnms <- gonl_dnms[,1:5]
names(gonl_dnms) <- c("ID", "CHR", "POS", "REF", "ALT")

itmi_dnms <- read.table(paste0(parentdir,
		"/reference_data/DNMs/goldmann_2016_dnms.txt"),
	header=T, stringsAsFactors=F)
itmi_dnms$ID <- "goldmann"
itmi_dnms <- itmi_dnms[,c(7,1,2,4,5)]
names(itmi_dnms) <- c("ID", "CHR", "POS", "REF", "ALT")
itmi_dnms$CHR <- gsub("chr", "", itmi_dnms$CHR)

dnms_full <- rbind(gonl_dnms, itmi_dnms)
dnms_full$CAT <- paste(dnms_full$REF, dnms_full$ALT, sep="")

dnms_full$Category[dnms_full$CAT=="AC" | dnms_full$CAT=="TG"] <- "AT_CG"
dnms_full$Category[dnms_full$CAT=="AG" | dnms_full$CAT=="TC"] <- "AT_GC"
dnms_full$Category[dnms_full$CAT=="AT" | dnms_full$CAT=="TA"] <- "AT_TA"
dnms_full$Category[dnms_full$CAT=="GA" | dnms_full$CAT=="CT"] <- "GC_AT"
dnms_full$Category[dnms_full$CAT=="GC" | dnms_full$CAT=="CG"] <- "GC_CG"
dnms_full$Category[dnms_full$CAT=="GT" | dnms_full$CAT=="CA"] <- "GC_TA"

dnms_full <- dnms_full %>%
  dplyr::select(ID, CHR, POS, Category) %>%
  arrange(CHR, POS)

if(write){
  categs <- c("AT_CG", "AT_GC", "AT_TA", "GC_AT", "GC_CG", "GC_TA")
  for(i in 1:6){
    cat <- categs[i]
    outdat <- dnms_full %>%
      filter(Category==cat)

    outfile <- paste0(parentdir, "/reference_data/DNMs/GoNL_", cat, ".txt")
    write.table(outdat, outfile, col.names=F, row.names=F, sep="\t", quote=F)

    annocmd <- paste0("bash ", parentdir,
      "/smaug-genetics/data_mgmt/process_dnms/annotate_dnms.sh ", cat)
    system(annocmd)
  }
}
