-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasyrna.py
57 lines (47 loc) · 1.75 KB
/
easyrna.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
"""
"actions":"fpkm,diff,heatmap"
Created on July 22, 2014
EasyRNA function
"""
__author__ = 'Linuxpham <[email protected]>'
__contact__ = '[email protected]'
__version__ = "1.0"
__date__ = '2014-07-22'
import sys, os
import optparse, subprocess
###Define the general information
DOCUMENT_ROOT = os.path.realpath(os.path.abspath("./"))
LIBRARY_PATH = os.path.realpath(DOCUMENT_ROOT + "/lib")
BIN_PATH = os.path.realpath(DOCUMENT_ROOT + "/bin")
###Parse command line options
parserInstance = optparse.OptionParser(usage="usage: python %prog [options]", version="EasyRNA 1.0")
parserInstance.add_option("-i", "--input", default="./example/data.json", help="Input JSON file")
parserInstance.parse_args()
###Add library system path
if LIBRARY_PATH not in sys.path:
sys.path.insert(0, LIBRARY_PATH)
sys.path.insert(0, BIN_PATH)
###Get all arguments data
INPUT_FILE = str(parserInstance.values.input)
###Escape shell
def shellEscape(s):
return s.replace("(","\\(").replace(")","\\)")
###Main function handler
def main():
###Debug information
print("Start the EasyRNA processing with JSON file : " + INPUT_FILE)
###Create command in R
command = "Rscript '" + shellEscape(BIN_PATH) + "/EasyRNA.R' " + INPUT_FILE
print(command)
###Get all output data
outData, _ = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True).communicate()
###Get all response data
for lineData in outData.splitlines():
outStringData = str(lineData)
print(outStringData)
###Debug information
print("End the EasyRNA processing")
###Default start all handlers
if __name__ == '__main__':
sys.exit(main())