cellranger實(shí)戰(zhàn)2:非正常數(shù)據(jù)之僅有bam文件

我所理解的cellranger軟件理想原始輸入數(shù)據(jù)就是SRA格式,然后利用sra-tools分為read、barcode+UMI、index三個(gè)fastq.gz文件。最后直接利用cellranger即可。但總會(huì)發(fā)現(xiàn)文獻(xiàn)提供的數(shù)據(jù)格式并非如此,就要花費(fèi)一些心思了。

如圖,基本了解到做了三組實(shí)驗(yàn),每組兩個(gè)重復(fù)。但關(guān)鍵作者提供的是bam文件格式,就要想辦法轉(zhuǎn)換為cellranger所需要的文件格式。

1、下載數(shù)據(jù)

cat > bam.txt
fasp.sra.ebi.ac.uk:/vol1/run/SRR117/SRR11798249/ICBtreated_Brca2null_rep1.bam
fasp.sra.ebi.ac.uk:/vol1/run/SRR117/SRR11798250/ICBtreated_Brca1null_rep2.bam
fasp.sra.ebi.ac.uk:/vol1/run/SRR117/SRR11798251/ICBtreated_Brca1null_rep1.bam
fasp.sra.ebi.ac.uk:/vol1/run/SRR117/SRR11798257/ICBtreated_Parental_rep2.bam
fasp.sra.ebi.ac.uk:/vol1/run/SRR117/SRR11798258/ICBtreated_Parental_rep1.bam
fasp.sra.ebi.ac.uk:/vol1/run/SRR117/SRR11798259/ICBtreated_Brca2null_rep2.bam

conda activate download
cat fq.txt |while read id
do ascp -QT -l 300m -P33001  \
-i ~/miniconda3/envs/download/etc/asperaweb_id_dsa.openssh \
era-fasp@$id  .
done
conda deactivate 
rawdata

conda環(huán)境配置可見實(shí)戰(zhàn)1,就是使用下ascp軟件

2、bam轉(zhuǎn)fastq

2.1 special bam of cellranger

samtools view ICBtreated_Parental_rep1.bam | less -SN
samtools view ICBtreated_Parental_rep1.bam | head -3 | tr "\t" "\n" | cat -n
bam tag

相關(guān)標(biāo)簽具體解釋見結(jié)尾,這里知道 CB或者CR代表barcode、UB或者UR代表UMI即可。

2.2 cellranger bamtofastq

  • 知道上述知識(shí)點(diǎn)后,我一開始想手動(dòng)提取下bam文件里的barcode與UMI序列,也查了很多l(xiāng)inux字符處理方法。但這樣之后還要自己組裝fastq,并且使header一致??傊苜M(fèi)事。
  • 后來知道 cellranger也有bamtofastq功能,就試試看和其它軟件的轉(zhuǎn)換有什么不同。
  • 如下圖是一個(gè)bam文件的處理結(jié)果。其很強(qiáng)大的功能:自動(dòng)根據(jù)bam文件,生成配套的三種文件。而且還修改為規(guī)范命名!I1,R1,R2的含義見實(shí)戰(zhàn)1
    ICBtreated_Brca1null_rep1.bam
three type fastq

I1代表的index序列,一般是用于區(qū)分混合樣品的,二代測(cè)序通配。這里為空,表示bam文件里沒有。而且的確也不需要,就提供一個(gè)空序列文件即可。

  • 批量處理
cat > bamtofastq.sh
bin=/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger
cat name.list |while read id
do
$bin bamtofastq $id ./fastq/${id}
done

bash bamtofastq.sh

3、cellranger count

  • 經(jīng)過上一步的處理,接下來就比較簡單了。
find /home/shensuo/test/fastq/ | grep bam/out | grep -v XX/bam > fq.txt

bin=/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger
db=/home/shensuo/biosoft/cellranger/test/refdata-gex-mm10-2020-A/
target=bamtofastq

cat fq.txt |while read id
do
echo $bin count --id=${id:0-39:14} \
--localcores=4 \
--transcriptome=$db \
--fastqs=$id \
--sample=$target \
--expect-cells=3000 \
--nosecondary  
done

cat > cellranger.sh
/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger count --id=ICBtreated_Brca1null_rep1 --localcores=10 --transcriptome=/home/shensuo/biosoft/cellranger/test/refdata-gex-mm10-2020-A/ --fastqs=/home/shensuo/test/fastq/ICBtreated_Brca1null_rep1.bam/output_0_1_HG3HHDRXX --sample=bamtofastq --expect-cells=13009 --nosecondary
/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger count --id=ICBtreated_Brca1null_rep2 --localcores=10 --transcriptome=/home/shensuo/biosoft/cellranger/test/refdata-gex-mm10-2020-A/ --fastqs=/home/shensuo/test/fastq/ICBtreated_Brca1null_rep2.bam/output_0_1_HG3HHDRXX --sample=bamtofastq --expect-cells=21789 --nosecondary
/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger count --id=ICBtreated_Brca2null_rep1 --localcores=10 --transcriptome=/home/shensuo/biosoft/cellranger/test/refdata-gex-mm10-2020-A/ --fastqs=/home/shensuo/test/fastq/ICBtreated_Brca2null_rep1.bam/output_0_1_HG3HHDRXX --sample=bamtofastq --expect-cells=18684 --nosecondary
/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger count --id=ICBtreated_Brca2null_rep2 --localcores=10 --transcriptome=/home/shensuo/biosoft/cellranger/test/refdata-gex-mm10-2020-A/ --fastqs=/home/shensuo/test/fastq/ICBtreated_Brca2null_rep2.bam/output_0_1_HG3HHDRXX --sample=bamtofastq --expect-cells=16731 --nosecondary
/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger count --id=ICBtreated_Parental_rep1 --localcores=10 --transcriptome=/home/shensuo/biosoft/cellranger/test/refdata-gex-mm10-2020-A/ --fastqs=/home/shensuo/test/fastq/ICBtreated_Parental_rep1.bam/output_0_1_HG3HHDRXX --sample=bamtofastq --expect-cells=13292 --nosecondary
/home/shensuo/biosoft/cellranger/cellranger-4.0.0/bin/cellranger count --id=ICBtreated_Parental_rep2 --localcores=10 --transcriptome=/home/shensuo/biosoft/cellranger/test/refdata-gex-mm10-2020-A/ --fastqs=/home/shensuo/test/fastq/ICBtreated_Parental_rep2.bam/output_0_1_HG3HHDRXX --sample=bamtofastq --expect-cells=20718 --nosecondary

nohup  bash /home/shensuo/test/cr_out/fq.txt &
#需要使用全路徑

耐心等待結(jié)果即可。估計(jì)一夜肯定是需要的。
此外其中有幾個(gè)注意點(diǎn),具體如下

  • 一開始想只用while語句運(yùn)行,發(fā)現(xiàn)還是不能盡善盡美。就echo下,再根據(jù)實(shí)際情況修改,保存為cellranger.sh
  • 關(guān)于--localcores=設(shè)置,可根據(jù)實(shí)際情況。我是設(shè)置10,之后也單獨(dú)嘗試了32,24,20。結(jié)果還是24還比較適合目前得到服務(wù)器環(huán)境的最大承受,如果想盡快跑完的話。
  • 關(guān)于--expect-cells設(shè)置,主要參考原文獻(xiàn)的測(cè)序結(jié)果細(xì)胞數(shù)。
    paper result

4、導(dǎo)出最終結(jié)果

  • 如前所述,cellranger count結(jié)果很多,主要是需要其中如下圖的三個(gè)文件(每個(gè)樣品)


    three type result
cat name.list | while read id
do 
mkdir ./out/$id
cp $id/outs/filtered_feature_bc_matrix/* ./out/$id
done

接下來就可以,將數(shù)據(jù)導(dǎo)入到R中,用seurat等包進(jìn)行下游分析了。

附:cellranger indexed bam

https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/output/bam

image.png

如官網(wǎng)介紹,Chromium cellular and molecular barcode information for each read is stored as TAG fields in this bam(produced by cellranger)
cellular and molecular barcode分別對(duì)應(yīng)我們之前說的barcode與UMI序列.前者用來區(qū)分不同GEMs,也就是對(duì)細(xì)胞做了一個(gè)標(biāo)記;后者用于表示基因文庫大小,即每種mRNA一個(gè)特定的UMI。
如圖介紹,介紹

  • CB、CR、CY表示barcode,一般是16個(gè)堿基;
  • UBUR、UY表示UMI,一般是10個(gè)堿基。
  • R一般代表原始測(cè)序數(shù)據(jù),Y代表質(zhì)量分?jǐn)?shù),而B代表校正后的R,可能對(duì)應(yīng)堿基質(zhì)量分?jǐn)?shù)太低等因素。一般來說RB都是相同的。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容