-
Notifications
You must be signed in to change notification settings - Fork 11
/
fslr_Generic_fslmaths_Maker.R
153 lines (137 loc) · 5.5 KB
/
fslr_Generic_fslmaths_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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
proper = function(x){
paste0(toupper(substr(x, 1,1)), substr(x, 2, nchar(x)))
}
#############################################
# Function maker that just makes a help file that calls fslmaths.help
#############################################
makehelp = function(opt, remove = TRUE){
x = readLines('fslr_maths_helpfile.R')
x = gsub("%opt%", opt, x)
funcname = paste0("fsl", opt, ".help")
writeLines(text=x, con = paste0("R/", funcname, ".R"))
if (remove) file.remove(paste0("R/", funcname, ".R"))
return(TRUE)
}
#############################################
# Function maker that involves 2 files
#############################################
makefunc2 = function(opt, longname, propername = NULL,
remove = TRUE, makehelp = TRUE){
if (is.null(propername)){
propername = proper(longname)
}
x = readLines('fslr_Generic_fslmaths.R')
x = gsub("%opt%", opt, x)
x = gsub("%propername%", propername, x)
x = gsub("%longname%", longname, x)
funcname = paste0("fsl", opt)
writeLines(text=x, con = paste0("R/", funcname, ".R"))
if (remove) file.remove(paste0("R/", funcname, ".R"))
makehelp(opt, remove = remove)
return(TRUE)
}
#############################################
# Function maker that involves 1 file
#############################################
makefunc = function(opt, longname, propername = NULL,
remove = TRUE, makehelp = TRUE){
if (is.null(propername)){
propername = proper(longname)
}
x = readLines('fslr_Generic_fslmaths_onefile.R')
x = gsub("%opt%", opt, x)
x = gsub("%propername%", propername, x)
x = gsub("%longname%", longname, x)
funcname = paste0("fsl", opt)
writeLines(text=x, con = paste0("R/", funcname, ".R"))
if (remove) file.remove(paste0("R/", funcname, ".R"))
makehelp(opt, remove = remove)
return(TRUE)
}
remove = FALSE
################################################################
# Make Functions that take in 2 files
################################################################
# makefunc("slope", write=TRUE, remove=remove)
makefunc2("div", longname = "be divided", propername = "Divide",
remove = remove)
makefunc2("sub", longname = "be subtracted", propername = "Subtract",
remove = remove)
makefunc2("mul", longname = "be multiplied", propername = "Multiply",
remove = remove)
makefunc2("add", longname = "be added", propername = "Add",
remove = remove)
makefunc2("rem", longname = paste0("divide the current image by ",
"and take remainder"),
propername = "Modulus Remainder of 2",
remove = remove)
################################################################
# Make Functions that take in 1 file
################################################################
makefunc("exp", longname = "exponentiated", propername = "Exponentiate",
remove = remove)
makefunc("log", longname = "log transform",
propername = "Log Transform",
remove = remove)
makefunc("sin", longname = "sine transform",
propername = "Sine Transform",
remove = remove)
makefunc("asin", longname = "arc sine transform",
propername = "Arc Sine Transform",
remove = remove)
makefunc("cos", longname = "cosine transform",
propername = "Cosine Transform",
remove = remove)
makefunc("acos", longname = "arc cosine transform",
propername = "Arc Cosine Transform",
remove = remove)
makefunc("tan", longname = "tangent transform",
propername = "Tangent Transform",
remove = remove)
makefunc("atan", longname = "arc tangent transform",
propername = "Arc Tangent Transform",
remove = remove)
makefunc("sqr", longname = "square",
propername = "Square",
remove = remove)
makefunc("sqrt", longname = "square root",
propername = "Square Root",
remove = remove)
makefunc("recip", longname = "take the reciprocal (1/image)",
propername = "Reciprocal",
remove = remove)
makefunc("abs", longname = "absolute value",
propername = "Absolute Value",
remove = remove)
makefunc("binv", longname = "take the binarized inverse",
propername = "Binarized Inverse",
remove = remove)
makefunc("index", longname = paste0("have non-zero entries ",
"replaced with index"),
propername = "Index",
remove = remove)
makefunc("edge", longname = paste0("estimate edge strength"),
propername = "Edge Strength",
remove = remove)
makefunc("nan", longname = paste0("replace NaNs (improper numbers) ",
"with 0"),
propername = "Replace NaNs in",
remove = remove)
makefunc("nanm", longname = paste0("set to 1 for NaN voxels,",
" 0 otherwise"),
propername = "Mask NaNs in",
remove = remove)
makefunc("rand", longname = paste0("add random uniform noise to"),
propername = "Add Random Uniform Noise",
remove = remove)
makefunc("randn", longname = paste0("add random standard to",
" Gaussian noise"),
propername = "Add Random Standard Guassian Noise",
remove = remove)
makehelp("smooth", remove = remove)
makehelp("mask", remove = remove)
makehelp("erode", remove = remove)
makehelp("fill", remove = remove)
makehelp("sub2", remove = remove)
makehelp("thresh", remove = remove)
makehelp("bin", remove = remove)