### Run scPagwas Main Function with Example Data Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/index.html A quick-start example demonstrating how to use the `scPagwas_main` wrapper function with provided example data, specifying input files, output directories, and various parameters for single-cell and cell type analysis. ```R library(scPagwas) system.time( #1.start to run the wrapper functions for example. Pagwas_data<-scPagwas_main(Pagwas = NULL, gwas_data =system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas"), # The GWAS Summary statistics files Single_data =system.file("extdata", "scRNAexample.rds", package = "scPagwas"),# scRNA-seq data in seruat format with "RNA" assays and normalized. output.prefix="test", # the prefix name for output files output.dirs="scPagwastest_output",# the directory file's name for output block_annotation = block_annotation_hg37,# gene position in chromosome is provided by package. default is hg38, block_annotation_hg37 is hg37. assay="RNA", # the assays for scRNA-seq data to use. Pathway_list=Genes_by_pathway_kegg,# pathway list is provided by package, including gene symbols. n.cores=1, iters_singlecell = 10, chrom_ld = chrom_ld,# The LD data is provided by package. singlecell=T, # Whether to run the singlecell process. celltype=T# Whether to run the celltype process. ) ) ``` -------------------------------- ### Install scPagwas R Package and Dependencies Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/index.html Instructions for installing the scPagwas R package and its dependencies from GitHub, including common R package managers and direct Git installation methods. ```R #install some dependence packages install.packages("Seurat") install.packages("ggpubr") if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("GenomicRanges") ``` ```R devtools::install_github("sulab-wmu/scPagwas") ``` ```R library(devtools) install_git("https://github.com/sulab-wmu/scPagwas.git", ref = "main") ``` -------------------------------- ### Quick-Start Example for scPagwas_main2 Function Source: https://github.com/sulab-wmu/scpagwas/blob/main/README.md This R code provides a quick-start example demonstrating how to use the `scPagwas_main2` function, the primary wrapper for scPagwas2. It illustrates loading the package and running the function with example GWAS summary statistics and scRNA-seq data, configuring various parameters such as output paths, gene annotations (hg37), pathway lists, and parallel processing settings. ```R library(scPagwas) system.time( #1.start to run the wrapper functions for example. Pagwas_data<-scPagwas_main2(Pagwas = NULL, gwas_data =system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas"), # The GWAS Summary statistics files Single_data =system.file("extdata", "scRNAexample.rds", package = "scPagwas"),# scRNA-seq data in seruat format with "RNA" assays and normalized. output.prefix="test", # the prefix name for output files output.dirs="scPagwastest_output",# the directory file's name for output block_annotation = block_annotation_hg37,# gene position in chromosome is provided by package. default is hg38, block_annotation_hg37 is hg37. assay="RNA", # the assays for scRNA-seq data to use. Pathway_list=Genes_by_pathway_kegg,# pathway list is provided by package, including gene symbols. n.cores=1, iters_singlecell = 10, chrom_ld = chrom_ld,# The LD data is provided by package. singlecell=T, # Whether to run the singlecell process. celltype=T# Whether to run the celltype process. ) ) ``` -------------------------------- ### Example Usage and Error Handling for Genes_by_pathway_hallmark Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Genes_by_pathway_hallmark.html This R code snippet provides an example of attempting to load and inspect the `Genes_by_pathway_hallmark` data. It demonstrates the expected warnings and errors if the data set is not found or the object is not loaded into the environment, which is common when running examples without the package loaded or data available. ```R data(Genes_by_pathway_hallmark) #> Warning: data set 'Genes_by_pathway_hallmark' not found str(Genes_by_pathway_hallmark) #> Error in str(Genes_by_pathway_hallmark): object 'Genes_by_pathway_hallmark' not found ``` -------------------------------- ### Example Usage of Pathway_pcascore_run in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Pathway_pcascore_run.html Illustrates a complete workflow for using `Pathway_pcascore_run` in R, including loading example data, preprocessing with `Single_data_input`, and executing the PCA score calculation. ```R library(scPagwas) Pagwas <- list() # Start to read the single cell data Single_data <- readRDS(system.file("extdata", "scRNAexample.rds", package = "scPagwas" )) Pagwas <- Single_data_input( Pagwas = Pagwas, assay = "RNA", Single_data = Single_data, Pathway_list = Genes_by_pathway_kegg ) #> Input single cell data! #> 10 cell types are remain, after filter! Single_data <- Single_data[, colnames(Pagwas$data_mat)] # Run pathway pca score! Pagwas <- Pathway_pcascore_run( Pagwas = Pagwas, Pathway_list = Genes_by_pathway_kegg ) #> * Start to get Pathway SVD socre! #> | | | 0% | |======= | 10%[1] "Celltype1" #> | |============== | 20%[1] "Celltype2" #> | |===================== | 30%[1] "Celltype3" #> | |============================ | 40%[1] "Celltype4" #> | |=================================== | 50%[1] "Celltype5" #> | |========================================== | 60%[1] "Celltype6" #> | |================================================= | 70%[1] "Celltype7" #> | |======================================================== | 80%[1] "Celltype8" #> | |=============================================================== | 90%[1] "Celltype9" #> | |======================================================================| 100%[1] "Celltype10" #> #> Using score as value column: use value.var to override. ``` -------------------------------- ### Example Usage of scPagwas_main in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/scPagwas_main.html Provides a complete R code example demonstrating how to invoke the scPagwas_main function. It shows how to load the package, specify input data files, define output paths, and configure various analysis parameters. ```R library(scPagwas) Pagwas_data <- scPagwas_main( Pagwas = NULL, gwas_data = system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas"), Single_data = system.file("extdata", "scRNAexample.rds", package = "scPagwas"), output.prefix = "test", output.dirs = "scPagwastest_output", block_annotation = block_annotation, assay = "RNA", Pathway_list = Genes_by_pathway_kegg, chrom_ld = chrom_ld, singlecell = TRUE, celltype = TRUE ) ``` -------------------------------- ### Load scPagwas R Package Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/PathwayPCAtest.html An example demonstrating how to load the `scPagwas` R package using the `library()` function. This snippet also shows the beginning of a variable assignment for `Pathway_list`. ```R library(scPagwas) Pathway_list<- ``` -------------------------------- ### Example usage and structure inspection of genes.by.immunologic.pathway in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/genes.by.immunologic.pathway.html This R code snippet provides an example of how to interact with the `genes.by.immunologic.pathway` dataset. It first attempts to load the data and then uses the `str()` function to display its internal structure, which is useful for understanding its components and types, despite the example output indicating potential loading issues. ```R data(genes.by.immunologic.pathway) str(genes.by.immunologic.pathway) ``` -------------------------------- ### Alternative Installation for scPagwas R Package Source: https://github.com/sulab-wmu/scpagwas/blob/main/README.md This R code snippet offers an alternative method to install the scPagwas package from GitHub using `devtools::install_git`. This method can be useful if the standard `devtools::install_github` command encounters issues, specifying the full repository URL and the 'main' branch. ```R library(devtools) install_git("https://github.com/WMU-SuLab/scPagwas.git", ref = "main") ``` -------------------------------- ### Install scPagwas R Package and Dependencies from GitHub Source: https://github.com/sulab-wmu/scpagwas/blob/main/README.md This snippet provides the R code to install necessary dependency packages like Seurat, ggpubr, and GenomicRanges (via BiocManager), followed by the main scPagwas package directly from its GitHub repository using devtools::install_github. ```R #install some dependence packages install.packages("Seurat")#‘5.0.3’ install.packages("ggpubr") if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("GenomicRanges") devtools::install_github("WMU-SuLab/scPagwas") ``` -------------------------------- ### scPagwas Function Parameters Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional Parameters and Usage Instructions with Demo Example Data.html Comprehensive list of parameters for configuring scPagwas computations, detailing their types, default values, and functional descriptions. ```APIDOC Pagwas: list = NULL Description: Typically not required. When 'seurat_return = FALSE', stores all intermediate data as a list, which can be used as input for subsequent computations to skip single-cell calculations. When 'seurat_return = TRUE', the returned result is the final Seurat object and cannot be used as input. gwas_data: string | dataframe = NULL Description: Required. Address or dataframe of the GWAS data. Refer to "Introduction to Data Input and Preprocessing in scPagwas" for formatting. output.prefix: string = "Test" Description: Sets the prefix for the output result files. output.dirs: string = "scPagwastest_output" Description: Specifies the directory for the output result files. block_annotation: object = block_annotation Description: The genomic annotation file, typically provided by scPagwas. Single_data: Seurat object = NULL Description: Required. Single-cell data in Seurat format, with preprocessed and annotated information in Idents. Refer to "Introduction to Data Input and Preprocessing in scPagwas" for processing steps. assay: string = "RNA" Description: The name of the assay for the single-cell data used in the computation. Pathway_list: list = Genes_by_pathway_kegg Description: Pathway data, a list of multiple pathways with their gene sets. Various options are provided by scPagwas; see "Introduction to Data Input and Preprocessing in scPagwas". chrom_ld: object = chrom_ld Description: LD (Linkage Disequilibrium) information file, typically provided by scPagwas. run_split: boolean = FALSE Description: Enables data subsetting and computation for large-scale single-cell data when server memory is insufficient. Results are integrated post-computation. See "Strategies for Large-scale Single-cell Data Subsetting and Computation". n.cores: integer = 1 Description: Enables multi-core computation, specifically for the "Link_pathway_blocks_gwas" function (sixth step of scPagwas). marg: integer = 10000 Description: Boundary distance in base pairs from the Transcription Start Site (TSS) position. Default 10 kb, resulting in a 20 kb window. maf_filter: float = 0.01 Description: Filtering threshold for Minor Allele Frequency (MAF) in GWAS data. Filters out SNPs to improve computational efficiency without impacting final results. min_clustercells: integer = 10 Description: Filtering criterion for single-cell annotation clusters. Only clusters with at least this many cells are considered. min.pathway.size: integer = 5 Description: Filtering criterion for pathway data. Only pathways with a gene count of at least 5 are included. max.pathway.size: integer = 300 Description: Filtering criterion for pathway data. Only pathways with a gene count of no more than 300 are included. Combined with 'min.pathway.size', this prevents abnormal pathway calculations. Filtered pathway data is in the "misc" section of scPagwas results. iters_celltype: integer = 200 Description: Number of iterations for bootstrap computation of cell-type p-values. iters_singlecell: integer = 100 Description: Number of iterations for background-corrected single-cell p-value computation. This parameter significantly affects computation time. n_topgenes: integer = 1000 Description: Number of top genes selected for calculating the Transcriptional Regulator Score (TRS), following common practice. singlecell: boolean = TRUE Description: Determines whether to generate single-cell results. celltype: boolean = TRUE Description: Determines whether to generate cell-type results. seurat_return: boolean = TRUE Description: Determines whether to output results in Seurat format. Only effective when 'singlecell = TRUE'. ``` -------------------------------- ### Load scPagwas R Library Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/scCount_data_input.html An example demonstrating how to load the `scPagwas` R package using the `library()` function, which is a prerequisite for using its functionalities like `scCount_data_input`. ```R library(scPagwas) ``` -------------------------------- ### R Example: Using Tissue_eqtls_Input Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Tissue_eqtls_Input.html Demonstrates how to load the `scPagwas` library and use the `Tissue_eqtls_Input` function. This example attempts to process eQTLs data, specifying to include only eQTLs, but it encounters an error because the 'eqtls_files' dataset is not found. ```R library(scPagwas) data(eqtls_files) #> Warning: data set 'eqtls_files' not found Pagwas <- Tissue_eqtls_Input(Pagwas = Pagwas, add_eqtls = "OnlyEqtls", eqtls_files = eqtls_files) #> Error in Tissue_eqtls_Input(Pagwas = Pagwas, add_eqtls = "OnlyEqtls", eqtls_files = eqtls_files): object 'eqtls_files' not found ``` -------------------------------- ### Example Usage and Structure Inspection of genes.by.celltype.pathway in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/genes.by.celltype.pathway.html This example attempts to load and inspect the structure of the `genes.by.celltype.pathway` dataset using `str()`. The provided output includes warnings and errors, indicating that the dataset might not be found or properly loaded in the given environment without the full package context. ```R data(genes.by.celltype.pathway) #> Warning: data set ‘genes.by.celltype.pathway’ not found str(genes.by.celltype.pathway) #> Error in eval(expr, envir, enclos): object 'genes.by.celltype.pathway' not found ``` -------------------------------- ### Run scPagwas_main for single-cell analysis Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional Parameters and Usage Instructions with Demo Example Data.html This snippet demonstrates how to execute the `scPagwas_main` function for single-cell analysis. It shows two approaches: one where the `Pagwas` object is initialized as NULL, and another where it reuses results from a previous cell type analysis (`Pagwas_celltypes`) to save computation time by skipping the SVD block. Both examples use example GWAS and single-cell RNA data, along with pathway and annotation information. The result is returned in Seurat format. ```R Pagwas_singlecell<-scPagwas_main(Pagwas =NULL, gwas_data =system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas"), Single_data =system.file("extdata", "scRNAexample.rds", package = "scPagwas"), output.prefix="Test", output.dirs="Test", Pathway_list=Genes_by_pathway_kegg, assay="RNA", singlecell=T, celltype=F, block_annotation = block_annotation, chrom_ld = chrom_ld) ``` ```R Pagwas_singlecell<-scPagwas_main(Pagwas =Pagwas_celltypes, gwas_data =system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas"), Single_data =system.file("extdata", "scRNAexample.rds", package = "scPagwas"), output.prefix="Test", output.dirs="Test", Pathway_list=Genes_by_pathway_kegg, assay="RNA", singlecell=T, celltype=F, block_annotation = block_annotation, chrom_ld = chrom_ld) ``` -------------------------------- ### Example Usage of Single_data_input in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Single_data_input.html This R example demonstrates how to use the `Single_data_input` function. It loads a sample single-cell RNA-seq dataset, initializes a Pagwas list, and then processes the data using the function, specifying the assay and a pathway list. ```R library(scPagwas) Pagwas <- list() # Start to read the single cell data Single_data <- readRDS(system.file("extdata", "scRNAexample.rds", package = "scPagwas" )) Pagwas <- Single_data_input( Pagwas = Pagwas, assay = "RNA", Single_data = Single_data, Pathway_list = Genes_by_pathway_kegg ) #> Input single cell data! #> 10 cell types are remain, after filter! ``` -------------------------------- ### R: Example Usage of Bootstrap_estimate_Plot Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Bootstrap_estimate_Plot.html Illustrates how to call the `Bootstrap_estimate_Plot` function in R using example data from the `scPagwas` package. The example loads a pre-existing dataset and attempts to plot the bootstrap results, demonstrating typical function invocation and potential argument mismatches. ```R library(scPagwas) load(system.file("extdata", "Pagwas_data.RData", package = "scPagwas")) Bootstrap_estimate_Plot( Pagwas = Pagwas_data, width = 9, height = 7, do_plot = TRUE ) #> Error in Bootstrap_estimate_Plot(Pagwas = Pagwas_data, width = 9, height = 7, do_plot = TRUE): unused argument (Pagwas = Pagwas_data) ``` -------------------------------- ### Inspect Structure of block_annotation Dataset in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/block_annotation.html This example shows how to load the `block_annotation` dataset and then use the `str()` function to display its internal structure, including the number of observations, variables, and their data types and initial values. It reveals the dataset is a data.frame with chromosomal, start, end, and label information. ```R data(block_annotation) str(block_annotation) #> 'data.frame': 62700 obs. of 4 variables: #> $ chrom: Factor w/ 25 levels "chr1","chr2",..: 1 1 1 1 1 1 1 1 1 1 ... #> $ start: int 11869 12010 14404 17369 29554 30366 34554 52473 57598 62949 ... #> $ end : int 14409 13670 29570 17436 31109 30503 36081 53312 64116 63887 ... #> $ label: chr "DDX11L2" "DDX11L1" "WASH7P" "MIR6859-1" ... ``` -------------------------------- ### R Example: Plotting Pathway Contribution Network Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/plot_pathway_contribution_network.html An example demonstrating the usage of `plot_pathway_contribution_network` with specific parameters. This snippet illustrates how to configure the function for plotting, including data sources, gene contribution, pathway highlighting, and visual settings. Note that the example output in the source text indicates that `vec_gene_contribution` and `vec_pathways_highlight` were unused arguments in this specific context, suggesting potential parameter changes or specific usage requirements. ```R plot_pathway_contribution_network( mat_datExpr = pca_cell_df, vec_gene_contribution = Pagwas$Pathway_block_heritability, vec_pathways_highlight = names(sort(Pagwas$Pathway_block_heritability, decreasing = T)[1:5]), n_max_genes = 20, igraph_algorithm = "drl", fontface_labels = "bold.italic", color_edge = "#9D9D9D", fontSize_label_lg = 4, fontSize_legend_lg = 4, fontSize_legend_xlg = 4, edge_thickness = 1 ) ``` -------------------------------- ### scPagwas_main function parameters and Pagwas_celltypes output structure Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional Parameters and Usage Instructions with Demo Example Data.html This API documentation describes key parameters for the `scPagwas_main` function and the structure of the `Pagwas_celltypes` result list. It details specific elements like `bootstrap_results`, `pca_scCell_mat`, and `pca_cell_df`, explaining their content and purpose within the scPagwas output. ```APIDOC scPagwas_main Parameters: remove_outlier: boolean Whether to filter out outliers. Pagwas_celltypes Result List: Celltype_anno data_mat VariableFeatures merge_scexpr rawPathway_list Pathway_list pca_scCell_mat: matrix A pathway and cell data matrix for pathway SVD (1st PCA) result for each cell. pca_cell_df: matrix A pathway and celltype data matrix for pathway SVD (1st PCA) result for each celltype. snp_gene_df lm_results bootstrap_results: data.frame The bootstrap data frame results for celltypes including bootstrap pvalue and confidence interval. Other elements: intermediate data. ``` -------------------------------- ### Example Usage and Structure Inspection of genes.by.immunesigdb.pathway in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/genes.by.immunesigdb.pathway.html This R example attempts to load the `genes.by.immunesigdb.pathway` dataset and then inspect its internal structure using the `str()` function. The provided output indicates that the dataset might not be found in the current environment, resulting in a warning and an error during execution. ```R data(genes.by.immunesigdb.pathway) #> Warning: data set 'genes.by.immunesigdb.pathway' not found str(genes.by.immunesigdb.pathway) #> Error in str(genes.by.immunesigdb.pathway): object 'genes.by.immunesigdb.pathway' not found ``` -------------------------------- ### R: Reading and Preprocessing GWAS Summary Statistics Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Introduction to Data Input and Preprocessing in scPagwas.html This R code snippet demonstrates how to read a GWAS summary statistics file using `bigreadr::fread2`. It highlights the initial step of loading the example data, which is expected to be a tab-delimited text file with six specific columns for scPagwas analysis. ```R gwas_data <- bigreadr::fread2(system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas")) ``` -------------------------------- ### R Example: Using GWAS_summary_input to Process GWAS Data Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/GWAS_summary_input.html Demonstrates how to use the `GWAS_summary_input` function in R. It shows loading example GWAS summary data, applying the function, and inspecting the filtered output. The example highlights the filtering of SNPs based on MAF and the addition of 'chr' prefix to chromosome names if missing. ```R library(scPagwas) Pagwas <- list() gwas_data <- bigreadr::fread2(system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas" )) Pagwas <- GWAS_summary_input(Pagwas = Pagwas, gwas_data = gwas_data) #> Input gwas summary data frame! #> No "chr" from chrom!, now pasting it! #> Filtering out SNPs with MAF criterion head(Pagwas$gwas_data) #> chrom pos rsid se beta maf #> 1 chr1 1138913 rs3819001 0.0724484 4.774317e-01 0.06761 #> 2 chr1 1691050 rs35672141 0.0368296 1.108626e-01 0.48200 #> 3 chr1 1722932 rs3737628 0.0324817 7.881858e-02 0.48820 #> 4 chr1 2369498 rs4592207 0.0399954 8.822031e-02 0.41790 #> 5 chr1 3259369 rs2483286 0.0352555 1.541813e-03 0.30470 #> 6 chr1 3811790 rs12085743 0.0405247 2.465163e-05 0.18500 ``` -------------------------------- ### R Example: Splitting and Merging scPagwas Data Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/merge_pagwas.html This R example demonstrates how to prepare and process single-cell RNA sequencing data for `scPagwas`. It covers splitting large datasets randomly or by cell type, saving intermediate results, and initializing GWAS summary data for use with `scPagwas_main`. ```R library(Seurat) scRNAexample <-readRDS(system.file("extdata", "scRNAexample.rds", package = "scPagwas")) #set the output.dirs for any directory. set.dirs="D:/OneDrive/GWAS_Multiomics/Pagwas/test/" #set the number of split time, it depend on the size of your single cell data. #There have two form of spliting the data: ######### ##1.By Random #Create the random index number. n_split=2 Split_index <- rep(1:n_split, time = ceiling(ncol(scRNAexample)/n_split), length = ncol(scRNAexample)) for (i in 1:n_split) { Example_splice <- scRNAexample[,Split_index==i] saveRDS(Example_splice,file = paste0(set.dirs,"Example_splice",i,".rds")) } ######### ###1.By celltypes #Create the random index number. for (i in levels(Idents(scRNAexample))) { Example_splice <- subset(scRNAexample,idents = i) saveRDS(Example_splice,file = paste0(set.dirs,"Example_splice",i,".rds")) } Pagwas<-list() gwas_data <- bigreadr::fread2(system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas")) Pagwas <- GWAS_summary_input( Pagwas = Pagwas, gwas_data = gwas_data, maf_filter = 0.1 ) Pagwas$snp_gene_df <- Snp2Gene(snp = Pagwas$gwas_data, refGene = block_annotation, marg = 10000) names(Pagwas) setwd(set.dirs) for (i in 1:n_split) { scPagwas_main(Pagwas =Pagwas, gwas_data =NULL, Single_data = paste0("Example_splice",i,".rds"), #the output.prefix=i, #the prefix can be the circulation coefficient i. output.dirs="splice_scPagwas", #the output.dirs shoukd be the same for each circulation Pathway_list=Genes_by_pathway_kegg, run_split=TRUE #This parameter is set to run single result for each split result. ) } ``` -------------------------------- ### R Example: Plotting Heritability Correlation Scatterplot Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/heritability_cor_scatterplot.html Demonstrates how to use the `heritability_cor_scatterplot` function with example data loaded from the `scPagwas` package. It sets various plotting parameters like colors, text size, and output dimensions. ```R load(system.file("extdata", "Pagwas_data.RData", package = "scPagwas")) heritability_cor_scatterplot( gene_heri_cor = Pagwas_data@misc$PCC, topn_genes_label = 10, color_low = "#035397", color_high = "#F32424", color_mid = "white", text_size = 2, do_plot = TRUE, max.overlaps = 20, width = 7, height = 7 ) #> Error in rep(NA, nrow(gene_heri_cor)): invalid 'times' argument ``` -------------------------------- ### R: scPagwas_main Function Usage Example Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/scPagwas_main.html Illustrates the basic syntax and parameters for calling the `scPagwas_main` function in R, which is the primary wrapper for scPagwas analyses. This snippet shows the function signature with default values for many parameters. ```R scPagwas_main( Pagwas = NULL, gwas_data = NULL, output.prefix = "Test", output.dirs = "scPagwastest_output", block_annotation = block_annotation, Single_data = NULL, assay = "RNA", Pathway_list = Genes_by_pathway_kegg, chrom_ld = chrom_ld, run_split = FALSE, n.cores = 1, marg = 10000, maf_filter = 0.01, min_clustercells = 10, min.pathway.size = 5, max.pathway.size = 300, iters_celltype = 200, iters_singlecell = 100, n_topgenes = 1000, singlecell = TRUE, celltype = TRUE, seurat_return = TRUE, remove_outlier = TRUE ) ``` -------------------------------- ### Run scPagwas with both single-cell and cell-type functions in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional Parameters and Usage Instructions with Demo Example Data.html This R code snippet demonstrates how to execute the `scPagwas_main` function to perform both single-cell and cell-type analyses. It requires specifying input GWAS summary data, single-cell RNA-seq data, pathway lists, and setting both `singlecell` and `celltype` parameters to TRUE. The output is stored in the `Pagwas` object. ```R library(scPagwas) Pagwas<-scPagwas_main(Pagwas =NULL, gwas_data =system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas"), Single_data =system.file("extdata", "scRNAexample.rds", package = "scPagwas"), output.prefix="Test", output.dirs="Test", Pathway_list=Genes_by_pathway_kegg, assay="RNA", singlecell=T, iters_singlecell = 100, celltype=T, block_annotation = block_annotation, chrom_ld = chrom_ld) ``` -------------------------------- ### R Code Example: Calling fortify.Seurat.tsne Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/fortify.Seurat.tsne.html Demonstrates the typical call signature for the `fortify` S3 method when used with a `Seurat.tsne` object in R. ```R # S3 method for Seurat.tsne fortify(x) ``` -------------------------------- ### Example Usage of Bootstrap_P_Barplot in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Bootstrap_P_Barplot.html This R code snippet demonstrates how to use the `Bootstrap_P_Barplot` function from the `scPagwas` package. It loads example data, extracts bootstrap p-values and names, and then calls the function to generate a bar plot with specified dimensions and title. ```R library(scPagwas) load(system.file("extdata", "Pagwas_data.RData", package = "scPagwas")) Bootstrap_P_Barplot( p_results = Pagwas_data@misc$bootstrap_results$bp_value[-1], p_names = rownames(Pagwas_data@misc$bootstrap_results)[-1], width = 5, height = 7, do_plot = TRUE, title = "Test" ) ``` -------------------------------- ### R Example for plot_bar_positie_nagtive Function Usage Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/plot_bar_positie_nagtive.html Demonstrates how to use the `plot_bar_positie_nagtive` function in R. It loads sample data and calls the function with specified parameters to generate a barplot, illustrating typical usage. ```R load(system.file("extdata", "Pagwas_data.RData", package = "scPagwas")) plot_bar_positie_nagtive( seurat_obj = Pagwas_data, var_ident = "anno", var_group = "positiveCells", vec_group_colors = c("#E8D0B3", "#7EB5A6"), do_plot = FALSE ) #> Error in x[[i, drop = TRUE]]: ‘Random_Correct_BG_adjp’ not found in this Seurat object #> ``` -------------------------------- ### Inspect Pagwas_celltypes result list structure in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional Parameters and Usage Instructions with Demo Example Data.html This R code demonstrates how to view the names of the elements within the `Pagwas_celltypes` list, which is the output when running scPagwas for cell-type analysis only. This helps in understanding the structure of the returned data. ```R names(Pagwas_celltypes) ``` -------------------------------- ### Example: Mapping SNPs to Genes with scPagwas Snp2Gene Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Snp2Gene.html Illustrates the end-to-end process of using the `Snp2Gene` function within the `scPagwas` package. This includes loading example GWAS summary data, applying a MAF filter using `GWAS_summary_input`, and then mapping SNPs to genes using `Snp2Gene` with a specified margin. ```R library(scPagwas) Pagwas <- list() gwas_data <- bigreadr::fread2(system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas" )) Pagwas <- GWAS_summary_input( Pagwas = Pagwas, gwas_data = gwas_data, maf_filter = 0.1 ) #> Input gwas summary data frame! #> No "chr" from chrom!, now pasting it! #> Filtering out SNPs with MAF criterion Pagwas$snp_gene_df <- Snp2Gene( snp = Pagwas$gwas_data, refGene = block_annotation, marg = 10000 ) #> * Computing distances between SNPs and genes #> 5332 SNPs not inside gene domain #> ** Computing distance to domain starts #> ** Computing distance to domain ends ``` -------------------------------- ### Perform Regression for Cell Types with Pagwas_perform_regression and Boot_evaluate (R) Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional Parameters and Usage Instructions with Demo Example Data.html This step executes regression analysis specifically for cell types using `Pagwas_perform_regression` and evaluates the results with `Boot_evaluate`. It generates `lm_results` (regression results for cell types) and `bootstrap_results` (p-value results from bootstrap testing). The `Pathway_ld_gwas_data` is then removed to free up memory. ```R Pagwas$lm_results <- Pagwas_perform_regression(Pathway_ld_gwas_data = Pagwas$Pathway_ld_gwas_data) Pagwas <- Boot_evaluate(Pagwas, bootstrap_iters = 200, part = 0.5) names(Pagwas) # [1] "Celltype_anno" "data_mat" "VariableFeatures" "merge_scexpr" # [5] "rawPathway_list" "Pathway_list" "pca_scCell_mat" "pca_cell_df" # [9] "snp_gene_df" "Pathway_sclm_results" "Pathway_ld_gwas_data" "lm_results" #[13] "bootstrap_results" #remove the Pathway_ld_gwas_data, it takes a lot of memory. Pagwas$Pathway_ld_gwas_data <- NULL ``` -------------------------------- ### scPagwas Output Variables Description Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional Parameters and Usage Instructions with Demo Example Data.html This section provides detailed descriptions of key output variables generated by the scPagwas analysis, including Trait Relevant Scores (TRS), background-corrected p-values, and merged cell type p-values, along with their interpretations and usage notes. ```APIDOC Single_data$scPagwas.TRS.Score1: Description: Trait relevant score based on top trait relevant genes. Single_data$scPagwas.downTRS.Score2: Description: Trait relevant score based on anti-relevant genes. Note: Although our article primarily focuses on the TRS scores, it does not imply that reverse “downTRS” are always devoid of significance. During our following research, we observed that in certain phenotypes, such as some cancer traits.When observing the density distribution plot of gPas scores, it becomes evident that it exhibits a high and sharp peak. This indicates that the majority of cells have minor effects. However, if the distribution shows a more pronounced long-tail behavior, the direction of this long tail can influence the impact of PCC gene pairs on the phenotype. Random_Correct_BG_pdf: Description: Dataframe containing the calculated results of p-values after background correction for TRS of each cell. Includes: pooled_p, adj_p, pooled_z, and other results. Merged_celltype_pvalue: Description: P-value results of cell types after merging the p-values of single cells. ``` -------------------------------- ### R Example: Mapping SNPs to Genes with SnpToGene Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/SnpToGene.html Illustrates the usage of the `SnpToGene` function from the `scPagwas` package in R. This example demonstrates loading GWAS summary data, preprocessing it, and then applying `SnpToGene` to map SNPs to genes. Note that the provided example code contains errors related to `fread` and `gwas_data` object availability. ```R library(scPagwas) Pagwas <- list() gwas_data <- bigreadr::fread(system.file("extdata", "GWAS_summ_example.txt", package = "scPagwas" )) #> Error: 'fread' is not an exported object from 'namespace:bigreadr' Pagwas <- GWAS_summary_input( Pagwas = Pagwas, gwas_data = gwas_data, maf_filter = 0.1 ) #> Input gwas summary data frame! #> Error in eval(expr, envir, enclos): object 'gwas_data' not found Pagwas$gwas_data_gene_df <- SnpToGene( gwas_data = Pagwas$gwas_data, block_annotation = block_annotation, marg = 10000 ) ``` -------------------------------- ### Pathway_pcascore_run Function Arguments Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Pathway_pcascore_run.html Details the arguments required by the `Pathway_pcascore_run` function, specifying their expected format and purpose. ```APIDOC Pagwas Pagwas format Pathway_list Pathawy gene list(gene symbol),list name is pathway name. min.pathway.size Threshold for min pathway gene size. max.pathway.size Threshold for max pathway gene size. ``` -------------------------------- ### Troubleshooting and Optimization Tips for scPagwas Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/scPagwas_main.html Offers practical advice for optimizing scPagwas performance and resolving common issues. It includes tips for managing CPU threads, checking and clearing R objects, and handling large datasets by splitting and merging. ```bash export OPENBLAS_NUM_THREADS=1 ``` ```R SOAR::Objects() SOAR::Remove(SOAR::Objects()) ``` -------------------------------- ### Prepare Single Cell Data Input for scPagwas Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Running_scPagwas_steps_by_SubFunctions.html This step demonstrates how to load single-cell expression data and filter clusters for a minimum number of cells using the 'Single_data_input' function. It initializes the 'Pagwas' list and prepares the single-cell data for subsequent analysis steps. ```R library(scPagwas) Pagwas <- list() Single_data <- readRDS(system.file("extdata", "scRNAexample.rds", package = "scPagwas")) Pagwas <- Single_data_input( Pagwas = Pagwas, assay = "RNA", Single_data = Single_data, Pathway_list = Genes_by_pathway_kegg ) Single_data <- Single_data[, colnames(Pagwas$data_mat)] ``` -------------------------------- ### Boot_evaluate Function Reference Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/index.html Documents the `Boot_evaluate` function within the scPagwas package. ```APIDOC Boot_evaluate() Description: Boot_evaluate ``` -------------------------------- ### Load `genes.by.reactome.pathway` dataset in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/genes.by.reactome.pathway.html This R code snippet shows how to load the `genes.by.reactome.pathway` dataset into your R session using the `data()` function. Once loaded, the dataset becomes available for immediate use in your analysis. ```R data(genes.by.reactome.pathway) ``` -------------------------------- ### scPagwas Output File Descriptions Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional result and visualization Instructions with Real-World Examples.html This section describes the various output files generated by the scPagwas analysis pipeline, detailing their content and purpose. ```APIDOC Output Files in 'monocytecount_bmmc' folder: *_cellytpes_bootstrap_results.csv: The result of cell types for bootstrap p results. *_gene_PCC.csv: The result of gene heritability correlation with gPAS score. *_Pathway_singlecell_lm_results.txt: The regression result for all pathway and single cell matrix. *_singlecell_scPagwas_score_pvalue.Result.csv: The data frame result for each cell including scPagwas.TRS.Score, scPagwas.downTRS.Score, scPagwas.gPAS.score, pValueHighScale, qValueHighScale. *_Merged_celltype_pvalue.csv: The merged single-cell p-value to cell type p-value. Temporary Folder: scPagwas_cache: A temporary folder to save SOAR data; can be removed after scPagwas completion. ``` -------------------------------- ### Execute scPagwas Main Analysis for Single-cell and Celltype Data Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Conventional result and visualization Instructions with Real-World Examples.html This R code block demonstrates how to run the core `scPagwas_main` function. It processes GWAS data and single-cell RNA-seq data to generate both single-cell and celltype-level results, saving the output in Seurat format. Key parameters include input file paths, output directories, pathway lists, number of cores, and iteration counts. ```R library(scPagwas) Pagwas<-scPagwas_main(Pagwas =NULL, gwas_data="./monocytecount_prune_gwas_data.txt", Single_data ="./Seu_Hema_data.rds", output.prefix="mono", output.dirs="monocytecount_bmmc", Pathway_list=Genes_by_pathway_kegg, n.cores=2, assay="RNA", singlecell=T, iters_singlecell = 100, celltype=T, block_annotation = block_annotation, chrom_ld = chrom_ld) save(Pagwas,file="./BMMC_scPagwas.RData") ``` -------------------------------- ### Get gene heritability correlation Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Running_scPagwas_steps_by_SubFunctions.html Calculates the heritability correlation for all genes using the scPagwas gPAS score and the data matrix. The resulting correlation values are then displayed. ```R Pagwas$gene_heritability_correlation <- scGet_gene_heritability_correlation(scPagwas.gPAS.score=Pagwas$scPagwas.gPAS.score, data_mat=Pagwas$data_mat) ``` ```R knitr::kable(head(Pagwas$gene_heritability_correlation)) ``` -------------------------------- ### Load and Process GSEA Pathway List in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Introduction to Data Input and Preprocessing in scPagwas.html This R code snippet demonstrates how to load gene pathway data from a GMT file, typically downloaded from GSEA. It reads the file line by line, splits the content by tabs, and structures the data into a named list where each element represents a pathway and contains its associated genes. ```R #such as: x <- readLines("c8.all.v7.5.1.symbols.gmt") res <- strsplit(x, "\t") names(res) <- vapply(res, function(y) y[1], character(1)) genes.by.celltype.pathway <- lapply(res, "[", -c(1:2)) ``` -------------------------------- ### Boot_evaluate Function API Reference Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Boot_evaluate.html API documentation for the `Boot_evaluate` function, which performs bootstrap evaluation for confidence intervals. It takes a Pagwas object, the number of bootstrap iterations, and a part parameter as input. ```APIDOC Boot_evaluate(Pagwas, bootstrap_iters = 200, part = 0.5) Pagwas: Pagwas format, default is NULL. bootstrap_iters: number of bootstrap iterations to run, default is 200. part: number of bootstrap iterations to perform, default is 0.5. Returns: Data frame for bootstrap results. ``` -------------------------------- ### API Documentation for p_merge Function Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/p_merge.html Detailed API reference for the `p_merge` function, including its parameters and return value, as documented in the `scPagwas` project. ```APIDOC Function: p_merge Usage: p_merge(pvalues) Arguments: pvalues: pvalues Value: p_total ``` -------------------------------- ### Load Genes by KEGG Pathway Dataset in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/Genes_by_pathway_kegg.html This R code snippet demonstrates how to load the `Genes_by_pathway_kegg` dataset into the R environment. This dataset is a pre-compiled list of genes categorized by KEGG pathways, useful for pathway-based analyses. ```R data(Genes_by_pathway_kegg) ``` -------------------------------- ### Inspect structure of `genes.by.reactome.pathway` dataset in R Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/reference/genes.by.reactome.pathway.html This R code demonstrates how to load the `genes.by.reactome.pathway` dataset and then inspect its internal structure using the `str()` function. This provides a summary of the dataset's components, including its list format and the types of data it contains. ```R data(genes.by.reactome.pathway) str(genes.by.reactome.pathway) ``` -------------------------------- ### Map SNPs to Genes in scPagwas Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Running_scPagwas_steps_by_SubFunctions.html Map SNPs to genes based on their genomic proximity using the 'SnpToGene' function. The 'marg' parameter defines the maximum distance (e.g., 10KB) from a SNP to a gene's Transcription Start Site (TSS) for mapping. ```R Pagwas$snp_gene_df <- SnpToGene( gwas_data = Pagwas$gwas_data, block_annotation = block_annotation, marg = 10000 ) ``` -------------------------------- ### Visualize scPagwas Score of single cell data in UMAP or TSNE plot Source: https://github.com/sulab-wmu/scpagwas/blob/main/docs/articles/Running_scPagwas_steps_by_SubFunctions.html Visualizes the scPagwas score of single-cell data using UMAP or TSNE plots. It includes examples for a standard Seurat `DimPlot` and a specialized `scPagwas_Visualization` function to highlight positive cells. ```R suppressMessages(require("RColorBrewer")) suppressMessages(require("Seurat")) suppressMessages(require("SeuratObject")) suppressMessages(require("ggsci")) suppressMessages(require("dplyr")) suppressMessages(require("ggplot2")) suppressMessages(require("ggpubr")) Seurat::DimPlot(Pagwas,pt.size=1,reduction="umap",label = T, repel=TRUE)+ umap_theme()+ggtitle("Test")+labs(x="UMAP",y="")+theme(aspect.ratio=1) ``` ```R scPagwas_Visualization(Single_data=Pagwas_singlecell, p_thre = 0.05, FigureType = "umap", width = 7, height = 7, lowColor = "white", highColor = "red", output.dirs="figure", size = 0.5, do_plot = T) ```