2020-07-22

参考文献:The landscape of accessible chromatin in mammalian preimplantation embryos. Nature 2016 Jun 30;534(7609):652-7. PMID: 27309802
参考教程://www.greatytc.com/p/5bce43a537fd
//www.greatytc.com/p/09e05bcd6981

miniconda

# https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/ 
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc 
#设置镜像。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda
conda config --set show_channel_urls yes
#other commands://www.greatytc.com/p/a20bb8c0bc5c
conda  create -n atac -y  python=2
conda info --envs
source activate atac
# 保证所有的软件都是安装在 atac这个环境下面
conda install -y sra-tools  
conda install -y trim-galore  samtools bedtools
conda install -y deeptools homer  meme
conda install -y macs2 bowtie bowtie2 
conda install -y  multiqc 
conda install -y  sambamba

download sra

#config.sra
2-cell-1 SRR2927015
2-cell-2 SRR2927016
2-cell-4 SRR2927018
#prefetch
mkdir {sra,raw,clean,align,peaks,motif,qc}
cd ../sra 
source activate atac 
cat config.sra |while read id;do 
arr=($id)
srr=${arr[1]}
nohup  prefetch $srr & 
done
## 默认下载目录:~/ncbi/public/sra/ 

fastq-dump

cat config.sra |while read id;
do arr=($id); srr=${arr[1]}; sample=${arr[0]}
nohup fastq-dump -A $sample -O ../raw --gzip --split-e ../$srr.sra &
done

QC

#config.raw
ls  ../*_1.fastq.gz > 1 #complete path
ls  ../*_2.fastq.gz > 2
paste 1 2 > config.raw

mkdir -p clean 
cat config.raw  |while read id;
do echo $id
arr=($id)
fq2=${arr[2]}
fq1=${arr[1]}
nohup  trim_galore -q 25 --phred33 --length 35 -e 0.1 --stringency 4 --paired -o  clean  $fq1   $fq2  & 
done 

cd ../qc 
mkdir -p clean 
fastqc -t 5  ../clean/2-cell-*gz -o clean 
mkdir -p raw 
fastqc -t 5  ../raw/2-cell-*gz -o raw

mapping

时间有限,只做了前两个数据

#config.clean
ls  ../_1*gz >1 
ls  ../_2*gz >2
ls ../_1*gz | cut -d"/" -f 6 | cut -d"_" -f 1 >0
#/home/zhangjianing/nature_2016/clean/2-cell-1_1_val_1.fq.gz
paste 0 1 2 >config.clean
cat config.clean |while read id;
do echo $id; arr=($id); fq2=${arr[2]}; fq1=${arr[1]}; sample=${arr[0]}
bowtie2  -p 10  --very-sensitive -X 2000 -x  ~/nature_2016/ref/mm10 -1 $fq1 -2 $fq2 |samtools sort  -O bam  -@ 5 -o - > ${sample}.raw.bam 
samtools index ${sample}.raw.bam 
bedtools bamtobed -i ${sample}.raw.bam  > ${sample}.raw.bed
samtools flagstat ${sample}.raw.bam  > ${sample}.raw.stat
sambamba markdup --overflow-list-size 600000  --tmpdir='./'  -r ${sample}.raw.bam  ${sample}.rmdup.bam
samtools index   ${sample}.rmdup.bam 
samtools flagstat  ${sample}.rmdup.bam > ${sample}.rmdup.stat

##Calculate %mtDNA:( ref:https://www.biostars.org/p/170294/ )
mtReads=$(samtools idxstats  ${sample}.rmdup.bam | grep 'chrM' | cut -f 3);
totalReads=$(samtools idxstats  ${sample}.rmdup.bam | awk '{SUM += $3} END {print SUM}')
echo '==>' ${sample} 'mtDNA Content:' $(bc <<< "scale=2;100*$mtReads/$totalReads")'%'

samtools view  -h  -f 2 -q 30    ${sample}.rmdup.bam   |grep -v chrM |samtools sort  -O bam  -@ 5 -o - > ${sample}.last.bam
samtools index   ${sample}.last.bam 
samtools flagstat  ${sample}.la
st.bam > ${sample}.last.stat 
bedtools bamtobed -i ${sample}.last.bam  > ${sample}.bed
done 

peak calling

ls *.bed | while read id ;
do macs2 callpeak -t $id  -g mm --nomodel --shift  -100 --extsize 200  -n ${id%%.*} --outdir ../peaks/ ;
# ${file%%.*}:拿掉第一个 “. ” 及其右边的字符串 (https://blog.csdn.net/chinalinuxzend/article/details/1826623)
done 

计算插入片段长度

#config.fraction
last.bam path/2-cell-1   2-cell-1     
last.bam path/2-cell-2   2-cell-2     
#insert_fraction.R
cmd=commandArgs(trailingOnly=TRUE); 
input=cmd[1]; output=cmd[2]; 
a=abs(as.numeric(read.table(input)[,1])); 
png(file=output);
hist(a,
main="Insertion Size distribution",
ylab="Read Count",xlab="Insert Size",
xaxt="n",
breaks=seq(0,max(a),by=10)
); 
axis(side=1,
at=seq(0,max(a),by=100),
labels=seq(0,max(a),by=100)
);
dev.off() 

cat config.fraction | while read id;
do arr=($id); input=${arr[0]}; output=${arr[1]}
samtools view $input.last.bam | cut -f 9 > $output.txt #提取bam文件中的第9列(插入片段长度)
Rscript insert_fraction.R $output.txt $output.png; 
done
2-cell-1

2-cell-2

FRIP value

bedtools intersect -a ../new/2-cell-1.bed -b 2-cell-1_peaks.narrowPeak |wc -l
148928
wc ../new/2-cell-1.bed
5105844
wc ../new/2-cell-1.raw.bed
5105844

ls *narrowPeak|while  read id;
do 
echo $id
bed=../new/$(basename $id "_peaks.narrowPeak").raw.bed
#ls  -lh $bed 
Reads=$(bedtools intersect -a $bed -b $id |wc -l|awk '{print $1}')
totalReads=$(wc -l $bed|awk '{print $1}')
echo $Reads  $totalReads 
echo '==> FRiP value:' $(bc <<< "scale=2;100*$Reads/$totalReads")'%'
done

overlap

#R studio serve安装失败,改用本地R studio
library(ChIPseeker)
library(ChIPpeakAnno)
setwd("/overlap")
list.files('./',"*.narrowPeak")
tmp = lapply(list.files('./',"*.narrowPeak"),function(x){
  return(readPeakFile(file.path('./', x)))
  })
`2-cell-` <- tmp #更改venn图中的名字,效果不是很好
ol <- findOverlapsOfPeaks(`2-cell-`[[1]],`2-cell-`[[2]]) 
png('overlapVenn.png')
makeVennDiagram(ol)
dev.off()
overlapVenn

6.deeptools可视化

cd /align
ls *last.bam |while read id;do
nohup bamCoverage -p 5 --normalizeUsing CPM -b $id -o ${id%%.*}.last.bw & 
done 
#TSS附近信号强度
cd /bw
ls *.bw | while read id;do
computeMatrix reference-point  --referencePoint TSS  -p 15  \
-b 10000 -a 10000    \
-R /ref/mm10.bed  \
-S  $id  \
--skipZeros  -o /TSS/${id%%.*}_TSS.gz  \
--outFileSortedRegions ${id%%.*}_sortedRegions.bed;
#plot
plotHeatmap -m TSS/${id%%.*}_TSS.gz  -out ${id%%.*}_TSS_Heatmap.png
plotProfile -m TSS/${id%%.*}_TSS.gz  -out ${id%%.*}_TSS_Profile.png
(plotHeatmap -m ${id%%.*}_TSS.gz  -out ${id%%.*}_TSS_Heatmap.pdf --plotFileFormat pdf  --dpi 720
plotProfile -m ${id%%.*}_TSS.gz  -out ${id%%.*}_TSS_Profile.pdf --plotFileFormat pdf --perGroup --dpi 720 )
#gene body 信号强度
ls *.bw | while read id;do
computeMatrix scale-regions  -p 15  \
-R /ref/mm10.bed  \
-S $id  \
-b 10000 -a 10000  \
--skipZeros -o ${id%%.*}_body.gz
plotHeatmap -m ${id%%.*}_body.gz  -out ${id%%.*}_body_Heatmap.png
plotProfile -m ${id%%.*}_body.gz  -out ${id%%.*}_body_Profile.png
2-cell-2_TSS_Heatmap.png
2-cell-1_TSS_Heatmap.png

7.peaks注释

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("TxDb.Mmusculus.UCSC.mm10.knownGene")
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("org.Mm.eg.db")
library('CHIPpeakAnno')
library('TxDb.Mmusculus.UCSC.mm10.knownGene')
library('clusterProfiler')

setwd("/")
peakfiles = lapply(list.files('./',"*.bed"),function(x){return(readPeakFile(file.path('./', x)))})
txdb <- TxDb.Mmusculus.UCSC.mm10.knownGene
peakAnno <- annotatePeak(peakfiles[[1]],tssRegion=c(-3000, 3000),TxDb=txdb, annoDb="org.Mm.eg.db")
peakAnno_df <- as.data.frame(peakAnno)
promoter <- getPromoters(TxDb=txdb, upstream=3000, downstream=3000)
tagMatrix <- getTagMatrix(peakfiles[[1]], windows=promoter)
# 查看这些peaks在所有基因的启动子附近的分布情况,热图模式
tagHeatmap(tagMatrix, xlim=c(-3000, 3000), color="red")
# 查看这些peaks在所有基因的启动子附近的分布情况,信号强度曲线图
plotAvgProf(tagMatrix, xlim=c(-3000, 3000), xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency")
2-cell-1
#others
plotAnnoPie(peakAnno)
plotAnnoBar(peakAnno)
#peak离最近基因的距离分布
plotDistToTSS(peakAnno, title="Distribution of transcription factor-binding loci\nrelative to TSS")
图片.png

图片.png

图片.png
#多图展示
peakAnnoList <- lapply(peakfiles, annotatePeak,TxDb=txdb,tssRegion=c(-3000, 3000))
plotAnnoBar(peakAnnoList)
plotDistToTSS(peakAnnoList)
图片.png

图片.png

homer peak annotation

# perl ~/miniconda3/envs/atac/share/homer-4.9.1-5/configureHomer.pl  -install mm10 
source activate atac
cd   ../peaks  
ls *.narrowPeak |while read id;
do 
echo $id
awk '{print $4"\t"$1"\t"$2"\t"$3"\t+"}' $id > ${id%%.*}.homer_peaks.tmp
annotatePeaks.pl  ${id%%.*}.homer_peaks.tmp mm10  \
1>${id%%.*}.peakAnn.xls \
2>${id%%.*}.annLog.txt
done

motifs

ls ../*.tmp |while read id;
do  findMotifsGenome.pl $id mm10 ${id%%.*}_motifDir -len 8,10,12  
done
图片.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,036评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,046评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,411评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,622评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,661评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,521评论 1 304
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,288评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,200评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,644评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,837评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,953评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,673评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,281评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,889评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,011评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,119评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,901评论 2 355