Skip to content

Commit

Permalink
Updated multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
salsalsal97 committed Dec 27, 2024
1 parent 4e9c315 commit 464009e
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 74 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(DGE_analysis)
export(correlation_analysis)
export(power_analysis)
export(within_data_correlation)
importFrom(EnsDb.Hsapiens.v79,EnsDb.Hsapiens.v79)
Expand Down
30 changes: 30 additions & 0 deletions R/correlation_analysis.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' Runs correlation analysis pipeline

#' @param dataset_name name of the dataset used to select significant DEGs from (specified as a string, name as in allstudies)
#' @param allstudies a list containing all the datasets (as SCE objects)
#' @param celltypes a list containing the celltypes to compute mean correlation across
#' @param pvals list of p-value cut-offs which will be used to select DEGs
#' @param data_names names of the datasets as they appear in the correlation plot
#' @param alphaval (alpha) transparency of the non-mean boxplots
#' @param numPerms number of random permutations of the dataset used to select significant DEGs from
#' @param numSubsets number of pairs of random subsets of the dataset used to select significant DEGs from
#' @param output_path base path in which outputs will be stored

#' Saves all plots and DE outputs in the appropriate directories
#' @export

correlation_analysis <- function(dataset_name="placeholder",
allstudies="placeholder",
celltypes="placeholder",
pvals=c(0.05,0.025,0.01,0.001,0.0001),
data_names="placeholder",
alphaval="placeholder",
numPerms="placeholder",
numSubsets="placeholder",
output_path=getwd()){

# create correlation plots for each p-value cut-off

return("TestOut")

}
67 changes: 6 additions & 61 deletions R/correlation_boxplots.r
Original file line number Diff line number Diff line change
Expand Up @@ -36,67 +36,12 @@ correlation_boxplots <- function(corrMats,
fontsize_legendtitle=9,
fontsize_facet_labels=9){

# check input parameters are fine
if(class(corrMats)!="list"){
stop("Error: corrMats should be a list of matrices")
}
if(floor(numRealDatasets)!=numRealDatasets){
stop("Error: numRealDatasets should be an integer specifying the number of real datasets (see description)")
}
if(!is.numeric(pval) | pval <= 0 | pval > 1){
stop("Error: pval should be a (positive) number between 0 and 1")
}
if(floor(numPerms)!=numPerms){
stop("Error: numPerms should be an integer specifying the number of random permutations of Tsai (see description)")
}
if(floor(numSubsets)!=numSubsets){
stop("Error: numSubsets should be an integer specifying the number of subsets of Tsai (see description)")
}
if(class(sexDEGs)!="logical"){
stop("Error: sexDEGs should be TRUE (if DEGs are chosen only from sex chromosomes) or FALSE")
}
if(class(fontsize_yaxislabels)!="numeric"){
stop("Error: fontsize_yaxislabels should be numerical.")
}else{
if(fontsize_yaxislabels-floor(fontsize_yaxislabels)!=0|fontsize_yaxislabels<0){
stop("Error: fontsize_yaxislabels should be a positive integer.")
}
}
if(class(fontsize_yaxisticks)!="numeric"){
stop("Error: fontsize_yaxisticks should be numerical.")
}else{
if(fontsize_yaxisticks-floor(fontsize_yaxisticks)!=0|fontsize_yaxisticks<0){
stop("Error: fontsize_yaxisticks should be a positive integer.")
}
}
if(class(fontsize_title)!="numeric"){
stop("Error: fontsize_title should be numerical.")
}else{
if(fontsize_title-floor(fontsize_title)!=0|fontsize_title<0){
stop("Error: fontsize_title should be a positive integer.")
}
}
if(class(fontsize_legendlabels)!="numeric"){
stop("Error: fontsize_legendlabels should be numerical.")
}else{
if(fontsize_legendlabels-floor(fontsize_legendlabels)!=0|fontsize_legendlabels<0){
stop("Error: fontsize_legendlabels should be a positive integer.")
}
}
if(class(fontsize_legendtitle)!="numeric"){
stop("Error: fontsize_legendtitle should be numerical.")
}else{
if(fontsize_legendtitle-floor(fontsize_legendtitle)!=0|fontsize_legendtitle<0){
stop("Error: fontsize_legendtitle should be a positive integer.")
}
}
if(class(fontsize_facet_labels)!="numeric"){
stop("Error: fontsize_facet_labels should be numerical.")
}else{
if(fontsize_facet_labels-floor(fontsize_facet_labels)!=0|fontsize_facet_labels<0){
stop("Error: fontsize_facet_labels should be a positive integer.")
}
}
# validate function input params
validate_input_parameters_correlation(corrMats=corrMats, numRealDatasets=numRealDatasets, pvalue=pval,
alphaval=alphaval, numPerms=numPerms, numSubsets=numSubsets,
sexDEGs=sexDEGs, fontsize_yaxislabels=fontsize_yaxislabels, fontsize_yaxisticks=fontsize_yaxisticks,
fontsize_title=fontsize_title, fontsize_legendlabels=fontsize_legendlabels, fontsize_legendtitle=fontsize_legendtitle,
fontsize_facet_labels=fontsize_facet_labels)

# midCor submatrix limits
midCorLim <- numPerms + numRealDatasets
Expand Down
16 changes: 3 additions & 13 deletions R/plot_mean_correlation.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@ plot_mean_correlation <- function(dataset_name,
pvalue,
data_names="placeholder"){

# check input parameters are fine
if(class(allstudies)!="list"){
stop("Error: allstudies should be a list")
}
if(!is.character(celltypes)){
stop("Error: celltypes should be a list containing strings specifying the celltypes")
}
if(!is.numeric(pvalue) | pvalue <= 0 | pvalue > 1){
stop("Error: pvalue should be a (positive) number between 0 and 1")
}
if(data_names!="placeholder" && !is.vector(data_names)){
stop("Error: data_names should be a list containing the names of all datasets as should appear in the final output (if these are different to the names in allstudies)")
}
# validate function input params
validate_input_parameters_correlation(dataset_name=dataset_name, allstudies=allstudies, celltypes=celltypes,
pvalue=pvalue, data_names=data_names)

# list for genes of each celltype at specified p-value
genes <- list()
Expand Down
150 changes: 150 additions & 0 deletions R/validate_input_parameters_correlation.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#' Tests input parameters for functions

#' @param dataset_name name of the dataset used to select significant DEGs from (specified as a string, name as in allStudies)
#' @param allstudies a list containing all the datasets (most likely as SCE objects)
#' @param celltypes a list containing the celltypes to compute mean correlation across
#' @param pvalue the cut-off p-value which will be used to select DEGs
#' @param data_names names of the datasets as they appear in the correlation plot
#' @param corrMats (named) list of correlation matrices for each celltype with the final element being the mean correlation matrix, all at specified p-value
#' @param numRealDatasets total number of *real* datasets (most likely the number of studies, but sometimes a study may be split e.g. into 2 brain regions, so in this case it would be the number of studies plus 1)
#' @param alphaval (alpha) transparency of the non-mean boxplots
#' @param numPerms number of random permutations of the dataset used to select significant DEGs from
#' @param numSubsets number of pairs of random subsets of the dataset used to select significant DEGs from
#' @param sexDEGs true if DEGs come from sex chromosomes, else false
#' @param fontsize_yaxislabels font size for axis labels in plot
#' @param fontsize_yaxisticks font size for axis tick labels in plot
#' @param fontsize_title font size for plot title
#' @param fontsize_legendlabels font size for legend labels in plot
#' @param fontsize_legendtitle font size for legend title in plot
#' @param fontsize_facet_labels font size for facet labels

#' Checks all correlation analysis parameters are specified correctly

validate_input_parameters_correlation <- function(dataset_name="placeholder",
allstudies="placeholder",
celltypes="placeholder",
pvalue="placeholder",
data_names="placeholder",
corrMats="placeholder",
numRealDatasets="placeholder",
alphaval="placeholder",
numPerms="placeholder",
numSubsets="placeholder",
sexDEGs="placeholder",
fontsize_yaxislabels="placeholder",
fontsize_yaxisticks="placeholder",
fontsize_title="placeholder",
fontsize_legendlabels="placeholder",
fontsize_legendtitle="placeholder",
fontsize_facet_labels="placeholder"){

# test each parameter to check if it works
if(dataset_name!="placeholder"){
if(!is.character(dataset_name)){
stop("Error: dataset_name should be a string")
}
}
if(allstudies!="placeholder"){
if(class(allstudies)!="list"){
stop("Error: allstudies should be a list")
}
}
if(celltypes!="placeholder"){
if(!is.character(celltypes)){
stop("Error: celltypes should be a list containing strings specifying the celltypes")
}
}
if(pvalue!="placeholder"){
if(!is.numeric(pvalue) | pvalue <= 0 | pvalue > 1){
stop("Error: pvalue should be a (positive) number between 0 and 1")
}
}
if(data_names!="placeholder" && !is.vector(data_names)){
stop("Error: data_names should be a list containing the names of all datasets as should appear in the final output (if these are different to the names in allstudies)")
}
if(corrMats!="placeholder"){
if(class(corrMats)!="list"){
stop("Error: corrMats should be a list of matrices")
}
}
if(numRealDatasets!="placeholder"){
if(floor(numRealDatasets)!=numRealDatasets){
stop("Error: numRealDatasets should be an integer specifying the number of real datasets (see description)")
}
}
if(alphaval!="placeholder"){
if(class(alphaval)!="numeric"){
stop("Error: alphaval should be numerical")
}
}
if(numPerms!="placeholder"){
if(floor(numPerms)!=numPerms){
stop("Error: numPerms should be an integer specifying the number of random permutations of Tsai (see description)")
}
}
if(numSubsets!="placeholder"){
if(floor(numSubsets)!=numSubsets){
stop("Error: numSubsets should be an integer specifying the number of subsets of Tsai (see description)")
}
}
if(sexDEGs!="placeholder"){
if(class(sexDEGs)!="logical"){
stop("Error: sexDEGs should be TRUE (if DEGs are chosen only from sex chromosomes) or FALSE")
}
}
if(fontsize_yaxislabels!="placeholder"){
if(class(fontsize_yaxislabels)!="numeric"){
stop("Error: fontsize_yaxislabels should be numerical")
}else{
if(fontsize_yaxislabels-floor(fontsize_yaxislabels)!=0|fontsize_yaxislabels<0){
stop("Error: fontsize_yaxislabels should be a positive integer")
}
}
}
if(fontsize_yaxisticks!="placeholder"){
if(class(fontsize_yaxisticks)!="numeric"){
stop("Error: fontsize_yaxisticks should be numerical")
}else{
if(fontsize_yaxisticks-floor(fontsize_yaxisticks)!=0|fontsize_yaxisticks<0){
stop("Error: fontsize_yaxisticks should be a positive integer")
}
}
}
if(fontsize_title!="placeholder"){
if(class(fontsize_title)!="numeric"){
stop("Error: fontsize_title should be numerical")
}else{
if(fontsize_title-floor(fontsize_title)!=0|fontsize_title<0){
stop("Error: fontsize_title should be a positive integer")
}
}
}
if(fontsize_legendlabels!="placeholder"){
if(class(fontsize_legendlabels)!="numeric"){
stop("Error: fontsize_legendlabels should be numerical")
}else{
if(fontsize_legendlabels-floor(fontsize_legendlabels)!=0|fontsize_legendlabels<0){
stop("Error: fontsize_legendlabels should be a positive integer")
}
}
}
if(fontsize_legendtitle!="placeholder"){
if(class(fontsize_legendtitle)!="numeric"){
stop("Error: fontsize_legendtitle should be numerical")
}else{
if(fontsize_legendtitle-floor(fontsize_legendtitle)!=0|fontsize_legendtitle<0){
stop("Error: fontsize_legendtitle should be a positive integer")
}
}
}
if(fontsize_facet_labels!="placeholder"){
if(class(fontsize_facet_labels)!="numeric"){
stop("Error: fontsize_facet_labels should be numerical")
}else{
if(fontsize_facet_labels-floor(fontsize_facet_labels)!=0|fontsize_facet_labels<0){
stop("Error: fontsize_facet_labels should be a positive integer")
}
}
}

}
41 changes: 41 additions & 0 deletions man/correlation_analysis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions man/validate_input_parameters_correlation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 464009e

Please sign in to comment.