summaryrefslogtreecommitdiff
path: root/Code/slice_TPM_to_JSON.R
diff options
context:
space:
mode:
authorLan Hui <lanhui@zjnu.edu.cn>2024-08-26 16:20:34 +0800
committerLan Hui <lanhui@zjnu.edu.cn>2024-08-26 16:20:34 +0800
commit965c52946eef4cd76f0a4119be63d82348cfee23 (patch)
tree7aba7ea456daa9abdedae049b3ea98c3c7fee177 /Code/slice_TPM_to_JSON.R
parentf312d8bbef849370aacefba1f6e8b1b420047cbb (diff)
Use R package jsonlite instead of rjson, to support the 'digits' option, which allows keeping fewer digits after decimal, thus saving disk storage space
Diffstat (limited to 'Code/slice_TPM_to_JSON.R')
-rw-r--r--Code/slice_TPM_to_JSON.R20
1 files changed, 20 insertions, 0 deletions
diff --git a/Code/slice_TPM_to_JSON.R b/Code/slice_TPM_to_JSON.R
new file mode 100644
index 0000000..e7021ef
--- /dev/null
+++ b/Code/slice_TPM_to_JSON.R
@@ -0,0 +1,20 @@
+
+#library(rjson)
+library(jsonlite)
+dir.name <- '../Data/history/expr/json'
+tpm.file <- '../Data/history/expr/assemble/TPM.6604.txt'
+take.log <- 'YES'
+X <- read.table(tpm.file, header=T, check.names=FALSE, sep="\t")
+gene.id <- as.vector(X[,1])
+X[,1] <- NULL # remove first column
+if (take.log == 'YES') {
+ X <- log(X+1)
+}
+if (!dir.exists(dir.name)) {
+ dir.create(dir.name)
+}
+for (i in 1:dim(X)[1]) {
+ y <- toJSON(X[i,], digits=I(3))
+ file.name = paste(dir.name, paste(gene.id[i], 'json', sep='.'), sep='/')
+ cat(y, file=file.name)
+}