# Purpose: convert results from three-way interaction analysis to edge format. # Usage: python process_3way_interaction.py output20160911.txt > edges.txt.interaction.wiggelab.timecourse # Create on 9 Aug 2019 by Hui Lan from geneid2name import make_gene_name_AGI_map_dict, get_gene_name def get_2tf_1target_1score(s): ''' s looks like 'AT1G73870_AT1G73870, AT5G10570_AT5G10570, AT2G05100_LHCB2.1 19.287 | 0.843 0.998 0.155 | -0.915 0.924 1.839 | 0.918 -0.419' ''' lst = s.split() tf1 = lst[0].split('_')[0] tf2 = lst[1].split('_')[0] target = lst[2].split('_')[0] score = lst[3] return (tf1, tf2, target, score) ## main import sys from datetime import datetime f = open(sys.argv[1]) lines = f.readlines() f.close() agi2name_dict = make_gene_name_AGI_map_dict('../Data/information/AGI-to-gene-names_v2.txt') result = '' for line in lines: line = line.strip() tf1, tf2, target, interaction_score_str = get_2tf_1target_1score(line) target_str = target + ' ' + get_gene_name(target, agi2name_dict) tf1_str = tf1 + ' ' + get_gene_name(tf1, agi2name_dict) tf2_str = tf2 + ' ' + get_gene_name(tf2, agi2name_dict) score_str = '0.5' cond_str = '.' curr_date = datetime.now().strftime('%Y%m%d') method_or_tissue = 'interact.with.%s' % (tf2 + '(' + get_gene_name(tf2, agi2name_dict) + ')') s = '\t'.join([target_str, tf1_str, score_str, 'mix', '15', cond_str, '.', curr_date, interaction_score_str.replace('-',''), method_or_tissue]) result += s + '\n' method_or_tissue = 'interact.with.%s' % (tf1 + '(' + get_gene_name(tf1, agi2name_dict) + ')') s = '\t'.join([target_str, tf2_str, score_str, 'mix', '15', cond_str, '.', curr_date, interaction_score_str.replace('-',''), method_or_tissue]) result += s + '\n' print(result)