summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2024-08-09 15:12:42 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2024-08-09 15:12:42 +0800
commiteb18d1994377c574bc191e9fee6c4921e3165883 (patch)
tree89bd4c9ca7a43e6de99b27972944e714ad0d7afb
parent54edc18f921fbb4b700e697e5a88b56bc306b515 (diff)
[update_network.py] Simplify code
-rwxr-xr-xCode/update_network.py47
1 files changed, 18 insertions, 29 deletions
diff --git a/Code/update_network.py b/Code/update_network.py
index 376b948..f4ceda1 100755
--- a/Code/update_network.py
+++ b/Code/update_network.py
@@ -584,23 +584,6 @@ if miss_lst != []: # miss_lst is non-empty when we first run this script.
create_edges0()
-# Make json (sliced TPM.txt). Copy json to the
-# web application folder static/edges [manual] for displaying gene
-# expression scatterplots.
-if os.path.exists(TPM_FILE):
- write_log_file('[update_network.py] Make individual json files for gene expression information. Don\'t forget to copy these files to folder static/edges in the web application.', UPDATE_NETWORK_LOG_FILE)
- cmd = 'python3 slice_TPM_to_JSON.py %s' % (PARAMETER_FOR_NET)
- os.system(cmd)
-
-# Make json2 (sliced binding.txt). Copy json2 to
-# the web application folder static/edges [do it manually] for displaying
-# binding strength plots.
-if os.path.exists(BINDING_FILE):
- write_log_file('[update_network.py] Make individual json files for binding information. Don\'t forget to copy these files to folder static/edges in the web application.', UPDATE_NETWORK_LOG_FILE)
- cmd = 'python3 slice_binding_to_JSON.py %s' % (PARAMETER_FOR_NET)
- os.system(cmd)
-
-
# Make sure parameter files are present and valid (rudimentary check but important)
validate_parameter_for_buildcmatrix(PARAMETER_FOR_BUILDCMATRIX)
validate_parameter_for_buildrmatrix(PARAMETER_FOR_BUILDRMATRIX)
@@ -668,16 +651,19 @@ updated_file_list = get_updated_files(FILE_LIST_TO_CHECK, timestamp_dict)
# the following from being True.
if 'parameter_for_buildRmatrix.txt' in updated_file_list and not hold_on(PARAMETER_FOR_BUILDRMATRIX):
write_log_file('[update_network.py] Parameter file %s has been updated.' % (PARAMETER_FOR_BUILDRMATRIX), UPDATE_NETWORK_LOG_FILE)
- write_log_file('[update_network.py] Rebuild TPM.txt ...', UPDATE_NETWORK_LOG_FILE)
- curr_time = datetime.now().strftime('%Y%m%d%H%M%S')
if os.path.exists(TPM_FILE):
- backup_file_name = '../Data/history/expr/TPM.txt.backup.at.%s' % (curr_time)
+ curr_time = datetime.now().strftime('%Y%m%d%H%M%S')
+ tpm_sample_size = number_rnaseq_id(TPM_FILE)
+ backup_file_name = os.path.join(os.path.dirname(TPM_FILE), 'TPM.txt.%d.%s' % (tpm_sample_size, curr_time))
+ write_log_file('[update_network.py] Backup TPM.txt as %s.' % (backup_file_name), UPDATE_NETWORK_LOG_FILE)
cmd = 'cp %s %s' % (TPM_FILE, backup_file_name)
os.system(cmd)
cmd = 'gzip %s' % (backup_file_name)
os.system(cmd)
- cmd = 'python3 buildRmatrix.py %s' % (PARAMETER_FOR_BUILDRMATRIX) # produce TPM.txt, whose location is specified in TPM_TABLE in buidlRmatrix.py
+ # Rebuild TPM.txt
+ write_log_file('[update_network.py] Rebuild TPM.txt ...', UPDATE_NETWORK_LOG_FILE)
+ cmd = 'python3 buildRmatrix.py %s' % (PARAMETER_FOR_BUILDRMATRIX)
os.system(cmd)
curr_date = datetime.now().strftime('%Y%m%d')
@@ -698,14 +684,17 @@ if 'TPM.txt' in updated_file_list: # we could _touch_ TPM.txt to make it recent.
cmd = 'python3 make_target_tf.py %s > %s' % (PARAMETER_FOR_NET, TARGET_TF_FILE)
os.system(cmd)
- write_log_file('[update_network.py] Update ../Data/history/expr/json using the new TPM.txt. Don\'t forget to update the static/edges/json folder in the web application.', UPDATE_NETWORK_LOG_FILE)
- ## json -- make/renew json directory for displaying scatterplots
- cmd = 'python3 slice_TPM_to_JSON.py %s' % (PARAMETER_FOR_NET)
- os.system(cmd) # turn this on if we are going to use this TPM.txt for displaying scatterplots
- write_log_file('[update_network.py] Update directory ../Data/history/bind/json2. Don\'t forget to copy json2 to static/edges in the web application.', UPDATE_NETWORK_LOG_FILE)
- cmd = 'python3 slice_binding_to_JSON.py %s' % (PARAMETER_FOR_NET)
- os.system(cmd) # turn this on if we are going to use this binding.txt for displaying bar charts of binding strengths
- ## copy ../Data/history/bind/json2 and ../Data/history/expr/json to the web application folder 'static/edges' [manual]
+ if os.path.exists(TPM_FILE):
+ write_log_file('[update_network.py] Update ../Data/history/expr/json using the new TPM.txt. Don\'t forget to update the static/edges/json folder in the web application.', UPDATE_NETWORK_LOG_FILE)
+ ## json -- make/renew json directory for displaying scatterplots
+ cmd = 'python3 slice_TPM_to_JSON.py %s' % (PARAMETER_FOR_NET)
+ os.system(cmd) # turn this on if we are going to use this TPM.txt for displaying scatterplots
+
+ if os.path.exists(BINDING_FILE):
+ write_log_file('[update_network.py] Update directory ../Data/history/bind/json2. Don\'t forget to copy json2 to static/edges in the web application.', UPDATE_NETWORK_LOG_FILE)
+ cmd = 'python3 slice_binding_to_JSON.py %s' % (PARAMETER_FOR_NET)
+ os.system(cmd) # turn this on if we are going to use this binding.txt for displaying bar charts of binding strengths
+ ## copy ../Data/history/bind/json2 and ../Data/history/expr/json to the web application folder 'static/edges' [manual]
if False: # TODO For now I will always use travadb's TPM.txt (138 columns) to display scatterplots. Simpler and faster.
write_log_file('Assign tissue, refine tissue and update rnaseq_info_database.json', UPDATE_NETWORK_LOG_FILE)