### Import Libraries and Setup Directory Source: https://github.com/dylkot/cnmf/blob/main/Extras/prepare_unittest_pbmc.ipynb Imports necessary Python libraries and creates a directory for example data if it doesn't exist. Sets a random seed for reproducibility. ```python import os import pandas as pd import numpy as np from scipy.io import mmread import scipy.sparse as sp import scanpy as sc from cnmf import cNMF if not os.path.exists('example_PBMC'): os.mkdir('example_PBMC') np.random.seed(14) ``` -------------------------------- ### Install and Load Package Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Installs a package if not already installed and then loads it. Use this for any package not included in base R. ```r if (!require(package_name)) { install.packages("package_name") } library(package_name) ``` -------------------------------- ### Import Libraries and Setup Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_batcheffectcorrect_BaronEtAl.ipynb Imports necessary Python libraries for data manipulation, plotting, and scNMF analysis. Sets up a random seed for reproducibility and creates a directory for example data if it doesn't exist. ```python %matplotlib inline import os import pandas as pd import numpy as np from scipy.io import mmread import scipy.sparse as sp import matplotlib.pyplot as plt from IPython.display import Image import scanpy as sc from cnmf import cNMF, Preprocess import seaborn as sns if not os.path.exists('example_islets'): os.mkdir('example_islets') np.random.seed(14) ``` -------------------------------- ### List Files in cNMF Example Directory Source: https://github.com/dylkot/cnmf/blob/main/Extras/prepare_unittest_simulation.ipynb Use this command to list all files within the example cNMF directory. This helps in understanding the structure and content of the simulation data. ```bash ! ls simulated_example_data/example_cNMF ``` -------------------------------- ### Install and Load R Packages Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Provides the standard R commands for installing a package from CRAN and then loading it into the current session for use. ```r install.packages("package_name") library(package_name) ``` -------------------------------- ### Download and Extract Example Data in R Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Downloads a tar.gz file containing the pbmc3k example dataset and extracts it to a specified directory. Ensures the directory exists before downloading. ```r data_url <- 'https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz' data_dir = './R_Example_Data/' if (!dir.exists(data_dir)) { dir.create(data_dir, recursive = TRUE) } # Path where the tar.gz file will be saved file_path <- file.path(data_dir, 'pbmc3k_filtered_gene_bc_matrices.tar.gz') # Download the file download.file(data_url, file_path, mode='wb') ``` ```r extract_command <- sprintf("tar -xzf %s -C %s", shQuote(file_path), shQuote(data_dir)) system(extract_command) rm_command <- sprintf("rm %s", file_path) system(rm_command) ``` -------------------------------- ### Download and Extract Example Data Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_batcheffectcorrect_BaronEtAl.ipynb Downloads a compressed archive containing example islet data and extracts it. This step is necessary to obtain the data for subsequent analysis. ```bash ! wget https://storage.googleapis.com/sabeti-public/dkotliar/data/example_islets.tar.gz -O example_islets/example_islets.tar.gz ! tar -xzf example_islets/example_islets.tar.gz ``` -------------------------------- ### Import Libraries and Setup Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_pbmc_example_data.ipynb Imports necessary libraries for data analysis and sets up the output directory and random seed. ```python %matplotlib inline import os import pandas as pd import numpy as np from scipy.io import mmread import scipy.sparse as sp import matplotlib.pyplot as plt from IPython.display import Image import scanpy as sc from cnmf import cNMF if not os.path.exists('example_PBMC'): os.mkdir('example_PBMC') np.random.seed(14) ``` -------------------------------- ### Download and Extract Example Data Source: https://github.com/dylkot/cnmf/blob/main/Extras/prepare_unittest_simulation.ipynb Downloads a compressed archive of example data from a specified URL and extracts its contents. The downloaded archive is removed after extraction. ```shell ! wget -O ./example_simulated_data.tar.gz https://storage.googleapis.com/sabeti-public/dkotliar/cNMF/example_data_20191024.tar.gz ! tar -zxvf ./example_simulated_data.tar.gz && rm ./example_simulated_data.tar.gz ``` -------------------------------- ### For Loop Example Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Demonstrates a basic for loop for iterating over a sequence. ```r for (i in 1:5) { print(paste("Iteration:", i)) } ``` -------------------------------- ### Getting Help Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Accesses the documentation for a specific function. ```r ?function_name help(function_name) ``` -------------------------------- ### R: Rcpp Integration Example Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Demonstrates basic integration with Rcpp for C++ code execution within R. ```r # Example Rcpp function (assuming it's defined elsewhere) # result <- cpp_function(input_data) ``` -------------------------------- ### Install Optional Dependencies for Batch Correction Source: https://github.com/dylkot/cnmf/blob/main/README.md Install harmonypy and scikit-misc if you plan to use the batch correction preprocessing feature of cNMF. ```bash pip install harmonypy pip install scikit-misc ``` -------------------------------- ### Move example data directory Source: https://github.com/dylkot/cnmf/blob/main/Extras/simulate_example_data.ipynb Moves the 'example_data' directory to 'simulated_example_data' using the 'mv' command. This is a shell command for file system operations. ```shell ! mv example_data simulated_example_data ``` -------------------------------- ### Remove Example Data Files Source: https://github.com/dylkot/cnmf/blob/main/Extras/simulate_example_data.ipynb Removes specific files ('geneparams.npz' and 'cellparams.npz') from the './example_data/' directory. Use with caution. ```bash ! rm ./example_data/geneparams.npz ! rm ./example_data/cellparams.npz ``` -------------------------------- ### AJAX Setup for Script Content Type Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Sets up AJAX to accept and process JavaScript content, including defining converters for script-to-JSON conversion. ```javascript S.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/\\b(?:java|ecma)script\\b/},converters:{"text script":function(e){return S.globalEval(e),e}}}),S.ajaxPrefilter("script",function(e){void 0===e.cache&&(e.cache=!1),e.crossDomain&&(e.type="GET")}) ``` -------------------------------- ### Data Manipulation with dplyr Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Demonstrates data filtering and selection using the dplyr package. Ensure dplyr is installed and loaded. ```r library(dplyr) filtered_data <- data %>% filter(x > 10) %>% select(y) ``` -------------------------------- ### Import Libraries for CNMF Analysis Source: https://github.com/dylkot/cnmf/blob/main/Extras/simulate_example_data.ipynb Imports necessary libraries for data manipulation, visualization, and CNMF analysis. Ensure these libraries are installed before running. ```python %matplotlib inline import sys sys.path.append('..') from cnmf import load_df_from_npz, get_highvar_genes import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.decomposition import PCA from sklearn import preprocessing from bhtsne import tsne import palettable import matplotlib.gridspec as gridspec ``` -------------------------------- ### Create output directory for simulation Source: https://github.com/dylkot/cnmf/blob/main/Extras/simulate_example_data.ipynb Create a directory named 'example_data' to store the simulation output. This ensures organized storage of generated data. ```bash ! mkdir ./example_data ``` -------------------------------- ### List Files in Directory Source: https://github.com/dylkot/cnmf/blob/main/Extras/simulate_example_data.ipynb Lists the contents of the './example_data/' directory. Useful for verifying file creation or deletion. ```bash ! ls ./example_data/ ``` -------------------------------- ### R Vignette Examples Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html A collection of R code snippets extracted from the vignette. These examples showcase various R functionalities and data manipulations. ```R QZetZRj7NqlQdhfUYZBbTwWuC/iSTp5WbqzD6BouFPrV1ZPwSEe9XzZt2ty5u2ngfA1bNXQZ+rcFvrfI2nZAM7B1VxxLtLMF1ui4yO3lW214aNNAhtMI1zr9tGmSnp7W3SFYRwIkQAIkQAInn4Dem9SOk9Ipfo88+VeT0iP22cILC9sXX3wh77zzjnzlK1+Jnwzit8JtYdGiRWYAEdwYvv/978e3c2FwEkDyhrlnzzCxd/3p+caKikFZUQ0/hhIJOR+RsA5U86oPK4pxY9B5cfFYtdruU7EJWdqpFiEGkffcDoYzLgutfnWBwP5Ov3CXGD9+vCAMms2wAjENFwjTP0KFxQp8ZU1CCOzaWW03d851e0FBgcnwYsU1wqNBrFoxjsaw6IbUJxfFl+6cj1lxvdh94JeMYztWaFh39SQ9YfMEIz093bUHF0mABEiABEhgYAngFumFISeFpbfbbgoP0+9d9Vnwfv755xpgP6eL2HWfJfw2L7jgAvnggw8oeN1gBslyTU2tbN6w1ZzNvIVzNLuZ38SldeLvRlXEFptoBVX7NNmDUZexL466G2QGNX2uL2RS9/qDXiN2ISiNqFSB3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SSgDJP+COAJ9ba7G1B2hqarKLZo4PS15enlmGoHWH1MIHCqJv ``` -------------------------------- ### Install cNMF with pip Source: https://github.com/dylkot/cnmf/blob/main/README.md Install the cNMF package using pip. Ensure you have Python 3.7 or higher and compatible versions of scikit-learn, scanpy, and AnnData. ```bash pip install cnmf ``` -------------------------------- ### List Files in PBMC Directory Source: https://github.com/dylkot/cnmf/blob/main/Extras/prepare_unittest_pbmc.ipynb Lists the contents of the ./example_PBMC directory, showing input data and CNMF output directories. ```bash ! ls ./example_PBMC ``` -------------------------------- ### Display cNMF Help Options Source: https://github.com/dylkot/cnmf/blob/main/Stepwise_Guide.md Run this command to see all available command-line options for cNMF. ```bash cnmf --help ``` -------------------------------- ### Create a Scatter Plot Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Generates a scatter plot using ggplot2. Requires the ggplot2 package to be installed and loaded. ```r library(ggplot2) ggplot(data, aes(x = x, y = y)) + geom_point() ``` -------------------------------- ### Create Tar Archive of PBMC Results Source: https://github.com/dylkot/cnmf/blob/main/Extras/prepare_unittest_pbmc.ipynb Creates a gzipped tar archive of all files within the ./example_PBMC directory. This is useful for backing up or transferring results. ```bash ! tar -czvf example_pbmc_results_20250301.tar.gz ./example_PBMC/* ``` -------------------------------- ### Getting Element Position Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Calculates the position of the first element in the set of matched elements relative to its offset parent. ```javascript S.fn.position=function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===S.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===S.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=S(e).offset()).top+=S.css(e,"borderTopWidth",!0),i.left+=S.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-S.css(r,"marginTop",!0),left:t.left-i.left-S.css(r,"marginLeft",!0)}}} ``` -------------------------------- ### List Files in PBMC cNMF Directory Source: https://github.com/dylkot/cnmf/blob/main/Extras/prepare_unittest_pbmc.ipynb Lists the contents of the ./example_PBMC/pbmc_cNMF directory, showing generated CNMF output files. ```bash ! ls ./example_PBMC/pbmc_cNMF ``` -------------------------------- ### Getting Element Offset Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Calculates the offset (position) of the first element in the set of matched elements relative to the document. ```javascript S.fn.offset=function(t){if(arguments.length)return void 0===t?this:this.each(function(e){S.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0} ``` -------------------------------- ### Set up plotting environment Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_simulated_example_data.ipynb Ensures plots are displayed inline within the notebook. ```python %matplotlib inline ``` -------------------------------- ### Load and Inspect Data in R Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Demonstrates loading a dataset into R and performing initial inspection. Ensure the file path is correct for your environment. ```r library(dplyr) library(readr) # Load the dataset data <- read_csv("path/to/your/data.csv") # Inspect the data structure and first few rows str(data) head(data) ``` -------------------------------- ### Initialize Table Visibility Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Sets the initial opacity of the table to 0 if horizontal space is not yet provided by the host. It then renders the table and sets up a retry mechanism for fitting columns if space is initially insufficient. ```javascript if (tableDiv.clientWidth <= 0) { tableDiv.style.opacity = "0"; } me.render(); function retryFit() { if (tableDiv.clientWidth <= 0) { setTimeout(retryFit, 100); } else { me.render(); triggerOnChange(); } } if (tableDiv.clientWidth <= 0) { retryFit(); } ``` -------------------------------- ### Create a Scatter Plot in R Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Generates a scatter plot using ggplot2. Requires the ggplot2 package to be installed and loaded. ```r library(ggplot2) ggplot(data, aes(x = column1, y = column2)) + geom_point() ``` -------------------------------- ### Initialize CNMF Object with Different Algorithm Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Demonstrates initializing a CNMF object using a different algorithm ('nmfstd'). This might be suitable for specific data characteristics or analysis goals. ```R cnmf_obj_nmfstd <- CNMF(data, k=5, alg='nmfstd', n_iter=1000, seed=123) ``` -------------------------------- ### Create a Bar Plot Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Creates a bar plot from summarized data. This example assumes 'category' and 'count' columns exist. ```r barplot(data$count, names.arg = data$category) ``` -------------------------------- ### CNMF with Different Initialization Methods Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Compares CNMF results obtained using different initialization strategies. ```python cnmf_init1 = CNMF(params, initialization='method1') ``` ```python cnmf_init2 = CNMF(params, initialization='method2') ``` -------------------------------- ### Getting Element Offset Parent Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Finds the closest positioned ancestor element for the first element in the set of matched elements. ```javascript S.fn.offsetParent=function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===S.css(e,"position"))e=e.offsetParent;return e||re})}} ``` -------------------------------- ### Get DataFrame Columns Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_simulated_example_data.ipynb Retrieves the column names of a pandas DataFrame. Useful for verifying merged data and understanding available features. ```python tsne_and_usages.columns ``` -------------------------------- ### List Files in Simulated Data Directory Source: https://github.com/dylkot/cnmf/blob/main/Extras/prepare_unittest_simulation.ipynb Use this command to list all files in the main simulated data directory. This provides an overview of all available simulation assets. ```bash ! ls simulated_example_data ``` -------------------------------- ### Display scsim help message Source: https://github.com/dylkot/cnmf/blob/main/Extras/simulate_example_data.ipynb Display the help message for the run_scsim.py script to understand available simulation parameters and their descriptions. This is useful for configuring simulation runs. ```bash ! python ../../scsim/run_scsim.py -h ``` -------------------------------- ### Using Rcpp for C++ Integration Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Example of integrating C++ code into R using Rcpp for performance improvements. Requires Rcpp package. ```r library(Rcpp) # Define C++ code as a string cxx_code <- " SEXP add_cpp(SEXP x, SEXP y) { return Rf_ScalarReal(Rcpp::as(x) + Rcpp::as(y)); } " # Compile and load the C++ function compiled_add <- cxxfunction(signature("x=numeric(1), y=numeric(1)"), plugin = "Rcpp", body = cxx_code) # Use the compiled C++ function in R result <- compiled_add(x = 5, y = 3) print(result) ``` -------------------------------- ### Highlight.js Initialization Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Configures and initializes Highlight.js for syntax highlighting on the page. It sets the available languages and then triggers the highlighting process. ```javascript if (window.hljs) { hljs.configure({languages: []}); hljs.initHighlightingOnLoad(); if (document.readyState && document.readyState === "complete") { window.setTimeout(function() { hljs.initHighlighting(); }, 0); } } ``` -------------------------------- ### Create a Network Graph with Layouts Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Visualizes network data using different layout algorithms for better representation. Requires 'igraph'. ```r library(igraph) graph <- graph_from_data_frame(d = edges_data) plot(graph, layout = layout_with_fr) ``` -------------------------------- ### Construct cNMF Prepare Command Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Constructs the command-line string for the cNMF 'prepare' step, specifying output directory, run name, input matrix, and NMF parameters. This command is then executed. ```R runname = "example_cNMF" cmd = paste("cnmf prepare --output-dir", data_dir, "--name", runname, "-c", paste0(filtered_dir, 'matrix.mtx'), "--max-nmf-iter 2000", "-k 5 6 7 8 9 10 --n-iter 20", sep=" ") print(cmd) ``` -------------------------------- ### Data Visualization with ggplot2 in R Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Provides an example of creating a scatter plot using ggplot2. Customize aesthetics and geoms for different plot types. ```r library(ggplot2) # Create a scatter plot ggplot(data, aes(x = x_column, y = y_column)) + geom_point() + labs(title = "Scatter Plot Example", x = "X Axis Label", y = "Y Axis Label") ``` -------------------------------- ### Scrolling Element Position Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Gets or sets the scroll position of each element in the set of matched elements. Supports both horizontal (scrollLeft) and vertical (scrollTop) scrolling. ```javascript S.each({"scrollLeft":"pageXOffset","scrollTop":"pageYOffset"},function(t,i){var o="pageYOffset"===i;S.fn\[t\]=function(e){return $(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r\[i\]:e\[t\];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e\[t\]=n},t,e,arguments.leng}) ``` -------------------------------- ### Combine Factorizations using Command Line Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_pbmc_example_data.ipynb Combine individual factorization results using the cNMF command-line interface. This prepares the data for consensus estimation. ```bash cmd = 'cnmf combine --output-dir example_PBMC/cNMF --name pbmc_cNMF' print('Command line - combine step: %s' % cmd) !{cmd} ``` -------------------------------- ### Load R Libraries for Data Handling Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Loads necessary R packages for data manipulation and Seurat object handling. Ensure these packages are installed before running. ```R suppressPackageStartupMessages({ library(data.table) library(Matrix) library(Seurat) }) ``` -------------------------------- ### Creating a Shiny App (Server) Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Defines the server logic for a Shiny application. ```r library(shiny) server <- function(input, output) { output$distPlot <- renderPlot({ x <- faithful[, 2] bins <- seq(min(x), max(x), length.out = input$bins + 1) hist(x, breaks = bins, col = 'skyblue', border = 'white', xlab = 'Waiting time to next eruption (in mins)', main = 'Histogram of waiting times') }) } ``` -------------------------------- ### Task Execution Output Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_pbmc_example_data.ipynb This output shows the progress of tasks being executed by worker 0. It indicates the start of each task, useful for monitoring the progress of distributed computations. ```text [Worker 0]. Starting task 0. [Worker 0]. Starting task 1. [Worker 0]. Starting task 2. [Worker 0]. Starting task 3. [Worker 0]. Starting task 4. [Worker 0]. Starting task 5. [Worker 0]. Starting task 6. [Worker 0]. Starting task 7. [Worker 0]. Starting task 8. [Worker 0]. Starting task 9. [Worker 0]. Starting task 10. [Worker 0]. Starting task 11. [Worker 0]. Starting task 12. [Worker 0]. Starting task 13. [Worker 0]. Starting task 14. [Worker 0]. Starting task 15. [Worker 0]. Starting task 16. [Worker 0]. Starting task 17. [Worker 0]. Starting task 18. [Worker 0]. Starting task 19. [Worker 0]. Starting task 20. [Worker 0]. Starting task 21. [Worker 0]. Starting task 22. [Worker 0]. Starting task 23. [Worker 0]. Starting task 24. [Worker 0]. Starting task 25. [Worker 0]. Starting task 26. [Worker 0]. Starting task 27. [Worker 0]. Starting task 28. [Worker 0]. Starting task 29. [Worker 0]. Starting task 30. [Worker 0]. Starting task 31. [Worker 0]. Starting task 32. [Worker 0]. Starting task 33. [Worker 0]. Starting task 34. [Worker 0]. Starting task 35. [Worker 0]. Starting task 36. [Worker 0]. Starting task 37. [Worker 0]. Starting task 38. [Worker 0]. Starting task 39. [Worker 0]. Starting task 40. [Worker 0]. Starting task 41. [Worker 0]. Starting task 42. [Worker 0]. Starting task 43. [Worker 0]. Starting task 44. [Worker 0]. Starting task 45. [Worker 0]. Starting task 46. [Worker 0]. Starting task 47. [Worker 0]. Starting task 48. [Worker 0]. Starting task 49. [Worker 0]. Starting task 50. [Worker 0]. Starting task 51. [Worker 0]. Starting task 52. [Worker 0]. Starting task 53. [Worker 0]. Starting task 54. [Worker 0]. Starting task 55. [Worker 0]. Starting task 56. [Worker 0]. Starting task 57. [Worker 0]. Starting task 58. [Worker 0]. Starting task 59. [Worker 0]. Starting task 60. [Worker 0]. Starting task 61. [Worker 0]. Starting task 62. [Worker 0]. Starting task 63. [Worker 0]. Starting task 64. [Worker 0]. Starting task 65. [Worker 0]. Starting task 66. [Worker 0]. Starting task 67. [Worker 0]. Starting task 68. [Worker 0]. Starting task 69. [Worker 0]. Starting task 70. [Worker 0]. Starting task 71. [Worker 0]. Starting task 72. [Worker 0]. Starting task 73. [Worker 0]. Starting task 74. [Worker 0]. Starting task 75. [Worker 0]. Starting task 76. [Worker 0]. Starting task 77. [Worker 0]. Starting task 78. [Worker 0]. Starting task 79. [Worker 0]. Starting task 80. [Worker 0]. Starting task 81. [Worker 0]. Starting task 82. [Worker 0]. Starting task 83. [Worker 0]. Starting task 84. [Worker 0]. Starting task 85. [Worker 0]. Starting task 86. [Worker 0]. Starting task 87. [Worker 0]. Starting task 88. [Worker 0]. Starting task 89. [Worker 0]. Starting task 90. [Worker 0]. Starting task 91. [Worker 0]. Starting task 92. [Worker 0]. Starting task 93. [Worker 0]. Starting task 94. [Worker 0]. Starting task 95. [Worker 0]. Starting task 96. [Worker 0]. Starting task 97. [Worker 0]. Starting task 98. [Worker 0]. Starting task 99. [Worker 0]. Starting task 100. [Worker 0]. Starting task 101. [Worker 0]. Starting task 102. [Worker 0]. Starting task 103. [Worker 0]. Starting task 104. [Worker 0]. Starting task 105. [Worker 0]. Starting task 106. [Worker 0]. Starting task 107. [Worker 0]. Starting task 108. [Worker 0]. Starting task 109. [Worker 0]. Starting task 110. [Worker 0]. Starting task 111. [Worker 0]. Starting task 112. ``` -------------------------------- ### Parameter Tuning for CNMF Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Demonstrates how to adjust parameters for optimal CNMF performance. This often involves iterative testing. ```python params.set('parameter_name', value) ``` -------------------------------- ### Execute cNMF Prepare Step Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Executes the cNMF 'prepare' command constructed previously using the system() function. This step normalizes the data and prepares it for factorization. ```R system(cmd) ``` -------------------------------- ### Create a Scatter Plot with ggplot2 in R Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Generates a scatter plot using ggplot2 to visualize the relationship between two variables. Requires the ggplot2 library to be installed and loaded. ```r library(ggplot2) ggplot(data, aes(x = var1, y = var2)) + geom_point() ``` -------------------------------- ### Creating Bar Plots with ggplot2 Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Illustrates how to create a bar plot using the ggplot2 package to visualize categorical data. This requires the ggplot2 package to be installed and loaded. ```r library(ggplot2) # Sample data frame for plotting plot_data <- data.frame( Category = c("A", "B", "C", "D"), Value = c(23, 45, 56, 12) ) # Create a bar plot ggplot(plot_data, aes(x = Category, y = Value)) + geom_bar(stat = "identity", fill = "steelblue") + labs(title = "Bar Plot of Categories", x = "Category", y = "Value") + theme_minimal() ``` -------------------------------- ### Initialize and Resize Paged Tables Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Initializes all paged tables on the page and sets up a listener to resize them on window resize events. Ensures tables are responsive. ```javascript var PagedTableDoc; (function (PagedTableDoc) { var allPagedTables = []; PagedTableDoc.initAll = function() { allPagedTables = []; var pagedTables = [].slice.call(document.querySelectorAll('["data-pagedtable"="false"],["data-pagedtable"=""]')); pagedTables.forEach(function(pagedTable, idx) { pagedTable.setAttribute("data-pagedtable", "true"); pagedTable.setAttribute("pagedtable-page", 0); pagedTable.setAttribute("class", "pagedtable-wrapper"); var pagedTableInstance = new PagedTable(pagedTable); pagedTableInstance.init(); allPagedTables.push(pagedTableInstance); }); }; PagedTableDoc.resizeAll = function() { allPagedTables.forEach(function(pagedTable) { pagedTable.render(); }); }; window.addEventListener("resize", PagedTableDoc.resizeAll); return PagedTableDoc; })(PagedTableDoc || (PagedTableDoc = {})); window.onload = function() { PagedTableDoc.initAll(); }; ``` -------------------------------- ### Create a Bar Plot with ggplot2 in R Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Illustrates how to create a bar plot to compare categorical data. This example uses `geom_bar()` for counts or `geom_col()` for pre-summarized values. ```r ggplot(data, aes(x = category_var)) + geom_bar() ``` -------------------------------- ### Preprocess Data for CNMF with Sex and Sample Covariates Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_batcheffectcorrect_BaronEtAl.ipynb Initializes the Preprocess object and runs the preprocessing pipeline for CNMF. Includes 'Sex' and 'Sample' as harmony variables to correct for batch effects. Plots are generated and output is saved to a specified directory. ```python p = Preprocess(random_seed=14) (adata_c, adata_tp10k, hvgs) = p.preprocess_for_cnmf(adata, harmony_vars=['Sex', 'Sample'], n_top_rna_genes = 2000, max_scaled_thresh = None, quantile_thresh = .9999, makeplots=True, save_output_base='./example_islets/batchcorrect_example_sex') ``` -------------------------------- ### Initialize Table Components Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Initializes data, page, measurer, and columns objects. Sets up table elements and caches client width. ```javascript var data = source.data; var page = new Page(data, options); var measurer = new Measurer(data, options); var columns = new Columns(data, source.columns, options); var table = null; var tableDiv = null; var header = null; var footer = null; var tbody = null; // Caches pagedTable.clientWidth, specially for webkit var cachedPagedTableClientWidth = null; var onChangeCallbacks = []; ``` -------------------------------- ### Get Elements by Tag Name or Query Selector Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Retrieves elements from a given context, either by tag name or using querySelectorAll. It merges results and handles context. ```javascript function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||""):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||""):[],void 0===t||t&&A(e,t)?S.merge([e],n):n} ``` -------------------------------- ### Special Event Handling Setup Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Configures special event handling for a given event type on an element. It uses a proxy handler to manage event triggers and element states. ```javascript function Se(e,i,o){o?(Y.set(e,i,!1),S.event.add(e,i,{namespace:!1,handler:function(e){var t,n,r=Y.get(this,i);if(1&e.isTrigger&&this[i]){if(r.length)(S.event.special[i]||{}).delegateType&&e.stopPropagation();else if(r=s.call(arguments),Y.set(this,i,r),t=o(this,i),this[i](),r!==(n=Y.get(this,i))||t?Y.set(this,i,!1):n={},r!==n)return e.stopImmediatePropagation(),e.preventDefault(),n&&n.value}})):void 0===Y.get(e,i)&&S.event.add(e,i,we)} ``` -------------------------------- ### Data Transformation with dplyr in R Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Shows common data manipulation tasks such as filtering, selecting, arranging, mutating, and summarizing data using the dplyr package. Ensure dplyr is installed and loaded. ```r library(dplyr) filtered_data <- data %>% filter(condition) %>% select(col1, col2) %>% arrange(col1) %>% mutate(new_col = col1 * 2) %>% group_by(group_col) %>% summarise(mean_val = mean(value_col)) ``` -------------------------------- ### Create a Calendar Heatmap Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Visualizes data over time on a calendar grid. Requires packages like 'calmap'. ```r library(calmap) calmap(data$date, data$value, start = "2023-01-01") ``` -------------------------------- ### Continued Task Execution Output Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/analyze_pbmc_example_data.ipynb This output shows the continuation of task execution by worker 0. It indicates the start of subsequent tasks, useful for monitoring the progress of distributed computations after a potential interruption or completion of a batch. ```text [Worker 0]. Starting task 113. [Worker 0]. Starting task 114. [Worker 0]. Starting task 115. [Worker 0]. Starting task 116. [Worker 0]. Starting task 117. [Worker 0]. Starting task 118. [Worker 0]. Starting task 119. ``` -------------------------------- ### Data Frame Creation Source: https://github.com/dylkot/cnmf/blob/main/Tutorials/R_vignette.nb.html Shows how to create a data frame in R. ```r df <- data.frame( Name = c("Alice", "Bob", "Charlie"), Age = c(25, 30, 35), City = c("New York", "Los Angeles", "Chicago") ) print(df) ```