1 aligner


1.1 hisat2

  • アラインメントの結果は-S(sam形式のoutput)を指定しなければ, 標準出力にsam形式として出力される. 標準エラー出力にマップ率の情報が出力される. samファイルを扱うことはほとんどないのでリダイレクトでsamtoolsに渡してbam形式のファイルを作成.
  • -U: シングルエンドの場合fastqファイルの指定
  • -1, -2 : ペアエンドの場合のfastqファイルの指定
  • -rna-strandness: strand指定 FR, RF,F,R
  • --dta: トランスクリプト用に調整されたアライメントの実行(stringtieを実行する場合推奨)
  • --no-spliced-alignment:
  • --un-conc-gz: ペアが適切にマップされなかったリードのfastqファイル
  • --summary-file: print alignment summary to this file.
  • --new-summary : print alignment summary in a new style, which is more machine-friendly.

1.4 複数サンプルをループ処理.

  • 出力ファイル名などを指定する場合入力ファイル名から部分文字列を取り出す.
    • ubuntuではpfx=${r1[1]:0:-12}
    • macではpfx=${r1[$i]:0:$((${#r1[$i]}))-12}
##  [1] "100000 reads; of these:"                                                
##  [2] "  100000 (100.00%) were paired; of these:"                              
##  [3] "    27240 (27.24%) aligned concordantly 0 times"                        
##  [4] "    66390 (66.39%) aligned concordantly exactly 1 time"                 
##  [5] "    6370 (6.37%) aligned concordantly >1 times"                         
##  [6] "    ----"                                                               
##  [7] "    27240 pairs aligned concordantly 0 times; of these:"                
##  [8] "      1318 (4.84%) aligned discordantly 1 time"                         
##  [9] "    ----"                                                               
## [10] "    25922 pairs aligned 0 times concordantly or discordantly; of these:"
## [11] "      51844 mates make up the pairs; of these:"                         
## [12] "        29890 (57.65%) aligned 0 times"                                 
## [13] "        16949 (32.69%) aligned exactly 1 time"                          
## [14] "        5005 (9.65%) aligned >1 times"                                  
## [15] "85.06% overall alignment rate"

2 samtools


sam形式のアラインメントファイルを扱うためのユーティリティ

2.1 ソート済bamか否かを確認

## @HD  VN:1.0  SO:unsorted
## @HD  VN:1.0  SO:coordinate

2.2 マップ率 samtools flagstat, bamtools

  • properly paired: 同じクロモソームに適切な向きと位置でアライメントされたペアリードの数
##  [1] "213600 + 0 in total (QC-passed reads + QC-failed reads)"
##  [2] "13600 + 0 secondary"                                    
##  [3] "0 + 0 supplementary"                                    
##  [4] "0 + 0 duplicates"                                       
##  [5] "183710 + 0 mapped (86.01% : N/A)"                       
##  [6] "200000 + 0 paired in sequencing"                        
##  [7] "100000 + 0 read1"                                       
##  [8] "100000 + 0 read2"                                       
##  [9] "145520 + 0 properly paired (72.76% : N/A)"              
## [10] "150132 + 0 with itself and mate mapped"                 
## [11] "19978 + 0 singletons (9.99% : N/A)"                     
## [12] "3966 + 0 with mate mapped to a different chr"           
## [13] "3133 + 0 with mate mapped to a different chr (mapQ>=5)"

2.3 リファレンス各位置にマップされたリード数: samtools depth

2.4 bamからランダムにリードを取り出す

2.4.1 bamtools random

2.4.2 sort -R | head -n

## [E::hts_open_format] Failed to open file input.bam
## samtools view: failed to open "input.bam" for reading: No such file or directory

2.4.3 shuf -n

3 発現解析


3.1 stringtie

RNA-seqの場合アラインメントデータ(bam)を元にして, transcriptを構築する(gtfが作られる). 構築されたtranscriptごとに定量することがができる.

  • primary GTFの作成
    • -G: ガイドgff
    • -m: 最小トランスクリプト長 (default: 200)
  • gtfファイルのマージ(gtfファイルのリストを入力とする.)
  • マージされたgtfファイルをガイドとして定量する
    • -e: リードカウントを-Gで指定されたgtfの領域に制限.
    • -A: カウントデータの出力ファイル
    • -b:カバレッジデータを含むBallgown入力テーブルファイル(* .ctab)を出力

3.2 rsem 

リードアラインメントと定量化を一括して実行できる. alignerをbowtie2, STARから選択する. transcriptとgeneのリストファイルを用いてリファレンスインデックスを作成すれば, それぞれ別個にカウントすることができる.

  • rsem-calculate-expression
    • 標準出力にコマンドやログが, 標準エラー出力にマップ率の結果が出力される.
    • --strand-specific : bowtie2の -- norc オプションがつく
    • -p:スレッド数指定
    • --bowtie2
    • --no-bam-output bamファイルを作らない.
    • --sort-bam-by-coordinate ソートされたbamを作る.
    • --strandednes <none|forward|reverse> norc’ / ’

3.3 salmon

mapping based modeとalignment-based modeがある. alignment-based modeでは, 好みのmapperで出力したbamを入力として使える.
- salmon index -t ref.fa -i ref - インデックスディレクトリができる. - インデックスディレクトリ中のduplicate_clusters.tsvに重複したトランスクリプトのリスト

  • salmon quant --help-reads, salmon quant --help-alignment
  • -a bamファイル
  • -o で出力ディレクトリ指定.
    • quant.sfカウントデータが中に作られる.
  • -l ライブラリタイプ. library typeについてFragment Library Types
    • A : bamインプットの場合自動判定
    • SR: ストランデッド. read1がリバースストランド
    • ISR: ペアエンド内向き. ストランデッド. read1がリバースストランド.
  • --validateMappings

3.4 kallisto

  • --single Quantify single-end reads
  • -l 64.3 平均フラグメント長[default: インプットから推定される.]
  • -s 2.2
  • -t thread数(bootstrapを実行する場合)

4 補足: ベースコール (*.bcl)ファイルからfastqファイルを生成する.
以下は, TruSeq CD Indexesを使用する場合.

4.1 SampleSheet.csvファイルを作成

  • エクセルで編集すると^MがついてくるのでRで編集して書き出す(macで作業している場合).
  • write.csvではなくwrite.table(sep=“,”, col.names=F)にする

5 環境

## R version 3.5.2 (2018-12-20)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS High Sierra 10.13.6
## 
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/C/ja_JP.UTF-8/ja_JP.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] dplyr_0.8.3
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.3          XVector_0.22.0      knitr_1.24         
##  [4] magrittr_1.5        zlibbioc_1.28.0     IRanges_2.16.0     
##  [7] BiocGenerics_0.28.0 hms_0.5.1           tidyselect_0.2.5   
## [10] R6_2.4.1            rlang_0.4.2         stringr_1.4.0      
## [13] tools_3.5.2         parallel_3.5.2      xfun_0.9           
## [16] htmltools_0.3.6     yaml_2.2.0          digest_0.6.23      
## [19] assertthat_0.2.1    tibble_2.1.3        crayon_1.3.4       
## [22] purrr_0.3.3         readr_1.3.1         S4Vectors_0.20.1   
## [25] vctrs_0.2.1         zeallot_0.1.0       glue_1.3.1         
## [28] evaluate_0.14       rmarkdown_1.15      stringi_1.4.3      
## [31] compiler_3.5.2      pillar_1.4.2        Biostrings_2.50.2  
## [34] backports_1.1.5     stats4_3.5.2        pkgconfig_2.0.3