# cellchat Algorithm

## Purpose

Use cellchat for cell communication analysis

## Usage

```bash
SDAS CCI cellchat -i st.h5ad --label_key anno_spotlight -o outdir \
--add_spatial \
--bin_size 100 \
--species human \
--type truncatedMean
```

## Input Parameter Description

| Parameter                | Required | Default          | Description                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------------------ | -------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **-i / --input**         | **Yes**  |                  | h5ad file, must contain raw expression matrix                                                                                                                                                                                                                                                                                                                                                          |
| **-o / --output**        | **Yes**  |                  | Output folder                                                                                                                                                                                                                                                                                                                                                                                          |
| **--label\_key**         | **Yes**  |                  | Column name used to distinguish cell types in cell communication analysis                                                                                                                                                                                                                                                                                                                              |
| --layer                  | No       |                  | Name of the layer in h5ad containing the raw expression matrix                                                                                                                                                                                                                                                                                                                                         |
| --gene\_symbol\_key      | No       | real\_gene\_name | Name of the column in Stereo-seq h5ad.var indicating gene symbol (\_index means using h5ad.var.index)                                                                                                                                                                                                                                                                                                  |
| --add\_spatial           | No       |                  | Use "--add\_spatial" if spatial information is considered in the analysis                                                                                                                                                                                                                                                                                                                              |
| --bin\_size              | No       |                  | If using "--add\_spatial", you need to provide bin\_size, such as cellbin, 10, 20, 50, 100                                                                                                                                                                                                                                                                                                             |
| --species                | No       | human            | Built-in database in cellchat, supports human, mouse, zebrafish, default 'human'; when --cellchat\_database is specified, this parameter is ignored                                                                                                                                                                                                                                                    |
| --cellchat\_database     | No       |                  | Path to custom cellchat database file                                                                                                                                                                                                                                                                                                                                                                  |
| --type                   | No       | triMean          | Used in computeCommunProb, computing the average gene expression per cell group. By default = 'triMean', producing fewer but stronger interactions; When setting type = "truncatedMean", a value should be assigned to trim, producing more interactions.                                                                                                                                              |
| --trim                   | No       | 0.1              | trim used in computeCommunProb when method is "truncatedMean", the fraction (0 to 0.25) of observations to be trimmed from each end of x before the mean is computed                                                                                                                                                                                                                                   |
| --spatial\_coords\_scale | No       | 0.5              | Global scaling factor for spatial coordinates. For stereo-seq, set to 0.5 to convert coordinates to microns for easier result interpretation                                                                                                                                                                                                                                                           |
| --scale\_distance        | No       | 2                | scale.distance used in computeCommunProb when setting '--add\_spatial'. A scale or normalization factor for the spatial distances when setting 'distance.use = TRUE'. For example, scale.distance equals 1, 0.1, 0.01, 0.001, 0.11, or 0.011. We choose this values such that the minimum value of the scaled distances is in \[1,2]. This value is not necessary when setting 'distance.use = FALSE'. |
| --pathway.file           | No       |                  | The selected pathway in csv file, show visualize the inferred communication network of signaling pathways using netVisual\_aggregate, when setting --add\_spatial will show spatial network diagram.  png for each pathway, pdf for all pathways in one file.                                                                                                                                          |
| --seed                   | No       | 42               | Random seed                                                                                                                                                                                                                                                                                                                                                                                            |

**Custom database construction can refer to the cellchat official tutorial:**

<https://htmlpreview.github.io/?https://github.com/jinworks/CellChat/blob/master/tutorial/Update-CellChatDB.html>

## Output Results Display

| Result File                                                                                                                                            | Description                                                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<input_name>_cellchat_LR.csv`                                                                                                                         | Ligand-receptor interaction results (not output if no significant interactions found)                                                                                                   |
| `<input_name>_cellchat_LR_pathway.csv`                                                                                                                 | Pathway results of ligand-receptor sets (not output if no significant interactions found)                                                                                               |
| <p><code>\<input\_name>\_interaction\_strength\_circle.png/pdf</code><br><code>\<input\_name>\_interaction\_strength\_heatmap.png/pdf</code></p>       | Circle and heatmap showing the strength of ligand-receptor interactions between cell clusters, outputs both pdf and png                                                                 |
| <p><code>\<input\_name>\_number\_of\_interactions\_circle.png/pdf</code><br><code>\<input\_name>\_number\_of\_interactions\_heatmap.png/pdf</code></p> | Circle and heatmap showing the number of ligand-receptor interactions between cell clusters, outputs both pdf and png                                                                   |
| `<input_name>_signalingRole_scatter.png/pdf`                                                                                                           | Scatter plot showing the role distribution of each cell cluster in the signaling network, outputs both pdf and png                                                                      |
| `<input_name>_pathway_communication_network.png/pdf`                                                                                                   | Network diagram of specified pathway between cells; when using "--add\_spatial", outputs spatial network diagram, outputs both pdf and png (not output if no significant pathway found) |
| `<input_name>_cellchat.rds`                                                                                                                            | rds file containing cell communication results                                                                                                                                          |

* **Circle plot of the number of ligand-receptor interactions between cell clusters**: `<input_name>_number_of_interactions_circle.png/pdf` shows the number of ligand-receptor interactions between cell clusters, reflecting the strength of interaction relationships. Circles represent cell clusters, lines represent ligand-receptor interactions, line thickness represents the number of interactions, and the size of the circle represents the total number of interactions the cell cluster participates in, allowing direct comparison of which cell clusters interact most frequently.

<figure><img src="/files/l2EQnBXqHou5YTdaJRS3" alt="" width="321"><figcaption></figcaption></figure>

* **Circle plot of the strength of ligand-receptor interactions between cell clusters**: `<input_name>_interaction_strength_circle.png/pdf` shows the strength of ligand-receptor interactions between cell clusters, reflecting the activity of signal transduction. Circles represent cell clusters, lines represent ligand-receptor interactions, line thickness represents interaction strength, and the size of the circle represents the total interaction strength the cell cluster participates in, allowing direct comparison of which cell clusters are most active in signal transduction.

<figure><img src="/files/6bWy6yX7ZC4ZPmnpusFr" alt="" width="329"><figcaption></figcaption></figure>

* **Heatmap of the number of ligand-receptor interactions between cell clusters**: `<input_name>_number_of_interactions_heatmap.png/pdf` shows the number of interactions in heatmap form for overall comparison. Both axes are cell clusters, color depth indicates the number of interactions, the deeper the color, the more interactions.

<figure><img src="/files/lTGZ0ZgMFMyTNnuWPegL" alt="" width="311"><figcaption></figcaption></figure>

* **Heatmap of the strength of ligand-receptor interactions between cell clusters**: `<input_name>_interaction_strength_heatmap.png/pdf` shows the strength of interactions in heatmap form for overall comparison. Both axes are cell clusters, color depth indicates interaction strength, the deeper the color, the stronger the signal transduction.

<figure><img src="/files/ndVKys2TEXxuT4JAChuP" alt="" width="375"><figcaption></figcaption></figure>

* **Scatter plot of signaling network role distribution**: `<input_name>_signalingRole_scatter.png/pdf` shows the role distribution of each cell cluster in the signaling network. The axes represent different network features (such as sender, receiver, modulator, etc.), each point represents a cell cluster, and the position of the point reflects its functional role in the network, allowing identification of major signal senders and receivers.

<figure><img src="/files/Lv5T2fqyWW3RSRU7DhHg" alt="" width="277"><figcaption></figcaption></figure>

* **Spatial network diagram of specified pathway**: `<input_name>_pathway_communication_network.png/pdf` shows the spatial network structure of the specified pathway between cells. When spatial information analysis is added ("--add\_spatial"), the spatial network diagram of the specified pathway is output. The axes are spatial coordinates, each point is a cell cluster, lines represent pathway-related cell communication, line thickness represents interaction strength, and the size of the node circle represents the total number of signal interactions the cell cluster participates in, allowing direct observation of the distribution and functional regions of specific pathways in space.

<figure><img src="/files/bhSJzMlAtzFs9LHwkFDQ" alt="" width="375"><figcaption></figcaption></figure>

* **Network structure diagram of specified pathway between cells (no spatial)**: `<input_name>_pathway_communication_network_nospatial.png/pdf` shows the network structure of the specified pathway between cells. Nodes are cell clusters, lines represent pathway-related cell communication, line thickness represents interaction strength, and the size of the node circle represents the total number of signal interactions the cell cluster participates in. Suitable for observing pathway network structure when there is no spatial information.

<figure><img src="/files/q7Vq1kup79hl8HBOuAPU" alt="" width="342"><figcaption></figcaption></figure>

## **Parameter Tuning Suggestions**

* `type` parameter: It is recommended to use the default triMean for stronger interactions. If you want to get more interactions, you can use truncatedMean and adjust trim (the smaller the trim, the more interactions); trim=0.1 means removing 10% of extreme values at both ends before calculating the mean.
* `scale_distance`: Normalization factor for spatial distance. When comparing communication between different CellChat objects, use the same scaling factor. For single sample analysis, different normalization factors do not affect the ranking of receptor-ligand signals.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mysite.gitbook.io/sdas_manual_eng/readme/04_manual/cci/03_cellchat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
