-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeMatrices.py
More file actions
52 lines (42 loc) · 1.26 KB
/
MergeMatrices.py
File metadata and controls
52 lines (42 loc) · 1.26 KB
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
49
50
51
52
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
"""
Helper script to merge two tab-delimited matrices of the same dimensions.
Assumption is that they are both symmetrical across their main diagonal,
so merging them along this diagonal will produce a single matrix with
the combined similarity data of both. Output matrix file = imerged_sim.txt
"""
# IMPORTANT: Both matrices must be of the same dimensions, and tab-delimited
# The matrix produced by the ReuseMapper tool
iSim = open("itext_sim.txt", "r")
# Another similarity matrix, e.g. one produced by TextHeatmapper
tSim = open("dist_sim.txt", "r")
i = 0
mergedSim = []
for iLine in iSim:
iRow = iLine.strip().split("\t")
maxDim = len(iRow)
tLine = tSim.readline()
tRow = tLine.strip().split("\t")
mergedRow = []
for j in range(0,maxDim):
if (j <= i):
mergedRow.append(iRow[j])
else:
mergedRow.append(tRow[j])
mergedSim.append(mergedRow)
i += 1
with open("imerged_sim.txt", 'w') as tabFile:
for row in mergedSim:
rowData = [];
for col in row:
if ((col < .01) or (col == 0)):
colStr = "0";
else:
colStr = str(col)
rowData.append(colStr)
rowStr = "\t".join(rowData)
tabFile.write(rowStr + "\n");