# Tangram Algorithm

### Purpose

Use Tangram for cell annotation.

### Usage

```bash
SDAS cellAnnotation tangram -i st.h5ad -o outdir --reference sc.h5ad --bin_size 20 --label_key annotation2 \
--filter_rare_cell 0
```

### Input Parameter Description

| Parameter                  | Required | Default          | Description                                                                                                                       |
| -------------------------- | -------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **-i / --input**           | **Yes**  |                  | Stereo-seq h5ad, must contain the raw expression matrix                                                                           |
| **-o / --output**          | **Yes**  |                  | Output folder                                                                                                                     |
| **--reference**            | **Yes**  |                  | Single-cell ref h5ad, must contain the raw expression matrix                                                                      |
| **--label\_key**           | **Yes**  |                  | Name of the column in single-cell ref h5ad.obs indicating cell type                                                               |
| **--bin\_size**            | **Yes**  |                  | Bin size, used to control the size of points in the plot, not used for calculation, e.g., 20, 50, 100, cellbin (equivalent to 20) |
| --input\_layer             | No       |                  | Layer in Stereo-seq h5ad storing raw counts                                                                                       |
| --ref\_layer               | No       |                  | Layer in single-cell ref h5ad storing raw counts                                                                                  |
| --input\_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)                               |
| --ref\_gene\_symbol\_key   | No       | \_index          | Name of the column in single-cell ref h5ad.var indicating gene symbol (\_index means using h5ad.var.index)                        |
| --slice\_key               | No       | sampleID         | Name of the column in multi-slice h5ad.obs indicating slice ID, used for plotting                                                 |
| --filter\_rare\_cell       | No       | 100              | The minimum cell count for a cell type to be included                                                                             |
| --top\_markers             | No       | 200              | Number of top marker genes for each cell type to use to run Tangram                                                               |
| --max\_epochs              | No       | 1000             | Number of epochs for model training                                                                                               |
| --seed                     | No       | 42               | Random seed                                                                                                                       |
| --gpu\_id                  | No       | -1               | ID of the GPU to use. If -1, use CPU                                                                                              |
| --n\_threads               | No       |                  | Number of threads to use in CPU mode, defaults to all CPUs                                                                        |

### Output Results

| Result File                               | Description                                                                                                                                                                    |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `<input_name>_anno_tangram.csv`           | Annotation results for each spot, including scores for each cell type                                                                                                          |
| `<input_name>_anno_tangram.h5ad`          | Input h5ad + annotation results. Scores for each cell type are stored in obsm\['anno\_score\_tangram'], and the type with the highest score is stored in obs\['anno\_tangram'] |
| `<input_name>_anno_tangram.png/pdf`       | Overall annotation result plot; for multiple slices, one plot per slice; both png and pdf are output                                                                           |
| `<input_name>_anno_tangram_split.png/pdf` | Separate display plot for each cell type; for multiple slices, one plot per slice; both png and pdf are output                                                                 |
| `<input_name>_anno_score_tangram.png/pdf` | Score plot for each cell type; for multiple slices, one plot per slice; both png and pdf are output                                                                            |

For detailed explanations and specific result displays, please refer to the following [link](../03_cell2location/02_anno#output-results) (cell2location algorithm → cell annotation → output results).
