Upload pull_gse65682.R with huggingface_hub
Browse files- pull_gse65682.R +136 -0
pull_gse65682.R
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Version info: R 4.2.2, Biobase 2.58.0, GEOquery 2.66.0, limma 3.54.0
|
| 2 |
+
################################################################
|
| 3 |
+
# Data plots for selected GEO samples
|
| 4 |
+
library(GEOquery)
|
| 5 |
+
library(limma)
|
| 6 |
+
library(hgu219.db)
|
| 7 |
+
library(umap)
|
| 8 |
+
library(here)
|
| 9 |
+
library(tidyverse)
|
| 10 |
+
|
| 11 |
+
# load series and platform data from GEO
|
| 12 |
+
|
| 13 |
+
dir.create("data/gse65682")
|
| 14 |
+
gset <- getGEO("GSE65682", destdir = "data/gse65682", GSEMatrix = TRUE, getGPL = FALSE)
|
| 15 |
+
if (length(gset) > 1) idx <- grep("GPL13667", attr(gset, "names")) else idx <- 1
|
| 16 |
+
gset <- gset[[idx]]
|
| 17 |
+
|
| 18 |
+
ex <- exprs(gset)
|
| 19 |
+
# log2 transform
|
| 20 |
+
qx <- as.numeric(quantile(ex, c(0., 0.25, 0.5, 0.75, 0.99, 1.0), na.rm = T))
|
| 21 |
+
LogC <- (qx[5] > 100) ||
|
| 22 |
+
(qx[6] - qx[1] > 50 && qx[2] > 0)
|
| 23 |
+
if (LogC) {
|
| 24 |
+
ex[which(ex <= 0)] <- NaN
|
| 25 |
+
ex <- log2(ex)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# box-and-whisker plot
|
| 29 |
+
dev.new(width = 3 + ncol(gset) / 6, height = 5)
|
| 30 |
+
par(mar = c(7, 4, 2, 1))
|
| 31 |
+
title <- paste("GSE65682", "/", annotation(gset), sep = "")
|
| 32 |
+
boxplot(ex, boxwex = 0.7, notch = T, main = title, outline = FALSE, las = 2)
|
| 33 |
+
dev.off()
|
| 34 |
+
|
| 35 |
+
# expression value distribution plot
|
| 36 |
+
par(mar = c(4, 4, 2, 1))
|
| 37 |
+
title <- paste("GSE65682", "/", annotation(gset), " value distribution", sep = "")
|
| 38 |
+
plotDensities(ex, main = title, legend = F)
|
| 39 |
+
|
| 40 |
+
# mean-variance trend
|
| 41 |
+
ex <- na.omit(ex) # eliminate rows with NAs
|
| 42 |
+
plotSA(lmFit(ex), main = "Mean variance trend, GSE65682")
|
| 43 |
+
|
| 44 |
+
# UMAP plot (multi-dimensional scaling)
|
| 45 |
+
ex <- ex[!duplicated(ex), ] # remove duplicates
|
| 46 |
+
ump <- umap(t(ex), n_neighbors = 15, random_state = 123)
|
| 47 |
+
plot(ump$layout, main = "UMAP plot, nbrs=15", xlab = "", ylab = "", pch = 20, cex = 1.5)
|
| 48 |
+
|
| 49 |
+
clean_char <- function(x, prefix_regex) {
|
| 50 |
+
val <- str_squish(str_remove(x, prefix_regex))
|
| 51 |
+
na_if(val, "NA")
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
pdat_mars <- as_tibble(pData(gset), rownames = "sample_id") |>
|
| 55 |
+
select(sample_id, starts_with("characteristics"))
|
| 56 |
+
|
| 57 |
+
purrr::imap(pdat_mars |> select(-sample_id), ~ count(tibble(value = .x), value, name = "n") |> arrange(desc(n)))
|
| 58 |
+
|
| 59 |
+
gse65682_metadata <- as_tibble(pData(gset), rownames = "sample_id") |>
|
| 60 |
+
mutate(
|
| 61 |
+
healthy_control = str_detect(title, "healthy"),
|
| 62 |
+
title_date = str_extract(title, "\\d\\d_\\d{2}_\\d{4}"),
|
| 63 |
+
title_identifier1 = str_extract(title, "(?<=\\d{2}_\\d{2}_\\d{4}_)\\w\\d+"),
|
| 64 |
+
title_identifier2 = str_extract(title, "\\d+(?=\\])"),
|
| 65 |
+
sex = clean_char(characteristics_ch1, "^gender:\\s*"),
|
| 66 |
+
age = as.numeric(clean_char(characteristics_ch1.1, "^age:\\s*")),
|
| 67 |
+
pneumonia_diagnosis = clean_char(characteristics_ch1.2, "^pneumonia diagnoses:\\s*"),
|
| 68 |
+
thrombocytopenia = clean_char(characteristics_ch1.3, "^thrombocytopenia:\\s*"),
|
| 69 |
+
endotype_cohort = clean_char(characteristics_ch1.4, "^endotype_cohort:\\s*"),
|
| 70 |
+
endotype_class = clean_char(characteristics_ch1.5, "^endotype_class:\\s*"),
|
| 71 |
+
mortality_28d = as.logical(as.integer(clean_char(characteristics_ch1.6, "^mortality_event_28days:\\s*"))),
|
| 72 |
+
time_to_event_28d = as.numeric(clean_char(characteristics_ch1.7, "^time_to_event_28days:\\s*")),
|
| 73 |
+
icu_acquired_infection = clean_char(characteristics_ch1.8, "^icu_acquired_infection:\\s*"),
|
| 74 |
+
icu_acquired_infection_paired = clean_char(characteristics_ch1.9, "^icu_acquired_infection_paired:\\s*"),
|
| 75 |
+
diabetes_mellitus = clean_char(characteristics_ch1.10, "^diabetes_mellitus:\\s*"),
|
| 76 |
+
abdominal_sepsis_or_control = clean_char(characteristics_ch1.11, "^abdominal_sepsis_and_controls:\\s*")
|
| 77 |
+
) |>
|
| 78 |
+
dplyr::select(
|
| 79 |
+
sample_id, title_identifier1, title_identifier2, healthy_control, sex,
|
| 80 |
+
age, pneumonia_diagnosis, thrombocytopenia, endotype_cohort, endotype_class,
|
| 81 |
+
mortality_28d, time_to_event_28d, icu_acquired_infection, icu_acquired_infection_paired,
|
| 82 |
+
diabetes_mellitus, abdominal_sepsis_or_control
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
stopifnot(gse65682_metadata |> filter(!is.na(endotype_class)) |> count(is.na(mortality_28d)) |> pull(n) == 479)
|
| 86 |
+
|
| 87 |
+
your_probes_mars <- rownames(exprs(gset))
|
| 88 |
+
biocu219_probes <- keys(hgu219.db, keytype = "PROBEID")
|
| 89 |
+
|
| 90 |
+
length(your_probes_mars)
|
| 91 |
+
length(biocu219_probes)
|
| 92 |
+
length(intersect(your_probes_mars, biocu219_probes))
|
| 93 |
+
stopifnot(mean(!your_probes_mars %in% biocu219_probes) == 0)
|
| 94 |
+
|
| 95 |
+
anno_u219 <- AnnotationDbi::select(
|
| 96 |
+
hgu219.db,
|
| 97 |
+
keys = your_probes_mars,
|
| 98 |
+
columns = c("SYMBOL", "ENTREZID", "ENSEMBL", "GENENAME", "UNIPROT"),
|
| 99 |
+
keytype = "PROBEID"
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
gse65682_feature_metadata <- anno_u219 |>
|
| 103 |
+
group_by(PROBEID) |>
|
| 104 |
+
reframe(
|
| 105 |
+
ENSEMBL = paste(unique(na.omit(ENSEMBL)), collapse = ";"),
|
| 106 |
+
ENTREZID = dplyr::first(ENTREZID),
|
| 107 |
+
SYMBOL = dplyr::first(SYMBOL),
|
| 108 |
+
GENENAME = dplyr::first(GENENAME),
|
| 109 |
+
UNIPROT = paste(unique(na.omit(UNIPROT)), collapse = ";")
|
| 110 |
+
) |>
|
| 111 |
+
ungroup() |>
|
| 112 |
+
mutate(across(c(ENSEMBL, UNIPROT), ~ na_if(.x, ""))) |>
|
| 113 |
+
rename(feature_id = PROBEID) |>
|
| 114 |
+
right_join(tibble(feature_id = your_probes_mars), by = "PROBEID") # guarantee every probe gets a row
|
| 115 |
+
|
| 116 |
+
stopifnot(nrow(gse65682_feature_metadata) == length(your_probes_mars))
|
| 117 |
+
stopifnot(!any(duplicated(gse65682_feature_metadata$feature_id)))
|
| 118 |
+
|
| 119 |
+
mean(is.na(gse65682_feature_metadata$SYMBOL)) # for comparison against the other datasets' rates
|
| 120 |
+
|
| 121 |
+
gse65682_expr_long <- as_tibble(exprs(gset), rownames = "feature_id") |>
|
| 122 |
+
pivot_longer(-feature_id, names_to = "sample_id", values_to = "value") |>
|
| 123 |
+
arrange(sample_id, feature_id)
|
| 124 |
+
|
| 125 |
+
stopifnot(nrow(gse65682_expr_long) == nrow(exprs(gset)) * ncol(exprs(gset)))
|
| 126 |
+
stopifnot(all(unique(gse65682_expr_long$sample_id) %in% gse65682_metadata$sample_id))
|
| 127 |
+
stopifnot(all(unique(gse65682_expr_long$PROBEID) %in% gse65682_feature_metadata$PROBEID))
|
| 128 |
+
|
| 129 |
+
stopifnot(!any(duplicated(gse65682_metadata$sample_id)))
|
| 130 |
+
stopifnot(nrow(gse65682_metadata) == 802)
|
| 131 |
+
|
| 132 |
+
dir.create("data/gse65682/parquet", recursive = TRUE, showWarnings = FALSE)
|
| 133 |
+
|
| 134 |
+
arrow::write_parquet(gse65682_metadata, "data/gse65682/parquet/sample_metadata.parquet")
|
| 135 |
+
arrow::write_parquet(gse65682_feature_metadata, "data/gse65682/parquet/feature_metadata.parquet")
|
| 136 |
+
arrow::write_parquet(gse65682_expr_long, "data/gse65682/parquet/expression.parquet")
|