-
Notifications
You must be signed in to change notification settings - Fork 3
/
this.R
75 lines (66 loc) · 2.28 KB
/
this.R
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
newReadsPerReplicate <- read.table("tmp/nReadsPerCluster.txt")
rs <- rowSums(newReadsPerReplicate)
nJobs <- 1000
if(K < 1000){
nJobs <- 10
}
rs <- rs[-1]
threshold <- sum(rs)/nJobs
i <- 0
groupIndex <- 0
vec2 <- array(0,c(nJobs,2))
j2 <- 0
while((i < nClusters-2)){
j1 <- i + 1
nObs <- 0;
while((nObs < threshold)&(i < nClusters - 1)){
i<-i+1;
nObs <- nObs + rs[i]
#cat(paste("i = ",i,", nObs = ",nObs,sep = ""),"\n")
}
j2 <- i
groupIndex <- groupIndex + 1
vec2[groupIndex,] <- c(j1,j2)
cat(paste("group ",groupIndex,": {",j1,",...,",j2,"}. Nobs = ",nObs,sep = ""),"\n")
cat("\n")
}
if (j2 < nClusters - 1){
j1 <- j2 + 1
j2 <- nClusters - 1
nObs <- sum(rs[j1:j2])
groupIndex <- groupIndex + 1
vec2[groupIndex,] <- c(j1,j2)
cat(paste("group ",groupIndex,": {",j1,",...,",j2,"}. Nobs = ",nObs,sep = ""),"\n")
cat("\n")
}
nJobs <- groupIndex
for (k in 1:nJobs){
vec <- vec2[k,]
job <- file(paste("job_",k,".sh",sep = ""),open = "w")
cat("#!/bin/bash","\n",file = job)
cat("cd tmp","\n",file = job)
cat("echo \"Running Reversible Jump \"","\n",file = job)
cat("cd clusters","\n",file = job)
cat(paste("for i in {",vec[1],"..",vec[2],"}",sep = ""),"\n",file = job)
cat("do","\n",file = job)
cat("echo \" Running RJMCMC at: cluster_$i\"","\n",file = job)
cat("cd cluster_$i","\n",file = job)
cat("echo \" number of transcripts:\"","\n",file = job)
cat("head -1 data.tr","\n",file = job)
cat("rjFULL > rjmcmc.log","\n",file = job)
cat("cd ..","\n",file = job)
cat("done","\n",file = job)
cat("cd ..","\n",file = job)
close(job)
system(paste("chmod u+x job_",k,".sh",sep=""))
}
job <- file(paste("jobArray",".sh",sep = ""),open = "w")
cat("#!/bin/bash","\n",file = job)
cat("#$ -S /bin/bash","\n",file = job)
cat("#$ -V","\n",file = job)
cat("#$ -cwd","\n",file = job)
cat("#$ -pe smp.pe 4","\n",file = job)
cat("export OMP_NUM_THREADS=$NSLOTS","\n",file = job)
cat(paste("#$ -t 1-",nJobs,sep=""),"\n",file = job)
cat("./job_${SGE_TASK_ID}.sh","\n",file = job)
close(job)