day31 画全基因范围内的染色体reads覆盖度图

分享
程序员 2024-10-3 21:06:36 50 0 来自 中国
参考教程:
https://cloud.tencent.com/developer/article/1054625
http://www.360doc.com/content/21/0714/12/76149697_986499282.shtml
http://www.bio-info-trainee.com/2163.html
一、统计根本覆盖信息
起首在linux内里运行:
samtools mpileup -f /data/zds209/database/cellranger/refdata-gex-GRCh38-2020-A/fasta/genome.fa  /data/zds209/ssresult/bam/B8D.rm.bam| perl -alne '{$pos=int($F[1]/1000); $key="$F[0]\t$pos";$GC{$key}++ if $F[2]=~/[GC]/;$counts_sum{$key}+=$F[3];$number{$key}++;}END{print "$_\t$number{$_}\t$GC{$_}\t$counts_sum{$_}" foreach sort{$a<=>$b} keys %number}'-f参数 输入有索引文件的fasta参考序列
用qsub提交以后,天生o文件就是详细内容。

下面这种也可以思量利用,但是天生文件略有差异。
nohup time samtools mpileup P_jmzeng.final.bam |perl -alne '{$pos{$F[0]}++;$depth{$F[0]}+=$F[3]} END{print "$_\t$pos{$_}\t$depth{$_}" foreach sort keys %pos}' 1>coverage_depth.txt 2>coverage_depth.log &关于samtool mpileup的详细阐明拜见教程:https://www.jianshu.com/p/a3791cf16474?ivk_sa=1024320u
https://cloud.tencent.com/developer/article/1441634
mpileup不利用-u或-g参数时,则不天生二进制的bcf文件,而天生一个文本文件(输出到标准输出)。该文本文件统计了参考序列中每个碱基位点的比对环境;该文件每一行代表了参考序列中某一个碱基位点的比对效果。上面下令就是把这个标准输出直继承道下令给perl 天生一个新的文件,大概输出到o文件。
二、做图可视化
把上面天生的o文件改名为coverage.txt,传到当地电脑。
在R里运行:
setwd("C:/temp/bed")rm(list = ls())file <- 'coverage.txt'dat <- read.table(file, sep = "\t", fill=TRUE,stringsAsFactors = F)colnames(dat)=c('chr','number','length','GC','counts')keep_chr <- dat$chr %in% c(paste0('chr',c(1:22,'X','Y')))dat <- dat[keep_chr,]dat$depth <- dat$counts/dat$lengthlibrary(ggplot2)head(dat)# To change plot order of facet wrap,# change the order of varible levels with factor()dat$chr <- factor(dat$chr , levels =c(paste0('chr',c(1:22,'X','Y'))) )png('coverage.png',height = 500,width = 2000)p <- ggplot(dat,aes(number,depth))+geom_area(aes(fill=chr))+ylim(0, 10)p <- p+facet_grid( ~ chr,scales = 'free_x',space = 'free_x')print(p)dev.off() 放个自己调解了的图,似乎比jimmy大神的看着悦目一丢丢。

2.png
三、
这两个教程内里用了差异的分面。。(关于R的详细细节有待深入学习。。近期安排上)https://cloud.tencent.com/developer/article/1054625
用了 facet_wrap
https://cloud.tencent.com/developer/article/1928651
用了facet_grid
学习这两种函数的差异,教程如下:
https://www.jianshu.com/p/dd6bbbba117b
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 16:53, Processed in 0.169300 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表