#'@author: James Gallant
#'@Description: Function to filter for valid values from a data frame. Options include:
#'              - in each group
#'              - in one group
#'              - in entire dataframe
#'
#'@param userData: The dataframe containing the data with columns to be filtered
#'
#'@param groupData: character vector containing the groups
#'
#'@param filterParameter: How to filter the data, options are onegroup, eachgroup, all. OneGroup will filter for
#'                        valid values in one of x groups, EachGroup will filter for valid values in every group,
#'                        All remove all invalid values, this is the most strict filtering
#'
#'@param minValidValues: Minimum number of values to retain per group, e.g 2 will keep all proteins with two valid values.
#'
#'@returns dataframe
#'
`%notin%` <- Negate(`%in%`)
colnames(userData) <- groupData
filterone <- function(ud, val) {
#'@Description filters for valid values in at least one group
#'
#'@param ud: userdata dataframe from the userData varaible
#'@param val: minimum valid value for filering from minValidValues
#'
#'@returns filtered dataframe
#'
conditions <- as.data.frame(table(unlist(names(ud))))
conditions <- conditions$Var1
cond.filter <- sapply(levels(conditions), function(i) {
temp.data <- ud[, grepl(i, names(ud))]
counts <- rowSums(is.finite(as.matrix(temp.data)))
counts >= user_val
})
ud$keep = apply(cond.filter, 1, any)
ud <- ud[!(ud$keep=="FALSE"),]
ud$keep <- NULL
return(ud)
}
filterall <- function(ud) {
#'@Description filters all NA values from a dataframe
#'
#'@param ud: userdata dataframe from the userData varaible
#'
#'@returns filtered dataframe
ud = do.call(data.frame, lapply(ud, function(dat) replace(dat, is.infinite(dat), NA)))
ud = na.omit(ud)
return(ud)
}
filterParameter_lower <- tolower(filterParameter)
filterOptions <- c("onegroup", "eachgroup", "all")
if (filterParameter_lower %notin% filterOptions) {
stop("filterParameter option not recognised. Options are onegroup, eachgroup, all")
}
switch (filterParameter_lower,
"onegroup" = return(filterone(ud=userData, val=minValidValues)),
"eachgroup" = return("eachgroup"),
"all" = return(filterall(ud=userData)),
)
}
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "onegroup", minValidValues = 1)
filterValidValues <- function(userData, groupData, filterParameter, minValidValues=0) {
#'@author: James Gallant
#'@Description: Function to filter for valid values from a data frame. Options include:
#'              - in each group
#'              - in one group
#'              - in entire dataframe
#'
#'@param userData: The dataframe containing the data with columns to be filtered
#'
#'@param groupData: character vector containing the groups
#'
#'@param filterParameter: How to filter the data, options are onegroup, eachgroup, all. OneGroup will filter for
#'                        valid values in one of x groups, EachGroup will filter for valid values in every group,
#'                        All remove all invalid values, this is the most strict filtering
#'
#'@param minValidValues: Minimum number of values to retain per group, e.g 2 will keep all proteins with two valid values.
#'
#'@returns dataframe
#'
`%notin%` <- Negate(`%in%`)
colnames(userData) <- groupData
filterone <- function(ud, val) {
#'@Description filters for valid values in at least one group
#'
#'@param ud: userdata dataframe from the userData varaible
#'@param val: minimum valid value for filering from minValidValues
#'
#'@returns filtered dataframe
#'
conditions <- as.data.frame(table(unlist(names(ud))))
conditions <- conditions$Var1
cond.filter <- sapply(levels(conditions), function(i) {
temp.data <- ud[, grepl(i, names(ud))]
counts <- rowSums(is.finite(as.matrix(temp.data)))
counts >= val
})
ud$keep = apply(cond.filter, 1, any)
ud <- ud[!(ud$keep=="FALSE"),]
ud$keep <- NULL
return(ud)
}
filterall <- function(ud) {
#'@Description filters all NA values from a dataframe
#'
#'@param ud: userdata dataframe from the userData varaible
#'
#'@returns filtered dataframe
ud = do.call(data.frame, lapply(ud, function(dat) replace(dat, is.infinite(dat), NA)))
ud = na.omit(ud)
return(ud)
}
filterParameter_lower <- tolower(filterParameter)
filterOptions <- c("onegroup", "eachgroup", "all")
if (filterParameter_lower %notin% filterOptions) {
stop("filterParameter option not recognised. Options are onegroup, eachgroup, all")
}
switch (filterParameter_lower,
"onegroup" = return(filterone(ud=userData, val=minValidValues)),
"eachgroup" = return("eachgroup"),
"all" = return(filterall(ud=userData)),
)
}
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "onegroup", minValidValues = 1)
View(out)
View(dummy_userData)
dummy_userData <- data.frame(
# structure of the dataframe, assuming protein id's are rownames
s1.rep1 = rnorm(50),
s1.rep2 = rnorm(50),
s1.rep3 = rnorm(50),
s2.rep1 = rnorm(50),
s2.rep2 = rnorm(50),
s2.rep3 = rnorm(50),
s3.rep1 = rnorm(50),
s3.rep2 = rnorm(50),
s3.rep3 = rnorm(50),
stringsAsFactors = F
)
# keep the groupData sequence the same as the dummyData columns
groupData <- c("s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3" )
dummy_userData[dummy_userData < 0] <- NA
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "onegroup", minValidValues = 1)
View(dummy_userData)
View(out)
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "onegroup", minValidValues = 2)
View(out)
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "onegroup", minValidValues = 3)
View(out)
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "all")
View(out)
filterValidValues <- function(userData, groupData, filterParameter, minValidValues=0) {
#'@author: James Gallant
#'@Description: Function to filter for valid values from a data frame. Options include:
#'              - in each group
#'              - in one group
#'              - in entire dataframe
#'
#'@param userData: The dataframe containing the data with columns to be filtered
#'
#'@param groupData: character vector containing the groups
#'
#'@param filterParameter: How to filter the data, options are onegroup, eachgroup, all. OneGroup will filter for
#'                        valid values in one of x groups, EachGroup will filter for valid values in every group,
#'                        All remove all invalid values, this is the most strict filtering
#'
#'@param minValidValues: Minimum number of values to retain per group, e.g 2 will keep all proteins with two valid values.
#'
#'@returns dataframe
#'
`%notin%` <- Negate(`%in%`)
colnames(userData) <- groupData
filterone <- function(ud, val) {
#'@Description filters for valid values in at least one group
#'
#'@param ud: userdata dataframe from the userData varaible
#'@param val: minimum valid value for filering from minValidValues
#'
#'@returns filtered dataframe
#'
conditions <- as.data.frame(table(unlist(names(ud))))
conditions <- conditions$Var1
cond.filter <- sapply(levels(conditions), function(i) {
temp.data <- ud[, grepl(i, names(ud))]
counts <- rowSums(is.finite(as.matrix(temp.data)))
counts >= val
})
ud$keep = apply(cond.filter, 1, any)
ud <- ud[!(ud$keep=="FALSE"),]
ud$keep <- NULL
return(ud)
}
filterall <- function(ud=userData, gd=groupData) {
#'@Description filters all NA values from a dataframe
#'
#'@param ud: userdata dataframe from the userData varaible
#'
#'@returns filtered dataframe
ud = do.call(data.frame, lapply(ud, function(dat) replace(dat, is.infinite(dat), NA)))
ud = na.omit(ud)
colnames(ud) <- gd
return(ud)
}
filterParameter_lower <- tolower(filterParameter)
filterOptions <- c("onegroup", "eachgroup", "all")
if (filterParameter_lower %notin% filterOptions) {
stop("filterParameter option not recognised. Options are onegroup, eachgroup, all")
}
switch (filterParameter_lower,
"onegroup" = return(filterone(ud=userData, val=minValidValues)),
"eachgroup" = return("eachgroup"),
"all" = return(filterall()),
)
}
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "all")
View(out)
filterValidValues <- function(userData, groupData, filterParameter, minValidValues=0) {
#'@author: James Gallant
#'@Description: Function to filter for valid values from a data frame. Options include:
#'              - in each group
#'              - in one group
#'              - in entire dataframe
#'
#'@param userData: The dataframe containing the data with columns to be filtered
#'
#'@param groupData: character vector containing the groups
#'
#'@param filterParameter: How to filter the data, options are onegroup, eachgroup, all. OneGroup will filter for
#'                        valid values in one of x groups, EachGroup will filter for valid values in every group,
#'                        All remove all invalid values, this is the most strict filtering
#'
#'@param minValidValues: Minimum number of values to retain per group, e.g 2 will keep all proteins with two valid values.
#'
#'@returns dataframe
#'
`%notin%` <- Negate(`%in%`)
filterParameter_lower <- tolower(filterParameter)
filterOptions <- c("onegroup", "eachgroup", "all")
if (filterParameter_lower %notin% filterOptions) {
stop("filterParameter option not recognised. Options are onegroup, eachgroup, all")
}
colnames(userData) <- groupData
filtersome <- function(ud=userData, val=minValidValues, filterparam) {
#'@Description filters for valid values in at least one group or in all groups based on filterParameter
#'
#'@param ud: userdata dataframe from the userData varaible
#'@param val: minimum valid value for filering from minValidValues
#'@param filterparam: filterparameter as set by filterParameter variable, accepts onegroup or eachgroup
#'
#'@returns filtered dataframe
#'
if (filterparam == "all") {
stop("AssertionError: filterparameter passed as all, valid options are onegroup or eachgroup")
}
conditions <- as.data.frame(table(unlist(names(ud))))
conditions <- conditions$Var1
cond.filter <- sapply(levels(conditions), function(i) {
temp.data <- ud[, grepl(i, names(ud))]
counts <- rowSums(is.finite(as.matrix(temp.data)))
counts >= val
})
if (filterparam == "onegroup") {
ud$keep = apply(cond.filter, 1, any)
} else {
ud$keep = apply(cond.filter, 1, all)
}
ud <- ud[!(ud$keep=="FALSE"),]
ud$keep <- NULL
return(ud)
}
filterall <- function(ud=userData, gd=groupData) {
#'@Description filters all NA values from a dataframe
#'
#'@param ud: userdata dataframe from the userData varaible
#'
#'@returns filtered dataframe
ud = do.call(data.frame, lapply(ud, function(dat) replace(dat, is.infinite(dat), NA)))
ud = na.omit(ud)
colnames(ud) <- gd
return(ud)
}
switch (filterParameter_lower,
"onegroup" = return(filtersome()),
"eachgroup" = return(filtersome()),
"all" = return(filterall()),
)
}
dummy_userData <- data.frame(
# structure of the dataframe, assuming protein id's are rownames
s1.rep1 = rnorm(50),
s1.rep2 = rnorm(50),
s1.rep3 = rnorm(50),
s2.rep1 = rnorm(50),
s2.rep2 = rnorm(50),
s2.rep3 = rnorm(50),
s3.rep1 = rnorm(50),
s3.rep2 = rnorm(50),
s3.rep3 = rnorm(50),
stringsAsFactors = F
)
# keep the groupData sequence the same as the dummyData columns
groupData <- c("s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3" )
dummy_userData[dummy_userData < 0] <- NA
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "eachgroup", minValidValues = 2)
filterValidValues <- function(userData, groupData, filterParameter, minValidValues=0) {
#'@author: James Gallant
#'@Description: Function to filter for valid values from a data frame. Options include:
#'              - in each group
#'              - in one group
#'              - in entire dataframe
#'
#'@param userData: The dataframe containing the data with columns to be filtered
#'
#'@param groupData: character vector containing the groups
#'
#'@param filterParameter: How to filter the data, options are onegroup, eachgroup, all. OneGroup will filter for
#'                        valid values in one of x groups, EachGroup will filter for valid values in every group,
#'                        All remove all invalid values, this is the most strict filtering
#'
#'@param minValidValues: Minimum number of values to retain per group, e.g 2 will keep all proteins with two valid values.
#'
#'@returns dataframe
#'
`%notin%` <- Negate(`%in%`)
filterParameter_lower <- tolower(filterParameter)
filterOptions <- c("onegroup", "eachgroup", "all")
if (filterParameter_lower %notin% filterOptions) {
stop("filterParameter option not recognised. Options are onegroup, eachgroup, all")
}
colnames(userData) <- groupData
filtersome <- function(ud=userData, val=minValidValues, filterparam=filterParameter) {
#'@Description filters for valid values in at least one group or in all groups based on filterParameter
#'
#'@param ud: userdata dataframe from the userData varaible
#'@param val: minimum valid value for filering from minValidValues
#'@param filterparam: filterparameter as set by filterParameter variable, accepts onegroup or eachgroup
#'
#'@returns filtered dataframe
#'
if (filterparam == "all") {
stop("AssertionError: filterparameter passed as all, valid options are onegroup or eachgroup")
}
conditions <- as.data.frame(table(unlist(names(ud))))
conditions <- conditions$Var1
cond.filter <- sapply(levels(conditions), function(i) {
temp.data <- ud[, grepl(i, names(ud))]
counts <- rowSums(is.finite(as.matrix(temp.data)))
counts >= val
})
if (filterparam == "onegroup") {
ud$keep = apply(cond.filter, 1, any)
} else {
ud$keep = apply(cond.filter, 1, all)
}
ud <- ud[!(ud$keep=="FALSE"),]
ud$keep <- NULL
return(ud)
}
filterall <- function(ud=userData, gd=groupData) {
#'@Description filters all NA values from a dataframe
#'
#'@param ud: userdata dataframe from the userData varaible
#'
#'@returns filtered dataframe
ud = do.call(data.frame, lapply(ud, function(dat) replace(dat, is.infinite(dat), NA)))
ud = na.omit(ud)
colnames(ud) <- gd
return(ud)
}
switch (filterParameter_lower,
"onegroup" = return(filtersome()),
"eachgroup" = return(filtersome()),
"all" = return(filterall()),
)
}
dummy_userData <- data.frame(
# structure of the dataframe, assuming protein id's are rownames
s1.rep1 = rnorm(50),
s1.rep2 = rnorm(50),
s1.rep3 = rnorm(50),
s2.rep1 = rnorm(50),
s2.rep2 = rnorm(50),
s2.rep3 = rnorm(50),
s3.rep1 = rnorm(50),
s3.rep2 = rnorm(50),
s3.rep3 = rnorm(50),
stringsAsFactors = F
)
# keep the groupData sequence the same as the dummyData columns
groupData <- c("s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3" )
dummy_userData[dummy_userData < 0] <- NA
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "eachgroup", minValidValues = 2)
View(out)
out <- filterValidValues(userData = dummy_userData, groupData = groupData, filterParameter = "onegroup", minValidValues = 2)
View(out)
dummy_userData <- data.frame(
# structure of the dataframe, assuming protein id's are rownames
s1.rep1 = rnorm(50),
s1.rep2 = rnorm(50),
s1.rep3 = rnorm(50),
s2.rep1 = rnorm(50),
s2.rep2 = rnorm(50),
s2.rep3 = rnorm(50),
s3.rep1 = rnorm(50),
s3.rep2 = rnorm(50),
s3.rep3 = rnorm(50),
stringsAsFactors = F
)
# keep the groupData sequence the same as the dummyData columns
groupData <- c("s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3" )
dummy_userData[dummy_userData < 0] <- NA
filterValidValues <- function(userData, groupData, filterParameter, minValidValues=0) {
#'@author: James Gallant
#'@Description: Function to filter for valid values from a data frame. Options include:
#'              - in each group
#'              - in one group
#'              - in entire dataframe
#'
#'@param userData: The dataframe containing the data with columns to be filtered
#'
#'@param groupData: character vector containing the groups
#'
#'@param filterParameter: How to filter the data, options are onegroup, eachgroup, all. OneGroup will filter for
#'                        valid values in one of x groups, EachGroup will filter for valid values in every group,
#'                        All remove all invalid values, this is the most strict filtering
#'
#'@param minValidValues: Minimum number of values to retain per group, e.g 2 will keep all proteins with two valid values.
#'
#'@returns dataframe
#'
`%notin%` <- Negate(`%in%`)
filterParameter_lower <- tolower(filterParameter)
filterOptions <- c("onegroup", "eachgroup", "all")
if (filterParameter_lower %notin% filterOptions) {
stop("filterParameter option not recognised. Options are onegroup, eachgroup, all")
}
colnames(userData) <- groupData
filtersome <- function(ud=userData, val=minValidValues, filterparam=filterParameter) {
#'@Description filters for valid values in at least one group or in all groups based on filterParameter
#'
#'@param ud: userdata dataframe from the userData varaible
#'@param val: minimum valid value for filering from minValidValues
#'@param filterparam: filterparameter as set by filterParameter variable, accepts onegroup or eachgroup
#'
#'@returns filtered dataframe
#'
if (filterparam == "all") {
stop("AssertionError: filterparameter passed as all, valid options are onegroup or eachgroup")
}
conditions <- as.data.frame(table(unlist(names(ud))))
conditions <- conditions$Var1
cond.filter <- sapply(levels(conditions), function(i) {
temp.data <- ud[, grepl(i, names(ud))]
counts <- rowSums(is.finite(as.matrix(temp.data)))
counts >= val
})
if (filterparam == "onegroup") {
ud$keep = apply(cond.filter, 1, any)
} else {
ud$keep = apply(cond.filter, 1, all)
}
ud <- ud[!(ud$keep=="FALSE"),]
ud$keep <- NULL
return(ud)
}
filterall <- function(ud=userData, gd=groupData) {
#'@Description filters all NA values from a dataframe
#'
#'@param ud: userdata dataframe from the userData varaible
#'
#'@returns filtered dataframe
ud = do.call(data.frame, lapply(ud, function(dat) replace(dat, is.infinite(dat), NA)))
ud = na.omit(ud)
colnames(ud) <- gd
return(ud)
}
switch (filterParameter_lower,
"onegroup" = return(filtersome()),
"eachgroup" = return(filtersome()),
"all" = return(filterall()),
)
}
# voorbeelde
filtered.all <- filterValidValues(userData = dummy_userData,
groupData = groupData,
filterParameter = "all")
filtered.eachGroup <- filterValidValues(userData = dummy_userData,
groupData = groupData,
filterParameter = "eachgroup",
minValidValues = 2)
filtered.onegroup <- filterValidValues(userData = dummy_userData,
groupData = groupData,
filterParameter = "onegroup",
minValidValues = 2)
setwd("D:/Eigenaara/Documents/dev/ProVision")
shiny::runApp()
runApp()
<body>
<div class = "welcometab">
<div id ="downDiv">
<a href="../data/proteinGroups.txt" download="proteinGroupsTutorial">
Get tutorial data here </a>
</div>
<div id ="downdiv">
<img src="../media/title2.svg" style="width:88vw; height:88vh;">
</div>
</div>
</body>
</html>
runApp()
runApp()
