An error occurred while loading the file. Please try again.
-
Fize Jacques authoredb69badf3
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
# coding = utf-8
import numpy as np
import argparse, json, os, re, sys, glob, time
from strpython.helpers.sim_matrix import matrix_to_pandas_dataframe, read_bz2_matrix
script_beg=time.time()
def _path(string):
if os.path.exists(string):
return string
else:
raise FileNotFoundError(string)
parser = argparse.ArgumentParser()
parser.add_argument("matricesDir", type=_path)
parser.add_argument("selectedFile", type=_path)
parser.add_argument("outputDir")
args = parser.parse_args()
if not os.path.isdir(args.outputDir):
try:
os.makedirs(args.outputDir)
except:
raise InterruptedError("Cannot create {0} dir".format(args.outputDir))
matrix_fns = glob.glob(os.path.join(args.matricesDir, "*.npy.bz2"))
selected = json.load(open(args.selectedFile))
for fn in matrix_fns:
measure = os.path.basename(fn).split("_")[0]
if os.path.basename(fn).split("_")[-2] in ["extension","gen"]:
type_ = "_".join(os.path.basename(fn).split("_")[-2:]).replace(".npy.bz2", "")
else:
type_ = os.path.basename(fn).split("_")[-1].replace(".npy.bz2", "")
print("Proceeding...",measure, type_)
df = matrix_to_pandas_dataframe(np.nan_to_num(read_bz2_matrix(fn)),
selected,
measure, type_)
df.to_csv(os.path.join(args.outputDir,"{0}_{1}.csv".format(measure,type_)))
print("The script took {0}s to finish".format(time.time()-script_beg))