Skip to main content

FastSCODE

Project description

Drawing

Indroduction

  • FastSCODE: an accelerated implementation of SCODE based on manycore computing

Installation

  • :snake: Anaconda is recommended to use and develop FastSCODE.
  • :penguin: Linux distros are tested and recommended to use and develop FastSCODE.

Anaconda virtual environment

After installing anaconda, create a conda virtual environment for FastSCODE. In the following command, you can change the Python version (e.g. python=3.12).

conda create -n fastscode python=3.12

Now, we can activate our virtual environment for FastSCODE as follows.

conda activate fastscode

Install from PyPi

pip install fastscode
  • Default backend framework of the FastSCODE is PyTorch.- You need to install other backend frameworks such as CuPy, Jax, and TensorFlow

Install from GitHub repository

First, clone the recent version of this repository.

git clone https://github.com/cxinsys/fastscode.git

Now, we need to install FastSCODE as a module.

cd fastscode
pip install -e .

FastSCODE tutorial

Create FastSCODE instance

The FastSCODE class requires loaded files such as expression data arrays and pseudo time arrays, as well as several parameters for linear ODE optimization.

parameters

  • exp_data: expression data array (Gene (G) x Cell (C)), required
  • pseudotime: pseudotime data vector (C), required
  • node_name: vector for name of genes (G), required
  • droot: root directory for storing score matrix and RSS arrays, optional, default value is None, which means that the results are not saved
  • num_tf: number of genes to use, optional, default value is None, and all genes are used
  • num_cell: number of cells to use, optional, default value is None, and all cells are used
  • num_z: length of vector z for optimization, optional, default: 4
  • max_iter: number of iterations for optimization, optional, default: 100
  • max_b: maximum initialization value for parameter b, optional, default: 2.0
  • min_b: minimum initialization value for parameter b, optional, default: -10.0
  • dtype: data type, optional, default: float32
import fastscode as fs

exp_data = np.loadtxt(dpath_exp_data, delimiter=",", dtype=str)
node_name = exp_data[0, 1:]
exp_data = exp_data[1:, 1:].astype(np.float64).T  # gene x cell

pseudotime = np.loadtxt(dpath_trj_data, delimiter="\t")

worker = fs.FastSCODE(exp_data=exp_data,
                      pseudotime=pseudotime,
                      node_name=node_name,
                      droot=spath_droot_r,
                      num_tf=None,
                      num_cell=None,
                      num_z=num_z,
                      max_iter=max_iter,
                      dtype=np.float32)


Run FastSCODE

parameters

  • backend: optional, default: 'cpu'
  • device_ids: list or number of devcies to use, optional, default: [0] (cpu), [list of whole gpu devices] (gpu)
  • batch_size_b: batch size of optimization parameter B, optional, default: 1
  • batch_size: gene batch size of expression data, optional, default: compute all gene data at once
rss, score_matrix = worker.run(backend='gpu',
                               device_ids=8,
                               sampling_batch=100,
                               batch_size=1024)


Run FastSCODE with tutorial_notf.py

  • Before run run_scode.py, batch_size_b and batch_size parameter must be modified to fit your gpu memory size

Usage

python run_scode.py --droot [root directory]
                    --fp_exp [expression file path]
                    --fp_trj [trajectory (pseudotime) file path] 
                    --fp_branch [cell select file path] 
                    --num_z [number of vector z]
                    --max_iter [number of optimization step]
                    --backend [name of backend framework]
                    --num_devices [number of devices]
                    --batch_size_b [number of parameter b]
                    --batch_size [number of batch size]
                    --sp_droot [droot directory for saving results]
                    --num_repeat [total number of computation iterations]

Example

python run_scode.py --droot .
                    --fp_exp expression_dataTuck_sub.csv
                    --fp_trj pseudotimeTuck.txt
                    --fp_branch cell_selectTuck.txt
                    --num_z 10
                    --max_iter 100
                    --backend gpu
                    --num_devices 8
                    --batch_size_b 10
                    --batch_size 4000
                    --sp_droot out
                    --num_repeat 6

Output

RSS.txt

ex)
3367844277.01837


score_matrix.txt                            

ex)
Score	GENE_1	GENE_2	GENE_3	...	GENE_M
GENE_1	0	0.05	0.02	...	0.004
GENE_2	0.01	0	0.04	...	0.12
GENE_3	0.003	0.003	0	...	0.001
.
.
.
GENE_M	0.34	0.012	0.032	...	0


Downstream analysis tutorial

Create NetWeaver instance

parameters

  • result_matrix: result TE matrix of FastTENET, required
  • gene_names: gene names from result matrix, required
  • tfs: tf list, optional
  • fdr: specifying fdr, optional, default: 0.01
  • links: specifying number of outdegrees, optional, default: 0
  • is_trimming: if set True, trimming operation is applied on grn, optional, default: True
  • trim_threshold: trimming threshold, optional, default: 0
result_matrix = np.loadtxt(fpath_result_matrix, delimiter='\t', dtype=str)
gene_name = result_matrix[0][1:]
result_matrix = result_matrix[1:, 1:].astype(np.float32)

tf = np.loadtxt(fpath_tf, dtype=str)

weaver = fte.NetWeaver(result_matrix=result_matrix,
                       gene_names=gene_name,
                       tfs=tf,
                       fdr=fdr,
                       links=links,
                       is_trimming=True,
                       trim_threshold=trim_threshold,
                       dtype=np.float32
                       )

Run weaver

  • backend: optional, default: 'cpu'
  • device_ids: list or number of devices to use, optional, default: [0] (cpu), [list of whole gpu devices] (gpu)
  • batch_size: if set to 0, batch size will automatically calculated, optional, default: 0
grn, trimmed_grn = weaver.run(backend=backend,
                              device_ids=device_ids,
                              batch_size=batch_size)

Count outdegree

  • grn: required
outdegrees = weaver.count_outdegree(grn)
trimmed_ods = weaver.count_outdegree(trimmed_grn)


Downstream analysis with reconstruct_grn.py

reconstruct_grn.py is a tutorial script for the output of grn and outdegree files.

Usage

When specifying an fdr

python reconstruct_grn.py --fp_rm [result matrix path] --fp_tf [tf file path] --fdr [fdr] --backend [backend] --device_ids [number of device]

Example

python reconstruct_grn.py --fp_rm TE_result_matrix.txt --fp_tf mouse_tf.txt --fdr 0.01 --backend gpu --device_ids 1

Output

score_matrix.fdr0.01.sif, score_matrix.fdr0.01.sif.outdegrees.txt
score_matrix.fdr0.01.trimIndirect0.sif, score_matrix.fdr0.01.trimIndirect0.sif.outdegrees.txt

Usage

When specifying the links

python reconstruct_grn.py --fp_rm [result matrix path] --fp_tf [tf file path] --links [links] --backend [backend] --device_ids [number of device]

Example

python reconstruct_grn.py --fp_rm TE_result_matrix.txt--fp_tf mouse_tf.txt --links 1000 --backend gpu --device_ids 1

Output

score_matrix.links1000.sif, score_matrix.links1000.sif.outdegrees.txt
score_matrix.links1000.trimIndirect0.sif, score_matrix.links1000.trimIndirect0.sif.outdegrees.txt

TODO

  • Upload to PyPi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastscode-0.0.4.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastscode-0.0.4-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file fastscode-0.0.4.tar.gz.

File metadata

  • Download URL: fastscode-0.0.4.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastscode-0.0.4.tar.gz
Algorithm Hash digest
SHA256 8a153baeeac47557f483be1bc35b73f57de167ae37cbb454129da4bba2cc8e19
MD5 51c3ec7c10ae4e04e6e6f5240a44452f
BLAKE2b-256 7bc6fc4ed8ad76862bcf9c31d6a75aa5b78ceee37c43e74eb6e69c98d7ac1cef

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastscode-0.0.4.tar.gz:

Publisher: publish.yml on cxinsys/fastscode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastscode-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: fastscode-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastscode-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a7d745af91bee2c0cefa3ebf6614aeca23458ab3b4a1b6a574735bd600b5a118
MD5 123d92fa10cebdedf08994b72bb6b13a
BLAKE2b-256 eee413c779af5dd68968b9ab08be6935c7890308f7e2c592113fd209e631cbc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastscode-0.0.4-py3-none-any.whl:

Publisher: publish.yml on cxinsys/fastscode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page