Created
August 2, 2023 13:21
-
-
Save kumeS/eb69bd9900df231a7cc19f6a09ba7488 to your computer and use it in GitHub Desktop.
This function processes the demultiplex stats by removing rows with "Undetermined" SampleID and splitting the Index column into two separate columns.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Demultiplex Stats Processing | |
#' | |
#' This function processes the demultiplex stats by removing rows with "Undetermined" SampleID and splitting the Index column into two separate columns. | |
#' | |
#' @title Process Demultiplex Stats | |
#' @description Removes rows with "Undetermined" SampleID from the input data frame and splits the Index column into two separate columns (index1 and index2). | |
#' @param x1 A data frame containing the demultiplex stats. The data frame should have a "SampleID" column and an "Index" column. | |
#' @importFrom assertthat is.data.frame noNA | |
#' @return A data frame with the processed demultiplex stats, including the split Index column. | |
#' @export Demultiplex_Stats_proc | |
#' @author Satoshi Kume | |
#' @examples | |
#' \dontrun{ | |
#' x1 <- read.csv("./Demultiplex_Stats.csv", header = TRUE, check.names = FALSE)[1:12,] | |
#' result <- Demultiplex_Stats_proc(x1) | |
#' head(result) | |
#' } | |
Demultiplex_Stats_proc <- function(x1){ | |
assertthat::is.data.frame(x1) | |
assertthat::noNA(x1$SampleID) | |
assertthat::noNA(x1$Index) | |
# Demultiplex: Remove rows with "Undetermined" SampleID | |
x1 <- x1[x1$SampleID != "Undetermined",] | |
# Split the Index column into two separate columns | |
cc <- data.frame(matrix(unlist(strsplit(x1$Index, "-")), ncol = 2, byrow = TRUE)) | |
y <- data.frame(x1[,1:2], | |
Index=sub("-", "", x1[,3]), | |
index1=cc[,1], | |
index2=cc[,2], | |
x1[,4:ncol(x1)], | |
check.names = FALSE) | |
return(y) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment