-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbGaP_all_study_info.Rmd
65 lines (62 loc) · 1.86 KB
/
dbGaP_all_study_info.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "Get info for all studies in dbGaP"
output: html_notebook
---
```{r}
source("fetch_dbgap_info.R")
```
```{r}
N <- 3809 # https://ftp.ncbi.nlm.nih.gov/dbgap/studies/
start <- 3801
end <- N
for (start in seq(1, 3701, 100)) {
end <- start+10-1
phs <- paste0("phs", stringr::str_pad(start:end, width=6, side="left", pad="0"))
dat <- lapply(phs, function(x) {
tmp <- fetch_study_xml(x)
date <- xml_release_date(tmp, version=1)
cons <- tmp %>%
xml_consent() %>%
select(-DUL) %>%
filter(consent_code != "EA") %>%
mutate(phs=x)
info <- tmp %>%
xml_info() %>%
select(-accession) %>%
mutate(parent=as.character(parent)) %>%
mutate(phs=x)
part <- xml_partners(tmp) %>%
arrange(trusted_partner) %>%
unlist(use.names=FALSE) %>%
paste(collapse=", ")
gsr <- xml_gsr(tmp) %>%
paste(collapse=", ")
vers <- xml_version(tmp) %>%
mutate(phs=x)
dars <- tryCatch({
count_dars(x, v=vers$version, p=vers$participant_set)
}, error=function(e) {
message(x, ": error in fetching DARs")
return(NA)
})
cons %>%
left_join(info, by="phs") %>%
left_join(vers, by="phs") %>%
mutate(release_date = date,
num_DARs = dars,
trusted_partner = part,
GSR = gsr) %>%
relocate(phs, version, participant_set)
}) %>%
bind_rows()
saveRDS(dat, file=paste0("dbGaP_study_consent_", start, ".rds"))
}
```
```{r}
files <- list.files(pattern="dbGaP_study_consent_")
dat <- lapply(files, readRDS) %>%
bind_rows() %>%
arrange(phs)
saveRDS(dat, "dbGaP_study_consent.rds")
write_tsv(dat, "dbGaP_study_consent.txt", na="")
```