diff options
Diffstat (limited to 'Code/utils.py')
-rw-r--r-- | Code/utils.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Code/utils.py b/Code/utils.py new file mode 100644 index 0000000..f78980a --- /dev/null +++ b/Code/utils.py @@ -0,0 +1,39 @@ +# Utility functions +# Purpose: check what new edges have been created today. +# Created by Hui on 20 July 2021 + +def get_edge_set(fname): + result = set() + with open(fname) as f: + for line in f: + line = line.strip() + lst = line.split('\t') + if len(lst) == 10: + target_id = lst[0].split()[0].upper() + tf_id = lst[1].split()[0].upper() + result.add(target_id + '_' + tf_id) + return result + + +def make_new_edges_file(Sold, Snew, fname_new, output_file): + Sdiff = Snew.difference(Sold) + result = [] + with open(fname_new) as f: + for line in f: + line = line.strip() + lst = line.split('\t') + if len(lst) == 10: + target_id = lst[0].split()[0].upper() + tf_id = lst[1].split()[0].upper() + if target_id + '_' + tf_id in Sdiff: # this is a new edge line, keep it + result.append(line) + with open(output_file, 'w') as f: + for line in result: + f.write(line + '\n') + + +if __name__ == '__main__': + S2 = get_edge_set('/home/lanhui/brain/Data/temp/edges.txt') + S1 = get_edge_set('/home/lanhui/brain/Data/temp/edges.txt.old') + make_new_edges_file(S1, S2, '/home/lanhui/brain/Data/temp/edges.txt', 'mynewedges.txt') + |