discotoolkit 1.1.1__tar.gz → 1.1.2__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.
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/PKG-INFO +1 -1
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/README.md +1 -1
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/CELLiD.py +49 -30
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/__init__.py +1 -1
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit.egg-info/PKG-INFO +1 -1
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/setup.py +1 -1
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/MANIFEST.in +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/CellMapper.py +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/DiscoClass.py +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/DownloadDiscoData.py +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/GeneSearch.py +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/GetMetadata.py +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit/GlobalVariable.py +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit.egg-info/SOURCES.txt +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit.egg-info/dependency_links.txt +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit.egg-info/requires.txt +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/discotoolkit.egg-info/top_level.txt +0 -0
- {discotoolkit-1.1.1 → discotoolkit-1.1.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: discotoolkit
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.2
|
|
4
4
|
Summary: DISCOtoolkit is an python package that allows users to access data and use the tools provided by the DISCO database.
|
|
5
5
|
Home-page: http://www.immunesinglecell.org/
|
|
6
6
|
Author: Li Mengwei, Rom Uddamvathanak
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
-->
|
|
9
9
|
[](https://discotoolkit-py.readthedocs.io/en/latest/?badge=latest) [](https://pepy.tech/project/discotoolkit) [](https://pypi.org/project/discotoolkit)
|
|
10
10
|
|
|
11
|
-
# DISCOtoolkit 1.1.
|
|
11
|
+
# DISCOtoolkit 1.1.2
|
|
12
12
|
|
|
13
13
|
DISCOtoolkit is an python package that allows users to access data and use the tools provided by the [DISCO database](https://www.immunesinglecell.org/). Read the documentation [DISCOtoolkit](https://discotoolkit-py.readthedocs.io/en/latest/). It provides the following functions:
|
|
14
14
|
|
|
@@ -214,14 +214,14 @@ def CELLiD_cluster(rna, ref_data : pd.DataFrame = None, ref_deg : pd.DataFrame =
|
|
|
214
214
|
Geneset enrichment analysis using DISCO data
|
|
215
215
|
"""
|
|
216
216
|
|
|
217
|
-
def CELLiD_enrichment(input : pd.DataFrame, reference : pd.DataFrame = None, ref_path : str = None, ncores : int =
|
|
217
|
+
def CELLiD_enrichment(input : pd.DataFrame, reference : pd.DataFrame = None, ref_path : str = None, ncores : int = 1):
|
|
218
218
|
"""Function to generate enrichment analysis based on the reference gene sets and following the DISCO pipeline.
|
|
219
219
|
|
|
220
220
|
Args:
|
|
221
221
|
input (Pandas DataFrame): User defined Dataframe in the format of `(gene, fc)`. `gene` refer to gene name and `fc` refer to log fold change.
|
|
222
222
|
reference (Pandas DataFrame, optional): Reference datasets from DISCO. Recommend to put as None as the function will automatically retrieve the dataset from the server. Defaults to None.
|
|
223
223
|
ref_path (String, optional): Path to the reference dataset or reading the file if it is existed. Defaults to None.
|
|
224
|
-
ncores (Integer, optional): Number of CPU cores to run the function. Defaults to
|
|
224
|
+
ncores (Integer, optional): Number of CPU cores to run the function. Defaults to 1.
|
|
225
225
|
|
|
226
226
|
Returns:
|
|
227
227
|
Pandas DataFrame: return the significant gene sets that is over-represented in a large set of genes.
|
|
@@ -270,39 +270,54 @@ def CELLiD_enrichment(input : pd.DataFrame, reference : pd.DataFrame = None, ref
|
|
|
270
270
|
|
|
271
271
|
# rename the name data to include the reference atlas
|
|
272
272
|
reference["name"] = reference["name"] + " in " + reference["atlas"]
|
|
273
|
-
|
|
273
|
+
input["gene"] = input["gene"].str.upper() # convert all the gene to upper string as the reference gene name is in uppercase
|
|
274
274
|
# condition when the user provide the fold change for the enrichment analysis
|
|
275
275
|
if input_shape == 2:
|
|
276
|
-
input["fc"]
|
|
277
|
-
input = input.set_index(
|
|
278
|
-
input["gene"]
|
|
279
|
-
input = input.loc[np.intersect1d(reference["gene"], input["gene"])] # only get the common genes for comparison
|
|
276
|
+
input["fc"] = 2 ** input["fc"] # 2 to the power of fc
|
|
277
|
+
input = input.set_index("gene", drop = False) # set index to the gene
|
|
278
|
+
input = input.loc[list(set(reference["gene"]) & set(input['gene']))] # only get the common genes for comparison
|
|
280
279
|
|
|
281
280
|
# else we only look at the ranked gene list
|
|
282
281
|
else:
|
|
283
|
-
input
|
|
284
|
-
input = input.loc[
|
|
285
|
-
|
|
282
|
+
input = input.set_index("gene", drop = False)
|
|
283
|
+
input = input.loc[list(set(reference["gene"]) & set(input['gene']))] # only get the common genes for comparison
|
|
286
284
|
# filter to get only the geneset that contain the input genes from the user
|
|
287
285
|
# this might good different result from the website so lets remove it for
|
|
288
286
|
# unique_names = reference[reference["gene"].isin(input["gene"])]["name"].unique()
|
|
289
|
-
unique_names = reference["name"].unique()
|
|
290
287
|
|
|
291
288
|
# now run the enrichment analysis
|
|
292
289
|
logging.info("Comparing the ranked gene list to reference gene sets...")
|
|
293
290
|
|
|
294
|
-
#
|
|
295
|
-
|
|
291
|
+
# optimise the CELLiD_enrichment function
|
|
292
|
+
atlas_dict = {}
|
|
293
|
+
name_dict = {}
|
|
294
|
+
reference_atlas = reference['atlas']
|
|
295
|
+
reference_name = reference['name']
|
|
296
296
|
|
|
297
|
+
# pre compute the parameters of the fisher exact test for the reference data
|
|
298
|
+
for rownum in range(len(reference)):
|
|
299
|
+
if reference_atlas[rownum] not in atlas_dict.keys():
|
|
300
|
+
atlas_dict[reference_atlas[rownum]] = [rownum]
|
|
301
|
+
else:
|
|
302
|
+
atlas_dict[reference_atlas[rownum]].append(rownum)
|
|
303
|
+
|
|
304
|
+
if reference_name[rownum] not in name_dict.keys():
|
|
305
|
+
name_dict[reference_name[rownum]] = [rownum]
|
|
306
|
+
else:
|
|
307
|
+
name_dict[reference_name[rownum]].append(rownum)
|
|
308
|
+
|
|
297
309
|
# apply function to the dataframe
|
|
298
|
-
def process_unique_name(
|
|
299
|
-
# use the
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
reference_filter[
|
|
305
|
-
|
|
310
|
+
def process_unique_name(reference_filter, input, atlas_dfs, input_shape, atlas_dict):
|
|
311
|
+
# use the compile`d pattern to search for matches
|
|
312
|
+
unique_name = reference_filter['name'].head(1).values[0]
|
|
313
|
+
atlas = reference_filter['atlas'].head(1).values
|
|
314
|
+
# print(unique_name)
|
|
315
|
+
reference_full = atlas_dfs[list(atlas_dict.keys()).index(atlas)]
|
|
316
|
+
# reference_filter = reference.iloc[name_dict[unique_name]].copy() # subset the reference data
|
|
317
|
+
# reference_full = reference.iloc[atlas_dict[atlas]].copy() # full reference to the atlas
|
|
318
|
+
reference_filter = reference_filter.set_index(["gene"], drop = False) # set gene as the index
|
|
319
|
+
# reference_filter["gene"] = reference_filter.index
|
|
320
|
+
input_filter = input.loc[list(set(reference_full["gene"]) & set(input["gene"]))] # subset the input genes
|
|
306
321
|
|
|
307
322
|
# condition for no passed gene set
|
|
308
323
|
if input_filter.empty:
|
|
@@ -319,24 +334,28 @@ def CELLiD_enrichment(input : pd.DataFrame, reference : pd.DataFrame = None, ref
|
|
|
319
334
|
b = len(np.setdiff1d(input_filter["gene"], reference_filter["gene"])) + 1
|
|
320
335
|
c = len(np.setdiff1d(reference_filter["gene"], input_filter["gene"])) + 1
|
|
321
336
|
d = len(set(reference_full["gene"])) - a - b - c
|
|
322
|
-
|
|
337
|
+
|
|
323
338
|
# get both value from the fisher exact test
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
# odds = odds_ratio(a, b, c, d)
|
|
328
|
-
|
|
339
|
+
# pval = pvalue(a, b, c, d).two_tail
|
|
340
|
+
_, pval = stats.fisher_exact(np.array([[a, b], [c, d]]))
|
|
341
|
+
odds = (a * d)/(b * c)
|
|
329
342
|
# only get the significant p_value
|
|
330
343
|
# we can make changes to the p_value as in like we allow the user to specify it so that they have more control on the result they can obtain
|
|
331
|
-
if
|
|
332
|
-
return pd.Series({"pval":
|
|
344
|
+
if pval < 0.01:
|
|
345
|
+
return pd.Series({"pval": pval, "or": odds, "name": unique_name,
|
|
333
346
|
"gene": ",".join(reference_filter.loc[reference_filter["gene"].isin(input_filter["gene"]), "gene"]),
|
|
334
347
|
"background": len(set(reference_full["gene"])), "overlap": len(reference_filter.loc[reference_filter["gene"].isin(input_filter["gene"])]), "geneset": len(reference_filter)})
|
|
335
348
|
else:
|
|
336
349
|
return None
|
|
337
350
|
|
|
351
|
+
# Split them into cores
|
|
352
|
+
unique_name_dfs = [reference.iloc[name_dict[key], :] for key in name_dict.keys()]
|
|
353
|
+
atlas_dfs = [reference.iloc[atlas_dict[key], :] for key in atlas_dict.keys()]
|
|
354
|
+
|
|
355
|
+
# return unique_name_dfs, atlas_dfs, input, input_shape
|
|
356
|
+
# return unique_name_dfs, atlas_dfs
|
|
338
357
|
# using joblib to apply multiprocessing
|
|
339
|
-
results = Parallel(n_jobs=ncores,
|
|
358
|
+
results = Parallel(n_jobs=ncores, verbose = 2, batch_size = 64)(delayed(process_unique_name)(unique_name_df, input, atlas_dfs, input_shape, atlas_dict) for unique_name_df in unique_name_dfs)
|
|
340
359
|
results = [res for res in results if res is not None]
|
|
341
360
|
|
|
342
361
|
# concatenate the result into the dataframe to the user
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: discotoolkit
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.2
|
|
4
4
|
Summary: DISCOtoolkit is an python package that allows users to access data and use the tools provided by the DISCO database.
|
|
5
5
|
Home-page: http://www.immunesinglecell.org/
|
|
6
6
|
Author: Li Mengwei, Rom Uddamvathanak
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|