diff options
Diffstat (limited to 'Code/update_network_by_force.py')
-rw-r--r-- | Code/update_network_by_force.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/Code/update_network_by_force.py b/Code/update_network_by_force.py index 11e8d72..0e56d95 100644 --- a/Code/update_network_by_force.py +++ b/Code/update_network_by_force.py @@ -72,7 +72,34 @@ def delete_edge_files(fname_lst): os.remove(fname) else: write_log_file('[update_network_by_force.py] In function delete_edge_files. Check file %s. It is probably still being written (age less than %d hours). So I don\'t delete it.' % (fname, age_in_hours), UPDATE_NETWORK_LOG_FILE) - + + +def summarize_edge_file(fname): + ''' Return number of lines in file fname. ''' + if not os.path.exists(fname): + return 'File %s does not exist.' % (fname) + f = open(fname) + tau = 2.0 + count_below = 0 + count_above = 0 + count_total = 0 + for line in f: + line = line.strip() + lst = line.split('\t') + if len(lst) == 10: + association_strength = float(lst[8]) + count_total += 1 + if association_strength > tau: + count_above += 1 + else: + count_below += 1 + f.close() + if count_total > 0: + return '#edges above %4.1f: %d (%4.3f percent), #edges below %4.1f: %d (%4.3f percent).' % (tau, count_above, 100.0*count_above/count_total, tau, count_below, 100.0*count_below/count_total) + else: + return 'Total edges is 0.' + + ########## Merge edges ####################### # update edges.txt, a merged file from two sources, HISTORY_DIR and HISTORY_DIR2. Some new edge files are being generated ... time.sleep(3) @@ -102,10 +129,12 @@ elif os.path.getmtime(MERGED_EDGE_FILE) < most_recent_edge_modification_time: # if os.path.getmtime(MERGED_EDGE_FILE) < os.path.getmtime(EDGE_POOL_DIR): # edge pool directory has been updated, create new edges.txt write_log_file('[update_network_by_force.py] Make a new edges.txt from edge files in %s.' % (EDGE_POOL_DIR), UPDATE_NETWORK_LOG_FILE) - write_log_file('[update_network_by_force.py] Number of lines in the old edges.txt: %d.' % (num_line(MERGED_EDGE_FILE)), UPDATE_NETWORK_LOG_FILE) + write_log_file('[update_network_by_force.py] Number of lines in the old edges.txt: %d.' % (num_line(MERGED_EDGE_FILE)), UPDATE_NETWORK_LOG_FILE) + write_log_file('[update_network_by_force.py] %s' % (summarize_edge_file(MERGED_EDGE_FILE)), UPDATE_NETWORK_LOG_FILE) cmd = 'python3 merge_edges.py' os.system(cmd) - write_log_file('[update_network_by_force.py] Number of lines in the new edges.txt: %d.' % (num_line(MERGED_EDGE_FILE)), UPDATE_NETWORK_LOG_FILE) + write_log_file('[update_network_by_force.py] Number of lines in the new edges.txt: %d.' % (num_line(MERGED_EDGE_FILE)), UPDATE_NETWORK_LOG_FILE) + write_log_file('[update_network_by_force.py] %s' % (summarize_edge_file(MERGED_EDGE_FILE)), UPDATE_NETWORK_LOG_FILE) manual_copy_commands = 'Please copy files to the web application: sudo cp /home/lanhui/brain/Data/temp/edges.txt /var/www/brain/brain/static/edges/edges.txt sudo find /home/lanhui/brain/Data/temp/html_edges -name "*.html" -exec mv -t /var/www/brain/brain/static/edges {} +' write_log_file('[update_network_by_force.py] %s' % (manual_copy_commands), UPDATE_NETWORK_LOG_FILE) copy_and_backup_file(MERGED_EDGE_FILE, '../Analysis') # the backup file will be used for further analysis |