-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.onestrand.r
135 lines (106 loc) · 3.27 KB
/
run.onestrand.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/Rscript
options(echo=TRUE)
args <- commandArgs(trailingOnly = TRUE)
print(args)
input.list = args[1]
cred.file = args[2]
#ec2 default settings
price = 3.0
realm = 'us-east-1'
region = paste0(realm,'d')
ami='ami-35dbde5c'
itype='c3.8xlarge'
print('parse credential file')
cf=readLines(cred.file)
cf=cf[-grep('#',cf)]
for(sp in strsplit(cf,':')){
print(sp)
assign(sp[1],sp[2])
}
if(!file.exists(rsa_key)){print('check rsa key is readable')}
keyname=rev(strsplit(rsa_key,'[/.]')[[1]])[2]
print('setting key name to:')
print(keyname)
tmp = paste0(tempfile(),'.rsa')
file.copy(rsa_key,tmp)
Sys.chmod(tmp,mode='600')
rsa_key = tmp
#set up credentials
starcluster.rsa = rsa_key
#mailaddr = '[email protected]' # MAKE SURE THIS EMAIL IS SET UP ON AMAZON SES
key.name = key_name
access.key = access_key
secret.key = secret_key
bucket.name = bucket_name
#'cgs-kmer-model'
system('mkdir /.aws')
system(paste0('printf \"[default]\naws_access_key_id=',access_key,'\naws_secret_access_key=',secret_key,'\" > /.aws/config'))
############
# default parameters (can be overwirtten in .list files
#organism specific
genome='hg19'
#runtime params
maxk=8
k=200
resol=1
#runtime params (used)
read.max=50
smooth.window=1
require('utils')
cov.num = 0
upb = 20
mbsize = 10240000
#probably dont need changing..
branch = 'no91'
# hardcoded directories
gbase = '/genome/'
### load input
input.lines=readLines(input.list)
input.lines=input.lines[nchar(input.lines)>0]
input.options=input.lines[grep('#',input.lines)]
bam.prefix=''
out.prefix=''
postfix=''
epointers = (1:length(input.lines))[-grep('#|//',input.lines)]
ep2 = c(0,epointers)
############
# functions
rsystem <- function(sh,intern=F,wait=T){
system(paste0('ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ',starcluster.rsa,' ubuntu@',INSTANCE_NAME,' ',shQuote(sh)),intern=intern,wait=wait)
}
scptoclus <- function(infile,out,intern=F){
system(paste0('scp -C -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -c arcfour -i ',starcluster.rsa,' ',shQuote(infile),' ubuntu@',INSTANCE_NAME,':',shQuote(out)))
}
scpstring <- function(infile,out,intern=F){
paste0('scp -C -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -c arcfour -i ',starcluster.rsa,' ',shQuote(infile),' ubuntu@',INSTANCE_NAME,':',shQuote(out))
}
scpfromclus <- function(infile,out,intern=F){
system(paste0('scp -C -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -c arcfour -i ',starcluster.rsa,' -r ubuntu@',INSTANCE_NAME,':',shQuote(infile),' ',shQuote(out)))
}
getFilename<-function(x){
rev(strsplit(x,'/')[[1]])[1]
}
############
# script
for( i in 1:length(epointers) ) {
t1=Sys.time()
if(epointers[i] > (ep2[i]+1)){
for(option in (ep2[i]+1):(epointers[i]-1)){
ss=strsplit(input.lines[option],'[# ]')[[1]]
ss=ss[nchar(ss)>0]
print(paste0('set:',ss[1],' to:',ss[2]))
assign(ss[1],ss[2])
}
}
#
input.bams = input.lines[epointers[i]]
rl = strsplit(input.bams,'[,]')[[1]]
exptname = rl[1]
bamlist = rl[-1]
save.image(paste0('state',i,'.RData'))
}
runlist=sapply(1:length(epointers),function(i){
paste0('/kmm/run.cluster.onestrand.r ',i)
})
writeLines(runlist,'/kmm/runlist.txt')
system('cat /kmm/runlist.txt | parallel')