-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_gamma_test_sge_files.py
110 lines (90 loc) · 5.22 KB
/
make_gamma_test_sge_files.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue May 30 11:36:41 2017
@author: lpsmith
"""
from __future__ import division
from os import walk
from os import path
from os import mkdir
from shutil import copytree
gamma_dir = "gamma_template/"
gamma_out = "gamma_test/"
if not(path.isdir(gamma_out)):
mkdir(gamma_out)
allfile = open(gamma_out + "run_all.bat", "w")
makelinks = open(gamma_out + "make_links.bat", "w")
onlysomepatients = True
eightplus = False
somepatients = ["141", "954", "163", "512"]
#somepatients = ["194"]
#somepatients = ["42", "43", "55", "59", "74"]
#somepatients = ["1005", "222", "391", "422", "43", "551", "575", "59", "611", "619", "639", "672", "686", "728", "88", "915", "954"]
infiles = []
patients = []
for (_, _, f) in walk(gamma_dir):
infiles += f
for file in infiles:
if file.find("_logR.txt") != -1:
patients.append(file.split("_")[0])
#for gamma in [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 2000, 2500, 3000]:
#for patient in firstpatients:
#for gamma in [3000, 1000, 400, 250, 100]:
#for gamma in [1000, 400, 250, 100, 2000, 200, 600, 800, 150, 300, 350, 450, 500, 700, 900, 1200, 1400, 1600, 2500]:
for gamma in [450, 400, 350, 300, 250, 550, 600, 650, 1100, 1200, 1300, 1400, 1500, 1750, 2000, 2500, 200, 150, 100, 50]:
pASCAT_dir = "pASCAT_input_g" + str(gamma) + "/"
if not(path.isdir(gamma_out + pASCAT_dir)):
mkdir(gamma_out + pASCAT_dir)
# copytree(gamma_dir, gamma_out + pASCAT_dir)
if not(path.isdir(gamma_out + pASCAT_dir + "diploid/")):
mkdir(gamma_out + pASCAT_dir + "diploid/")
if not(path.isdir(gamma_out + pASCAT_dir + "tetraploid/")):
mkdir(gamma_out + pASCAT_dir + "tetraploid/")
if eightplus:
if not(path.isdir(gamma_out + pASCAT_dir + "eight/")):
mkdir(gamma_out + pASCAT_dir + "eight/")
if not(path.isdir(gamma_out + pASCAT_dir + "eight_high/")):
mkdir(gamma_out + pASCAT_dir + "eight_high/")
if not(path.isdir(gamma_out + pASCAT_dir + "Rout/")):
mkdir(gamma_out + pASCAT_dir + "Rout/")
makelinks.write("cd " + pASCAT_dir + "\n")
makelinks.write("cp ../../" + gamma_dir + "*.R .\n")
for patient in patients:
if onlysomepatients and patient not in somepatients:
continue
# for patient in patients: #["266", "303", "360"]:
outfname = "run_" + patient + "_g" + str(gamma) + ".sge"
outfile = open(gamma_out + pASCAT_dir + outfname, "w")
outfile.write("module load modules modules-init modules-gs gcc/latest R/latest java_jdk/latest\n")
outfile.write("cd R/" + gamma_out + pASCAT_dir + ";\n")
outfile.write("R CMD BATCH '--no-save --no-restore --args " + patient + " " + str(gamma) + "' segment.R Rout/" + patient + "_segout.txt;\n")
#outfile.write("R CMD BATCH '--no-save --no-restore --args " + patient + " 0' ascat_on_segments.R Rout/" + patient + "_uncon_out.txt;\n")
#outfile.write("mv " + patient + "*raw* "+ patient + "_failed_arrays.txt " + patient + "_fcn_*txt" + " unconstrained;\n")
if not eightplus:
outfile.write("R CMD BATCH '--no-save --no-restore --args " + patient + " 2' ascat_on_segments.R Rout/" + patient + "_dip_out.txt;\n")
outfile.write("mv " + patient + "*raw* "+ patient + "_failed_arrays.txt " + patient + "_fcn_*" + " diploid;\n")
outfile.write("rm diploid/*" + patient + "_*.RData\n")
outfile.write("R CMD BATCH '--no-save --no-restore --args " + patient + " 4' ascat_on_segments.R Rout/" + patient + "_tet_out.txt;\n")
outfile.write("mv " + patient + "*raw* "+ patient + "_failed_arrays.txt " + patient + "_fcn_*" + " tetraploid;\n")
outfile.write("rm tetraploid/*" + patient + "_*.RData\n")
outfile.write("rm *" + patient + "_*.RData\n")
else:
outfile.write("R CMD BATCH '--no-save --no-restore --args " + patient + " 8' ascat_on_segments.R Rout/" + patient + "_eight_out.txt;\n")
outfile.write("mv " + patient + "*raw* "+ patient + "_failed_arrays.txt " + patient + "_fcn_*" + " eight;\n")
outfile.write("rm eight/*" + patient + "_*.RData\n")
outfile.write("R CMD BATCH '--no-save --no-restore --args " + patient + " 8plus' ascat_on_segments.R Rout/" + patient + "_eight_high_out.txt;\n")
outfile.write("mv " + patient + "*raw* "+ patient + "_failed_arrays.txt " + patient + "_fcn_*" + " eight_high;\n")
outfile.write("rm eight_high/*" + patient + "_*.RData\n")
outfile.close()
allfile.write("qsub -l mfree=6G -l h_rt=24:0:0 pASCAT_input_g" + str(gamma) + "/run_" + patient + "_g" + str(gamma) + ".sge\n")
makelinks.write("ln -s ../../" + gamma_dir + patient + "_BAF.txt " + patient + "_BAF.txt\n")
makelinks.write("ln -s ../../" + gamma_dir + patient + "_Normal_BAF.txt " + patient + "_Normal_BAF.txt\n")
makelinks.write("ln -s ../../" + gamma_dir + patient + "_logR.txt " + patient + "_logR.txt\n")
# makelinks.write("mkdir Rout\n")
# makelinks.write("mkdir unconstrained\n")
# makelinks.write("mkdir diploid\n")
# makelinks.write("mkdir tetraploid\n")
makelinks.write("cd ..\n")
allfile.close()
makelinks.close()