Giter Club home page Giter Club logo

sctour's Introduction

scTour

scTour is an innovative and comprehensive method for dissecting cellular dynamics by analysing datasets derived from single-cell genomics.

It provides a unifying framework to depict the full picture of developmental processes from multiple angles including the developmental pseudotime, vector field and latent space.

It further generalises these functionalities to a multi-task architecture for within-dataset inference and cross-dataset prediction of cellular dynamics in a batch-insensitive manner.

Key features

  • cell pseudotime estimation with no need for specifying starting cells.
  • transcriptomic vector field inference with no discrimination between spliced and unspliced mRNAs.
  • latent space mapping by combining intrinsic transcriptomic structure with extrinsic pseudotime ordering.
  • model-based prediction of pseudotime, vector field, and latent space for query cells/datasets/time intervals.
  • insensitive to batch effects; robust to cell subsampling; scalable to large datasets.

Installation

PyPI

pip install sctour

Conda

conda install -c conda-forge sctour

Documentation

Documentation Status

Full documentation can be found here.

Reference

Qian Li, scTour: a deep learning architecture for robust inference and accurate prediction of cellular dynamics. Genome Biology, 2023

sctour's People

Contributors

liqian-xc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sctour's Issues

Reusing trained models

Hi, thank you for writing this package. It's extremely easy to get up and running and seems to do wonderfully on our data.

Admittedly, I'm new to pytorch and I usually stick to using R, so there might be something obvious I'm missing. I'd like to train a model using a dataset (say, sorted cells) then apply the model to predict the latent space/pseudotime to another dataset.

In the tutorials you show how to apply a trained model to new data, but could you point me in the right direction on how load a model after saving it using tnode.save_model()?

tnode.train() Error

Hi,

When I run the following code:

tnode = sct.train.Trainer(adata, use_gpu=False)
tnode.train()
adata.obs['ptime'] = tnode.get_time()
mix_zs, zs, pred_zs = tnode.get_latentsp(alpha_z=0.7, alpha_predz=0.3)
adata.obsm['X_TNODE'] = mix_zs
adata.obsm['X_VF'] = tnode.get_vector_field(adata.obs['ptime'].values, mix_zs)

I'm getting the following error, it seems to be failing on the tnode.train()

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[7], [line 2](vscode-notebook-cell:?execution_count=7&line=2)
      [1](vscode-notebook-cell:?execution_count=7&line=1) tnode = sct.train.Trainer(adata, use_gpu=False)
----> [2](vscode-notebook-cell:?execution_count=7&line=2) tnode.train()
      [3](vscode-notebook-cell:?execution_count=7&line=3) adata.obs['ptime'] = tnode.get_time()
      [4](vscode-notebook-cell:?execution_count=7&line=4) mix_zs, zs, pred_zs = tnode.get_latentsp(alpha_z=0.7, alpha_predz=0.3)

File [~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:265](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:265), in Trainer.train(self)
    [263](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:263) with tqdm(total=self.nepoch, unit='epoch') as t:
    [264](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:264)     for tepoch in range(t.total):
--> [265](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:265)         train_loss = self._on_epoch_train(self.train_dl)
    [266](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:266)         val_loss = self._on_epoch_val(self.val_dl)
    [267](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:267)         self.log['train_loss'].append(train_loss)

File [~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:296](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:296), in Trainer._on_epoch_train(self, DL)
    [294](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:294) X = X.to(self.device)
    [295](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:295) Y = Y.to(self.device)
--> [296](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:296) loss, recon_loss_ec, recon_loss_ode, kl_div, z_div = self.model(X, Y)
    [297](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:297) loss.backward()
    [298](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/sctour/train.py:298) self.optimizer.step()

File [~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/module.py:1518](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/module.py:1518), in Module._wrapped_call_impl(self, *args, **kwargs)
   [1516](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/module.py:1516)     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   [1517](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/module.py:1517) else:
...
File [~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/linear.py:114](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/linear.py:114), in Linear.forward(self, input)
    [113](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/linear.py:113) def forward(self, input: Tensor) -> Tensor:
--> [114](https://file+.vscode-resource.vscode-cdn.net/Users/james/Documents/Work/Research%20Job/Computational/TEST/analysis/20240321/filtered/~/miniconda3/envs/parse/lib/python3.10/site-packages/torch/nn/modules/linear.py:114)     return F.linear(input, self.weight, self.bias)

RuntimeError: mat1 and mat2 must have the same dtype, but got Double and Float

I'm not sure how I can debug the error - are you able to provide any insight ?

Availability of demo dataset

Hi Qian,

Thanks a lot for this fantastic package. This is really a great tool.

In the tutorial of scTour’s cross-data predictions and Using scTour to infer cellular dynamics, the demo data can not be found:

'../../../mouse_endo_brain/raw_count_matrix_brain.txt'
'../../../mouse_endo_brain/Metadata.csv'
'../../../../EX_development_data/EX_development_human_cortex_10X.h5ad'
'../../../../EX_development_data/EX_development_human_cortex_DropSeq.h5ad'
'../../../../EX_development_data/EX_development_human_organoids_10X.h5ad'
'../../../../EX_development_data/EX_development_mouse_cortex_10X.h5ad'

Would you kindly upload them?

Cheers,
Yingcheng

`.X`. error using sct.train.Trainer()

Hi, Qian,

I am using adata as input of the h5ad file converted from Seurat. Adding data from RNA as X, adding counts from RNA as raw, transferring meta.data to obs.

During model training, I encountered the following error at the step involving sct.train.Trainer(). Even after adding the step adata.X <- adata.raw.X, the issue persists. Can you help me solve this problem? Thanks so much!

Related codes ad follows:
adata.X
<Compressed Sparse Row sparse matrix of dtype 'float64'
with 486880 stored elements and shape (5000, 1000)>
adata.raw.X
<Compressed Sparse Row sparse matrix of dtype 'float64'
with 17799636 stored elements and shape (5000, 33694)>

sc.pp.calculate_qc_metrics(adata, percent_top=None, log1p=False, inplace=True)
sc.pp.highly_variable_genes(adata, flavor='seurat_v3', n_top_genes=1000, subset=True)

/.../python3.10/site-packages/scanpy/preprocessing/_highly_variable_genes.py:75: UserWarning: flavor='seurat_v3' expects raw count data, but non-integers were found.
warnings.warn(

tnode = sct.train.Trainer(adata, loss_mode='nb', alpha_recon_lec=0.5, alpha_recon_lode=0.5)
tnode.train()


ValueError Traceback (most recent call last)
Cell In[36], line 1
----> 1 tnode = sct.train.Trainer(adata, loss_mode='nb', alpha_recon_lec=0.5, alpha_recon_lode=0.5)
2 tnode.train()

File /.../python3.10/site-packages/sctour/train.py:168, in Trainer.init(self, adata, percent, n_latent, n_ode_hidden, n_vae_hidden, batch_norm, ode_method, step_size, alpha_recon_lec, alpha_recon_lode, alpha_kl, loss_mode, nepoch, batch_size, drop_last, lr, wt_decay, eps, random_state, val_frac, use_gpu)
166 X = self.adata.X.data if sparse.issparse(self.adata.X) else self.adata.X
167 if (X.min() < 0) or np.any(~np.equal(np.mod(X, 1), 0)):
--> 168 raise ValueError(
169 f"Invalid expression matrix in .X. {self.loss_mode} mode expects raw UMI counts in .X of the AnnData."
170 )
172 self.n_cells = adata.n_obs
173 self.batch_size = batch_size

ValueError: Invalid expression matrix in .X. nb mode expects raw UMI counts in .X of the AnnData.

Depends on scikit-misc?

Hello - After installing sctour via pip, I received an error about needing scikit-misc. This is easy enough to install, but should this be added to setup.py?

calculating expression dynamics genes in Fig6E

Hi, Dr Li,
Thank you for your nice work which brought so much convenience.
After calculating the ptime, I want to further explore the genes changing along with the ptime, is there a function and visualization for this?
Thank you!

More demonstrations?

Hi,

Thanks for developing scTour which provides another possible solution to RNA velocity problem. I want to ask that, what would happen if the stem cells are on the middle of UMAP, like surrounded by different terminal cell types. Can scTour predict this scenario successfully?

Trajectory inference of datasets with batch

Hi Qian,

Thanks again for this beautiful work.

I have lists of UMI matrix, integrated them by using scTransform or harmony (in R, and transfer it to h5ad), and generated the dimension reduction coordinates (i.e. UMAP). Those lists of UMI matrix are generated at different timepoints and treatment conditions. When following the notebook of scTour_inference_basic.ipynb, it seems that the inferred trajectory is from batch 1 to batch 2 cells.

Cheers,
Yingcheng

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.