Skip to content

About

As a step-by-step tutorial to guides users build their own scRNAseq database by R package - SeuratExplorerServer, which also provide researchers a new tool to investigate fly scRNAseq data.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Deploy FLY CELL ATLAS database by SeuratExplorer Server

why do this?

As a step-by-step tutorial to guides users build their own scRNAseq database by R package - SeuratExplorerServer, which also provide researchers a new tool to investigate fly scRNAseq data.

Check the demo database, Account: shiny, Password: 12345.

1. prepare data

Download data from FLY CELL ATLAS, only select H5AD files.

1.1 get download links

Refer to s1_download-h5ad-files.md: manually copy the Data Table from the Fly Cell Atlas website (select "Show 100 entries", select all, paste into Excel).

All download links have already been extracted and saved in input-data_updated.csv (column H5AD_Links), in the format:

https://cloud.flycellatlas.org/index.php/s/{token}/download/{filename}.h5ad

1.2 download

Use download managers, such as Neat Download Manager (for windows) or Uget (for linux). Download all H5AD files into a flat directory, e.g. Downloaded_Data/.

1.3 arrange metadata

s2.0_arrange-data-meta.R: read input-data_updated.csv, deduplicate filenames (append (1) to duplicates), check file existence, add SCope/ASAP external viewer links, rename columns, and output metadata.csv.

metadata.csv is the master metadata table used by downstream conversion (step 2) and the index page (step 3.4).

1.4 reference genome

All Fly Cell Atlas single-cell data (both 10x and SMART-seq2) was mapped to the same reference:

Item Version
Genome assembly BDGP6 (dm6), patch BDGP6.31
Gene annotation FlyBase release 6.31 (r6.31)
Reference type pre-mRNA (introns retained, for single-nucleus sequencing)
Cell Ranger v3.1.0 (for 10x data)

See Reference-used-infered-by-AI.md for the full derivation.

2. Trans python anndata object to R Seurat object

2.1 install python environment

s2.1_trans-anndata-to-seurat.sh: create a conda environment scanpy and install scanpy, anndata, numpy, pandas, jupyter.

conda create --name scanpy
conda activate scanpy
conda install scanpy anndata numpy pandas jupyter
jupyter-notebook

2.2 update anndata to use raw

s2.2_update-anndata-to-use-raw.ipynb: for each H5AD file, convert to raw counts if adata.raw exists (raw usually has more genes), and save as *_new.h5ad.

Key logic per file:

  • If *_new.h5ad already exists → skip (print escaped!).
  • If adata.raw is not None → back up obsm['X_umap'], obsm['X_tsne'], and uns; do adata = adata.raw.to_adata(); restore the backed-up embeddings and uns; write *_new.h5ad.
  • If adata.raw is None → skip (print Escaped for no raw data found!).

The UMAP/tSNE/uns backup is necessary because raw.to_adata() only carries over X/var/obs and drops obsm and uns.

The notebook also generates two cell-count reports:

  • cell_counts.txt: filename and cell count (adata.n_obs) for each original H5AD.
  • cell_counts_new.txt: filename and cell count for each *_new.h5ad.

2.3 convert anndata to seurat

s2.3_trans-anndata-to-seurat.R: use R package schard to convert H5AD files to Seurat objects, saved in .qs2 format (via qs2).

Workflow:

  1. Read metadata.csv; for each tissue, create a parent directory Data/{Tissue}/; for each analysis, create Data/{Tissue}/{Analysis}/.
  2. For each analysis, prefer the *_new.h5ad file (from step 2.2) if it exists, otherwise fall back to the original H5AD.
  3. Convert via h5ad2seurat() and save as .qs2. Skip if the .qs2 already exists. Errors are caught with tryCatch so one failure does not stop the batch.
  4. Second pass: read back each .qs2 file, record cell count (ncol) into metadata.csv.
  5. Aggregate metadata by tissue (collapse multiple analyses per tissue into semicolon-separated strings) and write meta_data_index.csv.

Output directory structure:

Data/
├── Antenna/
│   ├── 10x_and_SMART-seq2_Integrated_Antenna/
│   │   └── antenna.qs2
│   ├── 10x_VSN_Antenna_(Relaxed)/
│   │   └── r_fca_biohub_antenna_10x.qs2
│   └── ...
├── Body/
│   └── ...
└── ...

3. Build scRNAseq database

3.1 prepare directory

Build directories bellow, which should under shinyserver site directory, refer to 'Database Deployment Guide' part from fentouxungui/SeuratExplorerServer

shiny-server/
├── apps
└── index-page

apps to save individual app for each tissue index-page to browse all apps, which has included all urls of all apps

3.2 generate credentials file

s3.1_generate-credentials-file.R: use shinymanager to create a credentials file credentials.rds.

After creating credentials, modify the credentials parameter in app.R_demo file to point to the absolute path of credentials.rds.

3.3 batch create apps

s3.2_batch-generate-apps.R: batch create apps for each tissue using SeuratExplorerServer.

For each tissue directory under ../Data:

  1. Create ../shiny-server/apps/{tissue}/.
  2. Copy app.R_demo into it as app.R.
  3. Scan for .qs2 / .rds files recursively under ../Data/{tissue}/.
  4. Initialize metadata (initialize_metadata) and save as data_meta.rds.

Now you can test each app by use url: IP address plus app directory

in the demo: http://netinfo.nibs.ac.cn:666 is the shiny-server IP address (with port), FlyCellAtlas-SES/shiny-server/apps/Antenna/ is the relative path to shiny-server site directory. The demo shiny-server site directory is set to /home/zhangyc/ShinyServer.

3.4 build index page

app.R_index.R: modify IP_address, relative_path, downloaded_data_info_file. then put it into index-page directory, and rename it to app.R.

The index page reads meta_data_index.csv (generated by step 2.3) and displays an interactive table with:

  • Tissue, Analysis, Technology, Age, Sex, Number of samples
  • Cell counts per analysis
  • Data link (to the tissue's Shiny app)
  • H5AD download links (direct download from Fly Cell Atlas cloud)
  • External viewer links (SCope, ASAP)

The info box documents the reference genome: FlyBase r6.31 pre-mRNA, CellRanger v3.1.0.

now you can visit index page use url: IP address plus index app directory

in the demo: http://netinfo.nibs.ac.cn:666 is the shiny-server IP address (with port), FlyCellAtlas-SES/shiny-server/index-page/ is the relative path to shiny-server site directory. The demo shiny-server site directory is set to /home/zhangyc/ShinyServer.

Scripts overview

Script Description
s1_download-h5ad-files.md Guide for obtaining H5AD download links from Fly Cell Atlas
s2.0_arrange-data-meta.R Process input-data_updated.csv into metadata.csv
s2.1_trans-anndata-to-seurat.sh Create conda environment with scanpy/anndata
s2.2_update-anndata-to-use-raw.ipynb Convert H5AD to raw counts, preserve embeddings, generate cell-count reports
s2.3_trans-anndata-to-seurat.R Convert H5AD to Seurat .qs2, organize by tissue/analysis, generate meta_data_index.csv
s3.1_generate-credentials-file.R Generate credentials.rds via shinymanager
s3.2_batch-generate-apps.R Batch generate Shiny apps per tissue
app.R_demo Template app.R for each tissue app
app.R_index.R Index page app showing all datasets with links
input-data_updated.csv Master table with H5AD download links
metadata.csv Processed metadata (generated by s2.0)
meta_data_index.csv Tissue-aggregated metadata with cell counts (generated by s2.3)
Reference-used-infered-by-AI.md Documentation of reference genome version

Data and codes availability

All data and scripts can be downloaded from Fly Cell Atlas - by SeuratExplorer Server, and the scripts can also be downloaded from github - fentouxungui/FlyCellAtlas-SES

Congratulations!

About

As a step-by-step tutorial to guides users build their own scRNAseq database by R package - SeuratExplorerServer, which also provide researchers a new tool to investigate fly scRNAseq data.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages