-
Notifications
You must be signed in to change notification settings - Fork 0
/
Obsidian.Table_to_Marker_Note.R
92 lines (73 loc) · 2.71 KB
/
Obsidian.Table_to_Marker_Note.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env Rscript
rm(list = ls())
options(stringsAsFactors = F)
library(optparse)
# Parse arguments
option_list <- list(
make_option(
opt_str = c("--INPUTFILE"),
action = "store",
type = "character",
default = NULL,
help = "Path to input file",
metavar = "character"
),
make_option(
opt_str = c("--OUTPUTDIR"),
action = "store",
type = "character",
default = NULL,
help = "Path to output directory",
metavar = "character"
)
)
opt_parser = OptionParser(option_list = option_list)
opt = parse_args(opt_parser)
inputfile <- as.character(opt$INPUTFILE)
outputdir <- as.character(opt$OUTPUTDIR)
# --- #
ReQ_packages = c("data.table", "dplyr", "tibble", "stringr", "magrittr", "tidyr")
for (pack in ReQ_packages) {
if(pack %in% rownames(installed.packages()) == FALSE) {
BiocManager::install(pack)
suppressPackageStartupMessages(library(pack, character.only = TRUE))
} else {
library(pack, character.only = TRUE)
}
}
# --- #
input <- fread(inputfile, data.table = FALSE, header = TRUE, encoding = "Latin-1")
input$`celltype-subtype-source-notes` <- paste0(input$`celltype`, ';',
input$`subtype`, ';',
input$`source`, ';',
input$`notes`)
for (gene in unique(input$`name`)) {
tmp <- input[input$`name` == gene,]
if (any(tmp$update == TRUE)) {
tmp[is.na(tmp$`mm-gene`), "mm-gene"] <- ""
tmp[is.na(tmp$`hs-gene`), "hs-gene"] <- ""
tmp[is.na(tmp$`common-name`), "common-name"] <- ""
tmp[is.na(tmp$`tumor`), "tumor"] <- ""
print(gene)
fileConn<-file(paste0(outputdir, "/", gene, ".md"))
writeLines(c("---",
paste0("aliases: [", paste(unique(tmp$`aliases`), collapse = ", "), "]"),
paste0('mm-gene: "', unique(tmp$`mm-gene`), '"'),
paste0('hs-gene: "', unique(tmp$`hs-gene`), '"'),
paste0('common-name: "', unique(tmp$`common-name`), '"'),
paste0('celltype:'),
paste0('- "', unique(tmp$`celltype`), '"'),
paste0('celltype-subtype-source-notes:'),
paste0('- "', tmp$`celltype-subtype-source-notes`, '"'),
paste0('tumor: "', paste(unique(tmp$`tumor`), collapse = ";"), '"'),
"---",
"",
"Links: [[000 Vault TOC]], [[030 Gene Cards]]",
"#marker",
"",
"---",
unique(tmp$`main-body`)
), fileConn)
close(fileConn)
}
}