RNAseq實際操作(實戰)
首先聲明,雖然是實戰,但是其實是學習筆記而已,初學,參考了大量大神的博客和帖子,還有大神引用的大牛的帖子,參考列表見最后。
1、軟件安裝
1.1 硬件系統情況
系統:BioLinux8(ubuntu14.04.2-x64)
吐槽個一下這個系統,普通帳戶竟然環境變量錯誤(source ~/.bashrc),對我等小白來說實在頭大,只有用root用戶運行了。
后來通過百度錯誤問題發現,這個系統用的是zsh,所以更新環境變量的代碼是 source ~/.zshrc 這樣就可以了。
電腦配置:
Lenovo-ThinkPad-E431
CPU系列 英特爾 酷睿i3 3代系列
CPU型號 Intel 酷睿i3 3120M
CPU主頻 2.5GHz
總線規格 DMI 5 GT/s
三級緩存 3MB
核心架構 Ivy Bridge
核心/線程數 雙核心/四線程
制程工藝 22nm
內存容量 12GB(4GB×1 + 8GB×1)
1.2 軟件安裝
有簡單的不必去重新編譯代碼了,bioconda幾個命令解決,可能軟件依賴會有點問題。
1)Miniconda安裝
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.zshrc
一路Enter搞定
2)sratoolkit
conda install -c jfear sratoolkit
3)fastqc
conda install fastqc
發現fastqc是BioLinux自帶的,執行這個命令只是升級了java
4)hisat2
conda install hisat2
hisat2 -h #測試
這有個小插曲,提示hisat2依賴于python3.5, 而我裝的是3.6,于是百度得知用conda安裝3.5版本的:
conda install python=3.5
5)samtools
conda install samtools
samtools
''#samtools也是自帶的,執行這個命令會說依賴沖突,因為我的conda是Python3.6版,有點新,不兼容正常。
6)htseq-count
conda install -c bioconda htseq
’#測試
python
>>> import HTSeq
7)R
BioLinux自帶了,升級一下到3.4.1
sudo add-apt-repository ppa:marutter/rrutter
sudo apt-get update
sudo apt-get install r-base r-base-dev
8)rstudio
conda install
rstudio
rstudio
2、讀文章拿到測序數據
直接拿jimmy的腳本修改得來的。仔細分析項目數據后,得到要下載的數據是SRR3589958-62
這個腳本包含了下載數據,sra格式轉化為fastq,fastqc對轉化的數據進行分析,代碼如下:
for ((i=958;i<=958;i++)) ;do wget ftp://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP075/SRP075747/SRR3589$i/SRR3589$i.sra;done
ls *sra |while read id; do fastq-dump --gzip --split-3 $id;done
看到大神用的.gz格式才發現太省空間了,至少省了一半以上,膜拜!
3、了解fastq測序數據(fastqc質量控制學習)
1.fastqc
zcat SRR3589956_1.fastq.gz | fastqc -t 4 stdin
fastqc SRR3589956_1.fastq.gz
#t 線程,每個250M內存
2.multiQC
conda install multiqc
# 先獲取QC結果
ls *gz | while read id; do fastqc -t 4 $id; done
# multiqc
multiqc *fastqc.zip --pdf
學習筆記是紙質版拍照的,哈哈。
4、了解參考基因組及基因注釋
1)下載參考基因組
wget http://hgdownload.soe.ucsc.edu/goldenPath/hg19/bigZips/chromFa.tar.gz
#wget 下載或者其他工具下載
tar -zvf chromFa.tar.gz
cat *.fa > hg19.fa
rm chr*
2)下載基因組注釋gtf文件
GTF和GFF之間的區別:
數據結構:都是由9列構成,分別是reference sequence name; annotation source; feature type; start coordinate; end coordinate; score; strand; frame; attributes.前8列都是相同的,第9列不同。
GFF第9列:都是以鍵值對的形式,鍵值之間用“=”連接,不同屬性之間用“;”分隔,都是以ID這個屬性開始。下圖中有兩個ID,說明是不同的序列。
GTF第9列:同樣以鍵值對的形式,鍵值之間是以空格區分,值用雙引號括起來;不同屬性之間用“;”分隔;開頭必須是<u>gene_id, transcipt_id</u>兩個屬性。
wget ftp://ftp.sanger.ac.uk/pub/gencode/Gencode_human/release_26/GRCh37_mapping/gencode.v26lift37.annotation.gtf.gz]ftp://ftp.sanger.ac.uk/pub/genco ... 7.annotation.gtf.gz
3)下載IGV(Integrative Genomics Viewer)
下載地址為: http://software.broadinstitute.org/software/igv/download
4)genome -> Load Genome From Files加載之前得到基因組文件
5)Tool -> Run igvtools,進行排序
6)加載gff基因注釋文件,File -> Load From Files
7)可視化分析
同樣推薦閱讀生信寶典公眾號文章。
https://mp.weixin.qq.com/s/Q7pqycmQH58xU6hw_LECWA
5、序列比對
5.1 下載index
cd referece && mkdir index && cd index
wget ftp://ftp.ccb.jhu.edu/pub/infphilo/hisat2/data/hg19.tar.gz
tar -zxvf hg19.tar.gz
5.2 比對
mkdir -p RNA-Seq/aligned
for i in seq ‘56 58’
do
hisat2 -t -x reference/index/hg19/genome -1 RNA-Seq/SRR35899${i}_1.fastq.gz -2 SRR35899${i}_2.fastq.gz -S RNA-Seq/aligned/SRR35899${i}.sam
done
5.3 HISAT2輸出結果
兩個同時跑,資源幾乎占滿。報錯,以為硬件不足,后來才發現是硬盤爆了,于是上移動硬盤。
5.4 格式轉換,排序,索引
for i in `seq 56 58`
do
samtools view -S SRR35899${i}.sam -b > SRR35899${i}.bam
samtools sort SRR35899${i}.bam SRR35899${i}_sorted.bam
#這里我用的是0.1.19版本,不用加參數 -o
#ps:我加了-o之后重定向輸出結果有5個G之工巨,xshell直接死機,直接運行,電腦終端一直不停跳亂碼的東西。
samtools index SRR35899${i}_sorted.bam
done
判斷sam排序兩種方式的不同:
head -100 SRR3589957.sam > test.sam
samtools view -b test.sam > test.bam
samtools view test.bam | head
默認排序
samtools sort test.bam default
samtools view default.bam | head
Sort alignments by leftmost coordinates, or by read name when -n is used
samtools sort -n test.bam sort_left
samtools view sort_left.bam | head
5.5 samtools view
提取1號染色體1234-123456區域的比對read
samtools view SRR3589957_sorted.bam chr1:1234-123456 | head
flagstat看下總體情況
samtools flagstat SRR3589957_sorted.bam
用samtools篩選恰好配對的read,就需要用0x10
samtools view -b -f 0x10 SRR3589957_sorted.bam chr1:1234-123456 > flag.bam
samtools flagstat flag.bam
5.6 比對質控(QC)
# Python2.7環境下
pip install RSeQC
對bam文件進行統計分析(70~90的比對率要求)
bam_stat.py -i SRR3589956_sorted.bam
基因組覆蓋率的QC
需要提供bed文件,可以直接RSeQC的網站下載(看文件只有1M多,就沒有考慮轉換):
wget https://downloads.sourceforge.net/project/rseqc/BED/Human_Ho<br>mo_sapiens/hg19_RefSeq.bed.gz
read_distribution.py -i RNA-Seq/aligned/SRR3589956_sorted.bam -r reference/hg19_RefSeq.bed
5.7 IGV查看
載入參考序列,注釋和BAM文件
6 reads計數
# 安裝
conda install htseq
# 使用
# htseq-count [options] <alignment_file> <gtf_file>
htseq-count -r pos -f bam RNA-Seq/aligned/SRR3589957_sorted.bam reference/gencode.v26lift37.annotation.sorted.gtf > SRR3589957.count
循環處理多個BAM文件:
mkdir -p RNA-Seq/matrix/
for i in `seq 56 58`
do
htseq-count -s no -r pos -f bam RNA-Seq/aligned/SRR35899${i}_sorted.bam reference/gencode.v26lift37.annotation.sorted.gtf > RNA-Seq/matrix/SRR35899${i}.count 2> RNA-Seq/matrix/SRR35899${i}.log
done
合并表達矩陣
在生信媛的python腳本上略做了修改
!/usr/bin/python3
def combine_count(count_list):
mydict = {}
for file in count_list:
for line in open(file, 'r'):
#print(line)
if line.startswith('E'):
key,value = line.strip().split('\t')
if key in mydict:
mydict[key] = mydict[key] + '\t' + value
else:
mydict[key] = value
sorted_mydict = sorted(mydict)
out = open('count_out.txt', 'w')
for k in sorted_mydict:
#print(k, mydict[k])
#break
out.write(k + '\t' + mydict[k] +'\n')
count_list = ['SRR3589956.count', 'SRR3589957.count', 'SRR3589958.count']
combine_count(count_list)
簡單分析(這里由于對R接觸還很少,不少命令不明白,只有運行一下試試)
- 導入數據
options(stringsAsFactors = FALSE)# import data if sample are small
control <- read.table("/media/biolinux/LENOVO_imcdul/biodata/SRR3589956.count",sep="\t", col.names = c("gene_id","control"))
- 數據整合
# merge data and delete the unuseful row
raw_count <- merge(merge(control, rep1, by="gene_id"), rep2, by="gene_id")
raw_count_filt <- raw_count[-1:-5,]
ENSEMBL <- gsub("(.*?)\\.\\d*?_\\d", "\\1", raw_count_filt$gene_id)
row.names(raw_count_filt) <- ENSEMBL
3) 總體情況
summary(raw_count_filt)
4)看幾個具體基因
> GAPDH <- raw_count_filt[rownames(raw_count_filt)=="ENSG00000111640",]
#EBI上搜索GAPDH找到ID為ENSG00000111640
> GAPDH
文章研究的AKAP95(ENSG00000105127)的表達量在KD中都降低了
> AKAP95 <- raw_count_filt[rownames(raw_count_filt)=="ENSG00000105127",]
> AKAP95
參考內容列表:
1、http://www.biotrainee.com/forum.php?mod=viewthread&tid=1750#lastpost#jimmy的導航貼
2、轉錄組(一)](http://www.biotrainee.com/thread-1800-1-1.html) ( HOPTOP )
3、轉錄組入門(1)](http://www.biotrainee.com/thread-1796-1-1.html)- (青山屋主)
4、轉錄組入門(1)Mac上軟件準備作業
5、PANDA姐的轉錄組入門(1):計算機資源的準備
6、轉錄組作業(一):來自零基礎的小白
[轉錄組入門(二) New(HOPTOP)
8、轉錄組入門(2)-(青山屋主)
10、轉錄組入門(3):了解fastq測序數據
11、轉錄組(三):(HOPTOP)
12、轉錄組入門(3)-(青山屋主)
13、PANDA姐的轉錄組入門(3):了解fastq測序數據
轉錄組入門(4):了解參考基因組及基因注釋
14、hoptop的:轉錄組作業(四)
轉錄組入門(5): 序列比對
15、轉錄組入門(5)](http://www.biotrainee.com/thread-1870-1-1.html): 序列比對(HOPTOP)
轉錄組入門(6): reads計數
16、生信媛
轉錄組入門(7): 差異基因分析
17、生信媛
18、http://www.bio-info-trainee.com/2218.html
https://jiawen.zd200572.com