prepDE.pyをpython3で動かす
StringTieで計算した発現量を入力として、Rの環境で発現解析するためにStringTieのパッケージではprepDE.pyが用意されているものの、python2で実装されているためにpython3の環境構築をしている人にとっては、一時的にでもpython2に変更する必要が生じる。これはいささか気持ちが悪いし、自分でコードを書く気力がない人にとっては大きな問題だろう。
python2のコードをpython3に変換する方法はいくつか用意されているが、実際は変換がうまくいくとは限らない。調べていると、RのライブラリーであるRNAseqRでは、StringTieのパイプラインを使った場合にRで読み込む際にprepDE.pyをバックエンドで利用する。このRNAseqRのマニュアルに、python3の場合の対応が記載されていた。引用開始>
5.9 The Reads Count Table Creator
Whether this step is executed depends on the availability of Python on your workstation.
- Input: ‘samplelst.txt’
- Output: ‘gene_count_matrix.csv’, ‘transcript_count_matrix.csv’
- The reads count table converter Python script is downloaded as
prepDE.py
- Python checking
- When Python is not available, this step is skipped.
- When Python2 is available,
prepDE.py
is executed.- When Python3 is available, the
2to3
command will be checked.(Usually, if Python3 is installed,2to3
command will be installed too.)- When Python3 is available but the
2to3
command is unavailable, the raw read count step will be skipped.- When Python3 and the
2to3
command are available,prepDE.py
is converted to a file that can be executed by Python2 and is automatically executed.
<引用終わり
つまり、幸いにも変換コマンドでpython3のコードに変換してもworkしそうだとわかった。ではやってみよう。環境はOSX10.13.4 High Sierra。
Option: Pythonの準備(ただしpyenvで管理している場合)
1. pyenvによるpythonのバージョンの変更
suimyenbookpuro:stringtie suimye$ pyenv versions
system
* 2.7.6 (set by /Users/suimye/.pyenv/version)
3.6.0
anaconda3-4.3.1
anaconda3-4.3.1/envs/py3.6.0
2. pyenvによるpythonのバージョンの変更
suimyenbookpuro:stringtie suimye$ pyenv global 3.6.0
suimyenbookpuro:stringtie suimye$ pyenv versions
system
2.7.6
* 3.6.0 (set by /Users/suimye/.pyenv/version)
anaconda3-4.3.1
anaconda3-4.3.1/envs/py3.6.0
prepDE.pyをpython3のコードにする
次のコマンドを実行すると、prepDE.pyは上書きされてpython3のコードに変換される。元のコードはprepDE.py.bakというファイルでバックアップされているので、もし動かなくてもこのファイルから復活させればよい。
2to3 -w ~/tools/stringtie-2.0.6.OSX_x86_64/prepDE.py
1. stringtieでgtf fileとctabファイルを生成
BAMFILE1=test1.sort.bam
BAMFILE2=test2.sort.bam
REFGTF=/Users/suimye/genome/hg19.refFlat.20130205.gtf
/Users/suimye/tools/stringtie-2.0.6.OSX_x86_64/stringtie $BAMFILE1 -e -B -G $REFGTF -o ball.test1.gtf
/Users/suimye/tools/stringtie-2.0.6.OSX_x86_64/stringtie $BAMFILE2 -e -B -G $REFGTF -o ball.test1.gtf
2. prepDE用のリストを作成
printf "test1\tball.test1.gtf\n" >list.txt
printf "test2\tball.test2.gtf\n" >>list.txt
4. prepDE.pyを実行
python ~/tools/stringtie-2.0.6.OSX_x86_64/prepDE.py -i list.txt
5. 実行結果(ls)
-rw-r--r-- 1 suimye staff 318K 12 25 13:32 gene_count_matrix.csv
drwxr-xr-x 32 suimye staff 1.0K 12 25 13:32 .
-rw-r--r-- 1 suimye staff 723K 12 25 13:32 transcript_count_matrix.csv
-rw-r--r-- 1 suimye staff 65M 12 25 13:03 ball.test2.gtf
-rw-r--r-- 1 suimye staff 65M 12 25 13:03 ball.test1.gtf
gene_count_matrix.csvの中身
suimyenbookpuro:stringtie suimye$ head gene_count_matrix.csv
gene_id,test1,test2
DDX11L1,15,2
WASH7P,0,1
MIR6859-1,0,0
MIR6859-2,0,0
MIR6859-3,0,0
MIR6859-4,0,0
------省略-----