Previous changeset 5:e424fa636281 (2024-05-20) Next changeset 7:1a2aeb8137bf (2024-06-06) |
Commit message:
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28 |
modified:
waveica_wrapper.R |
b |
diff -r e424fa636281 -r 071a424241ec waveica_wrapper.R --- a/waveica_wrapper.R Mon May 20 09:20:13 2024 +0000 +++ b/waveica_wrapper.R Thu May 30 14:54:02 2024 +0000 |
[ |
b'@@ -1,32 +1,32 @@\n read_file <- function(file, metadata, ft_ext, mt_ext, transpose) {\n- data <- read_data(file, ft_ext)\n+ data <- read_data(file, ft_ext)\n \n- if (transpose) {\n- col_names <- c("sampleName", data[[1]])\n- t_data <- data[-1]\n- t_data <- t(t_data)\n- data <- data.frame(rownames(t_data), t_data)\n- colnames(data) <- col_names\n- }\n+ if (transpose) {\n+ col_names <- c("sampleName", data[[1]])\n+ t_data <- data[-1]\n+ t_data <- t(t_data)\n+ data <- data.frame(rownames(t_data), t_data)\n+ colnames(data) <- col_names\n+ }\n \n- if (!is.na(metadata)) {\n- mt_data <- read_data(metadata, mt_ext)\n- data <- merge(mt_data, data, by = "sampleName")\n- }\n+ if (!is.na(metadata)) {\n+ mt_data <- read_data(metadata, mt_ext)\n+ data <- merge(mt_data, data, by = "sampleName")\n+ }\n \n- return(data)\n+ return(data)\n }\n \n read_data <- function(file, ext) {\n- if (ext == "csv") {\n- data <- read.csv(file, header = TRUE)\n- } else if (ext == "tsv") {\n- data <- read.csv(file, header = TRUE, sep = "\\t")\n- } else {\n- data <- arrow::read_parquet(file)\n- }\n+ if (ext == "csv") {\n+ data <- read.csv(file, header = TRUE)\n+ } else if (ext == "tsv") {\n+ data <- read.csv(file, header = TRUE, sep = "\\t")\n+ } else {\n+ data <- arrow::read_parquet(file)\n+ }\n \n- return(data)\n+ return(data)\n }\n \n waveica <- function(file,\n@@ -40,48 +40,48 @@\n t2,\n alpha,\n exclude_blanks) {\n- # get input from the Galaxy, preprocess data\n- ext <- strsplit(x = ext, split = "\\\\,")[[1]]\n+ # get input from the Galaxy, preprocess data\n+ ext <- strsplit(x = ext, split = "\\\\,")[[1]]\n \n- ft_ext <- ext[1]\n- mt_ext <- ext[2]\n+ ft_ext <- ext[1]\n+ mt_ext <- ext[2]\n \n- data <- read_file(file, metadata, ft_ext, mt_ext, transpose)\n+ data <- read_file(file, metadata, ft_ext, mt_ext, transpose)\n \n- required_columns <- c(\n- "sampleName", "class", "sampleType",\n- "injectionOrder", "batch"\n- )\n- data <- verify_input_dataframe(data, required_columns)\n+ required_columns <- c(\n+ "sampleName", "class", "sampleType",\n+ "injectionOrder", "batch"\n+ )\n+ data <- verify_input_dataframe(data, required_columns)\n \n- data <- sort_by_injection_order(data)\n+ data <- sort_by_injection_order(data)\n \n- # separate data into features, batch and group\n- feature_columns <- colnames(data)[!colnames(data) %in% required_columns]\n- features <- data[, feature_columns]\n- group <- enumerate_groups(as.character(data$sampleType))\n- batch <- data$batch\n+ # separate data into features, batch and group\n+ feature_columns <- colnames(data)[!colnames(data) %in% required_columns]\n+ features <- data[, feature_columns]\n+ group <- enumerate_groups(as.character(data$sampleType))\n+ batch <- data$batch\n \n- # run WaveICA\n- features <- recetox.waveica::waveica(\n- data = features,\n- wf = get_wf(wavelet_filter, wavelet_length),\n- batch = batch,\n- group = group,\n- K = k,\n- t = t,\n- t2 = t2,\n- alpha = alpha\n- )\n+ # run WaveICA\n+ features <- recetox.waveica::waveica(\n+ data = features,\n+ wf = get_wf(wavelet_filter, wavelet_length),\n+ batch = batch,\n+ group = group,\n+ K = k,\n+ t = t,\n+ t2 = t2,\n+ alpha = alpha\n+ )\n \n- data[, feature_columns] <- features\n+ data[, feature_columns] <- features\n \n- # remove blanks from dataset\n- if (exclude_blanks) {\n- data <- exclude_group(data, group)\n- }\n+ # remove blanks from dataset\n+ if (exclude_blanks) {\n+ data <- exclude_group(data, group)\n+ }\n \n- return(data)\n+ return(data)\n }\n \n waveica_singlebatch <- function(file,\n@@ -94,150 +94,150 @@\n alpha,\n cutoff,\n exclude_blanks) {\n- # get input from the Galaxy, preprocess data\n- ext <- strspl'..b' types\n- column_types <- list(\n- "sampleName" = c("character", "factor"),\n- "class" = c("character", "factor", "integer"),\n- "sampleType" = c("character", "factor"),\n- "injectionOrder" = "integer",\n- "batch" = "integer"\n- )\n+ # Specify the column names and their expected types\n+ column_types <- list(\n+ "sampleName" = c("character", "factor"),\n+ "class" = c("character", "factor", "integer"),\n+ "sampleType" = c("character", "factor"),\n+ "injectionOrder" = "integer",\n+ "batch" = "integer"\n+ )\n \n- column_types <- column_types[required_columns]\n+ column_types <- column_types[required_columns]\n \n- for (col_name in names(data)) {\n- actual_type <- class(data[[col_name]])\n- if (col_name %in% names(column_types)) {\n- expected_types <- column_types[[col_name]]\n+ for (col_name in names(data)) {\n+ actual_type <- class(data[[col_name]])\n+ if (col_name %in% names(column_types)) {\n+ expected_types <- column_types[[col_name]]\n \n- if (!actual_type %in% expected_types) {\n- stop(\n- "Column ", col_name, " is of type ", actual_type,\n- " but expected type is ",\n- paste(expected_types, collapse = " or "), "\\n"\n- )\n- }\n- } else {\n- if (actual_type != "numeric") {\n- data[[col_name]] <- as.numeric(as.character(data[[col_name]]))\n- }\n+ if (!actual_type %in% expected_types) {\n+ stop(\n+ "Column ", col_name, " is of type ", actual_type,\n+ " but expected type is ",\n+ paste(expected_types, collapse = " or "), "\\n"\n+ )\n+ }\n+ } else {\n+ if (actual_type != "numeric") {\n+ data[[col_name]] <- as.numeric(as.character(data[[col_name]]))\n+ }\n+ }\n }\n- }\n- return(data)\n+ return(data)\n }\n \n \n # Match group labels with [blank/sample/qc] and enumerate them\n enumerate_groups <- function(group) {\n- group[grepl("blank", tolower(group))] <- 0\n- group[grepl("sample", tolower(group))] <- 1\n- group[grepl("qc", tolower(group))] <- 2\n+ group[grepl("blank", tolower(group))] <- 0\n+ group[grepl("sample", tolower(group))] <- 1\n+ group[grepl("qc", tolower(group))] <- 2\n \n- return(group)\n+ return(group)\n }\n \n \n # Create appropriate input for R wavelets function\n get_wf <- function(wavelet_filter, wavelet_length) {\n- wf <- paste(wavelet_filter, wavelet_length, sep = "")\n+ wf <- paste(wavelet_filter, wavelet_length, sep = "")\n \n- # exception to the wavelet function\n- if (wf == "d2") {\n- wf <- "haar"\n- }\n+ # exception to the wavelet function\n+ if (wf == "d2") {\n+ wf <- "haar"\n+ }\n \n- return(wf)\n+ return(wf)\n }\n \n \n # Exclude blanks from a dataframe\n exclude_group <- function(data, group) {\n- row_idx_to_exclude <- which(group %in% 0)\n- if (length(row_idx_to_exclude) > 0) {\n- data_without_blanks <- data[-c(row_idx_to_exclude), ]\n- cat("Blank samples have been excluded from the dataframe.\\n")\n- return(data_without_blanks)\n- } else {\n- return(data)\n- }\n+ row_idx_to_exclude <- which(group %in% 0)\n+ if (length(row_idx_to_exclude) > 0) {\n+ data_without_blanks <- data[-c(row_idx_to_exclude), ]\n+ cat("Blank samples have been excluded from the dataframe.\\n")\n+ return(data_without_blanks)\n+ } else {\n+ return(data)\n+ }\n }\n \n store_data <- function(data, output, ext) {\n- if (ext == "parquet") {\n- arrow::write_parquet(data, output)\n- } else {\n- write.table(data,\n- file = output, sep = "\\t",\n- row.names = FALSE, quote = FALSE\n- )\n- }\n- cat("Normalization has been completed.\\n")\n+ if (ext == "parquet") {\n+ arrow::write_parquet(data, output)\n+ } else {\n+ write.table(data,\n+ file = output, sep = "\\t",\n+ row.names = FALSE, quote = FALSE\n+ )\n+ }\n+ cat("Normalization has been completed.\\n")\n }\n' |