{"metadata":{"kernelspec":{"name":"ir","display_name":"R","language":"R"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"4.0.5"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"**CiteSeq Target Analysis**\n\nCorrelated targets (proteins) have been suggested.\n\n[MmSCel🧬EDA Bioinfo Targets CITEseq 01](https://www.kaggle.com/code/alexandervc/mmscel-eda-bioinfo-targets-citeseq-01)\n\nWe attempted to adapt WGCNA to find its centrality.","metadata":{}},{"cell_type":"code","source":"library(rhdf5)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:20:13.409412Z","iopub.execute_input":"2022-10-31T12:20:13.413626Z","iopub.status.idle":"2022-10-31T12:20:13.630237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h5ls(\"../input/open-problems-multimodal/train_cite_targets.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:23:19.795856Z","iopub.execute_input":"2022-10-31T12:23:19.797973Z","iopub.status.idle":"2022-10-31T12:23:19.877112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h5ls(\"../input/open-problems-multimodal/train_cite_inputs.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:23:30.406099Z","iopub.execute_input":"2022-10-31T12:23:30.407785Z","iopub.status.idle":"2022-10-31T12:23:31.371028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"protein <- h5read(\"../input/open-problems-multimodal/train_cite_targets.h5\", '/train_cite_targets/axis0')\nhead(protein)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:29:57.288931Z","iopub.execute_input":"2022-10-31T12:29:57.290990Z","iopub.status.idle":"2022-10-31T12:29:57.334813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id <- h5read(\"../input/open-problems-multimodal/train_cite_targets.h5\", '/train_cite_targets/axis1')\nhead(id)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:30:44.873292Z","iopub.execute_input":"2022-10-31T12:30:44.875293Z","iopub.status.idle":"2022-10-31T12:30:44.970313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values <- h5read(\"../input/open-problems-multimodal/train_cite_targets.h5\", '/train_cite_targets/block0_values')\nhead(values)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:30:14.702858Z","iopub.execute_input":"2022-10-31T12:30:14.705438Z","iopub.status.idle":"2022-10-31T12:30:16.071901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dat <- as.data.frame(values)\nrownames(dat) <- protein\ncolnames(dat) <- id\n\nhead(t(dat))\ndim(t(dat))","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:38:59.471464Z","iopub.execute_input":"2022-10-31T12:38:59.473174Z","iopub.status.idle":"2022-10-31T12:39:01.575091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metadata <- read.csv('../input/open-problems-multimodal/metadata.csv',row.names=1)\nhead(metadata)\ndim(metadata)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:38:47.576134Z","iopub.execute_input":"2022-10-31T12:38:47.578621Z","iopub.status.idle":"2022-10-31T12:38:48.173003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df <- merge(t(dat) , metadata, by=0)\nhead(df)\ndim(df)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:40:32.735513Z","iopub.execute_input":"2022-10-31T12:40:32.737672Z","iopub.status.idle":"2022-10-31T12:40:35.113794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Df <- df[,2:145]\nrownames(Df) <- df[,1]","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:42:45.522350Z","iopub.execute_input":"2022-10-31T12:42:45.524020Z","iopub.status.idle":"2022-10-31T12:42:45.552141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"unique(Df$day)\nunique(Df$donor)\nunique(Df$cell_type)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:44:58.938157Z","iopub.execute_input":"2022-10-31T12:44:58.940177Z","iopub.status.idle":"2022-10-31T12:44:58.979900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"table(Df$cell_type)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:54:14.783619Z","iopub.execute_input":"2022-10-31T12:54:14.785303Z","iopub.status.idle":"2022-10-31T12:54:14.808662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I checked MasP instead of all of them because it takes time.","metadata":{}},{"cell_type":"code","source":"BiocManager::install(\"WGCNA\")\nlibrary(WGCNA)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T12:46:41.153812Z","iopub.execute_input":"2022-10-31T12:46:41.156044Z","iopub.status.idle":"2022-10-31T12:51:20.592334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data <- Df[Df$cell_type == 'MasP',][,1:140]\nData <- t(data)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:01:46.768656Z","iopub.execute_input":"2022-10-31T13:01:46.770779Z","iopub.status.idle":"2022-10-31T13:01:46.836377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"powers = c(seq(from = 1, to=100, by=10))\nsft = pickSoftThreshold(Data, powerVector = powers)\nRpowerTable <- pickSoftThreshold(Data, powerVector = powers)[[2]]","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:03:02.136924Z","iopub.execute_input":"2022-10-31T13:03:02.138626Z","iopub.status.idle":"2022-10-31T13:03:32.043986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cex1 = 0.7\nplot(RpowerTable[,1], -sign(RpowerTable[,3])*RpowerTable[,2], xlab = \"soft threshold (power)\", ylab = \"scale free topology model fit, signes R^2\", type = \"n\")\ntext(RpowerTable[,1], -sign(RpowerTable[,3])*RpowerTable[,2], labels = powers, cex = cex1, col = \"red\") \nabline(h = 0.90, col = \"red\")","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:03:34.878202Z","iopub.execute_input":"2022-10-31T13:03:34.880011Z","iopub.status.idle":"2022-10-31T13:03:34.973415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sft$powerEstimate","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:03:36.262658Z","iopub.execute_input":"2022-10-31T13:03:36.264340Z","iopub.status.idle":"2022-10-31T13:03:36.279761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"We choose the power 41, which is the lowest power for which the scale-free topology fit index curve flattens out upon reaching a high value (in this case, roughly 0.90)","metadata":{}},{"cell_type":"code","source":"Adj <- adjacency(t(Data), power = sft$powerEstimate)\n\nid <- colnames(t(Data))\ncolnames(Adj) <- id\nrownames(Adj) <- id","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:03:47.172108Z","iopub.execute_input":"2022-10-31T13:03:47.173725Z","iopub.status.idle":"2022-10-31T13:03:47.248074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"thre <- 0.1\nsubAdj <- (Adj>thre)*Adj","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:04:33.189433Z","iopub.execute_input":"2022-10-31T13:04:33.192465Z","iopub.status.idle":"2022-10-31T13:04:33.208174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"library(igraph) \nlibrary(visNetwork)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:04:34.129794Z","iopub.execute_input":"2022-10-31T13:04:34.131299Z","iopub.status.idle":"2022-10-31T13:04:34.145199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subnet <- graph.adjacency(subAdj, mode = \"undirected\", weighted = TRUE, diag = FALSE)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:04:35.032091Z","iopub.execute_input":"2022-10-31T13:04:35.033697Z","iopub.status.idle":"2022-10-31T13:04:35.048422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m <- fastgreedy.community(subnet)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:04:35.942782Z","iopub.execute_input":"2022-10-31T13:04:35.944281Z","iopub.status.idle":"2022-10-31T13:04:35.956339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:05:30.938341Z","iopub.execute_input":"2022-10-31T13:05:30.940140Z","iopub.status.idle":"2022-10-31T13:05:30.975426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mo <- m$membership %>%\n  table() %>%\n  data.frame()","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:04:36.840444Z","iopub.execute_input":"2022-10-31T13:04:36.841993Z","iopub.status.idle":"2022-10-31T13:04:36.856362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colnames(mo) <- c(\"module.ID\", \"No.of.node\")\nhead(mo)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:08:19.165470Z","iopub.execute_input":"2022-10-31T13:08:19.168078Z","iopub.status.idle":"2022-10-31T13:08:19.212008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"degree <- degree(subnet)\nstrength <- strength(subnet)\nbetween <- betweenness(subnet, normalized = TRUE)\npage.rank <- page_rank(subnet)$vector\nmodule <- m$membership\nresult_adj <- cbind(degree, strength, between, page.rank, module) %>%\n  data.frame()","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:08:24.036432Z","iopub.execute_input":"2022-10-31T13:08:24.042727Z","iopub.status.idle":"2022-10-31T13:08:24.072334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"H <- as.data.frame(page.rank)\ncolnames(H) <- c('centrality')","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:08:42.376390Z","iopub.execute_input":"2022-10-31T13:08:42.378068Z","iopub.status.idle":"2022-10-31T13:08:42.395251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"library(tidyverse)\nH_sort <- H %>% arrange(-centrality) %>% head","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:09:28.595481Z","iopub.execute_input":"2022-10-31T13:09:28.601576Z","iopub.status.idle":"2022-10-31T13:09:30.162430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"par(mar=c(3,10,3,3),las=2)\nbarplot(H_sort$centrality, xlab = \"centrality\", names.arg = row.names(H_sort),horiz=T)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:09:31.678660Z","iopub.execute_input":"2022-10-31T13:09:31.680812Z","iopub.status.idle":"2022-10-31T13:09:31.760868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Each TARGET formed its own cluster and seemed to be independent.","metadata":{}},{"cell_type":"markdown","source":"The correlation coefficient is not high. Next picture.","metadata":{}},{"cell_type":"code","source":"install.packages(\"corrplot\")\nlibrary(corrplot)","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:15:45.025907Z","iopub.execute_input":"2022-10-31T13:15:45.031479Z","iopub.status.idle":"2022-10-31T13:15:57.372861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr <-  cor(data, method = \"pearson\")\ncorrplot(corr, tl.col=\"black\", type = \"upper\")","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:16:09.860427Z","iopub.execute_input":"2022-10-31T13:16:09.862167Z","iopub.status.idle":"2022-10-31T13:16:10.800256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"No relationship was found between each target.\n\nAre there no protein interrelationships between single cells (MasP)?\n\nWe checked in all cells.","metadata":{}},{"cell_type":"code","source":"data2 <- Df[,1:140]\ncorr2 <-  cor(data2, method = \"pearson\")\ncorrplot(corr2, tl.col=\"black\", type = \"upper\")","metadata":{"execution":{"iopub.status.busy":"2022-10-31T13:52:59.502768Z","iopub.execute_input":"2022-10-31T13:52:59.505587Z","iopub.status.idle":"2022-10-31T13:53:00.812673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Is the correlation between TARGETs not strong?\n\nWhy is that?","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}