You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
1.2 KiB
R
25 lines
1.2 KiB
R
14 years ago
|
##################################################
|
||
|
################ ProvideSampleId #################
|
||
|
##################################################
|
||
|
ProvideSampleId <- function (fullpathwithfilename) {
|
||
|
### OBS! Only very rudimentary error-checking.
|
||
|
### If the filename is formatted as \w*-\w*-\w*, we use the middle segment,
|
||
|
### otherwise we use the whole string (excluding the extension)
|
||
|
# Extract the name of the parent directory of the datafilename argument
|
||
|
substrateid <- basename(dirname(fullpathwithfilename))
|
||
|
# Extract the name of the method from the filename-part
|
||
|
# First split the filename over all hyphens
|
||
|
nameparts <- strsplit(basename(fullpathwithfilename), "-")[[1]]
|
||
|
# If the number of nameparts exceed 3, save the whole filename as methodid, otherwise use the middle part
|
||
|
if (length(nameparts) > 3) {
|
||
|
# We need to lose the file extension from the last namepart
|
||
|
nameparts[length(nameparts)] <- strsplit(nameparts[length(nameparts)], "\\.")[[1]][1]
|
||
|
methodid <- paste(nameparts, collapse = "-")
|
||
|
} else {
|
||
|
methodid <- nameparts[2]
|
||
|
}
|
||
|
# Make an informative sampleid
|
||
|
sampleid <- paste(substrateid, methodid, sep = "-")
|
||
|
#
|
||
|
return(sampleid)
|
||
|
}
|