cfi-toolkit 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,736 @@
1
+ Metadata-Version: 2.4
2
+ Name: cfi-toolkit
3
+ Version: 0.1.0
4
+ Summary: CFI: Cell Functionality and Interaction Analysis Tool
5
+ License: GPL-3
6
+ License-File: LICENSE
7
+ Keywords: scRNA_seq,SEQ,GO,pathways,interactions,gene ontology,diseases,enrichment,OMIC
8
+ Author: Jakub Kubis - JBS
9
+ Author-email: jbiosystem@gmail.com
10
+ Requires-Python: >=3.12,<3.13
11
+ Classifier: License :: Other/Proprietary License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: gedspy (>=2.1.9,<3.0.0)
15
+ Requires-Dist: jdti (>=0.2.2,<0.3.0)
16
+ Requires-Dist: jvectorgraph (>=1.0.2,<2.0.0)
17
+ Requires-Dist: llvmlite (>=0.46.0,<0.47.0)
18
+ Requires-Dist: pandas (<3.0.0)
19
+ Project-URL: Homepage, https://github.com/jkubis96/CFI
20
+ Project-URL: Repository, https://github.com/jkubis96/CFI
21
+ Description-Content-Type: text/markdown
22
+
23
+ ## CFI: Cell Functionality and Interaction Analysis Tool
24
+
25
+ ![Python version](https://img.shields.io/badge/python-%E2%89%A53.12-blue?logo=python&logoColor=white.png) ![License](https://img.shields.io/badge/license-GPLv3-blue) ![Docs](https://img.shields.io/badge/docs-available-blueviolet)
26
+
27
+
28
+
29
+
30
+ <p align="right">
31
+ <img src="https://github.com/jkubis96/Logos/blob/main/logos/jbs_current.png?raw=true" alt="drawing" width="200" />
32
+ </p>
33
+
34
+
35
+ ### Author: Jakub Kubiś
36
+
37
+ <div align="left">
38
+ Institute of Bioorganic Chemistry<br />
39
+ Polish Academy of Sciences<br />
40
+ </div>
41
+
42
+
43
+ ## Description
44
+
45
+
46
+
47
+
48
+ </br>
49
+
50
+
51
+ CFI (Cell Functionality and Interaction Analysis Tool) is an analytical platform designed for the investigation of cellular functions, intra-cellular gene interactions, and intercellular communication, including ligand–receptor interactions and adhesion junctions.
52
+
53
+ The tool integrates the advanced enrichment and interaction analysis capabilities of [GEDSpy](https://github.com/jkubis96/GEDSpy) with the single-cell data processing functionalities provided by [JDtI](https://github.com/jkubis96/JDtI).
54
+
55
+ CFI extends these capabilities by enabling the identification of direct cell–cell interactions, dominant biological processes, and gene–gene interaction networks within individual cells, along with comprehensive visualization of these relationships.
56
+
57
+
58
+ <p align="center">
59
+ <img src="fig/log.png" alt="drawing" width="500" />
60
+ </p>
61
+
62
+
63
+ CFI is designed to streamline the interpretation of biological data, enabling researchers to perform in-depth analyses of cellular functions and interactions for drug target discovery.
64
+
65
+
66
+ </br>
67
+
68
+ Included data bases:
69
+
70
+ * [Gene Ontology (GO-TERM)](http://geneontology.org/)
71
+ * [KEGG (Kyoto Encyclopedia of Genes and Genomes)](https://www.genome.jp/kegg/)
72
+ * [Reactome](https://reactome.org/)
73
+ * [HPA (Human Protein Atlas)](https://www.proteinatlas.org/)
74
+ * [NCBI](https://www.ncbi.nlm.nih.gov/)
75
+ * [STRING](https://string-db.org/)
76
+ * [IntAct](https://www.ebi.ac.uk/intact/home)
77
+ * [CellTalk](https://tcm.zju.edu.cn/celltalkdb/)
78
+ * [CellPhone](https://www.cellphonedb.org/)
79
+
80
+
81
+ *If you use CFI, please remember to cite both CFI and the original sources of the data you utilized in your work.*
82
+
83
+ In the case of interactions network analyses, it is recommended to use the [JVectorGraph](https://github.com/jkubis96/JVectorGraph) library to easily adjust and customise graph and network visualisations from the Python side.
84
+
85
+
86
+ <br />
87
+
88
+ ## 📚 Table of Contents
89
+
90
+ - [Installation](#installation)
91
+ - [Documentation](#doc)
92
+ - [Example usage](#example)
93
+ - [1. Cell functionality](#bf)
94
+ - [1.1. Create project](#bf1)
95
+ - [1.2. Calculate cell marker genes](#bf2)
96
+ - [1.3. Marker gene enrichment analysis](#bf3)
97
+ - [1.4. Cell inside gene interactions](#bf4)
98
+ - [1.5. Cell-cell interactions](#bf5)
99
+ - [1.6. Saving & loading project](#bf6)
100
+ - [2. Comparison of cell interaction sets](#br)
101
+ - [2.1. Create projects](#br1)
102
+ - [2.2. Calculate interactions](#br2)
103
+ - [2.3. Comparison analysis](#br3)
104
+
105
+
106
+ <br />
107
+
108
+
109
+ # Installation <a id="installation"></a>
110
+
111
+ #### In command line write:
112
+
113
+ ```
114
+ pip install cfi
115
+ ```
116
+
117
+
118
+
119
+
120
+ ## Documentation <a id="doc"></a>
121
+
122
+
123
+ Documentation for classes and functions is available here 👉 [Documentation 📄](https://jkubis96.github.io/CFI/cfi.html)
124
+
125
+
126
+ <br />
127
+
128
+
129
+ ## Example usage <a id="example"></a>
130
+
131
+ ### 1. Cell functionality <a id="bf"></a>
132
+
133
+ ##### 1.1. Create project <a id="bf1"></a>
134
+
135
+ ```
136
+ # ------------------------------------------------------------
137
+ # Import required standard and project-specific libraries
138
+ # ------------------------------------------------------------
139
+
140
+ import os
141
+ from jdti import COMPsc # JDtI module for handling single-cell projects
142
+ from cfi import CellFunCon # Cell functional connectivity / enrichment analysis
143
+
144
+
145
+ # ------------------------------------------------------------
146
+ # Load single-cell sequencing data using the JDtI framework
147
+ # ------------------------------------------------------------
148
+
149
+ # Define the project directory containing input data
150
+ # and specify the sample identifiers to be loaded
151
+
152
+ jseq_object = COMPsc.project_dir(
153
+ os.path.join(os.getcwd(), "data"), # path to data directory
154
+ ["s1"] # list of project/sample IDs
155
+ )
156
+
157
+ # Load sparse expression matrices from the project structure
158
+ # normalized_data=True ensures that pre-normalized counts are used
159
+
160
+ jseq_object.load_sparse_from_projects(normalized_data=True)
161
+
162
+
163
+ # ------------------------------------------------------------
164
+ # Initialize CellFunCon analysis object
165
+ # ------------------------------------------------------------
166
+
167
+ # Create a CellFunCon instance using the loaded single-cell dataset.
168
+ # This object enables downstream functional enrichment,
169
+ # interaction analysis, and pathway inference.
170
+
171
+ instance = CellFunCon(jseq_object)
172
+ ```
173
+
174
+ <br />
175
+
176
+
177
+ ##### 1.2. Calculate cell marker genes <a id="bf2"></a>
178
+
179
+ ```
180
+ # ------------------------------------------------------------
181
+ # Required step before functional enrichment analysis
182
+ # ------------------------------------------------------------
183
+ # Identify cell-type–specific marker genes based on:
184
+ # - minimum expression threshold (min_exp)
185
+ # - minimum fraction of expressing cells (min_pct)
186
+ # - parallel computation across multiple processes (n_proc)
187
+ #
188
+ # The resulting marker set is used as input for downstream
189
+ # functional enrichment and pathway analysis.
190
+
191
+ instance.calculate_cells_markers(
192
+ min_exp=0,
193
+ min_pct=0.05,
194
+ n_proc=10
195
+ )
196
+ ```
197
+
198
+ <br />
199
+
200
+
201
+ ##### 1.3. Marker gene enrichment analysis <a id="bf3"></a>
202
+
203
+ ```
204
+ # ------------------------------------------------------------
205
+ # Perform functional enrichment analysis for each cell population
206
+ # ------------------------------------------------------------
207
+ # This step evaluates overrepresentation of biological functions,
208
+ # pathways, and gene sets using previously identified marker genes.
209
+ #
210
+ # Parameters:
211
+ # - p_value : significance threshold for enrichment results
212
+ # - log_fc : minimum log fold-change required for marker inclusion
213
+ # - top_max : maximum number of top-ranked markers used per cell type
214
+ #
215
+ # The output provides functionally annotated cell states
216
+ # for downstream biological interpretation.
217
+
218
+ instance.enrich_cells_fucntionality(
219
+ p_value=0.05,
220
+ log_fc=0.25,
221
+ top_max=500
222
+ )
223
+ ```
224
+
225
+ <br />
226
+
227
+
228
+ * GO-TERM
229
+
230
+ ```
231
+ data = instance.get_enrichment_data(
232
+ data_type = 'GO-TERM',
233
+ p_value = 0.05,
234
+ test = 'FISH',
235
+ adj = 'BH',
236
+ parent_inc = False,
237
+ top_n = 50)
238
+ ```
239
+
240
+ | parent | parent_genes | parent_pval_FISH | parent_pval_BIN | parent_n | parent_pct | child | child_genes | child_pval_FISH | child_pval_BIN | child_n | child_pct | parent_name | child_name | cell | source |
241
+ |------------|-------------------------------------------------|------------------|-----------------|----------|------------|-----------|-------------------------------------------|------------------|----------------|---------|-----------|-------------------------------------|----------------------------------------------------------|------------------|---------|
242
+ | GO:0060090 | ['LETMD1', 'TNRC6A'] | 0.01397 | 0.01402 | 2 | 0.04348 | GO:0030674 | ['TNRC6A', 'SRRT', 'CRADD', 'SLMAP'] | 3.22e-05 | 3.30e-05 | 4 | 0.08696 | MF : molecular adaptor activity | MF : protein-macromolecule adaptor activity | STRIATUM_1 # s1 | GO-TERM |
243
+ | GO:0032991 | ['CLU','SRRT','HSP90AA1','SNX4','CHEK1','PPP3CB'] | 9.38e-05 | 9.49e-05 | 6 | 0.13043 | GO:0005955 | ['PPP3CB'] | 0.00459 | 0.00458 | 1 | 0.02174 | CC : protein-containing complex | CC : calcineurin complex | STRIATUM_1 # s1 | GO-TERM |
244
+ | GO:0032991 | ['CLU','SRRT','HSP90AA1','SNX4','CHEK1','PPP3CB'] | 9.38e-05 | 9.49e-05 | 6 | 0.13043 | GO:0031428 | ['FBL'] | 0.00535 | 0.00535 | 1 | 0.02174 | CC : protein-containing complex | CC : box C/D methylation guide snoRNP complex | STRIATUM_1 # s1 | GO-TERM |
245
+ | GO:0032991 | ['CLU','SRRT','HSP90AA1','SNX4','CHEK1','PPP3CB'] | 9.38e-05 | 9.49e-05 | 6 | 0.13043 | GO:0005664 | ['ORC6'] | 0.00611 | 0.00611 | 1 | 0.02174 | CC : protein-containing complex | CC : nuclear origin of replication recognition complex | STRIATUM_1 # s1 | GO-TERM |
246
+ | GO:0032991 | ['CLU','SRRT','HSP90AA1','SNX4','CHEK1','PPP3CB'] | 9.38e-05 | 9.49e-05 | 6 | 0.13043 | GO:0008287 | ['PPP3CB'] | 0.00611 | 0.00611 | 1 | 0.02174 | CC : protein-containing complex | CC : protein serine/threonine phosphatase complex | STRIATUM_1 # s1 | GO-TERM |
247
+
248
+ <br />
249
+
250
+
251
+ Visualization
252
+
253
+ ```
254
+ from cfi import encrichment_cell_heatmap
255
+
256
+ fig = encrichment_cell_heatmap(data = data,
257
+ fig_size = (3,3),
258
+ sets = None,
259
+ top_n = 3,
260
+ test = 'FISH',
261
+ adj = 'BH',
262
+ parent_inc = False,
263
+ font_size = 16,
264
+ clustering = 'ward',
265
+ scale = True)
266
+ ```
267
+
268
+
269
+ <p align="center">
270
+ <img src="fig/heatmap.svg" alt="drawing" width="450" />
271
+ </p>
272
+
273
+
274
+ <br />
275
+
276
+ * KEGG
277
+
278
+ ```
279
+ data = instance.get_enrichment_data(
280
+ data_type = 'KEGG',
281
+ test = 'FISH',
282
+ adj = 'BH',
283
+ parent_inc = False,
284
+ top_n = 50)
285
+ ```
286
+ | 2nd | 2nd_genes | 2nd_pval | 2nd_n | 2nd_pct | 3rd | 3rd_genes | 3rd_pval | 3rd_n | 3rd_pct | cell | source |
287
+ |-------------------------|---------------------------------------------------------------------------|----------|-------|---------|--------------------------|-----------------------------------------------|----------|-------|---------|------------------|--------|
288
+ | Neurodegenerative disease | ['ATXN10','VDAC2','PSMA3','APC','SETX','CREBBP','PSMD8','PSMD7','NDUFA4'] | 1.10e-05 | 9 | 0.093 | Spinocerebellar ataxia | ['ATXN10','VDAC2','PSMA3','PSMD8','PSMD7'] | 7.51e-06 | 5 | 0.052 | STRIATUM_2 # s1 | KEGG |
289
+ | Neurodegenerative disease | ['ATXN10','VDAC2','PSMA3','APC','SETX','CREBBP','PSMD8','PSMD7','NDUFA4'] | 1.10e-05 | 9 | 0.093 | Huntington disease | ['VDAC2','PSMA3','CREBBP','PSMD8','PSMD7','NDUFA4'] | 2.08e-05 | 6 | 0.062 | STRIATUM_2 # s1 | KEGG |
290
+ | Neurodegenerative disease | ['ATXN10','VDAC2','PSMA3','APC','SETX','CREBBP','PSMD8','PSMD7','NDUFA4'] | 1.10e-05 | 9 | 0.093 | Alzheimer disease | ['VDAC2','PSMA3','APC','PSMD8','PSMD7','NDUFA4'] | 8.20e-05 | 6 | 0.062 | STRIATUM_2 # s1 | KEGG |
291
+ | Neurodegenerative disease | ['ATXN10','VDAC2','PSMA3','APC','SETX','CREBBP','PSMD8','PSMD7','NDUFA4'] | 1.10e-05 | 9 | 0.093 | Prion disease | ['VDAC2','PSMA3','PSMD8','PSMD7','NDUFA4'] | 1.23e-04 | 5 | 0.052 | STRIATUM_2 # s1 | KEGG |
292
+ | Neurodegenerative disease | ['ATXN10','VDAC2','PSMA3','APC','SETX','CREBBP','PSMD8','PSMD7','NDUFA4'] | 1.10e-05 | 9 | 0.093 | Parkinson disease | ['VDAC2','PSMA3','PSMD8','PSMD7','NDUFA4'] | 1.77e-04 | 5 | 0.052 | STRIATUM_2 # s1 | KEGG |
293
+
294
+
295
+ <br />
296
+
297
+ Visualization
298
+
299
+ ```
300
+ from cfi import encrichment_cell_heatmap
301
+
302
+ fig = encrichment_cell_heatmap(data = enr,
303
+ fig_size = (3,3),
304
+ sets = None,
305
+ top_n = 3,
306
+ test = 'FISH',
307
+ adj = 'BH',
308
+ parent_inc = False,
309
+ font_size = 16,
310
+ clustering = 'ward',
311
+ scale = True)
312
+ ```
313
+
314
+
315
+ <p align="center">
316
+ <img src="fig/heatmap2.svg" alt="drawing" width="450" />
317
+ </p>
318
+
319
+
320
+ > [!NOTE]
321
+ > In this case, **no significant KEGG terms** were detected for the second cell type.
322
+ > To indicate the absence of specific terms, use
323
+ > `instance1.get_included_cells()` to display both cells at the top.
324
+
325
+ <br />
326
+
327
+ Visualization
328
+
329
+ ```
330
+ from cfi import encrichment_cell_heatmap
331
+
332
+ fig2 = encrichment_cell_heatmap(data = enr,
333
+ fig_size = (3,3),
334
+ sets = instance1.get_included_cells(),
335
+ top_n = 3,
336
+ test = 'FISH',
337
+ adj = 'BH',
338
+ parent_inc = False,
339
+ font_size = 16,
340
+ clustering = 'ward',
341
+ scale = True)
342
+ ```
343
+
344
+ <br />
345
+
346
+ Visualization
347
+
348
+
349
+
350
+ <p align="center">
351
+ <img src="fig/heatmap3.svg" alt="drawing" width="450" />
352
+ </p>
353
+
354
+
355
+ <br />
356
+
357
+
358
+ * REACTOME
359
+
360
+ ```
361
+ data = instance.get_enrichment_data(
362
+ data_type = 'REACTOME',
363
+ p_value = 0.05,
364
+ test = 'FISH',
365
+ adj = 'BH',
366
+ parent_inc = False,
367
+ top_n = 50)
368
+ ```
369
+
370
+ | pathway | genes | p-value | n | pct | top level pathway | top genes | cell | source |
371
+ |----------------------------------------------|-------------|--------|---|------|---------------------------|----------------------|------------------|----------|
372
+ | Resistance of ERBB2 KD mutants to tesevatinib | [HSP90AA1] | 0.00306 | 1 | 0.0217 | Disease | [RNGTT,HSP90AA1,HMGB1] | STRIATUM_1 # s1 | REACTOME |
373
+ | Resistance of ERBB2 KD mutants to osimertinib | [HSP90AA1] | 0.00306 | 1 | 0.0217 | Disease | [RNGTT,HSP90AA1,HMGB1] | STRIATUM_1 # s1 | REACTOME |
374
+ | Resistance of ERBB2 KD mutants to AEE788 | [HSP90AA1] | 0.00306 | 1 | 0.0217 | Disease | [RNGTT,HSP90AA1,HMGB1] | STRIATUM_1 # s1 | REACTOME |
375
+ | Apoptosis induced DNA fragmentation | [HMGB1] | 0.00991 | 1 | 0.0217 | Programmed Cell Death | [HSP90AA1,HMGB1] | STRIATUM_1 # s1 | REACTOME |
376
+ | Regulation of CDH11 mRNA translation by miRNAs| [TNRC6A] | 0.00839 | 1 | 0.0217 | Cell-Cell communication | [TNRC6A] | STRIATUM_1 # s1 | REACTOME |
377
+
378
+ <br />
379
+
380
+ Visualization
381
+
382
+ ```
383
+ from cfi import encrichment_cell_heatmap
384
+
385
+ fig = encrichment_cell_heatmap(data = enr,
386
+ fig_size = (3,3),
387
+ sets = instance1.get_included_cells(),
388
+ top_n = 3,
389
+ test = 'FISH',
390
+ adj = 'BH',
391
+ parent_inc = False,
392
+ font_size = 16,
393
+ clustering = 'ward',
394
+ scale = True)
395
+ ```
396
+
397
+
398
+ <p align="center">
399
+ <img src="fig/heatmap4.svg" alt="drawing" width="450" />
400
+ </p>
401
+
402
+
403
+ <br />
404
+
405
+ * Specificity (HPA)
406
+
407
+ ```
408
+ data = instance.get_enrichment_data(
409
+ data_type = 'specificity',
410
+ p_value = 1,
411
+ test = 'FISH',
412
+ adj = 'BH',
413
+ parent_inc = False,
414
+ top_n = 50)
415
+ ```
416
+ | specificity | genes | p-value | n | pct | cell | source |
417
+ |------------------------|----------------------|--------|---|------|------------------|-------------|
418
+ | Cardiomyocytes | [SLMAP] | 0.116 | 1 | 0.0217 | STRIATUM_1 # s1 | specificity |
419
+ | Proximal tubular cells | [ALDH6A1] | 0.098 | 1 | 0.0217 | STRIATUM_1 # s1 | specificity |
420
+ | granulocytes | [CLU, ALDH6A1, TIMP2]| 0.132 | 3 | 0.0652 | STRIATUM_1 # s1 | specificity |
421
+ | liver | [ALDH6A1] | 0.288 | 1 | 0.0217 | STRIATUM_1 # s1 | specificity |
422
+ | kidney | [ALDH6A1] | 0.146 | 1 | 0.0217 | STRIATUM_1 # s1 | specificity |
423
+ | Schwann cells | [GRIK3] | 0.030 | 1 | 0.0217 | STRIATUM_1 # s1 | specificity |
424
+
425
+ <br />
426
+
427
+ Visualization
428
+
429
+ ```
430
+ from cfi import encrichment_cell_heatmap
431
+
432
+ fig = encrichment_cell_heatmap(data = enr,
433
+ fig_size = (3,3),
434
+ sets = instance1.get_included_cells(),
435
+ top_n = 3,
436
+ test = 'FISH',
437
+ adj = 'BH',
438
+ parent_inc = False,
439
+ font_size = 16,
440
+ clustering = 'ward',
441
+ scale = True)
442
+ ```
443
+
444
+
445
+ <p align="center">
446
+ <img src="fig/heatmap5.svg" alt="drawing" width="450" />
447
+ </p>
448
+
449
+ <br />
450
+
451
+ ##### 1.4. Cell inside gene interactions <a id="bf4"></a>
452
+
453
+ View available cell names
454
+
455
+ ```
456
+ # ------------------------------------------------------------
457
+ # List all cell populations included in the dataset
458
+ # ------------------------------------------------------------
459
+ # Useful for verifying dataset structure before selecting
460
+ # specific cell populations for further investigation.
461
+
462
+ instance.get_included_cells()
463
+ ```
464
+
465
+ <p align="center">
466
+ <img src="fig/out_cell.bmp" alt="drawing" width="450" />
467
+ </p>
468
+
469
+
470
+
471
+ Retrieve interaction data for the selected cell
472
+
473
+ ```
474
+ cell_int = instance.get_gene_interactions('STRIATUM_1 # s1')
475
+ ```
476
+
477
+ | A | B | interaction_type | connection_type | source |
478
+ |------|---------|----------------------|---------------------|-------------|
479
+ | CLU | CLU | physical association | protein -> protein | Alzheimers |
480
+ | CLU | HSP90AA1| physical association | protein -> protein | Alzheimers |
481
+ | FBL | KRR1 | | gene -> gene | STRING |
482
+ | FBL | KRR1 | | protein -> protein | STRING |
483
+ | KRR1 | FBL | | gene -> gene | STRING |
484
+ | KRR1 | FBL | | protein -> protein | STRING |
485
+
486
+
487
+ <br />
488
+
489
+ Visualization
490
+
491
+ ```
492
+ from cfi import gene_interaction_network
493
+
494
+ fig5 = gene_interaction_network(idata = cell_int, min_con = 2)
495
+
496
+ from JVG import JVG
497
+
498
+ nt = JVG.NxEditor(fig5)
499
+ nt.edit()
500
+ ```
501
+
502
+
503
+ <p align="center">
504
+ <img src="fig/gin.bmp" alt="drawing" width="300" />
505
+ </p>
506
+
507
+ <br />
508
+
509
+
510
+ ##### 1.5. Cell-cell interactions <a id="bf5"></a>
511
+
512
+
513
+ Calculate cells interactions
514
+
515
+ ```
516
+ # ------------------------------------------------------------
517
+ # Infer functional and molecular connections between cell populations
518
+ # ------------------------------------------------------------
519
+ # This step identifies potential interactions based on
520
+ # inferred molecular communication signals
521
+ #
522
+ # The resulting network describes relationships between cells
523
+ # and can be used for downstream visualization, pathway analysis,
524
+ # or biological interpretation of tissue organization.
525
+
526
+ instance.calculate_cell_connections()
527
+ ```
528
+
529
+ Get data
530
+
531
+ ```
532
+ cell_con = instance.get_cell_connections()
533
+ ```
534
+
535
+ | interaction | directionality | classification | modulatory_effect | interactor1 | interactor2 | cell1 | cell2 |
536
+ |--------------------------|--------------------|---------------------------------|-------------------|-------------|-------------|-------------|-------------|
537
+ | CDH2 -> CDH2 | Adhesion-Adhesion | Adhesion by Cadherin | | CDH2 | CDH2 | STRIATUM_1 | STRIATUM_2 |
538
+ | CDH6 -> CDH6 | Adhesion-Adhesion | Adhesion by Cadherin | | CDH6 | CDH6 | STRIATUM_1 | STRIATUM_2 |
539
+ | CDH7 -> CDH7 | Adhesion-Adhesion | Adhesion by Cadherin | | CDH7 | CDH7 | STRIATUM_1 | STRIATUM_2 |
540
+ | COL11A1 -> ITGA1+ITGB1 | Adhesion-Adhesion | Adhesion by Collagen/Integrin | | COL11A1 | ITGA1 | STRIATUM_1 | STRIATUM_2 |
541
+ | COL11A1 -> ITGA1+ITGB1 | Adhesion-Adhesion | Adhesion by Collagen/Integrin | | COL11A1 | ITGB1 | STRIATUM_1 | STRIATUM_2 |
542
+
543
+ <br />
544
+
545
+ Visualization
546
+
547
+ ```
548
+ from cfi import draw_cell_conections
549
+
550
+ fig = draw_cell_conections(cell_con)
551
+
552
+ from JVG import JVG
553
+
554
+ nt = JVG.NxEditor(fig)
555
+ nt.edit()
556
+ ```
557
+
558
+ <p align="center">
559
+ <img src="fig/cell_con.bmp" alt="drawing" width="300" />
560
+ </p>
561
+
562
+ <br />
563
+
564
+
565
+
566
+ ##### 1.6. Saving & loading project <a id="bf6"></a>
567
+
568
+
569
+ Saving current project
570
+
571
+ ```
572
+ instance.save_project('project')
573
+ ```
574
+
575
+
576
+ Loading previously saved project
577
+
578
+ ```
579
+ from cfi import CellFunCon
580
+
581
+ instance = CellFunCon.load_project('project.psc')
582
+ ```
583
+
584
+
585
+ <br />
586
+
587
+
588
+ ### 2. Comparison of cell interaction sets <a id="br"></a>
589
+
590
+ ##### 2.1. Create projects <a id="br1"></a>
591
+
592
+ ```
593
+ # ------------------------------------------------------------
594
+ # Import required libraries
595
+ # ------------------------------------------------------------
596
+ import os
597
+ from jdti import COMPsc # JDtI module for single-cell project handling
598
+ from cfi import CellFunCon # Functional analysis and cell interaction inference
599
+
600
+
601
+ # ------------------------------------------------------------
602
+ # Load single-cell datasets for two experimental conditions
603
+ # ------------------------------------------------------------
604
+ # Each COMPsc object represents an independent project/sample
605
+ # loaded from the same data directory but identified by
606
+ # different sample IDs (e.g., control vs. case).
607
+
608
+ jseq_object1 = COMPsc.project_dir(
609
+ os.path.join(os.getcwd(), "data"),
610
+ ["s1"] # first dataset / condition
611
+ )
612
+ jseq_object1.load_sparse_from_projects(normalized_data=True)
613
+
614
+
615
+ jseq_object2 = COMPsc.project_dir(
616
+ os.path.join(os.getcwd(), "data"),
617
+ ["s2"] # second dataset / condition
618
+ )
619
+ jseq_object2.load_sparse_from_projects(normalized_data=True)
620
+
621
+
622
+ # ------------------------------------------------------------
623
+ # Initialize CellFunCon analysis objects for comparative study
624
+ # ------------------------------------------------------------
625
+ # Separate instances enable:
626
+ # - independent marker detection
627
+ # - condition-specific functional enrichment
628
+ # - downstream comparison of cell functionality and interactions
629
+
630
+ instance1 = CellFunCon(jseq_object1)
631
+ instance2 = CellFunCon(jseq_object2)
632
+ ```
633
+ <br />
634
+
635
+
636
+ ##### 2.2. Calculate interactions <a id="br2"></a>
637
+
638
+ ```
639
+ # ------------------------------------------------------------
640
+ # Calculate cell–cell connection networks for each dataset
641
+ # ------------------------------------------------------------
642
+ # This step reconstructs potential functional and molecular
643
+ # interactions between cell populations independently for:
644
+ # - dataset 1 (e.g., control)
645
+ # - dataset 2 (e.g., disease / treated condition)
646
+
647
+ instance1.calculate_cell_connections()
648
+ instance2.calculate_cell_connections()
649
+ ```
650
+
651
+ <br />
652
+
653
+
654
+ ##### 2.3. Comparison analysis <a id="br3"></a>
655
+
656
+ ```
657
+ # ------------------------------------------------------------
658
+ # Compare cell–cell interaction networks between conditions
659
+ # ------------------------------------------------------------
660
+ # This step performs a comparative analysis of inferred
661
+ # cell–cell connections across multiple biological conditions.
662
+ #
663
+ # Each entry in `instances_dict` represents a fully processed
664
+ # CellFunCon object with reconstructed interaction networks.
665
+ # Here, we contrast:
666
+ # - healthy condition
667
+ # - disease condition
668
+
669
+ from cfi import compare_connections
670
+
671
+ instances_dict = {
672
+ "healthy": instance2,
673
+ "disease": instance1
674
+ }
675
+
676
+ comparison = compare_connections(instances_dict=instances_dict,
677
+ cells_compartment = None,
678
+ connection_type = ['Adhesion-Adhesion',
679
+ 'Gap-Gap',
680
+ 'Ligand-Ligand',
681
+ 'Ligand-Receptor',
682
+ 'Receptor-Receptor',
683
+ 'Undefined'])
684
+ ```
685
+
686
+ | feature | p-value | pct_valid | pct_ctrl | FC | log(FC) | norm_diff | group |
687
+ |---------|----------|-----------|----------|-------|---------|-----------|---------|
688
+ | HSP90B1 | 4.75e-14 | 0.164 | 0.935 | 0.160 | -2.65 | -6.58 | healthy |
689
+ | CANX | 5.90e-14 | 0.091 | 0.848 | 0.102 | -3.30 | -5.53 | healthy |
690
+ | ARPC5 | 1.34e-11 | 0.055 | 0.739 | 0.080 | -3.64 | -4.93 | healthy |
691
+ | CALR | 5.47e-09 | 0.182 | 0.761 | 0.226 | -2.14 | -4.41 | healthy |
692
+ | APLP2 | 1.16e-08 | 0.073 | 0.609 | 0.115 | -3.12 | -3.73 | healthy |
693
+ | ITGB1 | 1.44e-08 | 0.055 | 0.587 | 0.098 | -3.36 | -3.61 | healthy |
694
+
695
+ <br />
696
+
697
+ Visualization
698
+
699
+ ```
700
+ from cfi import volcano_plot_conections
701
+
702
+ fig = volcano_plot_conections(
703
+ deg_data = comparison,
704
+ p_adj = True,
705
+ top = 25,
706
+ top_rank = "p_value",
707
+ p_val = 0.05,
708
+ lfc = 0.25,
709
+ rescale_adj = True,
710
+ image_width = 12,
711
+ image_high = 12,
712
+ )
713
+ ```
714
+
715
+
716
+ <p align="center">
717
+ <img src="fig/volcano.svg" alt="drawing" width="450" />
718
+ </p>
719
+
720
+
721
+ <br />
722
+
723
+ An example analysis pipeline is available here → [Example file](example.py)
724
+
725
+ <br />
726
+
727
+
728
+ #### Have fun JBS©
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+