-
Notifications
You must be signed in to change notification settings - Fork 0
/
submitGTEx2eCAVIAR.py
71 lines (65 loc) · 2.5 KB
/
submitGTEx2eCAVIAR.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
64
65
66
67
68
69
70
71
import os
import glob
import time
import random
import sys, traceback
import subprocess
from myconfig import *
from subprocess import Popen, PIPE
def maxSubmitReached(max):
p1 = Popen(["qstat", "-u", "fhormoz"], stdout=PIPE)
p2 = Popen(["wc", "-l"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]
if(int(output) < max) :
return False;
else:
return True;
TEMPLATE_SERIAL = """
#####################################
#$ -S /bin/bash
#$ -cwd
#$ -N {name}
#$ -e {errfile}
#$ -o {logfile}
#$ -pe make {slots}
#$ -l h_data=2G
#$ -l h_rt=12:00:00
#####################################
echo "------------------------------------------------------------------------"
echo "Job started on" `date`
echo "------------------------------------------------------------------------"
module load python
{script}
echo "------------------------------------------------------------------------"
echo "Job ended on" `date`
echo "------------------------------------------------------------------------"
"""
tissueNames = glob.glob(gtexPath + "GTEx_Analysis_2015-01-12_MatrixEQTL_allCisSNPGenePairs/*.eqtl");
tissueNames = [tissueName.replace(gtexPath+"GTEx_Analysis_2015-01-12_MatrixEQTL_allCisSNPGenePairs/", '').replace('_Analysis.cis.eqtl','') for tissueName in tissueNames];
print tissueNames;
outputPath = os.getcwd();
logFolder = "/tmp/log/"
print outputPath;
for tissueName in tissueNames:
#make the bash file to submit
print tissueName;
scriptfile = outputPath + "/" + logFolder + "/command_line_" + tissueName;
logfile = outputPath + "/" + logFolder + "/command_line_" + tissueName + ".log";
errfile = outputPath + "/" + logFolder + "/command_line_" + tissueName + ".err";
if not os.path.exists(outputPath + "/tmp") :
os.makedirs(outputPath + "/tmp");
if not os.path.exists(outputPath + "/tmp/peak/") :
os.makedirs(outputPath + "/tmp/peak/");
if not os.path.exists(outputPath + "/tmp/in/") :
os.makedirs(outputPath + "/tmp/in/");
if not os.path.exists(outputPath + "/" + logFolder) :
os.makedirs(outputPath + "/" + logFolder);
script = "python " + outputPath+ "/peakFinder.py -n " + gwasName + \
" -g " + gtexPath + \
" -f " + gwasFile + \
" -s " + sigFile + \
" -o " + outputPath + "/tmp/" + \
" -t " + tissueName;
print script;
open(scriptfile+'.qsub', 'wb').write(TEMPLATE_SERIAL.format(script=script, name="GTEx2eCAVIAR", logfile=logfile, errfile=errfile, slots=1))
subprocess.call('qsub -cwd -l h_rt=12:00:00,h_data=2G ' + scriptfile + '.qsub', shell=True)