Run prepDE.py with python3

Run prepDE.py with python3

Although prepDE.py is prepared in the StringTie package to analyze the expression in the R environment by inputting the expression level calculated by StringTie, the person who is building the environment of python3 because it is implemented in python2. For me, I need to change to python2 even temporarily. This is a bit unpleasant and can be a big problem for people who aren't willing to write their own code.

There are several ways to convert python2 code to python3, but the conversion doesn't always work. According to my research, RNAseqR, which is a library of R, uses prepDE.py in the backend when reading in R when using the pipeline of StringTie. The [manual] of this RNAseqR (https://bioconductor.org/packages/release/bioc/vignettes/RNASeqR/inst/doc/RNASeqR.html) described the correspondence in the case of python3. Start quoting>

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’
  1. The reads count table converter Python script is downloaded as prepDE.py
  2. 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.

<End of quote

In other words, fortunately, I found that it seems to work even if I convert it to python3 code with the conversion command. Let's try it. The environment is OS X 10.13.4 High Sierra.

Option: Python preparation (if managed by pyenv)

1. Change python version with pyenv

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. Change python version with pyenv

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

Make prepDE.py code for python3

The following command overwrites prepDE.py and translates it into python3 code. The original code is backed up in a file called prepDE.py.bak, so if it doesn't work, you can restore it from this file.

2to3 -w ~/tools/stringtie-2.0.6.OSX_x86_64/prepDE.py 

1. Generate gtf file and ctab file with stringtie

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. Create a list for prepDE

printf "test1\tball.test1.gtf\n" >list.txt
printf "test2\tball.test2.gtf\n" >>list.txt

4. Run prepDE.py

python ~/tools/stringtie-2.0.6.OSX_x86_64/prepDE.py -i list.txt

5. Execution result (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
Contents of 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
------abridgement-----

Recommended Posts

Run prepDE.py with python3
Run Python with VBA
Run Blender with python
Run iperf with python
Run python with PyCharm (Windows)
Run Python with CloudFlash (arm926ej-s)
Let's run Excel with Python
Run Label with tkinter [Python]
Run DHT22 with RasPi + Python
Run Rotrics DexArm with python API
Run mruby with Python or Blender
Run XGBoost with Cloud Dataflow (Python)
Run Aprili from Python with Orange
Run python3 Django1.9 with mod_wsgi (deploy)
Until you run python with apache
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Run servo with Python on ESP32 (Windows)
Run a Python web application with Docker
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Posting tweets with python
Drive WebDriver with python