Last active
June 27, 2022 13:23
-
-
Save baobabprince/2eca0b491b3ccfbade9317cad13002af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "heatmap" | |
author: "Rotem Hadar" | |
date: "27/06/2022" | |
output: html_document | |
--- | |
```{r} | |
library(tidyverse) | |
serum <- "./Serum_metadata.txt" |> read_tsv() |> mutate(source = "serum") |> | |
mutate( Dysbiosis_Index = Dysbiosis_Index |> as.numeric() | |
, FCP_Absolute = FCP_Absolute |> as.numeric()) | |
stool <- "./Stool_metadata.txt" |> read_tsv() |> mutate(source = "stool") | |
``` | |
## Couples | |
```{r} | |
input <- | |
"Faith + dysbiosis index | |
Faith + FCP_Absolute | |
Faith + CRP_Absolute | |
Dysbiosis index + FCP absolute | |
Dysbiosis index + CRP absolute | |
FCP absolute + CRP absolute" | |
# AAAAAAAAHHHHHHHH! | |
input <- input |> str_replace_all("dysbiosis index", "Dysbiosis_Index") | |
input <- input |> str_replace_all("Dysbiosis index", "Dysbiosis_Index") | |
input <- input |> str_replace_all("Faith", "Faith_pd") | |
input <- input |> str_replace_all("FCP a", "FCP_A") | |
input <- input |> str_replace_all("CRP a", "CRP_A") | |
couples <- read.table(sep = '+', text = input) | |
couples$V1 <- couples$V1 |> trimws() | |
couples$V2 <- couples$V2 |> trimws() | |
``` | |
## Correlation | |
1. לכל זוג צריך לבדוק את קורלציית ספירמן | |
2. ואז הצבעים בהיטמאפ יהיה ה-R, | |
3. ואם זה מובהק אז צריך להוסיף את ה- PVAL לריבוע. | |
```{r} | |
couples$cor <- NA | |
couples$pval <- NA | |
for(row in couples |> nrow() |> seq()){ # Shame on me | |
v1 <- couples[row,1] ; v2 <- couples[row,2] | |
# 1 | |
couples[row, "cor"] <- serum |> | |
select(SampleID, Faith_pd, FCP_Absolute, CRP_Absolute, Dysbiosis_Index) |> drop_na() |> | |
summarise(cor(!!sym(v1), !!sym(v2), method = "spearman")) | |
# 3 | |
couples[row, "pval"] <- serum |> | |
select(SampleID, Faith_pd, FCP_Absolute, CRP_Absolute, Dysbiosis_Index) |> drop_na() |> | |
summarise(cor.test(x = !!sym(v1),y = !!sym(v2), method = "spearman")$p.value) | |
} | |
``` | |
```{r} | |
couples |> | |
ggplot(aes(x = V1, y = V2, fill = cor)) + # 2 | |
geom_tile() + | |
geom_text(aes(label = round(pval, 4))) + | |
theme_classic() + scale_fill_gradient2(low = "red", high = "blue", mid = "white") + | |
theme(axis.title = element_blank()) + ggtitle("Corplot of some measurments (serum metadata)") | |
``` | |
## Barplot | |
בנוסף, אם יש לך כוח, | |
צריך גם לעשות בר-פלוט שמשווה בין | |
כאשר ציר X הוא ה- disease status | |
וציר y הוא faith פעם אחת, | |
ופעם נוספת הוא dysibiosis index. | |
כמובן שצריך גם כאן לעשות מבחן סטטיסטי... | |
```{r} | |
mycompr <- list(c("CD_active", "Control"), | |
c("CD_Remission", "CD_active"), | |
c("CD_Remission", "Control")) | |
library(ggsignif) | |
serum |> select(SampleID, Disease_Status, Faith_pd, Dysbiosis_Index) |> | |
ggplot(aes(x = Disease_Status, y = Faith_pd)) + | |
geom_col() + | |
geom_signif(comparisons = mycompr, step_increase = 5, y_position = 1100) + | |
theme_classic() | |
``` | |
```{r} | |
serum |> select(SampleID, Disease_Status, Faith_pd, Dysbiosis_Index) |> | |
ggplot(aes(x = Disease_Status, y = Dysbiosis_Index)) + | |
geom_col() + | |
geom_signif(comparisons = mycompr, step_increase = 1, y_position = 10) + | |
theme_classic() | |
``` | |
מצורף קובץ המטהדטה של הסרומים ושל הצואות. | |
אני לא יודעת אם צריך לכל מטהדטה בנפרד או | |
שאפשר לאחד ביניהם ולבדוק את כולם ביחד, אז החלטה שלך... | |
אם אתה מצליח לעשות את זה עד שני | |
(כדי שאולי יהיה סיכוי שאני לא אצא גרועה ממש ואבקש מיעל לדחות) זה יהיה מעולה! | |
תודה רבה רבה רבה!!! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment