-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunAll_Galaxy_Array.py
More file actions
214 lines (112 loc) · 5.5 KB
/
runAll_Galaxy_Array.py
File metadata and controls
214 lines (112 loc) · 5.5 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
## Python stuff
from array import array
import os
import math as mt
import numpy as np
import re
import argparse
from collections import defaultdict
import pandas as pd
import sys
import csv
import glob
import shutil
import os.path
#--- Options
parser = argparse.ArgumentParser(usage="python3 runAll_Galaxy_Array.py --inputdir ArrayData")
parser.add_argument('--inputdir',dest='inputdir',required=True)
args = parser.parse_args()
for filename in os.listdir(args.inputdir):
print('+++++++++++++++++++++++++++')
print(' NEXT FILE ')
print('+++++++++++++++++++++++++++')
print (filename)
filename_trunc = filename.split("_")[0]
print (filename_trunc)
array = filename_trunc
print (array)
command = ( "python3 Galaxy_raw_Data_Array_MTDDB.py --array {} --data {}".format( array , args.inputdir+"/"+filename) )
print (command)
os.system(command)
print('')
print('+++++++++++++++++++++++++++')
print(' MOVING FILES ')
print('+++++++++++++++++++++++++++')
#+++++++++++++++++++++++++++++++++++++++++++
# Moving files in different directories
#+++++++++++++++++++++++++++++++++++++++++++
path = os.chdir("/data/cmsdaq/DimensionBench/Arrays/ArrayData")
path = os.getcwd()
print('=====> Raw Data directory: ',os.path.basename(path))
res_path = os.path.join(os.getcwd(),"../ArrayData_results")
processed_path = os.path.join(os.getcwd(),"../ArrayData_processed")
output_path = os.path.join(os.getcwd(),"../ArrayData_output")
plot_path = os.path.join(os.getcwd(),"../ArrayData_plot")
print('=====> Results directory: ',os.path.basename(res_path))
if not os.path.isdir(res_path):
os.makedirs(res_path)
print('=====> Created ArrayData_results directory: ', os.path.basename(res_path))
else:
print('=====>',os.path.basename(res_path) ,'directory already exists!')
if not os.path.isdir(processed_path):
os.makedirs(processed_path)
print('=====> Created ArrayData_processed directory: ', os.path.basename(processed_path))
else:
print('=====>',os.path.basename(processed_path) ,'directory already exists!')
if not os.path.isdir(output_path):
os.makedirs(output_path)
print('=====> Created ArrayData_output directory: ', os.path.basename(output_path))
else:
print('=====>',os.path.basename(output_path) ,'directory already exists!')
if not os.path.isdir(plot_path):
os.makedirs(plot_path)
print('=====> Created ArrayData_output directory: ', os.path.basename(plot_path))
else:
print('=====>',os.path.basename(plot_path) ,'directory already exists!')
files = os.listdir(path)
for file in files:
filename = os.path.join(path, file)
filedest = os.path.join(res_path, file)
filedest1 = os.path.join(processed_path, file)
filedest2 = os.path.join(output_path, file)
filedest3 = os.path.join(plot_path, file)
if (filename.endswith('.csv') or filename.endswith('.json')):
print('+++++++++++++++++++++++++++++++++++++++++++++')
print('-----> Processing file: ',os.path.basename(filename))
if os.path.exists(filedest):
os.remove(filedest)
print('-----> Removing file: ', os.path.basename(filedest), 'from',os.path.basename(res_path),'as it exists!')
else:
print('-----> Can not delete the file',os.path.basename(filedest), "as it doesn't exist!")
shutil.move(filename, filedest)
print('-----> File', file ,'moved successfully to', os.path.basename(res_path) ,'directory')
elif (filename.endswith('.TXT')):
print('+++++++++++++++++++++++++++++++++++++++++++++')
print('-----> Processing file: ',os.path.basename(filename))
if os.path.exists(filedest1):
os.remove(filedest1)
print('-----> Removing file: ', os.path.basename(filedest1), 'from',os.path.basename(processed_path),'as it exists!')
else:
print('-----> Can not delete the file',os.path.basename(filedest1), "as it doesn't exist!")
shutil.move(filename, filedest1)
print('-----> File', file ,'moved successfully to', os.path.basename(processed_path) ,'directory')
elif (filename.endswith('.txt') or filename.endswith('.pdf')):
print('+++++++++++++++++++++++++++++++++++++++++++++')
print('-----> Processing file: ',os.path.basename(filename))
if os.path.exists(filedest2):
os.remove(filedest2)
print('-----> Removing file: ', os.path.basename(filedest2), 'from',os.path.basename(output_path),'as it exists!')
else:
print('-----> Can not delete the file',os.path.basename(filedest2), "as it doesn't exist!")
shutil.move(filename, filedest2)
print('-----> File', file ,'moved successfully to', os.path.basename(output_path) ,'directory')
elif (filename.endswith('.png')):
print('+++++++++++++++++++++++++++++++++++++++++++++')
print('-----> Processing file: ',os.path.basename(filename))
if os.path.exists(filedest3):
os.remove(filedest3)
print('-----> Removing file: ', os.path.basename(filedest3), 'from',os.path.basename(output_path),'as it exists!')
else:
print('-----> Can not delete the file',os.path.basename(filedest3), "as it doesn't exist!")
shutil.move(filename, filedest3)
print('-----> File', file ,'moved successfully to', os.path.basename(plot_path) ,'directory')