forked from Ensembl/WiggleTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeProfileDirectory.py
50 lines (42 loc) · 1.07 KB
/
mergeProfileDirectory.py
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
#!/usr/bin/env python
import sys
import glob
import shutil
import wigglePlots
try:
target = sys.argv[1]
firstFile = True
array = None
files = glob.glob(target + "x/*")
if len(files) > 0:
# Scan through files and add up their profiles
for file in files:
for line in open(file):
items = line.strip().split('\t')
index = int(items[0])
value = float(items[1])
if firstFile and array is None:
array = [float(value)]
elif firstFile:
array.append(float(value))
else:
array[index] += float(value)
firstFile = False
if array is None:
# Create empty file with .empty suffix
open(target + ".empty", "w").close()
else:
# Write out results
file = open(target, 'w')
for index in range(len(array)):
file.write("%i\t%f\n" % (index, array[index]))
file.close()
# Do a little drawing
wigglePlots.make_profile_curve(target, target + ".png", format='png')
else:
# Create empty file with .empty suffix
open(target + ".empty", "w").close()
# Remove unnecessary files
shutil.rmtree(target + "x")
except:
sys.exit(100)