From 965c52946eef4cd76f0a4119be63d82348cfee23 Mon Sep 17 00:00:00 2001 From: Lan Hui Date: Mon, 26 Aug 2024 16:20:34 +0800 Subject: Use R package jsonlite instead of rjson, to support the 'digits' option, which allows keeping fewer digits after decimal, thus saving disk storage space --- Code/slice_TPM_to_JSON.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Code/slice_TPM_to_JSON.py') diff --git a/Code/slice_TPM_to_JSON.py b/Code/slice_TPM_to_JSON.py index e597b78..618310f 100644 --- a/Code/slice_TPM_to_JSON.py +++ b/Code/slice_TPM_to_JSON.py @@ -127,7 +127,7 @@ def make_json_file(expr_dict, dir_name, glb_param_dict): def make_json_file_using_r(dir_name, glb_param_dict): # use r script to make it faster r_code = ''' - library(rjson) + library(jsonlite) dir.name <- '%s' tpm.file <- '%s' take.log <- '%s' @@ -141,7 +141,7 @@ def make_json_file_using_r(dir_name, glb_param_dict): # use r script to make it dir.create(dir.name) } for (i in 1:dim(X)[1]) { - y <- toJSON(X[i,]) + y <- toJSON(X[i,], digits=I(3)) file.name = paste(dir.name, paste(gene.id[i], 'json', sep='.'), sep='/') cat(y, file=file.name) } -- cgit v1.2.1 From fa719fee177152cc9f5d4632c6aa68b91336f8df Mon Sep 17 00:00:00 2001 From: Lan Hui Date: Mon, 26 Aug 2024 17:50:12 +0800 Subject: JSON file should look like '{key:value}' but not ['{key:value}'] --- Code/slice_TPM_to_JSON.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Code/slice_TPM_to_JSON.py') diff --git a/Code/slice_TPM_to_JSON.py b/Code/slice_TPM_to_JSON.py index 618310f..b2edfa2 100644 --- a/Code/slice_TPM_to_JSON.py +++ b/Code/slice_TPM_to_JSON.py @@ -141,7 +141,7 @@ def make_json_file_using_r(dir_name, glb_param_dict): # use r script to make it dir.create(dir.name) } for (i in 1:dim(X)[1]) { - y <- toJSON(X[i,], digits=I(3)) + y <- toJSON(unbox(X[i,]), digits=I(3)) file.name = paste(dir.name, paste(gene.id[i], 'json', sep='.'), sep='/') cat(y, file=file.name) } -- cgit v1.2.1 From 837a291e6a1816920c7116410dd1e0df9fd3eaf7 Mon Sep 17 00:00:00 2001 From: Lan Hui Date: Wed, 28 Aug 2024 14:23:42 +0800 Subject: Pretty print JSON --- Code/slice_TPM_to_JSON.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Code/slice_TPM_to_JSON.py') diff --git a/Code/slice_TPM_to_JSON.py b/Code/slice_TPM_to_JSON.py index b2edfa2..7509f00 100644 --- a/Code/slice_TPM_to_JSON.py +++ b/Code/slice_TPM_to_JSON.py @@ -141,7 +141,7 @@ def make_json_file_using_r(dir_name, glb_param_dict): # use r script to make it dir.create(dir.name) } for (i in 1:dim(X)[1]) { - y <- toJSON(unbox(X[i,]), digits=I(3)) + y <- toJSON(unbox(X[i,]), digits=I(3), pretty=TRUE) file.name = paste(dir.name, paste(gene.id[i], 'json', sep='.'), sep='/') cat(y, file=file.name) } -- cgit v1.2.1