summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2024-08-07 15:19:26 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2024-08-07 15:19:26 +0800
commitb442a3ddf7f0452e5dd0d8c042a5e155effea154 (patch)
tree6556a965315015d961965f099bdfe1da4e38de8a
parent1c4b5c0208bd8335b685e594b146605e4453722e (diff)
Fix error occurred while running update_network.py
-rw-r--r--Code/configure.py2
-rw-r--r--Code/slice_TPM_to_JSON.R19
-rwxr-xr-xCode/update_network.py8
-rw-r--r--Code/utils.py1
4 files changed, 27 insertions, 3 deletions
diff --git a/Code/configure.py b/Code/configure.py
index 43dff60..73fc9cc 100644
--- a/Code/configure.py
+++ b/Code/configure.py
@@ -33,7 +33,7 @@ PARAMETER_FOR_NET_WIGGELAB_DIURNAL = '../Data/parameter/parameter_for_net_wig
BINDING_FILE = '../Data/history/bind/binding.txt'
TPM_FILE = '../Data/history/expr/TPM.txt' # gene expression data
-BUILDRMATRIX_RENEW_INTERVAL = 14 # check every 15 days for updating TPM.txt
+BUILDRMATRIX_RENEW_INTERVAL = 28 # check every 28 days for updating TPM.txt
MIN_RNA_SEQ_INCREASE = -999 # minimum RNA-seq experiments needed when updating parameter_for_buildRmatrix.txt
UPDATE_NETWORK_LOG_FILE = '../Data/log/update.network.log.txt' # network update log. We should check this file from time to time.
NEW_OR_UPDATED_CHIP_FILE = '../Data/log/new.or.updated.chip.file.txt'
diff --git a/Code/slice_TPM_to_JSON.R b/Code/slice_TPM_to_JSON.R
new file mode 100644
index 0000000..fb7a39d
--- /dev/null
+++ b/Code/slice_TPM_to_JSON.R
@@ -0,0 +1,19 @@
+
+library(rjson)
+dir.name <- '../Data/history/expr/json'
+tpm.file <- '../Data/history/expr/TPM.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,])
+ file.name = paste(dir.name, paste(gene.id[i], 'json', sep='.'), sep='/')
+ cat(y, file=file.name)
+}
diff --git a/Code/update_network.py b/Code/update_network.py
index 82c8cb9..376b948 100755
--- a/Code/update_network.py
+++ b/Code/update_network.py
@@ -41,7 +41,6 @@
# Last modified: 10 Sep 2019, hui <lanhui@zjnu.edu.cn> [correlation_mixtools, check the previous R session has finished before starting a new one.]
import os, sys
-import numpy as np
import glob
import time
from datetime import datetime
@@ -130,6 +129,11 @@ def write_sample_size_file(sample_size_file, curr_date, tpm_sample_size):
f.close()
+def empty_file(fname):
+ with open(fname) as f:
+ return f.read().strip() == ''
+
+
def age_of_file_in_days(fname):
''' Return age of fname in days. '''
st = os.stat(fname)
@@ -604,7 +608,7 @@ validate_parameter_for_net(PARAMETER_FOR_NET)
# If the file timestamp does not exist, create one
-if not os.path.exists(TIMESTAMP_FILE):
+if not os.path.exists(TIMESTAMP_FILE) or empty_file(TIMESTAMP_FILE):
record_file_time(FILE_LIST_TO_CHECK, TIMESTAMP_FILE)
# Get update time of mandatory files
diff --git a/Code/utils.py b/Code/utils.py
index 27922d0..2451b91 100644
--- a/Code/utils.py
+++ b/Code/utils.py
@@ -2,6 +2,7 @@
# Purpose: check what new edges have been created today.
# Created by Hui on 20 July 2021
+import os
from datetime import datetime
def get_edge_set(fname):