summaryrefslogtreecommitdiff
path: root/Code/process_3way_interaction.py
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2019-12-04 19:03:19 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2019-12-04 19:03:19 +0800
commit97fdefab064f63642fa3ece05b807d29b459df31 (patch)
treea058530023224f3e35b1783996f3530c80c04bc5 /Code/process_3way_interaction.py
brain: add python and R code to local repository.
Diffstat (limited to 'Code/process_3way_interaction.py')
-rw-r--r--Code/process_3way_interaction.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/Code/process_3way_interaction.py b/Code/process_3way_interaction.py
new file mode 100644
index 0000000..0be9b59
--- /dev/null
+++ b/Code/process_3way_interaction.py
@@ -0,0 +1,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)