Skip to content

Commit

Permalink
Merge branch 'main' of github.com:inoue0426/scBiGCN
Browse files Browse the repository at this point in the history
  • Loading branch information
inoue0426 committed Mar 31, 2024
2 parents 5aab9e9 + b21aa35 commit f572c15
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 56 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/python-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Python Formatting

on: [push]

jobs:
format-code:
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install black
run: python -m pip install black
- name: Format code
run: black .
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply auto-formatting
branch: ${{ github.head_ref }}
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.9-slim
USER root

# install the notebook package
RUN pip install --no-cache --upgrade pip && \
pip install --no-cache torch --index-url https://download.pytorch.org/whl/cpu && \
pip install --no-cache torch_geometric && \
pip install --no-cache pyg_lib torch_sparse -f https://data.pyg.org/whl/torch-2.0.0+cpu.html
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
# BiGCN: Leveraging Cell and Gene Similarities for Single-cell Transcriptome Imputation with Bi-Graph Convolutional Networks

This is an official implementation of the paper, "BiGCN: Leveraging Cell and Gene Similarities for Single-cell Transcriptome Imputation with Bi-Graph Convolutional Networks"
![](overview.png)

scBiGCN is a method that utilizes two GCNs to reconstruct gene expression matrices based on the similarity matrices of cells and genes. Utilizing each similarity enables the recovery of information lost through Dropout.
This is an official implementation of the paper, "BiGCN: Leveraging Cell and Gene Similarities for Single-cell Transcriptome Imputation with Bi-Graph Convolutional Networks"

<img width="1027" alt="Screenshot 2023-09-14 at 15 49 53" src="https://github.com/inoue0426/scBiGCN/assets/8393063/c9d1fbc0-bdf0-49b3-91b3-50181cbe16ec">
scBiGCN is a method that utilizes two GCNs to reconstruct gene expression matrices based on the similarity matrices of cells and genes. Using each similarity enables the recovery of information lost through Dropout.

scBiGCN has been implemented in Python.

To get started immediately, check out our tutorials:
- [Tutorial](https://github.com/inoue0426/scBiGCN/blob/main/sample%20notebook.ipynb)

## Installation from GitHub
To clone the repository and install manually, run the following from a terminal:
```
git clone [email protected]:inoue0426/scBiGCN.git
cd scBiGCN
conda create --name scBiGCN python=3.10 -y
conda activate scBiGCN
pip install -r requirement.txt
```

## Requirement

```
numpy==1.23.5
pandas==2.0.3
scikit-learn==1.3.0
torch==1.13.1
torch==1.13.1+cu116
torch-geometric==2.3.1
torch-sparse==0.6.17
torch-sparse==0.6.17+pt113cu116
tqdm==4.65.0
```

** Note: To utilize GPU acceleration, it is necessary to configure your own CUDA environment for PyTorch and PyTorch-Sparse.

## Environment

Our experiment was conducted on Ubuntu with an RTX 2080 and Nvidia A100. To use this model, please adjust the requirements to suit your environment, paying special attention to the PyTorch-related libraries.

## Installation from GitHub
To clone the repository and install manually, run the following from a terminal:
```
git clone [email protected]:inoue0426/scBiGCN.git
cd scBiGCN
conda create --name scBiGCN python=3.10 -y
conda activate scBiGCN
pip install -r requirement.txt
# Please make sure to change the version to match the version of your GPU/CPU machine exactly.
pip install --no-cache-dir torch==1.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install --no-cache-dir torch_geometric
pip install --no-cache-dir pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-1.13.1%2Bcu116.html
```

## Usage

### Quick Start
Expand All @@ -50,4 +58,4 @@ bigcn.run_model(df, verbose=True)
```

## Help
If you have any questions or require assistance using MAGIC, please feel free to make a issues on https://github.com/inoue0426/scBiGCN/
If you have any questions or require assistance using MAGIC, please feel free to make an issue on https://github.com/inoue0426/scBiGCN/
77 changes: 43 additions & 34 deletions Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"id": "53d47961",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/export/scratch/inoue019/envs/scBiGCN/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
Expand All @@ -32,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "ede9e8c6",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -395,7 +404,7 @@
"[1000 rows x 5000 columns]"
]
},
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -415,7 +424,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "bc4d19df",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -789,7 +798,7 @@
"[1000 rows x 5000 columns]"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -809,23 +818,23 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "486ba660",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1500/1500 [02:01<00:00, 12.37it/s]"
"100%|██████████| 1500/1500 [02:01<00:00, 12.34it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 2min 6s, sys: 3.59 s, total: 2min 10s\n",
"Wall time: 2min 3s\n"
"CPU times: user 2min 6s, sys: 3.54 s, total: 2min 10s\n",
"Wall time: 2min 4s\n"
]
},
{
Expand All @@ -838,22 +847,22 @@
{
"data": {
"text/plain": [
"array([[0.02243742, 0. , 0.176742 , ..., 0.11798435, 0. ,\n",
" 0.0194989 ],\n",
" [0.16287151, 0.03038947, 0.12390558, ..., 0.04714939, 0.023552 ,\n",
" 0.25994456],\n",
" [0.04037532, 0.01580523, 0.13696328, ..., 0.13242072, 0. ,\n",
" 0.05790219],\n",
"array([[0.06184705, 0.01784644, 0.1660583 , ..., 0.02843533, 0. ,\n",
" 0.03826597],\n",
" [0.15132436, 0.03581575, 0.1416667 , ..., 0.0666969 , 0.00558404,\n",
" 0.22870545],\n",
" [0. , 0. , 0.17596829, ..., 0.00705822, 0. ,\n",
" 0.00371063],\n",
" ...,\n",
" [0.07433029, 0.04123527, 0.10616948, ..., 0.04192581, 0.02231284,\n",
" 0.06234603],\n",
" [0.08945477, 0.05060229, 0.1150779 , ..., 0.05662287, 0.0437512 ,\n",
" 0.07167498],\n",
" [0.06099119, 0. , 0.02700689, ..., 0.06171517, 0.0186478 ,\n",
" 0.11376322]], dtype=float32)"
" [0.07470302, 0.02687185, 0.14962952, ..., 0.05768366, 0.01138911,\n",
" 0.03132814],\n",
" [0.08545761, 0.03409339, 0.1452198 , ..., 0.06482822, 0.01634106,\n",
" 0.07690162],\n",
" [0.08783356, 0.00831476, 0.03660469, ..., 0.03977096, 0.0350069 ,\n",
" 0.10716291]], dtype=float32)"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -890,7 +899,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "bca9f626",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -1253,7 +1262,7 @@
"[1000 rows x 5000 columns]"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1273,7 +1282,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "92139141",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1647,7 +1656,7 @@
"[995 rows x 4744 columns]"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1672,23 +1681,23 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "4fb7ab66",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 100/100 [00:03<00:00, 25.88it/s]"
"100%|██████████| 100/100 [00:03<00:00, 26.11it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 8.35 s, sys: 2.53 s, total: 10.9 s\n",
"Wall time: 4.9 s\n"
"CPU times: user 8.22 s, sys: 2.67 s, total: 10.9 s\n",
"Wall time: 4.87 s\n"
]
},
{
Expand Down Expand Up @@ -1716,7 +1725,7 @@
" -1.1651450e-02, -1.5314183e-02, -2.4916604e-03]], dtype=float32)"
]
},
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1738,9 +1747,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "test",
"display_name": "scBiGCN",
"language": "python",
"name": "test"
"name": "scbigcn"
},
"language_info": {
"codemirror_mode": {
Expand Down
6 changes: 3 additions & 3 deletions bigcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def forward(self, data, x, adj, x_t, adj_t, clustering):
return res


def run_model(input_data, params=None, clustering=False, verbose=False):
def run_model(input_data, params=None, clustering=False, verbose=False, device=False):
"""Run model
input_data: gene expression matrix
Expand Down Expand Up @@ -114,8 +114,8 @@ def run_model(input_data, params=None, clustering=False, verbose=False):
"optimizer": "Adam",
"clustering": True,
}

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
if device:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

x, adj = get_data(input_data)
x_t, adj_t = get_data(input_data.T)
Expand Down
Binary file added overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions requirement.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
numpy==1.23.5
pandas==2.0.3
scikit-learn==1.3.0
torch==1.13.1
torch-geometric==2.3.1
torch-sparse==0.6.17
tqdm==4.65.0

0 comments on commit f572c15

Please sign in to comment.