-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPYF_dataProcess.py
63 lines (45 loc) · 1.95 KB
/
PYF_dataProcess.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
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
import pandas as pd
import operator as op
import MoNeT_MGDrivE as monet
def getPopRepsRatios(base, trace, gIx):
(basePop, tracePops) = (base['population'], trace['landscapes'])
ratioReps = [monet.getPopRatio(trace, basePop, gIx) for trace in tracePops]
ratioArr = np.asarray(ratioReps)
return ratioArr
def compRatioToThreshold(repsRatios, thld, cmprOp=op.lt):
thresholdArray = np.apply_along_axis(cmprOp, 0, repsRatios, thld)
return thresholdArray
def calcTTI(repRto, thiS):
thiSBool = [compRatioToThreshold(repRto, i, op.lt) for i in thiS]
ttiS = [np.argmax(thiBool == 1, axis=1) for thiBool in thiSBool]
return ttiS
def calcTTO(repRto, thoS):
(reps, days) = repRto.shape
thoSBool = [compRatioToThreshold(repRto, i, op.gt) for i in thoS]
ttoS = [np.subtract(days, np.argmin(np.flip(thoBool), axis=1)) for thoBool in thoSBool]
return ttoS
def calcWOP(repRto, thwS):
thwSBool = [compRatioToThreshold(repRto, i, op.lt) for i in thwS]
wopS = [np.sum(thwBool, axis=1) for thwBool in thwSBool]
return wopS
def calcMinMax(repRto):
(mni, mxi) = (repRto.min(axis=1), repRto.max(axis=1))
mnx = np.asarray([np.where(repRto[i] == mni[i])[0][0] for i in range(len(mni))])
mxx = np.asarray([np.where(repRto[i] == mxi[i])[0][0] for i in range(len(mxi))])
return ((mni, mnx), (mxi, mxx))
def getRatioAtTime(repRto, ttpS):
return np.asarray([repRto[:, ttp] for ttp in ttpS])
def initEmptyDFs(
fPaths, header, thiS, thoS, thwS, ttpS,
peak=['min', 'minx', 'max', 'maxx']
):
fNum = len(fPaths)
heads = [(list(header)+i) for i in (thiS, thoS, thwS, ttpS, peak)]
DFEmpty = [pd.DataFrame(int(0), index=range(fNum), columns=h) for h in heads]
return DFEmpty
def filterDFWithID(df, xpid):
xpidz = list(zip(list(df.columns)[:7], xpid))
filters = [df[i[0]] == i[1] for i in xpidz]
filter = list(map(all, zip(*filters)))
return df[filter]