summaryrefslogtreecommitdiff
path: root/Code/download_and_map.py
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2025-08-19 14:25:07 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2025-08-19 14:25:07 +0800
commit9a4a23c89cdba6a8eebe4ee13cd55e6d3aed5b81 (patch)
treeceb8cd2bf76d60ecba3e8ccc4726ac46565ec361 /Code/download_and_map.py
parent9ff8b3390fb5175cf00cbdfac3f4055dbc6f4e30 (diff)
Running the publisher as a seperate script seems solved the problem of not being able to receive messages.
Diffstat (limited to 'Code/download_and_map.py')
-rw-r--r--Code/download_and_map.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/Code/download_and_map.py b/Code/download_and_map.py
index 0e8f160..2a0a157 100644
--- a/Code/download_and_map.py
+++ b/Code/download_and_map.py
@@ -392,6 +392,7 @@ def publish(mapped_data_directory):
redis_password = os.getenv('REDIS_PASSWORD', '123456')
r = redis.Redis(host=redis_host, port=6379, password=redis_password, db=0)
r.publish(REDIS_CHANNEL, json.dumps({'filename':'REDIS_START.txt', 'data':str(datetime.now())}))
+ time.sleep(3)
for fname in glob.glob('%s/*_quant.txt' % (mapped_data_directory.rstrip('/'))):
try:
file_basename = os.path.basename(fname)
@@ -400,7 +401,7 @@ def publish(mapped_data_directory):
r.publish(REDIS_CHANNEL, json.dumps({'filename':file_basename, 'data':data}))
except Exception as e:
r.publish(REDIS_CHANNEL, json.dumps({'filename':'REDIS_ERROR.txt', 'data':str(e)}))
- time.sleep(1)
+ time.sleep(3)
## main
@@ -421,6 +422,8 @@ if not last_session_finished(DOWNLOADED_SRA_ID_LOG_FILE): # last session not fin
write_network_log_file(s, UPDATE_NETWORK_LOG_FILE)
if age_of_file_in_hours(DOWNLOADED_SRA_ID_LOG_FILE) > 24: # add DONE to the log file anyway
append_done(DOWNLOADED_SRA_ID_LOG_FILE)
+ download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, 'DONE at %s\n' % (curr_time))
+ reverse_lines(DOWNLOADED_SRA_ID_LOG_FILE, os.path.splitext(DOWNLOADED_SRA_ID_LOG_FILE)[0] + '_reversed.txt')
kill_process('wget')
sys.exit()
@@ -450,14 +453,21 @@ if not os.path.isdir(MAPPED_RDATA_DIR):
# after mapping is finished, move all resulting files to MAPPED_RDATA_DIR
if glob.glob('%s/*_quant.txt' % (SALMON_MAP_RESULT_DIR.rstrip('/'))) != []:
- publish(SALMON_MAP_RESULT_DIR)
- cmd = 'mv %s/*_quant.txt %s' % (SALMON_MAP_RESULT_DIR.rstrip('/'), MAPPED_RDATA_DIR)
+
+ try:
+ write_log_file('[download_and_map.py] Ready to publish quant files.', UPDATE_NETWORK_LOG_FILE)
+ publish(SALMON_MAP_RESULT_DIR)
+ time.sleep(5)
+ except Exception as e:
+ write_log_file('[download_and_map.py] Publish error %s.' % (str(e)), UPDATE_NETWORK_LOG_FILE)
+
+ cmd = 'cp %s/*_quant.txt %s' % (SALMON_MAP_RESULT_DIR.rstrip('/'), MAPPED_RDATA_DIR)
os.system(cmd)
print('[download_and_map.py] Done. Check directory %s.' % (os.path.abspath(MAPPED_RDATA_DIR)))
else:
print('[download_and_map.py] No quant files to move.')
-
+ write_log_file('[download_and_map.py] No quant files to move.', UPDATE_NETWORK_LOG_FILE)
write_download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, '%s\n' % ('\n'.join(map_list)))
-write_download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, 'DONE at %s\n' % (curr_time))
+download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, 'DONE at %s\n' % (curr_time))
reverse_lines(DOWNLOADED_SRA_ID_LOG_FILE, os.path.splitext(DOWNLOADED_SRA_ID_LOG_FILE)[0] + '_reversed.txt')