复盘总结(一)

新年最适合干什么?当然是复盘总结!!
先从代码开始复盘。

linux处理bed文件

#对输入的文件进行处理,使得其满足methylkit的输入文件格式
for file in /data/home/lt/data/brain_adrenal/*
do  
var="$file"
tmp=$(echo ${var##*/}) 
a=$(echo ${tmp%.*}) 
echo $a #在屏幕上显示即将生成的文件名
gawk '{print $1"."$3,$1,$3,$6,$10,$11,100-$11}' $file | \
gawk '{if($4=="+"){$4="F"}else{$4="R"}print $0}' | \
sed '1d' | sed '1i\chrBase chr base strand coverage freqC freqT' > $a #
done

用linux不多,还是一开始尝试上游分析(测序数据的质控、比对)的时候用的比较多。linux的优点是比较快。

methylkit R包上游处理

setwd("D:/DMP_mk_")
library(methylKit)
#创建file list
#多个对象
if(T)
{
  file.list <- list(
    "adrenal_1.txt",
    "adrenal_2.txt",
    "brain_1.txt",
    "brain_2.txt",
    "Breast_1.txt",
    "Breast_2.txt",
    "Kidney_1.txt",
    "Kidney_2.txt",
    "Left_Ventricle_1.txt",
    "Left_Ventricle_2.txt",
    "Liver_1.txt",
    "Liver_2.txt",
    "Lung_1.txt",
    "Lung_2.txt",
    "Pancreas_1.txt",
    "Pancreas_2.txt",
    "SkeletalMuscle_1.txt",
    "SkeletalMuscle_2.txt",
    "SkeletalMuscle_3.txt",
    "SkeletalMuscle_4.txt",
    "Skin_1.txt",
    "Skin_2.txt",
    "Stomach_1.txt",
    "Stomach_2.txt",
    "Testis_1.txt",
    "Testis_2.txt",
    "Uterus_1.txt",
    "Uterus_2.txt"
  )
  
}

# read the files to a methylRawList object: myobj
#多个分组对象读取
if(T)
{
  myobj <- methRead(
    file.list,
    sample.id=list(
      "adrenal_1.txt",
      "adrenal_2.txt",
      "brain_1.txt",
      "brain_2.txt",
      "Breast_1.txt",
      "Breast_2.txt",
      "Kidney_1.txt",
      "Kidney_2.txt",
      "Left_Ventricle_1",
      "Left_Ventricle_2",
      "Liver_1.txt",
      "Liver_2.txt",
      "Lung_1.txt",
      "Lung_2.txt",
      "Pancreas_1.txt",
      "Pancreas_2.txt",
      "SkeletalMuscle_1.txt",
      "SkeletalMuscle_2.txt",
      "SkeletalMuscle_3.txt",
      "SkeletalMuscle_4.txt",
      "Skin_1.txt",
      "Skin_2.txt",
      "Stomach_1.txt",
      "Stomach_2.txt",
      "Testis_1.txt",
      "Testis_2.txt",
      "Uterus_1.txt",
      "Uterus_2.txt"),
    assembly="hg19",
    sep = " ",
    treatment=c(0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,8,8,9,9,10,10,11,11,12,12),
    context="CpG",
    mincov = 10
  )
  
}
#去除覆盖率较低的reads(count<10)
myobj=filterByCoverage(myobj,lo.count=10,lo.perc=NULL,hi.count=NULL,hi.perc=99.9)
#归一化
myobj <- normalizeCoverage(myobj) 
#合并所有样本中共有的位点
meth=unite(myobj, destrand=FALSE)
save(meth,file = "united_data.Rdata")
#样品聚类信息
pdf(file = "correlation_meth_.pdf",width = 7,height = 20)#在pdf编辑器中进行了编辑
clusterSamples(meth, dist="correlation", method="ward", plot=TRUE)
dev.off()

methylKit是一个用来分析RRBS数据及其变体的R包,利用 filterByCoverage 函数可以对RRBS数据进行初步的过滤以及归一化,消除PCR过度扩增以及在此位点上覆盖的reads过小所带来的偏差。


测序深度和覆盖度

在这里的coverage个人认为是覆盖了某个base的reads数目。hi.perc=99.9表示去掉最大的0.1%。

normalizeCoverage 函数使用从样本覆盖率分布的均值或中位数之间的差异派生的比例因子来标准化样本之间的覆盖率值。这样可以消除不同样本的测序总reads数目所带来的差异。(个人感觉如果最后计算的是甲基化的百分比,标准化的作用不大。)

没有过滤之前:

> getMethylationStats(myobj[[1]],both.strands=FALSE)
methylation statistics per base
summary:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   0.000   3.226  22.795  33.333 100.000 
percentiles:
        0%        10%        20%        30%        40%        50%        60%        70% 
  0.000000   0.000000   0.000000   0.000000   1.612903   3.225806   6.086957  15.789474 
       80%        90%        95%        99%      99.5%      99.9%       100% 
 60.869565  90.909091  96.551724 100.000000 100.000000 100.000000 100.000000 

> getCoverageStats(myobj[[1]],both.strands=FALSE)
read coverage statistics per base
summary:
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
   10.00    24.00    42.00    58.41    69.00 46296.00 
percentiles:
   0%   10%   20%   30%   40%   50%   60%   70%   80%   90%   95%   99% 99.5% 99.9% 
   10    15    21    28    35    42    51    62    77   106   150   241   271   336 
 100% 
46296 

过滤之后:

> getMethylationStats(myobj[[1]],both.strands=FALSE)
methylation statistics per base
summary:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   0.000   3.226  22.799  33.333 100.000 
percentiles:
        0%        10%        20%        30%        40%        50%        60%        70% 
  0.000000   0.000000   0.000000   0.000000   1.612903   3.225806   6.060606  15.789474 
       80%        90%        95%        99%      99.5%      99.9%       100% 
 60.869565  90.909091  96.551724 100.000000 100.000000 100.000000 100.000000 

> getCoverageStats(myobj[[1]],both.strands=FALSE)
read coverage statistics per base
summary:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  10.00   24.00   42.00   54.65   68.00  335.00 
percentiles:
   0%   10%   20%   30%   40%   50%   60%   70%   80%   90%   95%   99% 99.5% 99.9% 
   10    15    21    28    35    42    51    62    77   105   148   237   263   306 
 100% 
  335 

归一化之后:

> getMethylationStats(myobj[[1]],both.strands=FALSE)
methylation statistics per base
summary:
  Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.000   0.000   3.125  22.760  33.333 100.000 
percentiles:
       0%        10%        20%        30%        40%        50%        60%        70% 
 0.000000   0.000000   0.000000   0.000000   1.351351   3.125000   6.000000  15.789474 
      80%        90%        95%        99%      99.5%      99.9%       100% 
61.016949  91.176471  96.774194 100.000000 100.000000 100.000000 100.000000 

> getCoverageStats(myobj[[1]],both.strands=FALSE)
read coverage statistics per base
summary:
  Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 13.00   30.00   53.00   68.96   86.00  423.00 
percentiles:
  0%   10%   20%   30%   40%   50%   60%   70%   80%   90%   95%   99% 99.5% 99.9% 
  13    19    26    35    44    53    64    78    97   132   187   299   332   386 
100% 
 423 

生成聚类图:

> clusterSamples(meth, dist="correlation", method="ward", plot=TRUE)
The "ward" method has been renamed to "ward.D"; note new "ward.D2"

Call:
hclust(d = d, method = HCLUST.METHODS[hclust.method])

Cluster method   : ward.D 
Distance         : pearson 
Number of objects: 28 

在这一步中我们得到了united_data.Rdata文件。

另外一种unite选择

if(F){
meth=unite(myobj,destrand=FALSE,min.per.group = 1L)
perc.meth=percMethylation(meth)
  tmp <- data.frame(perc.meth)
  for (i in 1:715765)
  {
  for (j in seq(1,25,2))
    {
    if(is.na(tmp[i,j]))
      tmp[i,j] =  tmp[i,j+1]
    }
  
  }
  
  rm(i,j)
  for (i in 1:715765)
  {

      if(is.na(tmp[i,27]))
        {tmp[i,27] =  tmp[i,28]}

    
  }

  
  rm(i)
  tmp_1 <- tmp

  for (i in 1:715765)
  {
    for (j in seq(2,28,2))
    {
      if(is.na(tmp_1[i,j]))
        tmp_1[i,j] =  tmp_1[i,j-1]
    }
    
  }
  
  rm(i,j)
  tmp_2 <- tmp_1
  for (i in 1:715765)
  {
   
      if(is.na(tmp_2[i,17]))
        tmp_2[i,17] =  tmp_2[i,19]
      if(is.na(tmp_2[i,18]))
        tmp_2[i,18] =  tmp_2[i,20]
      if(is.na(tmp_2[i,19]))
        tmp_2[i,19] =  tmp_2[i,17]
      if(is.na(tmp_2[i,20]))
        tmp_2[i,20] =  tmp_2[i,18]

  }
meth_1 <- meth
perc.meth_1 <- tmp_2
rm(meth,perc.meth)
save(meth_1,perc.meth_1,file = "united_data_1.Rdata") 
  
  }
  

这里我们就可以得到同组至少包含一个样本的unite文件。我们将它另存为united_data_1.Rdata文件。但是上述代码运行的时间在一个小时以上,R语言的for循环速度实在太慢了,暂时还没有找到好的解决方法。

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

推荐阅读更多精彩内容