[[PageOutline]] = Velvet & NGS = * [問題] Velvet 在處理 NGS (Next Generation Sequencing,新一代的定序技術)時,會遇到記憶體需求高達 1 TB的情形。解決方法可分為兩階段:(1) 使用單機的 CPU,使用 memcached 提供共享記憶體 (2) 完全 MPI 化。 == Stage 1 : 理解 Velvet 運算特性 == == [wiki:jazz/11-05-04 2011-05-04] == * [wiki:biocluster/Velvet Velvet 安裝紀錄(2009-11-11)] * 測試 Velvet 1.1.03 (支援 OpenMP) * 系統:Debian Squeeze {{{ ~$ sudo apt-get update; sudo apt-get upgrade; sudo apt-get dist-upgrade ~$ sudo apt-get install build-essential ~$ wget http://www.ebi.ac.uk/~zerbino/velvet/velvet_1.1.03.tgz ~$ tar zxvf velvet_1.1.03.tgz ~$ cd velvet_1.1.03 ~/velvet_1.1.03$ make ~/velvet_1.1.03$ ./velveth output 17 -fasta -short data/test_long.fa ~/velvet_1.1.03$ ./velvetg output/ -exp_cov 3 -min_contig_lgth 100 }}} * <參考 1> [http://blog.dccmx.com/2011/01/gprof/ 讓程序飛 之 性能工具: gprof & gprof2dot] * <參考 2> [http://blog.dccmx.com/2011/01/valgrind-memcheck/ 讓程序飛 之 內存工具: valgrind –tool=memcheck] * <參考 3> [http://blog.dccmx.com/2011/01/valgrind-massif/ 讓程序飛 之 內存工具: valgrind –tool=massif & massif-visualizer] * <參考 4> [http://blog.dccmx.com/2011/01/callgrind/ 讓程序飛 之 性能工具: valgrind –tool=callgrind & kcachegrind] * 使用 [http://packages.debian.org/valgrind valgrind] 來進行記憶體分析 - (1) Memory Leak 分析 {{{ ~/velvet_1.1.03$ sudo apt-get install valgrind ~/velvet_1.1.03$ valgrind -v --leak-check=full --show-reachable=yes --read-var-info=yes ./velveth output 17 -fasta -short data/test_long.fa 2> velveth.log ~/velvet_1.1.03$ valgrind -v --leak-check=full --show-reachable=yes --read-var-info=yes ./velvetg output/ -exp_cov 3 -min_contig_lgth 100 2> velvetg.log }}} * 使用 [http://packages.debian.org/valgrind valgrind] 的 [http://valgrind.org/docs/manual/ms-manual.html Massif] 工具來進行記憶體分析 - (2) Memory Usage 分析 * Valgrind's skin Massif ('valgrind --tool=massif application') traces memory usage of the application.[http://ktown.kde.org/~seli/memory/analysis.html 參考來源] {{{ ~/velvet_1.1.03$ valgrind --tool=massif ./velveth output 17 -fasta -short data/test_long.fa ~/velvet_1.1.03$ ms_print massif.out.10571 ~/velvet_1.1.03$ valgrind --tool=massif ./velvetg output/ -exp_cov 3 -min_contig_lgth 100 ~/velvet_1.1.03$ ms_print massif.out.10561 }}} {{{ -------------------------------------------------------------------------------- Command: ./velveth output 17 -fasta -short data/test_long.fa Massif arguments: (none) ms_print arguments: massif.out.10571 -------------------------------------------------------------------------------- MB 66.60^ @@@@@@@@@@# | :@:::::::::@:::::::::::::::::::::::::::::::::::::::::@ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # | :@:::: ::::@ : : : @ # 0 +----------------------------------------------------------------------->Mi 0 120.8 Number of snapshots: 71 Detailed snapshots: [2, 4, 57, 67, 68 (peak)] -------------------------------------------------------------------------------- n time(i) total(B) useful-heap(B) extra-heap(B) stacks(B) -------------------------------------------------------------------------------- 0 0 0 0 0 0 1 201,656 34,224 34,099 125 0 2 14,964,257 33,864 33,747 117 0 }}} {{{ -------------------------------------------------------------------------------- Command: ./velvetg output/ -exp_cov 3 -min_contig_lgth 100 Massif arguments: (none) ms_print arguments: massif.out.10561 -------------------------------------------------------------------------------- MB 2.277^ # | # | # | # | # | # | # | # | # | # | # | # | # | # | # | # | # | @@@:: # | ::@ ::: # | :::@ :::::#:::::::@:::::::::@:::@:::::::::::::::::::::::::: 0 +----------------------------------------------------------------------->Mi 0 125.5 Number of snapshots: 73 Detailed snapshots: [2, 5, 6, 14, 16, 22, 30 (peak), 42, 58, 68] -------------------------------------------------------------------------------- n time(i) total(B) useful-heap(B) extra-heap(B) stacks(B) -------------------------------------------------------------------------------- 0 0 0 0 0 0 1 896,153 8,888 8,478 410 0 2 1,973,156 11,872 11,099 773 0 }}} * <註> 目前有兩個工具可以把 ms_print 的 ASCII 圖變成更好看,一個是 KDE 的 [https://projects.kde.org/projects/extragear/sdk/massif-visualizer massif-visualizer],另一個是 GNOME 的 [http://live.gnome.org/MassifG MassifG](有 Ubuntu 套件在 PPA) * <備註> [http://milianw.de/blog/massif-visualizer-now-with-user-interaction#comment-951 安裝 massif-visualizer 的步驟] * 使用 [http://packages.debian.org/valgrind valgrind] 的 [http://valgrind.org/docs/manual/cl-manual.html callgrind] 工具來進行動態連結分析 {{{ ~/velvet_1.1.03$ valgrind --tool=callgrind ./velveth output 17 -fasta -short data/test_long.fa ~/velvet_1.1.03$ valgrind --tool=callgrind ./velvetg output/ -exp_cov 3 -min_contig_lgth 100 ~/velvet_1.1.03$ callgrind_annotate callgrind.out.12046 > velveth_callgrind.log ~/velvet_1.1.03$ callgrind_annotate callgrind.out.12074 > velvetg_callgrind.log }}} * 使用 gprof 進行 profile 分析 {{{ ~/velvet_1.1.03$ cat Makefile | sed "s#^CFLAG.*#CFLAGS = -Wall -pg#" > Makefile.new ~/velvet_1.1.03$ mv Makefile.new Makefile ~/velvet_1.1.03$ make ~/velvet_1.1.03$ ./velveth output 17 -fasta -short data/test_long.fa ~/velvet_1.1.03$ du -sh gmon.out 56K gmon.out ~/velvet_1.1.03$ ./velvetg output/ -exp_cov 3 -min_contig_lgth 100 ~/velvet_1.1.03$ du -sh gmon.out 152K gmon.out ~/velvet_1.1.03$ gprof velveth > velveth.log ~/velvet_1.1.03$ gprof velvetg > velvetg.log }}} * 使用 [http://code.google.com/p/jrfonseca/wiki/Gprof2Dot gprof2dot] 把 gprof log 轉成 graphviz 的 dot 格式,就可以畫出圖形了。 {{{ ~/velvet_1.1.03$ sudo apt-get install graphviz python ~/velvet_1.1.03$ wget http://gprof2dot.jrfonseca.googlecode.com/hg/gprof2dot.py ~/velvet_1.1.03$ chmod a+x gprof2dot.py ~/velvet_1.1.03$ gprof velveth | ./gprof2dot.py | dot -Tpng -o velveth.png ~/velvet_1.1.03$ gprof velvetg | ./gprof2dot.py | dot -Tpng -o velvetg.png }}} * [[Image(jazz/11-05-04:velveth.png)]] * [[Image(jazz/11-05-04:velvetg.png)]] == 2011-05-13 == * 序列格式的轉換:如何從 *.sra 格式轉換成 *.fa (fastq)格式? * 範例:http://trace.ncbi.nlm.nih.gov/Traces/sra/?study=SRP005020 * 範例:ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/data/NA19240/sequence_read/ * <參考> [http://www.ncbi.nlm.nih.gov/books/NBK47540/#SRA_Download_Guid_B.3_Installing_the_Too 5 Converting SRA format data into FASTQ] * <下載> [http://www.ncbi.nlm.nih.gov/Traces/sra/sra.cgi?cmd=show&f=software&m=software&s=software NCBI SRA SDK (Software Development Kit)] - 2011-04-29, version 2.0.1 release * <編譯> {{{ ~$ sudo apt-get install build-essential libxml2-dev libbz2-dev zlib1g-dev ~$ wget http://trace.ncbi.nlm.nih.gov/Traces/sra/static/sra_sdk-2.0.1.tar.gz ~$ tar zxvf sra_sdk-2.0.1.tar.gz ~$ cd sra_sdk-2.0.1 ~/sra_sdk-2.0.1$ make ; cd .. ~$ wget ftp://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByExp/sra/SRX/SRX036/SRX036906/SRR089345/SRR089345.sra }}}