immucellai2 2.1.33__tar.gz → 2.1.34__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {immucellai2-2.1.33 → immucellai2-2.1.34}/PKG-INFO +1 -1
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/Deconvolution.py +50 -113
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/ObtainCategory.py +1 -1
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/PrepareData.py +18 -17
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/myclasses.py +18 -21
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2.egg-info/PKG-INFO +1 -1
- {immucellai2-2.1.33 → immucellai2-2.1.34}/setup.cfg +1 -1
- {immucellai2-2.1.33 → immucellai2-2.1.34}/README.md +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/Drawplot.py +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/Time.py +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/__init__.py +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/myconfig/Celltype.category +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/myconfig/MarkerUsedDeconvolution.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/myconfig/reference_normalCelltypes.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/myconfig/reference_tumorCelltypes.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2.egg-info/SOURCES.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2.egg-info/dependency_links.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2.egg-info/entry_points.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2.egg-info/requires.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2.egg-info/top_level.txt +0 -0
- {immucellai2-2.1.33 → immucellai2-2.1.34}/pyproject.toml +0 -0
|
@@ -8,9 +8,13 @@ from immucellai2.myclasses import CLASS_FOR_RUN, CLASS_FOR_RUNRESULT, CLASS_FOR_
|
|
|
8
8
|
import scipy
|
|
9
9
|
import os
|
|
10
10
|
import tqdm
|
|
11
|
+
import joblib
|
|
12
|
+
import dask
|
|
13
|
+
import dask.delayed
|
|
14
|
+
import dask.multiprocessing
|
|
15
|
+
from dask.distributed import Client, LocalCluster
|
|
11
16
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
12
17
|
from itertools import chain
|
|
13
|
-
import joblib
|
|
14
18
|
import multiprocessing
|
|
15
19
|
from copy import deepcopy
|
|
16
20
|
|
|
@@ -22,7 +26,6 @@ class Move:
|
|
|
22
26
|
raise NotImplementedError
|
|
23
27
|
def propose(self, state, random_state):
|
|
24
28
|
raise NotImplementedError
|
|
25
|
-
|
|
26
29
|
class GibbsMHMove(Move):
|
|
27
30
|
def __init__(self, phi, alpha, sp):
|
|
28
31
|
self.phi = phi
|
|
@@ -34,13 +37,12 @@ class GibbsMHMove(Move):
|
|
|
34
37
|
q, _ = self.get_proposal(state.coords, random_state)
|
|
35
38
|
new_state = State(q)
|
|
36
39
|
return new_state, np.ones(state.coords.shape[0], dtype=bool)
|
|
37
|
-
|
|
38
40
|
def gibbs_proposal_function(coords, random, phi, alpha, sp):
|
|
39
41
|
min_threshold = 1e-6
|
|
40
42
|
updated_coords = np.copy(coords)
|
|
41
43
|
column_sums = np.sum(phi, axis=0)
|
|
42
44
|
normalized_matrix = phi / column_sums
|
|
43
|
-
G, K = normalized_matrix.shape
|
|
45
|
+
G, K = normalized_matrix.shape # ʹ�� normalized_matrix ����״
|
|
44
46
|
for n in range(len(coords)):
|
|
45
47
|
theta_n = updated_coords[n, :]
|
|
46
48
|
prob_mat = np.multiply(normalized_matrix, theta_n)
|
|
@@ -48,7 +50,7 @@ def gibbs_proposal_function(coords, random, phi, alpha, sp):
|
|
|
48
50
|
for g in range(G):
|
|
49
51
|
row_sum = np.sum(prob_mat[g, :]) # ʹ�� NumPy ���������к�
|
|
50
52
|
pvals = np.full(K, 1/K) if row_sum < min_threshold else prob_mat[g, :] / row_sum
|
|
51
|
-
Z_n.append(
|
|
53
|
+
Z_n.append(np.random.multinomial(n=round(sp[g]), pvals=pvals))
|
|
52
54
|
Z_nk = np.sum(Z_n, axis=0)
|
|
53
55
|
alpha_param = Z_nk + alpha
|
|
54
56
|
updated_coords[n, :] = np.random.dirichlet(alpha=alpha_param)
|
|
@@ -64,7 +66,7 @@ class EnsembleSampler:
|
|
|
64
66
|
self.alpha_value = alpha_value
|
|
65
67
|
self.sp_value = sp_value
|
|
66
68
|
self.backend = Backend(nwalkers=nwalkers, ndim=ndim, iterations=iterations)
|
|
67
|
-
self.
|
|
69
|
+
self._random = np.random.mtrand.RandomState()
|
|
68
70
|
def sample(self, initial_state, iterations=1, progress=False, progress_kwargs=None):
|
|
69
71
|
if progress_kwargs is None:
|
|
70
72
|
progress_kwargs = {}
|
|
@@ -126,101 +128,36 @@ def get_progress_bar(display, total, **kwargs):
|
|
|
126
128
|
return getattr(tqdm, "tqdm_" + display)(total=total, **kwargs)
|
|
127
129
|
return _NoOpPBar()
|
|
128
130
|
|
|
129
|
-
'''
|
|
130
|
-
def mcse_python(samples):
|
|
131
|
-
n_iter, n_dim = samples.shape
|
|
132
|
-
mcse_vec = np.empty(n_dim)
|
|
133
|
-
for k in range(n_dim):
|
|
134
|
-
x = samples[:, k]
|
|
135
|
-
rho = np.correlate(x - x.mean(), x - x.mean(), mode='full')
|
|
136
|
-
rho = rho[n_iter - 1:] / rho[n_iter - 1]
|
|
137
|
-
lag = next((i for i, r in enumerate(rho[1:], 1) if r < 0.05), n_iter)
|
|
138
|
-
ess = n_iter / (1 + 2 * rho[1:lag + 1].sum())
|
|
139
|
-
mcse_vec[k] = np.std(x, ddof=1) / np.sqrt(ess)
|
|
140
|
-
return mcse_vec
|
|
141
|
-
def mcse_python(segment):
|
|
142
|
-
return np.std(segment, axis=0) / np.sqrt(len(segment))
|
|
143
131
|
def ThreadRunEachSamples(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
SampleExpressionData = None,
|
|
147
|
-
SampleName=None,
|
|
148
|
-
MAPorMLE = ('MAP','MLE'),
|
|
149
|
-
*args):
|
|
150
|
-
samplename = SampleName
|
|
151
|
-
phi_value = referenceMatrix
|
|
152
|
-
alpha_value = 1
|
|
153
|
-
sp_value = SampleExpressionData
|
|
154
|
-
K = EmceeParameters.ndims
|
|
155
|
-
rng = np.random.RandomState(seed)
|
|
156
|
-
max_iter = EmceeParameters.nsteps
|
|
157
|
-
nwalkers = EmceeParameters.nwalkers
|
|
158
|
-
tol_ratio = 0.01
|
|
159
|
-
eval_step = 50
|
|
160
|
-
theta = EmceeParameters.position
|
|
161
|
-
if theta.ndim == 1:
|
|
162
|
-
theta = theta.reshape(nwalkers, K)
|
|
163
|
-
else:
|
|
164
|
-
theta = theta[:nwalkers, :K]
|
|
165
|
-
full_chain = np.zeros((max_iter, nwalkers, K))
|
|
166
|
-
converged = False
|
|
167
|
-
converged_step = None
|
|
168
|
-
for i in range(max_iter):
|
|
169
|
-
gibbs_move = GibbsMHMove(phi_value, alpha_value, sp_value)
|
|
170
|
-
state, _ = gibbs_move.propose(State(theta), rng)
|
|
171
|
-
theta = state.coords
|
|
172
|
-
full_chain[i] = theta
|
|
173
|
-
if (i + 1) % eval_step == 0 and i + 1 >= eval_step:
|
|
174
|
-
segment = full_chain[(i + 1 - eval_step): (i + 1)].reshape(-1, K)
|
|
175
|
-
mcse_vec = mcse_python(segment)
|
|
176
|
-
theta_hat = segment.mean(axis=0)
|
|
177
|
-
theta_hat_safe = np.where(theta_hat == 0, 1e-10, theta_hat)
|
|
178
|
-
ratio = mcse_vec / theta_hat_safe
|
|
179
|
-
if np.all(np.abs(ratio) <= tol_ratio):
|
|
180
|
-
converged = True
|
|
181
|
-
converged_step = i + 1
|
|
182
|
-
break
|
|
183
|
-
if converged and converged_step is not None:
|
|
184
|
-
start_step = max(0, converged_step - 100)
|
|
185
|
-
truncated_chain = full_chain[start_step:converged_step]
|
|
186
|
-
else:
|
|
187
|
-
start_step = max(0, max_iter - 100)
|
|
188
|
-
truncated_chain = full_chain[start_step:max_iter]
|
|
189
|
-
flat_samples = truncated_chain.reshape(-1, K)
|
|
190
|
-
return full_chain, flat_samples'''
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def ThreadRunEachSamples(
|
|
194
|
-
EmceeParameters = None, referenceMatrix = None,
|
|
195
|
-
SampleExpressionData = None, SampleName=None, MAPorMLE = ('MAP','MLE'), *args):
|
|
132
|
+
EmceeParameters = None, referenceMatrix = None,
|
|
133
|
+
SampleExpressionData = None, SampleName=None, MAPorMLE = ('MAP','MLE'), *args):
|
|
196
134
|
nwalkers, ndims = EmceeParameters.nwalkers, EmceeParameters.ndims
|
|
197
135
|
position, nsteps = EmceeParameters.position, EmceeParameters.nsteps
|
|
198
|
-
discard, thin = EmceeParameters.discard, EmceeParameters.thin
|
|
136
|
+
discard, thin = EmceeParameters.discard, EmceeParameters.thin
|
|
199
137
|
samplename = SampleName
|
|
200
|
-
phi_value = referenceMatrix
|
|
201
|
-
alpha_value = 1
|
|
202
|
-
sp_value = SampleExpressionData
|
|
203
|
-
print(" create new threading for sample '%s'"%str(samplename))
|
|
204
|
-
if MAPorMLE == 'MAP':
|
|
138
|
+
phi_value = referenceMatrix
|
|
139
|
+
alpha_value = 1
|
|
140
|
+
sp_value = SampleExpressionData
|
|
141
|
+
print(" create new threading for sample '%s'"%str(samplename))
|
|
142
|
+
if MAPorMLE == 'MAP':
|
|
205
143
|
sampler = EnsembleSampler(nwalkers, ndims, phi_value, alpha_value, sp_value)
|
|
206
144
|
sampler.run_mcmc(position, nsteps, progress=True)
|
|
207
145
|
mcmc_samples, flat_samples = [[[]]], [[]]
|
|
208
146
|
mcmc_samples = sampler.get_chain()
|
|
209
147
|
flat_samples = sampler.get_chain( discard = discard, thin = thin, flat = True)
|
|
210
148
|
print( "Threading for sample '%s' run over, exiting..."%str(samplename))
|
|
211
|
-
return mcmc_samples, flat_samples
|
|
212
|
-
|
|
149
|
+
return mcmc_samples, flat_samples
|
|
150
|
+
|
|
213
151
|
class MultiprocessesResult(object):
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
152
|
+
def __init__(self, SampleName, SamplingResult, CellType):
|
|
153
|
+
self.SampleName = SampleName
|
|
154
|
+
self.CellTypeList = CellType
|
|
155
|
+
self.ResultObjectOne = CLASS_FOR_RUNRESULT(
|
|
156
|
+
SampleNameList = [ self.SampleName ] ,
|
|
157
|
+
McmcSamplingResultList = np.array([ SamplingResult[0] ]) ,
|
|
158
|
+
FlatSamplingResultList = np.array([ SamplingResult[1] ]) ,
|
|
159
|
+
CellTypeList = CellType
|
|
160
|
+
)
|
|
224
161
|
def MergeResultsForAllSample(ThreadList=list(), OtherParams=[], *args):
|
|
225
162
|
print("Merge all results from deconvolution into one ResultObject...")
|
|
226
163
|
if len(ThreadList) < 1:
|
|
@@ -243,34 +180,35 @@ def MergeResultsForAllSample(ThreadList=list(), OtherParams=[], *args):
|
|
|
243
180
|
FileCellTypeCategory = OtherParams[1]
|
|
244
181
|
# Creating the final merged result object
|
|
245
182
|
MergeResultsObject = CLASS_FOR_RUNRESULT(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
183
|
+
SampleNameList=SampleNameWhole,
|
|
184
|
+
CellTypeList=CellTypeWhole,
|
|
185
|
+
FileCellTypeCategory=FileCellTypeCategory,
|
|
186
|
+
McmcSamplingResultList=McmcSamplingWhole,
|
|
187
|
+
FlatSamplingResultList=FlatSamplingWhole,
|
|
188
|
+
CellTypeRatioResult=CellTypeRatioResultWhole,
|
|
189
|
+
CellTypeRatioResultFinal=CellTypeRatioResultFinalWhole)
|
|
253
190
|
return MergeResultsObject
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
EnvironmentRun = RunObject.EnvironmentRun
|
|
191
|
+
def MainRun(RunObject, seed = 42, MultithreadModule = 'joblib'):
|
|
192
|
+
EnvironmentRun = RunObject.EnvironmentRun
|
|
257
193
|
RecordTime = CLASS_FOR_TIME()
|
|
258
194
|
nsamples = len(RunObject.SampleList)
|
|
195
|
+
EmceeParameterCopy = RunObject.EmceeParameter.mycopy()
|
|
196
|
+
CelltypesReferenceMatrix = RunObject.CelltypesReferenceMatrix
|
|
259
197
|
SampleNameToIndex = {name: idx for idx, name in enumerate(RunObject.SampleList)}
|
|
260
|
-
parameterlist = []
|
|
198
|
+
parameterlist = []
|
|
261
199
|
for SampleNameii in range(nsamples):
|
|
262
200
|
SampleName = RunObject.SampleList[SampleNameii]
|
|
263
|
-
SampleIndex = SampleNameToIndex[SampleName]
|
|
201
|
+
SampleIndex = SampleNameToIndex[SampleName] # ��ȡ����
|
|
264
202
|
parameterlist.append((
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
RunObject.SamplesBulkRNAseqExpression[SampleIndex],
|
|
203
|
+
EmceeParameterCopy,
|
|
204
|
+
CelltypesReferenceMatrix,
|
|
205
|
+
RunObject.SamplesBulkRNAseqExpression[SampleIndex], # ʹ��������������
|
|
268
206
|
SampleName,
|
|
269
207
|
RunObject.MAPorMLE
|
|
270
208
|
))
|
|
271
|
-
MultiprocessingReturnValue = []
|
|
209
|
+
MultiprocessingReturnValue = []
|
|
272
210
|
if MultithreadModule == 'joblib':
|
|
273
|
-
try:
|
|
211
|
+
try:
|
|
274
212
|
MultiprocessingReturnValue = joblib.Parallel(n_jobs=int(EnvironmentRun.ThreadNum), backend='loky',verbose=0)(joblib.delayed(ThreadRunEachSamples)(*arg) for arg in parameterlist)
|
|
275
213
|
except:
|
|
276
214
|
print('error occurs while paralleling')
|
|
@@ -288,15 +226,14 @@ def MainRun(RunObject, seed=42, MultithreadModule = 'joblib'):
|
|
|
288
226
|
pool.join()
|
|
289
227
|
print('Finished all!')
|
|
290
228
|
MergedResultObject = MergeResultsForAllSample(
|
|
291
|
-
ThreadList = [MultiprocessesResult(
|
|
292
|
-
SampleName = RunObject.SampleList[Sampleii],
|
|
293
|
-
SamplingResult = MultiprocessingReturnValue[Sampleii],
|
|
229
|
+
ThreadList = [MultiprocessesResult(
|
|
230
|
+
SampleName = RunObject.SampleList[Sampleii],
|
|
231
|
+
SamplingResult = MultiprocessingReturnValue[Sampleii],
|
|
294
232
|
CellType=deepcopy(RunObject.CellType),
|
|
295
233
|
) for Sampleii in range(len(MultiprocessingReturnValue))],
|
|
296
234
|
OtherParams=[deepcopy(RunObject.CellType), RunObject.FileCellTypeCategory]
|
|
297
|
-
)
|
|
235
|
+
)
|
|
298
236
|
RecordTime.ShowCostTime()
|
|
299
|
-
if os.path.exists("TempThread"):
|
|
300
|
-
os.system("rm -rf TempThread")
|
|
237
|
+
if os.path.exists("TempThread"): os.system("rm -rf TempThread")
|
|
301
238
|
print("###<----Main program Run finished...")
|
|
302
239
|
return MergedResultObject
|
|
@@ -49,7 +49,7 @@ def ObtainInformation2(line, SearchString, DictValue):
|
|
|
49
49
|
else:
|
|
50
50
|
DictValue[SearchString] = obcontent
|
|
51
51
|
|
|
52
|
-
def
|
|
52
|
+
def ObtainCellTypeCategory(CellTypeCateogry):
|
|
53
53
|
if CellTypeCateogry is None or not os.path.isfile(CellTypeCateogry):
|
|
54
54
|
try:
|
|
55
55
|
from importlib.resources import files
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/python3
|
|
2
|
-
from
|
|
3
|
-
from
|
|
2
|
+
from .myclasses import CLASS_FOR_RUN
|
|
3
|
+
from .ObtainCategory import ObtainCellTypeCategory
|
|
4
4
|
import pandas
|
|
5
5
|
import os
|
|
6
|
+
import importlib.util
|
|
6
7
|
import re
|
|
7
8
|
import sys
|
|
8
9
|
import multiprocessing as mp
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
def Obtainmyconfigpath():
|
|
12
|
+
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
13
|
+
return os.path.join(script_dir, "immucellai2", "myconfig", "")
|
|
10
14
|
|
|
11
15
|
def get_package_dir(package_name):
|
|
12
16
|
spec = importlib.util.find_spec(package_name)
|
|
13
17
|
if spec is None:
|
|
14
18
|
raise ModuleNotFoundError(f"Package '{package_name}' not found")
|
|
15
19
|
path = spec.origin or spec.submodule_search_locations[0]
|
|
16
|
-
return os.path.dirname(path)
|
|
20
|
+
return os.path.dirname(path)
|
|
17
21
|
|
|
18
22
|
def SelectGeneForDeconvolution(DFReferenceProfile, FileCoveredGenes="", Method="UsedMarker"):
|
|
19
23
|
print("Select the gene for the following deconvolution...")
|
|
@@ -29,10 +33,6 @@ def SelectGeneForDeconvolution(DFReferenceProfile, FileCoveredGenes="", Method="
|
|
|
29
33
|
GeneUsedForDeconvolution = list(set(GeneUsedForDeconvolution0).intersection(set(DFReferenceProfileGenes)))
|
|
30
34
|
return GeneUsedForDeconvolution
|
|
31
35
|
|
|
32
|
-
def Obtainmyconfigpath():
|
|
33
|
-
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
34
|
-
return os.path.join(script_dir, "immucellai2", "myconfig", "")
|
|
35
|
-
|
|
36
36
|
def CelltypeCategoryCheck(FileCellTypeCategory = "", celltypelist = [] ):
|
|
37
37
|
print("Check the Celltype covered by configfile")
|
|
38
38
|
if FileCellTypeCategory == "":
|
|
@@ -67,11 +67,11 @@ def InitialCellTypeRatioCheck(InitialCellTypeRatio, FileInitialCellTypeRatio = "
|
|
|
67
67
|
elif Expactedcelltypenum in [ ncelltype, ncelltype -1 ]:
|
|
68
68
|
return FileInitialCellTypeRatio
|
|
69
69
|
else:
|
|
70
|
-
InitialCellTypeRatio = 'randn'
|
|
70
|
+
InitialCellTypeRatio = 'randn'
|
|
71
71
|
|
|
72
72
|
def PrepareData(FileReferenceProfile ,
|
|
73
73
|
FileSampleExpressionProfile ,
|
|
74
|
-
EnvironmentConfig = "" ,
|
|
74
|
+
EnvironmentConfig = ("", "") ,
|
|
75
75
|
FileCoveredGenes = "" ,
|
|
76
76
|
FileCellTypeCategory = "" ,
|
|
77
77
|
FileInitialCellTypeRatio = "" ,
|
|
@@ -80,26 +80,27 @@ def PrepareData(FileReferenceProfile ,
|
|
|
80
80
|
if FileReferenceProfile.shape[1] < 2:
|
|
81
81
|
print("warning: When open Reference File, might sep = ' ' not '\t'")
|
|
82
82
|
print("celltype reference raw matrix:\n", FileReferenceProfile.iloc[0:4, 0:4])
|
|
83
|
-
ReferenceCelltype = {}
|
|
83
|
+
ReferenceCelltype = {}
|
|
84
84
|
for oneCellType in FileReferenceProfile.columns.values.tolist():
|
|
85
85
|
numbertail = re.findall("\.[0-9]*$", oneCellType)
|
|
86
86
|
oneCellType0 = oneCellType
|
|
87
87
|
if numbertail != []: oneCellType = oneCellType[:-len(numbertail)]
|
|
88
|
-
if oneCellType in ReferenceCelltype.keys():
|
|
88
|
+
if oneCellType in ReferenceCelltype.keys():
|
|
89
89
|
ReferenceCelltype[oneCellType].append(ReferenceCelltype[oneCellType])
|
|
90
90
|
else: ReferenceCelltype[oneCellType] = [oneCellType0]
|
|
91
91
|
DFReferenceProfile = pandas.DataFrame(columns = list(ReferenceCelltype.keys()),
|
|
92
92
|
index = FileReferenceProfile.index.values)
|
|
93
93
|
for celltype in DFReferenceProfile.columns.values:
|
|
94
|
-
DFReferenceProfile[celltype] = (
|
|
94
|
+
DFReferenceProfile[celltype] = (
|
|
95
95
|
FileReferenceProfile.loc[:, ReferenceCelltype[celltype] ]).mean(axis = 1)
|
|
96
|
-
print("celltype reference matrix:\n", DFReferenceProfile.iloc[0:4, 0:4])
|
|
96
|
+
print("celltype reference matrix:\n", DFReferenceProfile.iloc[0:4, 0:4])
|
|
97
97
|
DFSampleExpressionProfile = pandas.read_table(FileSampleExpressionProfile, sep = "\t", header = 0, index_col = 0)
|
|
98
|
-
print(" initialize a Object For running...")
|
|
99
|
-
print("environment config(threads): ", EnvironmentConfig)
|
|
98
|
+
print(" initialize a Object For running...")
|
|
99
|
+
print("environment config(cpus, threads): ", EnvironmentConfig)
|
|
100
100
|
GeneUsedForDeconvolution = SelectGeneForDeconvolution(DFReferenceProfile)
|
|
101
101
|
#FileCellTypeCategory = CelltypeCategoryCheck(FileCellTypeCategory, celltypelist = list(ReferenceCelltype.keys()))
|
|
102
|
-
FileInitialCellTypeRatio = InitialCellTypeRatioCheck(InitialCellTypeRatio,
|
|
102
|
+
FileInitialCellTypeRatio = InitialCellTypeRatioCheck(InitialCellTypeRatio,
|
|
103
|
+
FileInitialCellTypeRatio, ncelltype = DFReferenceProfile.shape[1])
|
|
103
104
|
DFReferenceProfile0 = DFReferenceProfile.loc[GeneUsedForDeconvolution, ]
|
|
104
105
|
DFReferenceProfile0 = DFReferenceProfile0[DFReferenceProfile0.index.isin(DFSampleExpressionProfile.index)]
|
|
105
106
|
selected_DFSampleExpressionProfile = DFSampleExpressionProfile.loc[DFReferenceProfile0.index]
|
|
@@ -103,15 +103,15 @@ class CLASS_FOR_RUNRESULT(object):
|
|
|
103
103
|
return FlatSamplingResultOne / FlatSamplingResultOne.sum(axis=1)[:, None]
|
|
104
104
|
elif FlatSamplingResultOne.shape[1] + 1 == nCellType:
|
|
105
105
|
return numpy.column_stack((FlatSamplingResultOne, 1 - FlatSamplingResultOne.sum(axis=1)))
|
|
106
|
-
def EmceeFunction2(self, FlatSamplingResultList):
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
def EmceeFunction2(self, FlatSamplingResultList):
|
|
107
|
+
fshape = FlatSamplingResultList.shape
|
|
108
|
+
nCellType = len(self.CellType)
|
|
109
|
+
NewFlatSamplingResultList = numpy.zeros((fshape[0], fshape[1], nCellType))
|
|
110
|
+
for sampleii in range(fshape[0]):
|
|
111
|
+
FlatSamplingResultOne = FlatSamplingResultList[sampleii, :, :]
|
|
112
|
+
NewFlatSamplingResultOne = self.optimized_calculation(FlatSamplingResultOne, nCellType)
|
|
113
|
+
NewFlatSamplingResultList[sampleii, :, :] = NewFlatSamplingResultOne
|
|
114
|
+
return NewFlatSamplingResultList
|
|
115
115
|
def CalculateCellTypeRatio(self):
|
|
116
116
|
CellTypeRatioResult = pandas.DataFrame(numpy.zeros(( len(self.SampleName),
|
|
117
117
|
len(self.CellType) )),
|
|
@@ -127,7 +127,7 @@ class CLASS_FOR_RUNRESULT(object):
|
|
|
127
127
|
CellTypeRatioResult.loc[SampleNameOne, ] = FlatSamplingAverageOne
|
|
128
128
|
FinalSampling = self.McmcSamplingResult[Oneii, -1, :, :]
|
|
129
129
|
CellTypeRatioResultFinal.loc[SampleNameOne, ] = numpy.mean(FinalSampling, axis = 0)
|
|
130
|
-
return CellTypeRatioResult, CellTypeRatioResultFinal
|
|
130
|
+
return CellTypeRatioResult, CellTypeRatioResultFinal
|
|
131
131
|
def CalculateRatioOld(self):
|
|
132
132
|
CellTypeRatioResult = pandas.DataFrame([[]], columns = self.CellType, index = self.SampleName )
|
|
133
133
|
for Oneii in range(len(self.FlatSamplingResult)):
|
|
@@ -135,19 +135,19 @@ class CLASS_FOR_RUNRESULT(object):
|
|
|
135
135
|
SampleNameOne = self.SampleName[Oneii]
|
|
136
136
|
CellTypeRatioOne = list()
|
|
137
137
|
for ii in range(len(self.Celltype)):
|
|
138
|
-
|
|
139
|
-
CellTypeRatioResult.loc[SampleNameOne
|
|
138
|
+
CellTypeRatioOne.append((FlatSamplingOne[:, :, ii].sum(axis =1))[1])
|
|
139
|
+
CellTypeRatioResult.loc[SampleNameOne,] = CellTypeRatioOne
|
|
140
140
|
return CellTypeRatioResult
|
|
141
141
|
def save_result(self, FilenameToSave, ResultIndex = 0):
|
|
142
142
|
DataCelltypeRatio = self.get_result( ResultIndex = ResultIndex )
|
|
143
143
|
(DataCelltypeRatio.T).to_excel(FilenameToSave, index = True, header = True)
|
|
144
144
|
def get_result(self, ResultIndex = 0):
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
if ResultIndex == 0:
|
|
146
|
+
return self.CellTypeRatioResult
|
|
147
|
+
elif ResultIndex == 1:
|
|
148
|
+
return self.CellTypeRatioResultFinal
|
|
149
|
+
else:
|
|
150
|
+
pass
|
|
151
151
|
@property
|
|
152
152
|
def CellTypeCateogryContent(self):
|
|
153
153
|
return self._CellTypeCateogryContent
|
|
@@ -156,7 +156,6 @@ class CLASS_FOR_RUNRESULT(object):
|
|
|
156
156
|
self._CellTypeCateogryContent = CellTypeCateogryContent
|
|
157
157
|
del self.FileCellTypeCategory
|
|
158
158
|
|
|
159
|
-
|
|
160
159
|
class CLASS_FOR_EMCEEPARAMETER(object):
|
|
161
160
|
def __init__(self, position, CellType = list(), nsteps = 1000,
|
|
162
161
|
nwalkers = 1,
|
|
@@ -242,6 +241,4 @@ class CLASS_ENVIRONMENT_CONFIG(object):
|
|
|
242
241
|
def __init__(self, Environment):
|
|
243
242
|
self.ThreadNum = Environment
|
|
244
243
|
|
|
245
|
-
|
|
246
244
|
|
|
247
|
-
#exmaples1 = CLASSONE(111)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{immucellai2-2.1.33 → immucellai2-2.1.34}/immucellai2/myconfig/reference_normalCelltypes.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|