Skip to content

Commit bcfbfb3

Browse files
author
Tommaso Biancalani
authored
Merge pull request #8 from broadinstitute/release-v0.2.1
Release v0.2.1
2 parents 3faa359 + 81490ad commit bcfbfb3

File tree

6 files changed

+100
-25
lines changed

6 files changed

+100
-25
lines changed

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release to PyPI
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
jobs:
8+
release:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python 3.6
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.6
18+
- name: Install Tools
19+
run: |
20+
python3 -m pip install --user --upgrade setuptools wheel
21+
python3 -m pip install --user --upgrade twine
22+
- name: Package and Upload
23+
env:
24+
TANGRAM_VERSION: ${{ github.event.release.tag_name }}
25+
TWINE_USERNAME: __token__
26+
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
27+
run: |
28+
python3 setup.py sdist bdist_wheel
29+
python3 -m twine upload dist/*
30+

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
<img src="figures/tangram_large.png" width="400">
1+
<img src="https://raw.githubusercontent.com/broadinstitute/Tangram/master/figures/tangram_large.png" width="400">
22

3-
Tangram is a Python package, written in [PyTorch](https://pytorch.org/) and based on [scanpy](https://scanpy.readthedocs.io/en/stable/), for mapping single-cell (or single-nucleus) gene expression data onto spatial gene expression data. The single-cell dataset and the spatial dataset should be collected from the same anatomical region/tissue type, ideally from a biological replicate, and need to share a set of genes. Tangram aligns the single-cell data in space by fitting gene expression on the shared genes. The best way to familiarize yourself with Tangram is to check out [our tutorial](example/1_tutorial_tangram.ipynb).
3+
[![PyPI version](https://badge.fury.io/py/tangram-sc.svg)](https://badge.fury.io/py/tangram-sc)
44

5-
![Tangram_overview](figures/tangram_overview.png)
5+
Tangram is a Python package, written in [PyTorch](https://pytorch.org/) and based on [scanpy](https://scanpy.readthedocs.io/en/stable/), for mapping single-cell (or single-nucleus) gene expression data onto spatial gene expression data. The single-cell dataset and the spatial dataset should be collected from the same anatomical region/tissue type, ideally from a biological replicate, and need to share a set of genes. Tangram aligns the single-cell data in space by fitting gene expression on the shared genes. The best way to familiarize yourself with Tangram is to check out [our tutorial](https://github.com/broadinstitute/Tangram/blob/master/example/1_tutorial_tangram.ipynb). [![colab tutorial](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1SVLUIZR6Da6VUyvX_2RkgVxbPn8f62ge?usp=sharing)
6+
7+
![Tangram_overview](https://raw.githubusercontent.com/broadinstitute/Tangram/master/figures/tangram_overview.png)
68
Tangram has been tested on various types of transcriptomic data (10Xv3, Smart-seq2 and SHARE-seq for single cell data; MERFISH, Visium, Slide-seq, smFISH and STARmap as spatial data). In our [preprint](https://www.biorxiv.org/content/10.1101/2020.08.29.272831v1), we used Tangram to reveal spatial maps of cell types and gene expression at single cell resolution in the adult mouse brain. More recently, we have applied our method to different tissue types including human lung, human kidney developmental mouse brain and metastatic breast cancer.
79

810
***
911
## How to run Tangram
1012

11-
To install Tangram, make sure you have [PyTorch](https://pytorch.org/) and [scanpy](https://scanpy.readthedocs.io/en/stable/) installed. If you need more details on the dependences, look at the `environment.yml` file. Then clone this repo, and import as follows:
13+
To install Tangram, make sure you have [PyTorch](https://pytorch.org/) and [scanpy](https://scanpy.readthedocs.io/en/stable/) installed. If you need more details on the dependences, look at the `environment.yml` file. To install and import tangram, please use the following code:
1214

1315
```
14-
import sys
15-
sys.path.append("/home/tbiancal/git/Tangram")
16+
pip install tangram-sc
1617
import tangram as tg
1718
```
1819

@@ -38,7 +39,7 @@ The returned AnnData,`ad_map`, is a cell-by-voxel structure where `ad_map.X[i, j
3839

3940
The returned `ad_ge` is a voxel-by-gene AnnData, similar to spatial data `ad_sp`, but where gene expression has been projected from the single cells. This allows to extend gene throughput, or correct for dropouts, if the single cells have higher quality (or more genes) than single cell data. It can also be used to transfer cell types onto space.
4041

41-
For more details on how to use Tangram check out [our tutorial](example/1_tutorial_tangram.ipynb).
42+
For more details on how to use Tangram check out [our tutorial](https://github.com/broadinstitute/Tangram/blob/master/example/1_tutorial_tangram.ipynb). [![colab tutorial](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1SVLUIZR6Da6VUyvX_2RkgVxbPn8f62ge?usp=sharing)
4243

4344
***
4445
## How Tangram works under the hood
@@ -48,7 +49,7 @@ Tangram instantiates a `Mapper` object passing the following arguments:
4849

4950
Then, Tangram searches for a mapping matrix _M_, with shape voxels-by-cells, where the element _M\_ij_ signifies the probability of cell _i_ of being in spot _j_. Tangram computes the matrix _M_ by minimizing the following loss:
5051

51-
<img src="figures/tangram_loss.gif" width="400">
52+
<img src="https://raw.githubusercontent.com/broadinstitute/Tangram/master/figures/tangram_loss.gif" width="400">
5253

5354
where cos_sim is the cosine similarity. The meaning of the loss function is that gene expression of the mapped single cells should be as similar as possible to the spatial data _G_, under the cosine similarity sense.
5455

@@ -79,7 +80,9 @@ If you have questions, please contact the authors of the method:
7980
- Tommaso Biancalani - <[email protected]>
8081
- Gabriele Scalia - <[email protected]>
8182

82-
The artwork has been curated by:
83-
- Anna Hupalowska <ahupalow@broadinstitute.org>
84-
83+
PyPI maintainer:
84+
- Tommaso Biancalani - <tbiancal@broadinstitute.org>
85+
- Ziqing Lu - <[email protected]>
8586

87+
The artwork has been curated by:
88+
- Anna Hupalowska <[email protected]>

example/1_tutorial_tangram.ipynb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@
99
"- The notebook uses data from mouse brain cortex, although different than those adopted in the manuscript (which need to wait May 2020 before being released).\n",
1010
"\n",
1111
"#### Changelog\n",
12+
"- Fixes - Jan 31 2021 by Ziqing Lu <[email protected]>\n",
1213
"- Fixes - Jan 4th 2021 by Ziqing Lu <[email protected]>\n",
1314
"- Written - Dec 30th 2020 by Tommaso Biancalani <[email protected]>"
1415
]
1516
},
17+
{
18+
"source": [
19+
"First of all, make sure tangram-sc is installed (pip install tangram-sc) and environment is set up according to environment.yml"
20+
],
21+
"cell_type": "markdown",
22+
"metadata": {}
23+
},
1624
{
1725
"cell_type": "code",
1826
"execution_count": 1,
@@ -25,9 +33,6 @@
2533
"import matplotlib.pyplot as plt\n",
2634
"import scanpy as sc\n",
2735
"import torch\n",
28-
"\n",
29-
"# add path of Tangram repository for importing it\n",
30-
"sys.path.append(\"./..\") \n",
3136
"import tangram as tg"
3237
]
3338
},
@@ -182,7 +187,7 @@
182187
"\n",
183188
"- By single cell data, we generally mean either scRNAseq or snRNAseq.\n",
184189
"- We start by mapping the MOp 10Xv3 dataset, which contains single nuclei collected from a posterior region of the primary motor cortex.\n",
185-
"- They are approximately 53k profiled cells with 28k genes."
190+
"- They are approximately 26k profiled cells with 28k genes."
186191
]
187192
},
188193
{
@@ -453,9 +458,6 @@
453458
"import matplotlib.pyplot as plt\n",
454459
"import scanpy as sc\n",
455460
"import torch\n",
456-
"\n",
457-
"# add path of Tangram repository for importing it\n",
458-
"sys.path.append(\"./..\") \n",
459461
"import tangram as tg"
460462
]
461463
},
@@ -477,7 +479,7 @@
477479
"- Mapping should be interrupted after the score plateaus,which can be controlled by passing the `num_epochs` parameter. \n",
478480
"- The score measures the similarity between the gene expression of the mapped cells vs spatial data: higher score means \n",
479481
"- Note that we obtained excellent mapping even if Tangram converges to a low scores (the typical case is when the spatial data are very sparse): we use the score merely to assess convergence.\n",
480-
"- If you are running Tangram with a GPU, uncomment`device=cuda: 0` and comment the line `device=cpu`. On a MacBook Pro 2018, it takes ~1h to run. On a P100 GPU it should be done in a few minutes.\n",
482+
"- If you are running Tangram with a GPU, uncomment `device=cuda: 0` and comment the line `device=cpu`. On a MacBook Pro 2018, it takes ~1h to run. On a P100 GPU it should be done in a few minutes.\n",
481483
"- For this basic mapping, we do not use regularizers (hence the `NaN`). More sophisticated loss functions can be used using the Tangram library (refer to manuscript or dive into the code)."
482484
]
483485
},
@@ -568,9 +570,6 @@
568570
"import matplotlib.pyplot as plt\n",
569571
"import scanpy as sc\n",
570572
"import torch\n",
571-
"\n",
572-
"# add path of Tangram repository for importing it\n",
573-
"sys.path.append(\"./..\") \n",
574573
"import tangram as tg"
575574
]
576575
},
@@ -579,7 +578,7 @@
579578
"metadata": {},
580579
"source": [
581580
"- We load the single cell data, the spatial data and the mapping results.\n",
582-
"- We load the original datasets, rather than the `AnnData`s pre-processed with `pp_adatas`, as we would like to "
581+
"- We load the original datasets, rather than the `AnnData` pre-processed with `pp_adatas`, as we would like to "
583582
]
584583
},
585584
{
@@ -1370,7 +1369,7 @@
13701369
"metadata": {},
13711370
"source": [
13721371
"- We can use again `plot_genes` to visualize gene patterns.\n",
1373-
"- Interestingly, the agreement for genes `Atp1b1` or `Apt1a3`, seems less good that that for `Ctgf` and `Nefh`, despite the scores are higher for the former genes. This is because even though the latter gene patterns are localized correctly, their expression values are not so well correlated (for instance, in `Ctgf` the \"bright yellow spot\" is in different part of layer 6b). In contrast, for `Atpb1` the gene expression pattern is largely recover, even though the overall gene expression in the spatial data is more dim."
1372+
"- Interestingly, the agreement for genes `Atp1b1` or `Apt1a3`, seems less good than that for `Ctgf` and `Nefh`, despite the scores are higher for the former genes. This is because even though the latter gene patterns are localized correctly, their expression values are not so well correlated (for instance, in `Ctgf` the \"bright yellow spot\" is in different part of layer 6b). In contrast, for `Atpb1` the gene expression pattern is largely recover, even though the overall gene expression in the spatial data is more dim."
13741373
]
13751374
},
13761375
{
@@ -1429,4 +1428,4 @@
14291428
},
14301429
"nbformat": 4,
14311430
"nbformat_minor": 4
1432-
}
1431+
}

setup.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
3+
import setuptools
4+
5+
with open("README.md","r", encoding="utf-8") as fh:
6+
long_description = fh.read()
7+
8+
d = {}
9+
with open('tangram/_version.py') as f: exec(f.read(), d)
10+
11+
setuptools.setup(
12+
name="tangram-sc",
13+
version=d['__version__'],
14+
author="Tommaso Biancalani, Gabriele Scalia",
15+
author_email="[email protected]",
16+
description="Spatial alignment of single cell transcriptomic data.",
17+
long_description=long_description,
18+
long_description_content_type="text/markdown",
19+
url="https://github.com/broadinstitute/Tangram",
20+
packages=setuptools.find_packages(),
21+
classifiers=[
22+
"Programming Language :: Python :: 3.6",
23+
"Operating System :: MacOS",
24+
],
25+
python_requires='>=3.6',
26+
install_requires=[
27+
"pip>=19.0.0",
28+
"torch>=1.4.0",
29+
"pandas>=1.1.0",
30+
"numpy>=1.19.1",
31+
"scipy>=1.5.2",
32+
"matplotlib>=3.0.0",
33+
"seaborn>=0.10.1",
34+
"scanpy==1.6.0",
35+
# "jupyterlab>=2.2.6",
36+
]
37+
)
38+
39+
40+

tangram/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from ._version import __version__
12
from .mapping_utils import *
23
from .utils import *
34
from .plot_utils import *

tangram/_version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import os
2+
__version__ = os.environ.get('TANGRAM_VERSION')

0 commit comments

Comments
 (0)