<jupyter_start><jupyter_text>CCNMF analysis of simulated paired scRNA and scDNA data<jupyter_code># Load necessary packages
library(CCNMF)
library(Seurat)
library(NMF)
library(pheatmap)
library(ggplot2)
library(cowplot)
library(ggplotify)
library(Rtsne)
# Load Data
CNVmatrix <- as.matrix(read.csv('~/CCNMF/testdata/DNA.csv'))
RNAmatrix <- as.matrix(read.csv('~/CCNMF/testdata/RNA.csv'))
# Preprocessing scRNA-seq data by Seurat
rownames(RNAmatrix) <- paste0('gene', 1:dim(RNAmatrix)[1])
colnames(RNAmatrix) <- paste0('cell', 1:dim(RNAmatrix)[2])
RNAobject <- run_Seurat_RNA(RNAmatrix)
# Then we use a sigmoid fucnction transform the negative elements in scaled RNA matrix to non-negative 
# since the CCNMF needs non-negative matrices as input.
sigmoid <- function(x){1/(1+ exp(-x))}
RNAmatrix1 <- RNAobject@assays$RNA@scale.data[RNAobject@assays$RNA@meta.features$vst.variable, ]
replaceindex <- which(RNAmatrix1 < 0 )
RNAmatrix2 <- RNAmatrix1
RNAmatrix2[replaceindex] <- sigmoid(RNAmatrix1)[replaceindex]
# Preprocessing scDNA-seq data 
rownames(CNVmatrix) <- paste0('gene', 1:dim(CNVmatrix)[1])
colnames(CNVmatrix) <- paste0('cell', 1:dim(CNVmatrix)[2])
CNVmatrix1 <- CNVmatrix[RNAobject@assays$RNA@meta.features$vst.variable, ]
# Set the coupledMatrix as identify matrix 
# CoupledMatrix <- as(as.matrix(diag(dim(RNAmatrix1)[1]), 'dgCMatrix')
CoupledMatrix <- as.matrix(diag(dim(RNAmatrix1)[1]))
# Run CCNMF
ResultsCCNMF <- run_CCNMF(ncluster = 3, CNVmatrix1, RNAmatrix2, CoupledMatrix, lambda1=1, lambda2=1, mu=1)
length(ResultsCCNMF)
# Find the differential genes between clusters based on scRNA data
DElist <- DiffExp(RNAmatrix2, ResultsCCNMF[[6]])
# Output the heatmap and tsne figures of CCNMF, the main figure's pdf can be saved in current path.
PlotMainResult(CNVmatrix1, RNAmatrix2, ResultsCCNMF, DElist)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13264753654574987, 'fraction_numerical': 0.021115322144017325, 'mean_word_length': 7.286995515695067, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '645164', 'license': 'MIT', 'n_tokens_mistral': 714, 'n_tokens_neox': 647, 'n_words': 144, 'path': 'notebooks/CCNMF_analyze_simulated_data.ipynb', 'repo_name': 'XQBai/CCNMF', 'size': '1847'}