Skip to content

Commit 700462b

Browse files
committed
test
1 parent 388b971 commit 700462b

8 files changed

+1403
-4
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
notebooks/
2+
figures_ignore/
3+
.ipynb_checkpoints/

notebooks_github/useful_code.ipynb

+1,142
Large diffs are not rendered by default.
153 KB
Binary file not shown.

notebooks_github/useful_code_R.ipynb

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "ea4f6f59-47f5-4890-9339-17d7be855b07",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"custom_heatmap = function(object,signaling = NULL, pattern = c(\"outgoing\",\"incoming\",\"all\"), slot.name = \"netP\",\n",
11+
" color.use = NULL, color.heatmap = 'Blues', pathway.col = c(\"Cell-Cell Contact\" = \"red\", \"ECM-Receptor\" = \"green\", \"Mixed\" = \"blue\",\n",
12+
" \"MK PTN family\" = \"yellow\",\"Secreted Signaling\" = \"orange\"),\n",
13+
" title = NULL, width = 8, height = 20, font.size = 8, font.size.title = 10,\n",
14+
" row_clusters = NULL, column_clusters = NULL, seed = 99){\n",
15+
" pattern <- match.arg(pattern)\n",
16+
" set.seed(seed)\n",
17+
" ##############################\n",
18+
" #######construct matrix#######\n",
19+
" ##############################\n",
20+
" centr <- slot(object, slot.name)$centr\n",
21+
" outgoing <- matrix(0, nrow = nlevels(object@idents), ncol = length(centr))\n",
22+
" incoming <- matrix(0, nrow = nlevels(object@idents), ncol = length(centr))\n",
23+
" dimnames(outgoing) <- list(levels(object@idents), names(centr))\n",
24+
" dimnames(incoming) <- dimnames(outgoing)\n",
25+
" for (i in 1:length(centr)) {\n",
26+
" outgoing[,i] <- centr[[i]]$outdeg\n",
27+
" incoming[,i] <- centr[[i]]$indeg\n",
28+
" }\n",
29+
" if (pattern == \"outgoing\") {\n",
30+
" mat <- t(outgoing)\n",
31+
" legend.name <- \"Outgoing\"\n",
32+
" } else if (pattern == \"incoming\") {\n",
33+
" mat <- t(incoming)\n",
34+
" legend.name <- \"Incoming\"\n",
35+
" } else if (pattern == \"all\") {\n",
36+
" mat <- t(outgoing+ incoming)\n",
37+
" legend.name <- \"Overall\"\n",
38+
" }\n",
39+
" if (!is.null(signaling)) {\n",
40+
" mat1 <- mat[rownames(mat) %in% signaling, , drop = FALSE]\n",
41+
" mat <- matrix(0, nrow = length(signaling), ncol = ncol(mat))\n",
42+
" idx <- match(rownames(mat1), signaling)\n",
43+
" mat[idx[!is.na(idx)], ] <- mat1\n",
44+
" dimnames(mat) <- list(signaling, colnames(mat1))\n",
45+
" }\n",
46+
" mat.ori <- mat\n",
47+
" mat <- sweep(mat, 1L, apply(mat, 1, max), '/', check.margin = FALSE)\n",
48+
" \n",
49+
" ##############################\n",
50+
" ###setup legend and colors####\n",
51+
" ##############################\n",
52+
" if (is.null(title)) {\n",
53+
" title <- paste0(legend.name, \" signaling patterns\")\n",
54+
" } else {\n",
55+
" title <- paste0(paste0(legend.name, \" signaling patterns\"), \" - \",title)\n",
56+
" }\n",
57+
" if (min(mat, na.rm = T) == max(mat, na.rm = T)) {\n",
58+
" legend.break <- max(mat, na.rm = T)\n",
59+
" } else {\n",
60+
" legend.break <- c(round(min(mat, na.rm = T), digits = 1), round(max(mat, na.rm = T), digits = 1))}\n",
61+
"\n",
62+
" #heatmap color\n",
63+
" color.heatmap.use = grDevices::colorRampPalette((RColorBrewer::brewer.pal(n = 9, name = color.heatmap)))(100)\n",
64+
" color.heatmap.use[1] = '#ffffff' #set 0 point to white\n",
65+
" \n",
66+
" ##############################\n",
67+
" #####heatmap annotations######\n",
68+
" ##############################\n",
69+
" ###Rows###\n",
70+
" #Left annotation\n",
71+
" library(dplyr)\n",
72+
" pathway_annotations = distinct(data.frame(pathway = cellchat@DB$interaction$pathway_name,\n",
73+
" annotation = cellchat@DB$interaction$annotation))\n",
74+
" pathway_annotations[pathway_annotations$pathway %in% \n",
75+
" pathway_annotations[duplicated(pathway_annotations$pathway),]$pathway,]$annotation = 'Mixed'\n",
76+
" pathway_annotations = distinct(pathway_annotations)\n",
77+
" pathway_annotations = pathway_annotations[match(row.names(mat),pathway_annotations$pathway),]\n",
78+
" rownames(pathway_annotations) <- NULL\n",
79+
" \n",
80+
" pathway.col = pathway.col[pathway_annotations$annotation]\n",
81+
" \n",
82+
" row_anno = HeatmapAnnotation(\"Signaling Type\" = pathway_annotations$annotation,\n",
83+
" col = list(\"Signaling Type\" = pathway.col),\n",
84+
" which = \"row\",\n",
85+
" show_legend = TRUE, show_annotation_name = FALSE,\n",
86+
" simple_anno_size = grid::unit(0.1, \"cm\"))\n",
87+
"\n",
88+
" #right annotation\n",
89+
" pSum <- rowSums(mat.ori)\n",
90+
" pSum.original <- pSum\n",
91+
" pSum <- -1/log(pSum)\n",
92+
" pSum[is.na(pSum)] <- 0\n",
93+
" idx1 <- which(is.infinite(pSum) | pSum < 0)\n",
94+
" if (length(idx1) > 0) {\n",
95+
" values.assign <- seq(max(pSum)*1.1, max(pSum)*1.5, length.out = length(idx1))\n",
96+
" position <- sort(pSum.original[idx1], index.return = TRUE)$ix\n",
97+
" pSum[idx1] <- values.assign[match(1:length(idx1), position)]\n",
98+
" }\n",
99+
" ha1 = rowAnnotation(Strength = anno_barplot(pSum, border = FALSE), show_annotation_name = FALSE)\n",
100+
"\n",
101+
" ###columns###\n",
102+
" if (is.null(color.use)) {\n",
103+
" color.use <- scPalette(length(colnames(mat)))\n",
104+
" }\n",
105+
" df<- data.frame(group = colnames(mat)); rownames(df) <- colnames(mat)\n",
106+
" names(color.use) <- colnames(mat)\n",
107+
"\n",
108+
" #bottom annotation\n",
109+
" col_annotation <- HeatmapAnnotation(df = df, col = list(group = color.use),which = \"column\",\n",
110+
" show_legend = FALSE, show_annotation_name = FALSE,\n",
111+
" simple_anno_size = grid::unit(0.2, \"cm\"))\n",
112+
" #top annotation\n",
113+
" ha2 = HeatmapAnnotation(Strength = anno_barplot(colSums(mat.ori), border = FALSE,gp = gpar(fill = color.use, col=color.use)), show_annotation_name = FALSE) \n",
114+
" \n",
115+
" \n",
116+
" ##############################\n",
117+
" #######plotting heatmap#######\n",
118+
" ##############################\n",
119+
" ht1 = Heatmap(mat, col = color.heatmap.use, na_col = \"white\", name = \"Relative strength\",\n",
120+
" right_annotation = ha1,\n",
121+
" left_annotation = row_anno,\n",
122+
" bottom_annotation = col_annotation, top_annotation = ha2,\n",
123+
" #cluster_rows=hclust(dist(mat.noNA),method = 'average'),\n",
124+
" #cluster_columns =hclust(dist(t(mat.noNA)),method = 'average'),\n",
125+
" row_km = row_clusters, row_km_repeats = 5,\n",
126+
" column_km = column_clusters, column_km_repeats = 5,\n",
127+
" border = TRUE,\n",
128+
" row_names_side = \"left\",row_names_rot = 0,row_names_gp = gpar(fontsize = font.size),column_names_gp = gpar(fontsize = font.size),\n",
129+
" width = unit(width, \"cm\"), height = unit(height, \"cm\"),\n",
130+
" column_title = title,column_title_gp = gpar(fontsize = font.size.title),column_names_rot = 90,\n",
131+
" heatmap_legend_param = list(title_gp = gpar(fontsize = 8, fontface = \"plain\"),title_position = \"leftcenter-rot\",\n",
132+
" border = NA, at = legend.break,\n",
133+
" legend_height = unit(20, \"mm\"),labels_gp = gpar(fontsize = 8),grid_width = unit(2, \"mm\"))\n",
134+
" )\n",
135+
" return(ht1)\n",
136+
" }"
137+
]
138+
}
139+
],
140+
"metadata": {
141+
"kernelspec": {
142+
"display_name": "cellchat",
143+
"language": "R",
144+
"name": "cellchat"
145+
},
146+
"language_info": {
147+
"codemirror_mode": "r",
148+
"file_extension": ".r",
149+
"mimetype": "text/x-r-source",
150+
"name": "R",
151+
"pygments_lexer": "r",
152+
"version": "4.3.3"
153+
}
154+
},
155+
"nbformat": 4,
156+
"nbformat_minor": 5
157+
}
66.7 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Mcm5
2+
Pcna
3+
Tyms
4+
Fen1
5+
Mcm2
6+
Mcm4
7+
Rrm1
8+
Ung
9+
Gins2
10+
Mcm6
11+
Cdca7
12+
Dtl
13+
Prim1
14+
Uhrf1
15+
Cenpu
16+
Hells
17+
Rfc2
18+
Rpa2
19+
Nasp
20+
Rad51ap1
21+
Gmnn
22+
Wdr76
23+
Slbp
24+
Ccne2
25+
Ubr7
26+
Pold3
27+
Msh2
28+
Atad2
29+
Rad51
30+
Rrm2
31+
Cdc45
32+
Cdc6
33+
Exo1
34+
Tipin
35+
Dscc1
36+
Blm
37+
Casp8ap2
38+
Usp1
39+
Clspn
40+
Pola1
41+
Chaf1b
42+
Brip1
43+
E2f8
44+
Hmgb2
45+
Cdk1
46+
Nusap1
47+
Ube2c
48+
Birc5
49+
Tpx2
50+
Top2a
51+
Ndc80
52+
Cks2
53+
Nuf2
54+
Cks1b
55+
Mki67
56+
Tmpo
57+
Cenpf
58+
Tacc3
59+
Pimreg
60+
Smc4
61+
Ccnb2
62+
Ckap2l
63+
Ckap2
64+
Aurkb
65+
Bub1
66+
Kif11
67+
Anp32e
68+
Tubb4b
69+
Gtse1
70+
Kif20b
71+
Hjurp
72+
Cdca3
73+
Jpt1
74+
Cdc20
75+
Ttk
76+
Cdc25c
77+
Kif2c
78+
Rangap1
79+
Ncapd2
80+
Dlgap5
81+
Cdca2
82+
Cdca8
83+
Ect2
84+
Kif23
85+
Hmmr
86+
Aurka
87+
Psrc1
88+
Anln
89+
Lbr
90+
Ckap5
91+
Cenpe
92+
Ctcf
93+
Nek2
94+
G2e3
95+
Gas2l3
96+
Cbx5
97+
Cenpa
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
2-
2+
cd notebooks
33
for filename in *.ipynb; do
4-
jupyter nbconvert $filename --to webpdf --allow-chromium-download
4+
jupyter nbconvert $filename --to webpdf --allow-chromium-download \
5+
--output ../notebooks_github/$filename
56
jupyter nbconvert $filename --to notebook \
6-
--ClearOutputPreprocessor.enabled=True --output ../github_notebooks/$filename
7+
--ClearOutputPreprocessor.enabled=True --output ../notebooks_github/$filename
78
done

test.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)