diff --git a/FUNCTIONS.R b/FUNCTIONS.R index 906d6a68efdddf329d90d469455eb77286f9e6ad..31371cb023d2477cdf032a6e7962a7f2e5eff203 100644 --- a/FUNCTIONS.R +++ b/FUNCTIONS.R @@ -61,21 +61,33 @@ runRelativeAntibodyUnits = function(fname1, fname2, MFI_CSV, MFI_N_ANTIGENS, TEM if(MFI_CSV){ # Updated reading - L <- data.frame(read.csv(fname1, - header=T, - stringsAsFactors=FALSE, - colClasses=c(rep("character",3+as.integer(MFI_N_ANTIGENS))), - na.string=c(""))) + L_full <- data.frame(read.csv(fname1, + header=T, + stringsAsFactors=FALSE, + colClasses=c(rep("character",3+as.integer(MFI_N_ANTIGENS))), + na.string=c(""))) - # Identify first row - ROW_N = match("Location", L[,1]) + # Identify rows + median_row_number <- which(L_full[,2] == "Median") + count_row_number <- which(L_full[,2] == "Count") + endcount_row_number <- which(L_full[,2] == "Avg Net MFI") # Select data - L = L[ROW_N:(ROW_N+96),1:(3+as.integer(MFI_N_ANTIGENS))] + L = L_full[(median_row_number+1):nrow(L_full),1:(3+as.integer(MFI_N_ANTIGENS))] # the first row will be the header colnames(L) = L[1, ] # removing the first row. L = L[-1, ] + + ## Find all blank rows (i.e. rows that are all NA). + ## Then keep rows preceding the first blank row. + blank.row.number <- which(rowSums(is.na(L)) == length(names(L)))[1] + if(is.na(blank.row.number)){ + L = L + }else{ + L <- L[1:(blank.row.number-1),] + } + ## Exclude column that corresponds to "Total events" L <- L[, !(colnames(L) %in% c("Total Events","TotalEvents"))] @@ -92,16 +104,7 @@ runRelativeAntibodyUnits = function(fname1, fname2, MFI_CSV, MFI_N_ANTIGENS, TEM L[,-which(colnames(L) %in% c("Location","Sample","Total Events","TotalEvents"))] = lapply(L[,-which(colnames(L) %in% c("Location","Sample","Total Events"))], as.numeric) ## Load the counts to check for run quality control - C <- data.frame(read.csv(fname1, - header=T, - stringsAsFactors=FALSE, - colClasses=c(rep("character",3+as.integer(MFI_N_ANTIGENS))), - na.string=c(""))) - - # Row - ROW_C = 239 - # Select data - C = C[ROW_C:(ROW_C+nrow(L)),1:(3+as.integer(MFI_N_ANTIGENS))] + C = L_full[(count_row_number+1):(count_row_number+1+nrow(L)),1:(3+as.integer(MFI_N_ANTIGENS))] # the first row will be the header colnames(C) = C[1, ] # removing the first row.