Skip to content

Commit 0f6627f

Browse files
committed
allow csv and tsv for input for QC-workflow
1 parent 4c1da61 commit 0f6627f

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

R/prepareData.R

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#'
33
#' @param data_path \strong{character} \cr
44
#' The path to an .xlsx file containing the input data.
5+
#' @param filetype **character(1)** \cr Type of input file: "csv" or "tsv" or "txt" or "xlsx".
6+
#' @param sep **character(1)** \cr The field separator, e.g. " " for blanks, "," for comma or "\\t" for tab. Default is ",".
7+
#' @param dec **character(1)** \cr Decimal separator, e.g. "," for comma or "." for dot. Default is ".".
8+
#' @param header **logical(1)** \cr If TRUE, first line is counted as column names.
9+
#' @param sheet **integer(1)** \cr Sheet number (only needed for xlsx files, default is to use the first sheet).
510
#' @param intensity_columns \strong{integer vector} \cr
611
#' The numbers of the intensity columns in the table.
712
#' @param na_strings \strong{character} \cr
@@ -28,6 +33,11 @@
2833
#'
2934

3035
prepareData <- function (data_path,
36+
filetype = "xlsx",
37+
sep = ",",
38+
dec = ".",
39+
header = TRUE,
40+
sheet = 1,
3141
intensity_columns,
3242
na_strings = c("NA", "NaN", "Filtered","#NV"),
3343
zero_to_NA = TRUE,
@@ -38,7 +48,24 @@ prepareData <- function (data_path,
3848

3949
#### read and prepare data file ####
4050

41-
D <- openxlsx::read.xlsx(data_path, na.strings = na_strings)
51+
52+
if (filetype == "csv" | filetype == "txt" | filetype == "tsv") {
53+
if (filetype == "csv") {
54+
sep <- ","
55+
} else if (filetype == "tsv") {
56+
sep <- "\t"
57+
}
58+
D <- utils::read.table(data_path,
59+
sep = sep,
60+
header = header,
61+
dec = dec)
62+
}
63+
if (filetype == "xlsx") {
64+
D <- openxlsx::read.xlsx(data_path, colNames = header, sheet = sheet)
65+
}
66+
67+
68+
#D <- openxlsx::read.xlsx(data_path, na.strings = na_strings)
4269
mess = ""
4370

4471
id <- D[, -intensity_columns]

R/workflow_QC.R

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@
1212
#'
1313
#' @param data_path \strong{character} \cr
1414
#' The path to an .xlsx file containing the input data.
15+
#'
16+
#'
17+
#' @param filetype **character(1)** \cr Type of input file: "csv" or "tsv" or "txt" or "xlsx".
18+
#' @param sep **character(1)** \cr The field separator, e.g. " " for blanks, "," for comma or "\\t" for tab. Default is ",".
19+
#' @param dec **character(1)** \cr Decimal separator, e.g. "," for comma or "." for dot. Default is ".".
20+
#' @param header **logical(1)** \cr If TRUE, first line is counted as column names.
21+
#' @param sheet **integer(1)** \cr Sheet number (only needed for xlsx files, default is to use the first sheet).
1522
#' @param output_path \strong{character} \cr
1623
#' The path to the output folder.
24+
#' @param output_type **character(1)** \cr Type of input file: "csv" or "tsv" or "xlsx".
1725
#'
1826
# mandatory parameters
1927
#' @param intensity_columns \strong{integer vector} \cr
@@ -131,7 +139,13 @@
131139

132140

133141
workflow_QC <- function(data_path,
142+
filetype = "xlsx",
143+
sep = ",",
144+
dec = ".",
145+
header = TRUE,
146+
sheet = 1,
134147
output_path,
148+
output_type = "xlsx",
135149

136150
intensity_columns,
137151
normalization_method = "loess",
@@ -180,7 +194,13 @@ workflow_QC <- function(data_path,
180194

181195
#### Prepare Data ####
182196

183-
prepared_data <- prepareData(data_path = data_path, intensity_columns = intensity_columns,
197+
prepared_data <- prepareData(data_path = data_path,
198+
filetype = filetype,
199+
sep = sep,
200+
dec = dec,
201+
header = header,
202+
sheet = sheet,
203+
intensity_columns = intensity_columns,
184204
na_strings = na_strings, zero_to_NA = zero_to_NA,
185205
do_log_transformation = do_log_transformation, log_base = log_base,
186206
use_groups = use_groups, group_colours = group_colours,
@@ -195,9 +215,19 @@ workflow_QC <- function(data_path,
195215
utils::write.csv(x = prepared_data$D, file = paste0(output_path, "/D_norm_wide", suffix, ".csv"), row.names = FALSE)
196216
utils::write.csv(x = prepared_data$D_long, file = paste0(output_path, "/D_norm_long", suffix, ".csv"), row.names = FALSE)
197217

198-
openxlsx::write.xlsx(x = cbind(prepared_data$ID, prepared_data$D), file = paste0(output_path, "/D_norm_ID", suffix, ".xlsx"),
199-
rowNames = FALSE, overwrite = TRUE, keepNA = TRUE)
200218

219+
if (output_type == "xlsx") {
220+
openxlsx::write.xlsx(x = cbind(prepared_data$ID, prepared_data$D), file = paste0(output_path, "/D_norm_ID", suffix, ".xlsx"),
221+
rowNames = FALSE, overwrite = TRUE, keepNA = TRUE)
222+
}
223+
if (output_type == "csv") {
224+
utils::write.csv(x = cbind(prepared_data$ID, prepared_data$D), file = paste0(output_path, "/D_norm_ID", suffix, ".csv"),
225+
row.names = FALSE)
226+
}
227+
if (output_type == "tsv") {
228+
utils::write.table(x = cbind(prepared_data$ID, prepared_data$D), file = paste0(output_path, "/D_norm_ID", suffix, ".tsv"),
229+
row.names = FALSE, sep = "\t")
230+
}
201231

202232

203233
#### Calculate Valid Value Plot ####

man/prepareData.Rd

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/workflow_QC.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)