{"id":319,"date":"2024-11-06T17:57:58","date_gmt":"2024-11-06T09:57:58","guid":{"rendered":"https:\/\/www.kz-hub.tech\/?p=319"},"modified":"2025-07-10T11:03:08","modified_gmt":"2025-07-10T03:03:08","slug":"%e4%bb%8ecellranger-count%e5%bc%80%e5%a7%8b%e7%9a%84velocyto%e3%80%81scvelo%e9%80%9f%e7%8e%87%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.kz-hub.tech\/index.php\/2024\/11\/06\/%e4%bb%8ecellranger-count%e5%bc%80%e5%a7%8b%e7%9a%84velocyto%e3%80%81scvelo%e9%80%9f%e7%8e%87%e5%88%86%e6%9e%90\/","title":{"rendered":"\u4eceCellranger Count\u5f00\u59cb\u7684velocyto\u3001scvelo\u901f\u7387\u5206\u6790"},"content":{"rendered":"<h4>1. \u9996\u5148\u4f7f\u7528 cellranger count \u5904\u7406\u539f\u59cbfastq\u6587\u4ef6<\/h4>\n<pre><code class=\"language-bash\"># \u6ce8\u610f\u6240\u6709fastq\u6587\u4ef6\u5fc5\u987b\u4e3aSampleName_S1_L001_R1_001.fastq.gz\u7684\u683c\u5f0f\ncellranger count --create-bam true --id SAMPLE --transcriptome=\/path\/to\/cellranger\/ref\/folder\/refdata-gex-GRCh38-2020-A --fastqs=\/path\/to\/fastq\/folder\/SAMPLE --sample=SAMPLE\n\n# \u8fd0\u884c\u540e\u5f97\u5230SAMPLE\u6587\u4ef6\u5939<\/code><\/pre>\n<p>\u6784\u5efa\u6279\u91cf\u8fd0\u884cCellRanger\u811a\u672c: CreateCellRangerScript.sh<\/p>\n<pre><code>#!\/bin\/bash\n\n# \u8bbe\u7f6e\u53d8\u91cf\nBASE_DIR=&quot;\/data02\/zhangmengmeng\/BPT\/scRNA\/RawData\/GEX&quot;\nCR_Ref=&quot;\/data02\/zhangmengmeng\/database\/cellranger\/refdata-gex-GRCh38-2024-A&quot;\nOUTPUT_SCRIPT=&quot;RunCellRanger.sh&quot;\n\n# \u6e05\u7a7a\u8f93\u51fa\u6587\u4ef6\n> &quot;$OUTPUT_SCRIPT&quot;\n\n# \u904d\u5386\u6bcf\u4e2a\u5b50\u76ee\u5f55\u5e76\u751f\u6210\u547d\u4ee4\nfor SAMPLE_DIR in &quot;$BASE_DIR&quot;\/*\/; do\n    SAMPLE=$(basename &quot;$SAMPLE_DIR&quot;)\n    echo &quot;cellranger count --create-bam true --id $SAMPLE --transcriptome $CR_Ref --fastqs $BASE_DIR\/$SAMPLE --sample $SAMPLE&quot; &gt;&gt; &quot;$OUTPUT_SCRIPT&quot;\ndone\n\n# \u8d4b\u4e88\u8f93\u51fa\u811a\u672c\u53ef\u6267\u884c\u6743\u9650\nchmod +x &quot;$OUTPUT_SCRIPT&quot;<\/code><\/pre>\n<h4>2. \u4f7f\u7528 conda \u5b89\u88c5 velocyto \u73af\u5883<\/h4>\n<pre><code class=\"language-bash\">conda create -n velocyto # python\u7248\u672c\u5e94\u8be5\u5927\u4e8e3.6\nconda activate velocyto\n\n# \u5b89\u88c5\u4f9d\u8d56\u5305\nconda install numpy scipy cython numba matplotlib scikit-learn h5py click\n\n# \u5b89\u88c5\u8f6f\u4ef6\npip install pysam\npip install velocyto\n\n# \u5c1d\u8bd5\u8fd0\u884cvelocyto\nvelocyto --help\n<\/code><\/pre>\n<h4>3. \u8fd0\u884cvelocyto<\/h4>\n<p>\u6ce8\u610f\u6b64\u5904\u6709bug\uff0ccellranger\u7684\u6587\u4ef6\u5939\u4e0b\uff0c\u5fc5\u987b\u6709outs\/filtered_feature_bc_matrix\/ \u6587\u4ef6\u5939\uff0c\u4e14filtered_feature_bc_matrix\u91cc\u7684barcodes.tsv\u5fc5\u987b\u540c\u65f6\u6709barcodes.tsv.gz\uff0c\u5426\u5219velocyto\u65e0\u6cd5\u8bc6\u522bbarcodes.tsv\uff0c\u4f1a\u62a5&quot;ERROR - Can not locate the barcodes.tsv file! for Cellranger Multiplexing outputs&quot;<\/p>\n<pre><code>\u4ecescAllele\u5206\u5f00\u7684bam\u6587\u4ef6\u91cd\u65b0\u63d0\u53d6barcode\uff1a\nfor f in FETB*.bam; do basename &quot;$f&quot; .bam | awk -F&#039;.&#039; &#039;{print $2}&#039;; done &gt; barcode.tsv<\/code><\/pre>\n<pre><code class=\"language-bash\">velocyto run10x -v .\/SAMPLE \/path\/to\/cellranger\/ref\/folder\/refdata-gex-GRCh38-2020-A\/genes\/genes.gtf\n\n# \u5f85\u7a0b\u5e8f\u8fd0\u884c\u5b8c\u5373\u53ef\u5728SAMPLE\u6587\u4ef6\u5939\u4e0b\u7684velocyto\u6587\u4ef6\u5939\u4e2d\u627e\u5230SAMPLE.loom\n\n# \u53ef\u9009\uff1a\u4eceUCSC\u4e0b\u8f7d\u8868\u8fbe\u91cd\u590d\u6ce8\u91ca\u6587\u4ef6\uff08expressed repeats annotation\uff09\nhttps:\/\/genome.ucsc.edu\/cgi-bin\/hgTables?hgsid=611454127_NtvlaW6xBSIRYJEBI0iRDEWisITa&clade=mammal&org=Human&db=0&hgta_group=allTracks&hgta_track=rmsk&hgta_table=rmsk&hgta_regionType=genome&position=&hgta_outputType=gff&hgta_outFileName=UCSC_hg38_rmsk.gtf\n\n# \u8fd0\u884c\u6d41\u7a0b\u6dfb\u52a0-m\nvelocyto run10x -v -m UCSC_hg38_rmsk.gtf .\/SAMPLE \/path\/to\/cellranger\/ref\/folder\/refdata-gex-GRCh38-2020-A\/genes\/genes.gtf<\/code><\/pre>\n<p>\u6784\u5efa\u6279\u91cf\u8fd0\u884cvelocyto\u811a\u672c: CreateVelocytoScript.sh<\/p>\n<pre><code>#!\/bin\/bash\n\n# \u8bbe\u7f6e\u53d8\u91cf\nBASE_DIR=&quot;\/data02\/zhangmengmeng\/BPT\/scRNA\/RawData\/GEX&quot;\nMASK_GTF=&quot;\/data02\/zhangmengmeng\/database\/cellranger\/UCSC_hg38_rmsk.gtf&quot;\nGENES_GTF=&quot;\/data02\/zhangmengmeng\/database\/cellranger\/genes.gtf&quot;\nOUTPUT_SCRIPT=&quot;RunVelocyto.sh&quot;\n\n# \u6e05\u7a7a\u8f93\u51fa\u6587\u4ef6\n> &quot;$OUTPUT_SCRIPT&quot;\n\n# \u904d\u5386\u6bcf\u4e2a\u5b50\u76ee\u5f55\u5e76\u751f\u6210\u547d\u4ee4\nfor SAMPLE_DIR in &quot;$BASE_DIR&quot;\/*\/; do\n    SAMPLE=$(basename &quot;$SAMPLE_DIR&quot;)\n    echo &quot;velocyto run10x -v -m $MASK_GTF $BASE_DIR\/$SAMPLE $GENES_GTF &gt;&gt; &quot;$OUTPUT_SCRIPT&quot;\ndone\n\n# \u8d4b\u4e88\u8f93\u51fa\u811a\u672c\u53ef\u6267\u884c\u6743\u9650\nchmod +x &quot;$OUTPUT_SCRIPT&quot;\n<\/code><\/pre>\n<h4>4. \u5c06loom\u6587\u4ef6\u5bfc\u5165R\u4e2d\u8fdb\u884c\u540e\u7eed\u5206\u6790<\/h4>\n<pre><code class=\"language-R\">devtools::install_github(&quot;rrydbirk\/velocyto.R&quot;)\nremotes::install_github(&#039;satijalab\/seurat-wrappers&#039;)\n\nlibrary(Seurat)\nlibrary(velocyto.R)\nlibrary(SeuratDisk)\nlibrary(SeuratWrappers)\n\n# \u8bfb\u53d6\u901f\u7387\u6587\u4ef6\u5e76\u8f6c\u6362\u4e3aseurat\nIBC01_T &lt;- ReadVelocity(&quot;\/home\/zhoukaiwen\/IBC\/scRNA\/cellranger_count\/velocyto\/loom\/IBC01-T.loom&quot;)\nIBC01_T &lt;- as.Seurat(IBC01_T)\n\n# \u5355\u7ec6\u80de\u6570\u636e\u5e38\u89c4\u5904\u7406\nIBC01_T@meta.data$orig.ident &lt;- &quot;IBC01_T&quot;\nIBC01_T[[&quot;RNA&quot;]] &lt;- IBC01_T[[&quot;spliced&quot;]]\nIBC01_T &lt;- NormalizeData(IBC01_T, normalization.method = &quot;LogNormalize&quot;, scale.factor = 10000)\nIBC01_T &lt;- FindVariableFeatures(IBC01_T, selection.method = &quot;vst&quot;, nfeatures = 2000)\nIBC01_T &lt;- ScaleData(IBC01_T, features = rownames(IBC01_T))\nIBC01_T &lt;- RunPCA(IBC01_T, features = VariableFeatures(object = IBC01_T), nps=50, verbose=TRUE)\nIBC01_T &lt;- FindNeighbors(IBC01_T,reduction = &quot;pca&quot;,dims = 1:20)\nIBC01_T &lt;- FindClusters(IBC01_T, resolution = 0.1)\nIBC01_T &lt;- RunUMAP(IBC01_T,dims = 1:20,reduction = &quot;pca&quot;)\n\n# \u5355\u72ec\u63d0\u53d6spliced\u548cunspliced\u6587\u4ef6\nemat &lt;- IBC01_T$spliced\nnmat &lt;- IBC01_T$unspliced\n\n# \u6b64\u5904\u8fd8\u9700\u5bfc\u5165\u6ce8\u91ca\u597d\u7684\u6587\u4ef6\uff0c\u7528\u6765\u63d0\u53d6umap embeddings\nIBC01-T_annotated &lt;- readRDS(&quot;\/path\/to\/annotated\/rds\/IBC01-T_annotated.rds&quot;)\nemb &lt;- IBC01-T_annotated@reductions$umap@cell.embeddings\n\n# Estimate the cell-cell distances \ncell.dist &lt;- as.dist(1-armaCor(t(IBC01-T_annotated@reductions$umap@cell.embeddings)))\n\ncolnames(emat) &lt;- paste(substring(colnames(emat),6,21),&quot;_1&quot;,sep=&quot;&quot;)\ncolnames(nmat) &lt;- paste(substring(colnames(nmat),6,21),&quot;_1&quot;,sep=&quot;&quot;)\n\nDefaultAssay(IBC01_T) &lt;- &quot;RNA&quot;\n\n# \u4fdd\u5b58\u4e3ah5Seurat\u548ch5ad\nSaveH5Seurat(IBC01_T,filename = &quot;\/home\/zhoukaiwen\/IBC\/scRNA\/cellranger_count\/velocyto\/loom\/IBC01_T.h5Seurat&quot;)\nConvert(&quot;\/home\/zhoukaiwen\/IBC\/scRNA\/cellranger_count\/velocyto\/loom\/IBC01_T.h5Seurat&quot;,dest = &quot;h5ad&quot;)\n\n# velocyto.R\u8fdb\u884c\u901f\u7387\u5206\u6790\u53ca\u53ef\u89c6\u5316\nIBC01_T &lt;- RunVelocity(object = IBC01_T, deltaT = 1, kCells = 25, fit.quantile = 0.02)\nsaveRDS(IBC01_T,&quot;\/home\/zhoukaiwen\/IBC\/scRNA\/cellranger_count\/velocyto\/loom\/IBC01_T_after_velocyto.rds&quot;)\n\np&lt;-DimPlot(IBC01_T,reduction = &quot;umap&quot;, seed = 3, label = T, group.by = c(&quot;orig.ident&quot;))\n\nIBC01_T &lt;- RunVelocity(object = IBC01_T, deltaT = 1, kCells = 25, fit.quantile = 0.02)\nident.colors &lt;- (scales::hue_pal())(n = length(x = levels(x = IBC01_T)))\nnames(x = ident.colors) &lt;- levels(x = IBC01_T)\ncell.colors &lt;- ident.colors[Idents(object = IBC01_T)]\nnames(x = cell.colors) &lt;- colnames(x = IBC01_T)\np&lt;-show.velocity.on.embedding.cor(emb = Embeddings(object = IBC01_T, reduction = &quot;umap&quot;), vel = Tool(object = IBC1234,  slot = &quot;RunVelocity&quot;), n = 200, scale = &quot;sqrt&quot;, cell.colors = ac(x = cell.colors, alpha = 0.5), cex = 0.8, arrow.scale = 3, show.grid.flow = TRUE, min.grid.cell.mass = 0.5, grid.n = 40, arrow.lwd = 1, do.par = FALSE, cell.border.alpha = 0.1)\n\nggsave(&quot;\/home\/zhoukaiwen\/IBC\/scRNA\/cellranger_count\/velocyto\/loom\/IBC1234TS_AllCells_velocyto.png&quot;,p)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \u9996\u5148\u4f7f\u7528 cellranger count \u5904\u7406\u539f\u59cbfastq\u6587\u4ef6 # \u6ce8\u610f\u6240\u6709fastq\u6587\u4ef6\u5fc5\u987b\u4e3aSa&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-319","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/comments?post=319"}],"version-history":[{"count":10,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":606,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/319\/revisions\/606"}],"wp:attachment":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/media?parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/categories?post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/tags?post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}