-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_job_file_maker.R
83 lines (56 loc) · 2.73 KB
/
batch_job_file_maker.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
######################################################################################################
### creating an R script for each job - essentially changing the lines which refer to the job name ###
######################################################################################################
files <- list.files(here::here("species_lists/"))
if(!dir.exists(here::here("r_jobs"))){
dir.create(here::here("r_jobs"))
}
for(file in files){
ptc <- readLines(here::here("r_jobs", "job_001.R")) #Read in the template file
job <- gsub(".csv", "", file)
ptc[17] <- gsub("job_001", job, ptc[17])
ptc[46] <- gsub("job_001.csv", file, ptc[46])
file_out <- gsub(".csv", ".R", file)
writeLines(ptc, here::here("r_jobs",file_out)) #Use this as the file name and write it to the output directory
}
################################################################################
### R file to delete files created during job - after it has been tarred up. ###
################################################################################
if(!dir.exists(here::here("delete_jobs"))){
dir.create(here::here("delete_jobs"))
}
for(file in files){
ptc <- readLines(here::here("delete_jobs", "job_001.R")) #Read in the template file
job <- gsub(".csv", "", file)
ptc[1] <- gsub("job_001", job, ptc[1])
ptc[3] <- gsub("job_001.csv", file, ptc[3])
file_out <- gsub(".csv", ".R", file)
writeLines(ptc, here::here("delete_jobs",file_out)) #Use this as the file name and write it to the output directory
}
###########################################
### bash_scripts to submit all the jobs ###
###########################################
if(!dir.exists(here::here("bash_scripts"))){
dir.create(here::here("bash_scripts"))
}
files <- gsub("\\..*","",files)
for(file in files){
ptc <- readLines(here::here("bash_scripts","job_001.sh")) #Read in the template file
ptc[5] <- gsub("job_001", file, ptc[5])
ptc[23] <- gsub("job_001", file, ptc[23])
ptc[24] <- gsub("job_001", file, ptc[24])
ptc[25] <- gsub("job_001", file, ptc[25])
writeLines(ptc, here::here("bash_scripts",paste0(file, ".sh")), sep = "\n") #Use this as the file name and write it to the output directory
}
####################################################
### Changing the EOL formatting from dos to unix ###
### Code to be run in cmd on windows ###
####################################################
unix_convert <- "tr -d '\015' <job_001.sh > ujob_001.sh"
convert_out <- NULL
for (file in files){
ptc <- "tr -d '\015' <job_001.sh > ujob_001.sh"
ptc <- gsub("job_001", file, ptc)
convert_out <- rbind(convert_out, ptc)
}
write.table(convert_out, file = "convert_unix.txt", row.names = FALSE)