summaryrefslogtreecommitdiff
path: root/Code/process_3way_interaction.py
blob: 0be9b59af45f460e3535c7f681c2b5bc8a565041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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 <lanhui@zjnu.edu.cn>

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)