cat >srrlist.txt
/sra/sra-instant/reads/ByRun/sra/SRR/SRR292/SRR2927015/SRR2927015.sra
/sra/sra-instant/reads/ByRun/sra/SRR/SRR292/SRR2927016/SRR2927016.sra
/sra/sra-instant/reads/ByRun/sra/SRR/SRR354/SRR3545580/SRR3545580.sra
/sra/sra-instant/reads/ByRun/sra/SRR/SRR292/SRR2927018/SRR2927018.sra
nohup /home/xlfang/.aspera/connect/bin/ascp -T -l 200M -P 33001 -i ~/.aspera/connect/etc/asperaweb_id_dsa.openssh -T --mode recv --host ftp-private.ncbi.nlm.nih.gov --user anonftp --file-list ./srrlist.txt ./ & ##3803
nohup /home/xlfang/.aspera/connect/bin/ascp -T -P 33001 -i ~/.aspera/connect/etc/asperaweb_id_dsa.openssh -k 1 -l 200m anonftp@ftp-private.ncbi.nlm.nih.gov:/sra/sra-instant/reads/ByRun/sra/SRR/SRR354/SRR3545580/SRR3545580.sra ./ &
cat >fq.txt
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR292/005/SRR2927015/SRR2927015_1.fastq.gz
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR292/005/SRR2927015/SRR2927015_2.fastq.gz
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR292/006/SRR2927016/SRR2927016_1.fastq.gz
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR292/006/SRR2927016/SRR2927016_2.fastq.gz
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR292/008/SRR2927018/SRR2927018_1.fastq.gz
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR292/008/SRR2927018/SRR2927018_2.fastq.gz
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR354/000/SRR3545580/SRR3545580_1.fastq.gz
fasp.sra.ebi.ac.uk:/vol1/fastq/SRR354/000/SRR3545580/SRR3545580_2.fastq.gz
cat >fq.command
cat fq.txt|while read id
do ( ascp -QT -l 300m -P33001 -i ~/.aspera/connect/etc/asperaweb_id_dsa.openssh era-fasp@$id ./ )
done
ls -lh *fastq.gz|cut -d " " -f 5-
2.5G Apr 10 11:15 SRR2927015_1.fastq.gz
2.4G Apr 10 11:20 SRR2927015_2.fastq.gz
3.2G Apr 10 11:26 SRR2927016_1.fastq.gz
3.5G Apr 10 11:32 SRR2927016_2.fastq.gz
1.1G Apr 10 11:34 SRR2927018_1.fastq.gz
1.2G Apr 10 11:36 SRR2927018_2.fastq.gz
4.1G Apr 10 11:44 SRR3545580_1.fastq.gz
4.6G Apr 10 11:52 SRR3545580_2.fastq.gz
###conda activate rna
###fastqc
nohup fastqc -t 2 -o ./ ./*.fastq.gz &
###multiqc
multiqc ./*zip -o ./
###trim
for i in `ls *_1.fastq.gz`
do
i=${i/_1.fastq.gz/}
echo "trim_galore --phred33 -q 25 --length 35 --stringency 4 -e 0.1 --fastqc --paired -o ../2.clean ${i}_1.fastq.gz ${i}_2.fastq.gz"
done > trim_galore.command
cat trim_galore.command
###下載小鼠的mm10基因索引
nohup wget -4 -q ftp://ftp.ccb.jhu.edu/pub/data/bowtie2_indexes/mm10.zip &
ls -lh|cut -d " " -f 5-
#3.2G Apr 11 03:14 mm10.zip 大小為3.2G
unzip mm10.zip ##解壓
cd 2.clean
## 相對目錄需要理解
index=/zju/phf5a/data/bwindex/mm10
## 一定要搞清楚自己的bowtie2軟體安裝在哪裡,以及自己的索引文件在什麼地方!!!
#conda activate rna
for i in `ls *_1_val_1.fq.gz`
do
i=${i/_1_val_1.fq.gz/}
echo "bowtie2 -p 2 --very-sensitive -X 2000 -x ${index} -1 ${i}_1_val_1.fq.gz -2 ${i}_2_val_2.fq.gz |samtools sort -O bam -T ${i} -@ 2 -o - > ${i}.raw.bam"
done > mapping.command
ls -lh *raw.bam|cut -d " " -f 5-
3.7G Apr 11 22:55 SRR2927015.raw.bam
4.6G Apr 12 07:19 SRR2927016.raw.bam
1.7G Apr 12 09:50 SRR2927018.raw.bam
5.4G Apr 12 19:23 SRR3545580.raw.bam
conda activate rna
for i in `ls *.raw.bam`
do
i=${i/.raw.bam/}
echo " samtools index ${i}.raw.bam | bedtools bamtobed -i ${i}.raw.bam > ${i}.raw.bed|samtools flagstat ${i}.raw.bam > ${i}.raw.stat|sambamba markdup --overflow-list-size 600000 --tmpdir='./' -r ${i}.raw.bam ${i}.rmdup.bam |samtools index ${i}.rmdup.bam"
done > rmdup.command
###
## ref:https://www.biostars.org/p/170294/
## Calculate %mtDNA:
mtReads=$(samtools idxstats ${i}.rmdup.bam | grep 'chrM' | cut -f 3)
totalReads=$(samtools idxstats ${i}.rmdup.bam | awk '{SUM += $3} END {print SUM}')
echo '==> mtDNA Content:' $(bc <<< "scale=2;100*$mtReads/$totalReads")'%'
echo "samtools flagstat ${i}.rmdup.bam > ${i}.rmdup.stat|samtools view -h -f 2 -q 30 ${i}.rmdup.bam |grep -v chrM |samtools sort -O bam -@ 2 -o - > ${i}.last.bam|samtools index ${i}.last.bam|samtools flagstat ${i}.last.bam > ${i}.last.stat|bedtools bamtobed -i ${i}.last.bam > ${i}.bed"
cat SRR3545580.raw.stat
# 105342880 + 0 in total (QC-passed reads + QC-failed reads)
# 0 + 0 secondary
# 0 + 0 supplementary
# 0 + 0 duplicates
# 103697403 + 0 mapped (98.44%:-nan%)
# 105342880 + 0 paired in sequencing
# 52671440 + 0 read1
# 52671440 + 0 read2
# 100212070 + 0 properly paired (95.13%:-nan%)
# 103230528 + 0 with itself and mate mapped
# 466875 + 0 singletons (0.44%:-nan%)
# 477956 + 0 with mate mapped to a different chr
# 18927 + 0 with mate mapped to a different chr (mapQ>=5)
for i in `ls *.raw.bam`
do
i=${i/.raw.bam/}
mtReads=$(samtools idxstats ${i}.rmdup.bam | grep 'chrM' | cut -f 3)
totalReads=$(samtools idxstats ${i}.rmdup.bam | awk '{SUM += $3} END {print SUM}')
echo '==> mtDNA Content:' $(bc <<< "scale=2;100*$mtReads/$totalReads")'%'
echo " samtools flagstat ${i}.rmdup.bam > ${i}.rmdup.stat|samtools view -h -f 2 -q 30 ${i}.rmdup.bam |grep -v chrM |samtools sort -O bam -T ${i} -@ 2 -o - > ${i}.last.bam|samtools index ${i}.last.bam|samtools flagstat ${i}.last.bam > ${i}.last.stat"
done > quality.command
for i in `ls *.raw.bam`
do
i=${i/.raw.bam/}
echo "bedtools bamtobed -i ${i}.last.bam> ${i}.bed "
done > bed.command
ls -lh *.bed|cut -d " " -f 5-
247M Apr 14 16:40 SRR2927015.bed
352M Apr 14 16:41 SRR2927016.bed
211M Apr 14 16:41 SRR2927018.bed
264M Apr 14 16:41 SRR3545580.bed
conda create -n actc python=3 ###重新創建爬蟲3的環境
conda activate actc
conda install -c bioconda macs2
macs2 -h##能調用就說明沒有問題
conda activate atac
cat >macs2.command
ls *.bed | while read id ;do (macs2 callpeak -t $id -g mm --nomodel --shift -100 --extsize 200 -n ${id%%.*} --outdir ../3.macs2/) ;done
###參數含義
ls -lh|cut -d " " -f 5-
# 644K Apr 14 17:06 SRR2927015_peaks.narrowPeak
# 704K Apr 14 17:06 SRR2927015_peaks.xls
# 441K Apr 14 17:06 SRR2927015_summits.bed
# 1.2M Apr 14 17:07 SRR2927016_peaks.narrowPeak
# 1.3M Apr 14 17:07 SRR2927016_peaks.xls
# 835K Apr 14 17:07 SRR2927016_summits.bed
# 374K Apr 14 17:07 SRR2927018_peaks.narrowPeak
# 409K Apr 14 17:07 SRR2927018_peaks.xls
# 256K Apr 14 17:07 SRR2927018_summits.bed
# 1.1M Apr 14 17:07 SRR3545580_peaks.narrowPeak
# 1.2M Apr 14 17:07 SRR3545580_peaks.xls
# 714K Apr 14 17:07 SRR3545580_summits.bed
conda activate rna
ls *.last.bam >1
ls *.last.stat >2
paste 1 2 >config_bam
cat config_bam
#SRR2927015.last.bam SRR2927015.last.stat
#SRR2927016.last.bam SRR2927016.last.stat
#SRR2927018.last.bam SRR2927018.last.stat
#SRR3545580.last.bam SRR3545580.last.stat
###bash腳本
cat >length.sh
cat config_bam |while read id;
do
arr=($id)
sample=${arr[0]}
sample_name=${arr[1]}
samtools view $sample |awk '{print $9}' > ${sample_name}_length.txt
done
ls -lh *last.stat_length.txt
-rw-rw-r-- 1 xlfang xlfang 22M Apr 16 10:48 SRR2927015.last.stat_length.txt
-rw-rw-r-- 1 xlfang xlfang 32M Apr 16 10:49 SRR2927016.last.stat_length.txt
-rw-rw-r-- 1 xlfang xlfang 19M Apr 16 10:49 SRR2927018.last.stat_length.txt
-rw-rw-r-- 1 xlfang xlfang 24M Apr 16 10:49 SRR3545580.last.stat_length.txt
indel_length_distribution.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()
ls *last.stat_length.txt >3
ls *last.stat_length.txt|cut -d "." -f 1-3>4
paste 3 4 >config.indel_length_distribution
cat config.indel_length_distribution
# SRR2927015.last.stat_length.txt SRR2927015.last.stat_length
# SRR2927016.last.stat_length.txt SRR2927016.last.stat_length
# SRR2927018.last.stat_length.txt SRR2927018.last.stat_length
# SRR3545580.last.stat_length.txt SRR3545580.last.stat_length
cat >indel_length_distribution.sh
cat config.indel_length_distribution |while read id;
do
arr=($id)
input=${arr[0]}
output=${arr[1]}
Rscript indel_length_distribution.R $input $output
done
a=read.delim("SRR2927015.last.stat_length.txt")
a=abs(as.numeric(a[,1]))
png(file=output)
hist(a,
main="SRR2927015_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()
conda activate rna
for i in `ls *.narrowPeak`
do
i=${i/_peaks.narrowPeak/}
bed=../2.clean/${i}.bed
Reads=$(bedtools intersect -a ${bed} -b ${i}_peaks.narrowPeak |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 > frip.command
cat frip.command
148214 5105856
==> FRiP value: 2.90%
320405 7292136
==> FRiP value: 4.39%
90854 4399724
==> FRiP value: 2.06%
258981 5466470
==> FRiP value: 4.73%
library(ChIPseeker)
library(ChIPpeakAnno)
setwd("E://desktop/sept/ATAC-seq_practice/find_peaks_overlaping/")
list.files('./',"*.narrowPeak")
tmp = lapply(list.files('./',"*.narrowPeak"),function(x){
return(readPeakFile(file.path('./', x)))
})
tmp
ol <- findOverlapsOfPeaks(tmp[[1]],tmp[[2]],tmp[[3]],tmp[[4]])
png('overlapVenn.png')
makeVennDiagram(ol)
dev.off()
##安裝IDR
conda activate atac
conda isntall -y idr
ls -lh *narrowPeak|cut -d " " -f 9|tr -s "\n" " "
#SRR2927015_peaks.narrowPeak SRR2927016_peaks.narrowPeak SRR2927018_peaks.narrowPeak SRR3545580_peaks.narrowPeak
###2個樣本的overlap peaks IDR只能對於2個重複樣本進行比較,所以分為2組
idr --samples SRR2927015_peaks.narrowPeak SRR2927016_peaks.narrowPeak \
--input-file-type narrowPeak \
--rank p.value \
--output-file group1-idr \
--plot \
--log-output-file group1.idr.log
idr --samples SRR2927018_peaks.narrowPeak SRR3545580_peaks.narrowPeak \
--input-file-type narrowPeak \
--rank p.value \
--output-file group2-idr \
--plot \
--log-output-file group2.idr.log
ls -lh group*|cut -d " " -f 5-
# 740K Apr 19 22:00 group1-idr
# 205 Apr 19 22:00 group1.idr.log
# 341K Apr 19 22:00 group1-idr.png
# 315K Apr 19 22:00 group2-idr
# 202 Apr 19 22:00 group2.idr.log
# 218K Apr 19 22:00 group2-idr.png
cat group1.idr.log
# Initial parameter values: [0.10 1.00 0.20 0.50]
# Final parameter values: [0.59 1.05 0.62 0.79]
# Number of reported peaks - 5869/5869 (100.0%)
# Number of peaks passing IDR cutoff of 0.05 - 1571/5869 (26.8%)
cat group2.idr.log
# Initial parameter values: [0.10 1.00 0.20 0.50]
# Final parameter values: [0.35 1.06 0.47 0.50]
# Number of reported peaks - 2505/2505 (100.0%)
# Number of peaks passing IDR cutoff of 0.05 - 38/2505 (1.5%)
###安裝deeptools
conda activate atac ###激活小環境
conda install -y deeptools ###安裝
cd ../../zju/phf5a/atac/
mkdir deeptools
cd deeptools/
ln -s ../2.clean/*.last.bam ./
###構建索引
ls *.bam |xargs -i samtools index {}
###將最終的bam轉換成bigwig文件
ls *last.bam |while read id;do
nohup bamCoverage -b ${id} -p 5 --normalizeUsing RPKM -o ${id%%.*}.last.bw &
done
###將去重的bam轉換成bigwig文件
ls *rmdup.bam |while read id;do
nohup bamCoverage --normalizeUsing CPM -b $id -o ${id%%.*}.rm.bw &
done
curl 'http://genome.ucsc.edu/cgi-bin/hgTables?hgsid=646311755_P0RcOBvAQnWZSzQz2fQfBiPPSBen&boolshad.hgta_printCustomTrackHeaders=0&hgta_ctName=tb_ncbiRefSeq&hgta_ctDesc=table+browser+query+on+ncbiRefSeq&hgta_ctVis=pack&hgta_ctUrl=&fbQual=whole&fbUpBases=200&fbExonBases=0&fbIntronBases=0&fbDownBases=200&hgta_doGetBed=get+BED' >
###16m大小下載了18min。。
cut -f 1-3 mm10.refseq.bed > ref.bed
computeMatrix reference-point --referencePoint TSS -p 15 \
-b 10000 -a 10000 \
-R ./ref.bed \
-S ./*.bw \
--skipZeros -o matrix1_test_TSS.gz \
--outFileSortedRegions regions1_test_genes.bed