前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >转录组数据拼接之应用篇

转录组数据拼接之应用篇

作者头像
生信技能树
发布2018-03-05 15:58:29
3.2K0
发布2018-03-05 15:58:29
举报
文章被收录于专栏:生信技能树生信技能树

前前后后接触了一些基因组和转录组拼接的工作,而且后期还会持续进行。期间遇到了各种各样莫名其妙的坑,也尝试了一些不同的方法和软件,简单做一个阶段性小结。上周的今天更新了原理部分 二代测序数据拼接之原理篇 (点击阅读),本篇是阉割版应用部分(原文代码太多影响阅读体验)。

10000 字(含代码),约20分钟,文|思考问题的熊

感觉本文过长可直接收藏,然后阅读 2018,从“丢”开始(点击阅读)


拼接大致流程

流程的前面4步和DBG算法相关,尤其是一二两步需要较大的内存。拼接结果受 kmer size,kmer coverage cutoff 和 length and coverage parameters 的影响


数据预处理

去接头和低质量reads

类似于通常 RNA-seq 数据处理,略~

使用软件 khmer 进行标准化

digital normalization

关于是否进行 digital normalization 其实一直有不少讨论,最初一篇介绍 digital normalization 的文章指出,所谓digital normalization,是 discards redundant data and both sampling variation and the number of errors present in deep sequencing data sets。其最大的好处是可以降低拼接对内存的要求并且节省时间,而且对于拼出的 contig 没有什么影响。之所以不影响拼接质量,是因为并没有去掉那些低覆盖度的数据。具体可以参考这篇文章 What is digital normalization, anyway。

当然,过了一段时间,还是上文作者又写了一篇博客,说明digital normalization 存在的一些问题。

另附 软件官网使用说明

软件主要功能

  • normalizing read coverage ("digital normalization")
  • dividing reads into disjoint sets that do not - connect ("partitioning")
  • eliminating reads that will not be used by a de - Bruijn graph assembler;
  • removing reads with low- or high-abundance k-mers;
  • trimming reads of certain kinds of sequencing errors;
  • counting k-mers and estimating data set coverage based on k-mer counts;
  • running Velvet and calculating assembly statistics;
  • converting FASTQ to FASTA;
  • converting between paired and interleaved formats for paired FASTQ data

在使用khmer处理数据之前,首先要想清楚是否进行处理。其中最重要的参数是 graph-size filtering 和 graph partitioning。这个软件拼接的时候可以用,计算表达量差异的切忌使用。

另一个是关于 memory 的设置问题,在官方给出的建议中说了一大堆,总的来说就是越大越好 :)

建议使用服务器总内存的一半,如果内存不够的话会报错。一般1 billion 的 mRNAseq 需要 -M16G 16G内存。如果kmer过小,在进行数据清洗的时候,很可能会造成误伤。

Khmer 的四种用法

  • k-mer counting and abundance filtering
  • Partitioning
  • Digital normalization
  • Read handling: interleaving, splitting, etc.

这里主要使用Digital normalization

关于kmer设置的说明

The interaction between these three parameters and the filtering process is complex and depends on the data set being processed, but higher coverage levels and longer k-mer sizes result in less data being removed. Lower memory allocation increases the rate at which reads are removed due to erroneous estimates of their abundance, but this process is very robust in practice

针对mRANseq的拼接,官方文献给出的建议是

By normalizing to a higher coverage of 20, removing errors, and only then reducing coverage to 5, digital normalization can retain accurate reads for most regions. Note that this three-pass protocol is not considerably more computationally expensive than the single-pass protocol: the first pass discards the majority of data and errors, so later passes are less time and memory intensive than the first pass

但是针对本身数量不是过大的数据,目前推荐使用single-pass digital normalization的方法。

pair end 数据合并

代码语言:javascript
复制
for i in `ls /projects/zhaofei/wheat_rawdata/LF0*_1.fq.gz`
do
id=`basename $i |sed 's/_1.fq.gz//'`
interleave-reads.py $i /projects/zhaofei/wheat_rawdata/${id}_2.fq.gz -o ${id}_pair.fq.gz --gzip
done

for i in `ls /projects/zhaofei/wheat_rawdata/LF1*_1.fq.gz`
do
id=`basename $i |sed 's/_1.fq.gz//'`
interleave-reads.py $i /projects/zhaofei/wheat_rawdata/${id}_2.fq.gz -o ${id}_pair.fq.gz --gzip
done

single-pass digital normalization

核心步骤,设定相应的cutoff和kmer进行数据处理,cutoff 20; kmer 21/25/27/31/

此处的cutoff 是指:when the median k-mer coverage level is above this number the read is not kept

代码语言:javascript
复制
normalize-by-median.py -p -k 27 -M 50G -C 20 -R LF01.log \
-o LF01k32c28.fq.gz --gzip LF01_pair.fq.gz > runLF01.log 2>&1 &

如果在去街头和低质量数据过程中产生了单端数据,可以在命令中加入-u se.fq 参数

如果想保留生成的dbg文件,可以添加参数 --savegraph normC20k27.ct

去除可能错误的kmer

这一步去除上一步中coverage很高,但是kmer abundanc 低的reads。

代码语言:javascript
复制
filter-abund.py -V -Z 18 normC20k20.ct input.keep.fa && \
  rm input.keep.fa normC20k20.ct

# 我自己使用的时候实际没有执行这一步

提取pair end reads

代码语言:javascript
复制
extract-paired-reads.py input.keep.fq

这一步会分别生成仍是pair reads和非 pair reads,生成的数据可以用来后续正式的拼接过程。

分离pair end reads

代码语言:javascript
复制
split-paired-reads.py input.fq.pe

分离后得到的两个fastq文件就可以正式的拼接了。


使用 Trinity 进行拼接

软件介绍

下载地址

https://github.com/trinityrnaseq/trinityrnaseq/wiki

相关文献:

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3571712/

Trinity是目前最常用的转录组拼接软件。

拼接过程共分为三步

Inchworm: 拼接过程。从reads到contigs的过程,contigs可能代表一个全长转录本或者一个转录本的一部分。会提取所有的重叠k-mers,根据丰度高低检查每个k-mers,然后将重叠的k-mers延长,形成一个contig

Chrysalis: 将上一步生成的contigs聚类,对每个聚类结果构建DBG图。一个DBG图代表了一个基因的全长转录本。

Butterfly: 根据上一步构建的DBG图和图中的pair end reads 信息寻找最优路径。得到具有可变剪接的全长转录本,同时分开旁系基因的转录本。

直系同源的序列因物种形成(speciation)而被区分开(separated):若一个基因原先存在于某个物种,而该物种分化为了两个物种,那么新物种中的基因是直系同源的;旁系同源的序列因基因复制(gene duplication)而被区分开(separated):若生物体中的某个基因被复制了,那么两个副本序列就是旁系同源的。

常用命令示例

代码语言:javascript
复制
trinityrnaseq-Trinity-v2.4.0/Trinity \
--seqType fq --max_memory 40G --CPU 4 \
--left left.fq.gz \
--right right.fq.gz \
--output test_trinity --full_cleanup \
--no_version_check > test.log 2>&1 &

想要详细了解trinity的处理过程,只需要认真读一下生成的log文件就可以。

大体上是如下几步:

代码语言:javascript
复制
---------------------------
Trinity Phase 1: Clustering of RNA-Seq Reads
---------------------------

In silico Read Normalization
-- (Removing Excess Reads Beyond 50 Coverage --

Jellyfish
-- (building a k-mer catalog from reads) --

Inchworm
-- (Linear contig construction from k-mers) --

Chrysalis
-- (Contig Clustering & de Bruijn Graph Construction) --

------------------------
 Trinity Phase 2: Assembling Clusters of Reads
 ---------------------

Butterfly assemblies are written to \
/projects/zhaofei/wheat_assembly/trinity/LF20_1_trinity.Trinity.fasta

可能出现的报错

需要注意的是,有时候使用trinity拼接一些公用数据会报错

代码语言:javascript
复制
#If your data come from SRA, be sure to dump the fastq file like so:
 #SRA_TOOLKIT/fastq-dump --defline-seq '@$sn[_$rn]/$ri' --split-files --gzip file.sra

可以使用命令

代码语言:javascript
复制
fastq-dump --defline-seq '@$sn[_$rn]/$ri' --split-files --gzip input.sra

有的时候不是公用数据仍然报错,是因为pair end 数据第一行@开头的名字不能有空格,必须用1/;2/结尾

代码语言:javascript
复制
#如果中间有空格,结尾正确

 zcat ERR037683_1.fastq.gz|awk '{ if (NR%4==1) { print $1"_"$2"" } else { print } }'|gzip >ERR037683_new_1.fastq.gz

 #跑循环修改
 for i in ERR037679_2.fastq.gz ERR037681_2.fastq.gz ERR037687_2.fastq.gz
  do
  zcat $i | awk '{ if (NR%4==1) { print $1"_"$2"" } else { print } }'|gzip > ${i/_2.fastq.gz/}_new_2.fastq.gz && rm -f $i
 done

 #如果结尾不正确
 zcat ERR037683_1.fastq.gz|awk '{ if (NR%4==1) { print $1"_"$2"/1" } else { print } }'|gzip >ERR037683_new_1.fastq.gz
 #_2.fq 同理替换

测试小众Bridger拼接软件

github 地址:

https://github.com/fmaguire/Bridger_Assembler

文献

https://genomebiology.biomedcentral.com/articles/10.1186/s13059-015-0596-2

按照文章里的这个软件结合了trinity和cufflinks的优点,和trinity相比拼接速度更快占内存更小,可以产生更好的contig(注意:不一定是好事)

安装软件

首先安装boost

代码语言:javascript
复制
a) download latest boost and unpack it.

        $ tar zxvf boost_1_47_0.tar.gz

     b) change to the boost directory and run ./bootstrap.sh.

        $ cd  boost_1_47_0
        $ ./bootstrap.sh

        $ ./b2 install --prefix=<YOUR_BOOST_INSTALL_DIRECTORY>

        For example,if you want install boost in /home/czheng/local/boost,the commnd is :
        $ ./b2 install --prefix=/home/czheng/local/boost

        If the boost is installed successfully, you would fild two sub-directories in /home/czheng/local/boost/:
        /home/czheng/local/boost/include/
        /home/czheng/local/boost/lib/

       Note: The default Boost installation directory is /usr/local. Take note of the boost installation
        directory, beacuase you need to tell the Bridger installer where to find boost later on.

     d) Set the LD_LIBRARY_PATH enviroment variable:

        The ~/.bash_profile ($HOME/.bash_profile) or ~/.profile file is executed when you login using console or remotely using ssh.
        Append the following command to  ~/.bash_profile or ~/.profile file:
        $ export LD_LIBRARY_PATH=/home/czheng/local/boost/lib:$LD_LIBRARY_PATH

        Save and close the file.

        OR

        just type the command:
        $ export LD_LIBRARY_PATH=/home/czheng/local/boost/lib:$LD_LIBRARY_PATH

        Note: please replace "/home/czheng/local/boost/lib" with your own directory "<YOUR_BOOST_INSTALL_DIRECTORY>/lib"
        If you do not set this variable , you would possible see the follwoing error information:
         "error while loading shared libraries: libboost_serialization.so.1.47.0: cannot open shared object file: No such file or dire    ctory"

再安装bridger

代码语言:javascript
复制
Building Bridger [Make sure Boost has been installed successfully]

     a) Unpack the Bridger and change to the Bridger direcotry.

        $ tar zxvf Bridger_r2013-06-02.tar.gz
        $ cd Bridger_r2013-06-02

     b) Configure Bridger. If Boost is installed somewhere other than /usr/local, you will need to tell
        the installer where to find it using --with-boost option.

        $ ./configure --with-boost=/home/czheng/local/boost/
        Note: please replace "/home/czheng/local/boost/" with your own directory "<YOUR_BOOST_INSTALL_DIRECTORY>"


     c) Make Bridger.

        $ make

       note: If you build boost suffessfully without using --prefix option, the following commands may need before "make":
           export LIBS="-L/home/czheng/boost_1_47_0/stage/lib" (replace "/home/czheng/boost_1_47_0/" with your own directory)
           export CPPFLAGS="-I/home/czheng/boost_1_47_0/"

报错和解决方法

如果安装最新版本的软件,是会报错的。这个问题已经有人在GitHub上提出来了,但是软件的作者已经到阿里巴巴上班了,于是只能自己想办法改一下原始代码。

代码语言:javascript
复制
Splicing Graphs Reconstruction
CMD: ~/software/Bridger_r2014-12-01/src/Assemble --reads both.fa -k 25 --pair_end --fr_strand 2 2>Assemble.log
Error, cmd: ~/software/Bridger_r2014-12-01/src/Assemble --reads both.fa -k 25 --pair_end --fr_strand 2 2>Assemble.log died with ret 256 !

Assemble.log:
[Error] Cannot create directory ./RawGraphs/ !

出现报错以后,如果查看目录会发现已经有/RawGraphs/目录,尝试更改相关源代码解决问题。比如增加生成文件夹的一步。

修改 Bridger.pl 文件

代码语言:javascript
复制
## Assemble step:
print "\n### Splicing Graphs Reconstruction ###\n\n";
my $graphdir = "RawGraphs"; #新加
mkdir "$output_directory/$graphdir"; #新加
my $assemble_cmd = "$SRC_DIR/Assemble --reads $target_fa -k $kmer_length ";

核心命令

代码语言:javascript
复制
perl Bridger_r2014-12-01/Bridger.pl --seqType fq -k 31 --left left.fq --right right.fq --CPU 6 --debug -o output

cd-hit 聚类去冗余

cd-hit 是一个聚类软件,可以对DNA序列或者蛋白质序列进行聚类,其本质应该还是多序列比对。为了让拼出来的scaffold更少一些,可以尝试对拼接结果再次聚类,输出每个聚类结果中最长的序列。类似的软件还有corset和lace。

但是实际使用过程中,发现效果也一定会特别明显。

代码语言:javascript
复制
cd-hit-est -i input.fasta -o output-cdhit -T 10 -M 200000

会输出两个结果文件,一个包含序列信息,一个是fasta文件。


评估拼接质量

使用软件 transrate

相关文献 :http://genome.cshlp.org/content/early/2016/06/01/gr.196469.115

官方网站 :http://hibberdlab.com/transrate/index.html

主要有三个功能

  • by inspecting the contig sequences
  • by mapping reads to the contigs and inspecting the alignments
  • by aligning the contigs against proteins or transcripts from a related species and inspecting the alignments

这里我们主要使用前两个功能,如果是有参转录组的拼接,可以尝试使用第三个。但如果是为了查看新的转录本,进行第三项评估也没有太大意义。针对转录组拼接而言,第一步中各种长度的统计结果意义也不大,只有回帖率这个指标是最重要的。通过第二部评估,transrate会返回非常多的有用信息。具体结果解读可以参考网站。需要说明的是,在输出结果中,会直接生成一个good.fasta 文件,本质是在计算转录本表达量时不为0的序列。

这个软件进行第二部计算时,调用了SNAP 进行map,调用了salmon 评估转录本表达量,只调用了 salmon quant这一步。

以下是几个不同拼接结果的评估比较

bridger

khmer treatment and bridger

和trinity拼接结果对比

自行检验

可以使用 salmon 或者 kaillsto 进行表达量的快速统计分析。

至此,已经完成了常规的转录组拼接工作,可以进行更多的后续分析。比如基因结构注释等等。

基因结构注释

使用PAPS进行GENE结构注释,一定要提前安装好gmap或者blat中的一个或者全部

首先创建conf.txt文件

代码语言:javascript
复制
cp $PASAHOME/pasa_conf/pasa.CONFIG.template $PASAHOME/pasa_conf/conf.txt
 ##修改conf.txt以下配置
 #MYSQLSERVER=localhost
 #MYSQL_RW_USER=mysql
 #MYSQL_RW_PASSWORD=1234
 #MYSQL_RO_USER=readonly
 #MYSQL_RO_PASSWORD=1234

配置具体任务的alignAssembly.config

代码语言:javascript
复制
cp $PASAHOME/pasa_conf/pasa.alignAssembly.Template.txt./alignAssembly.config
#修改alignAssembly.config 的内容
#MYSQLDB=<you_task_name>

用trinity生成的文件进行基因注释;-h查看帮助文档。这一步使用的是适合长序列比对的软件GMAP

代码语言:javascript
复制
/PASApipeline-2.1.0/scripts/Launch_PASA_pipeline.pl-c alignAssembly.config-C-R-g genome.fa-tTrinity.fasta--ALIGNERS gmap--transcribed_is_aligned_orient--stringent_alignment_overlap30.0--CPU5

结果文件

代码语言:javascript
复制
{name}#.pasa_assemblies.bed/gff3/gtf/described.txt
{name}.assemblie.fasta
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-03-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 生信技能树 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 10000 字(含代码),约20分钟,文|思考问题的熊
    • 去接头和低质量reads
      • 使用软件 khmer 进行标准化
        • single-pass digital normalization
          • 去除可能错误的kmer
            • 提取pair end reads
              • 分离pair end reads
                • 软件介绍
                  • 常用命令示例
                    • 可能出现的报错
                      • 安装软件
                        • 报错和解决方法
                          • 核心命令
                            • 使用软件 transrate
                              • 自行检验
                              领券
                              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档