-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcreateCSVFileFromModel.R
47 lines (37 loc) · 1.22 KB
/
createCSVFileFromModel.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
library( randomForest )
stopQuietly <- function(...)
{
blankMsg <- sprintf( "\r%s\r", paste( rep(" ", getOption( "width" ) - 1L ), collapse = " ") );
stop( simpleError( blankMsg ) );
} # stopQuietly()
args <- commandArgs( trailingOnly = TRUE )
###############################################
#
# Selected parameters
#
###############################################
if( length( args ) < 2 )
{
cat( "Usage: Rscript createCSVFileFromModel.R inputModel maskImage imagePrefix outputCSVFile", sep = "" )
stopQuietly()
}
inputModelName <- args[1]
maskImage <- args[2]
imagePrefix <- args[3]
outputFile <- args[4]
###############################################
#
# Load model: contained in the variable "modelForest"
#
###############################################
load( inputModelName )
featureNames <- attr( modelForest$terms, "term.labels" )
fileNames <- c();
for( i in 1:length( featureNames ) )
{
fileNames[i] <- paste0( imagePrefix, featureNames[i], ".nii.gz" )
}
featureNames <- append( featureNames, "MASK", after = 0 )
fileNames <- append( fileNames, maskImage, after = 0 )
write.table( rbind( featureNames, fileNames ), file = outputFile,
append = FALSE, col.names = FALSE, row.names = FALSE, sep = ",")