-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathgrnboost2Runner.py
63 lines (51 loc) · 2.41 KB
/
grnboost2Runner.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
58
59
60
61
62
63
import os
import pandas as pd
from pathlib import Path
import numpy as np
def generateInputs(RunnerObj):
'''
Function to generate desired inputs for GRNBoost2.
If the folder/files under RunnerObj.datadir exist,
this function will not do anything.
'''
if not RunnerObj.inputDir.joinpath("GRNBOOST2").exists():
print("Input folder for GRNBOOST2 does not exist, creating input folder...")
RunnerObj.inputDir.joinpath("GRNBOOST2").mkdir(exist_ok = False)
if not RunnerObj.inputDir.joinpath("GRNBOOST2/ExpressionData.csv").exists():
ExpressionData = pd.read_csv(RunnerObj.inputDir.joinpath(RunnerObj.exprData),
header = 0, index_col = 0)
# Write .csv file
ExpressionData.T.to_csv(RunnerObj.inputDir.joinpath("GRNBOOST2/ExpressionData.csv"),
sep = '\t', header = True, index = True)
def run(RunnerObj):
'''
Function to run GRNBOOST2 algorithm
'''
inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1] + \
"/GRNBOOST2/ExpressionData.csv"
# make output dirs if they do not exist:
outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/GRNBOOST2/"
os.makedirs(outDir, exist_ok = True)
outPath = "data/" + str(outDir) + 'outFile.txt'
cmdToRun = ' '.join(['docker run --rm -v', str(Path.cwd())+':/data/ --expose=41269',
'grnbeeline/arboreto:base /bin/sh -c \"time -v -o', "data/" + str(outDir) + 'time.txt',
'python runArboreto.py --algo=GRNBoost2',
'--inFile='+inputPath, '--outFile='+outPath, '\"'])
print(cmdToRun)
os.system(cmdToRun)
def parseOutput(RunnerObj):
'''
Function to parse outputs from GRNBOOST2.
'''
# Quit if output directory does not exist
outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/GRNBOOST2/"
if not Path(outDir+'outFile.txt').exists():
print(outDir+'outFile.txt'+'does not exist, skipping...')
return
# Read output
OutDF = pd.read_csv(outDir+'outFile.txt', sep = '\t', header = 0)
outFile = open(outDir + 'rankedEdges.csv','w')
outFile.write('Gene1'+'\t'+'Gene2'+'\t'+'EdgeWeight'+'\n')
for idx, row in OutDF.iterrows():
outFile.write('\t'.join([row['TF'],row['target'],str(row['importance'])])+'\n')
outFile.close()