Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
explodecomputer committed Oct 31, 2024
1 parent 7c1cec7 commit 9f548f8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
19 changes: 13 additions & 6 deletions R/Dataset.r
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ Dataset <- R6::R6Class("Dataset", list(
stop("Are you authenticated?")
}

if(r$status_code == 200)
o <- httr::content(r)

if(is.list(o))
{
message("ID already in process: ", id)
self$metadata_uploaded <- TRUE
self$metadata <- self$api_metadata_check(id=id) %>% httr::content()
invisible(FALSE)
if("id" %in% names(o))
{
if(o$id == igd_id)
{
message("ID already in process: ", id)
self$metadata_uploaded <- TRUE
self$metadata <- o
invisible(FALSE)
}
}
}

invisible(TRUE)
},

Expand Down
19 changes: 12 additions & 7 deletions R/EbiDataset.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ EbiDataset <- R6::R6Class("EbiDataset", inherit = Dataset, list(
#' @param ftp_url Default=options()$ebi_ftp_url
#' @param outdir Default=self$wd
#' @importFrom glue glue
download_dataset = function(ftp_path=self$ftp_path, ftp_url=options()$ebi_ftp_url, outdir=self$wd)
download_dataset = function(ftp_path=self$ftp_path, outdir=self$wd, dl=TRUE)
{
dir.create(self$wd, recursive=TRUE, showWarnings=FALSE)
dir.create(outdir, recursive=TRUE, showWarnings=FALSE)
b <- basename(ftp_path)
filename <- file.path(outdir, b)
ftp <- file.path(ftp_url, ftp_path)
ftp <- file.path(ftp_path)
cmd <- glue::glue("wget -q -O {filename} {ftp}")
system(cmd)
if(dl) {
system(cmd)
}
self$filename <- filename
},

Expand Down Expand Up @@ -101,18 +103,21 @@ EbiDataset <- R6::R6Class("EbiDataset", inherit = Dataset, list(
organise_metadata = function(ebi_id=self$ebi_id, or_flag=self$or_flag, igd_id=self$igd_id, units=NULL, sex="NA", category="NA", subcategory="NA", build="HG19/GRCh37", group_name="public", traitname=self$traitname)
{
l <- list()
j <- jsonlite::read_json(paste0(options()$ebi_api, ebi_id))
# j <- jsonlite::read_json(paste0(options()$ebi_api, ebi_id))
j <- gwasrapidd::get_studies(ebi_id)

l[["id"]] <- igd_id
if(is.null(traitname))
{
l[["trait"]] <- j[["diseaseTrait"]][["trait"]]
l[["trait"]] <- j@studies[["reported_trait"]]
} else {
l[["trait"]] <- traitname
}
l[["note"]] <- ""
if(or_flag) l[["note"]] <- paste0(l[["note"]], "beta+se converted from OR+CI; ")
if(!is.null(j[["studyDesignComment"]])) paste0(l[["note"]], j[["studyDesignComment"]], "; ")
if(!is.na(j@studies[["study_design_comment"]])) {
l[["note"]] <- paste0(l[["note"]], j@studies[["study_design_comment"]], "; ")
}
l[["pmid"]] <- j[["publicationInfo"]][["pubmedId"]]
l[["year"]] <- j[["publicationInfo"]][["publicationDate"]]
if(!is.null(l[["year"]])) l[["year"]] <- strsplit(l[["year"]], split="-")[[1]][1]
Expand Down
4 changes: 2 additions & 2 deletions R/liftover.r
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ liftover_gwas <- function(dat, build=c(37,38,36), to=37, chr_col="chr", pos_col=
d19 <- rtracklayer::liftOver(datg, ch) %>% unlist()
message("Organising again")
dat <- dat[d19$ind,]
dat[[chr_col]] <- d19@seqnames
dat[[pos_col]] <- d19@ranges@start
dat[[chr_col]] <- as.character(d19@seqnames)
dat[[pos_col]] <- as.numeric(d19@ranges@start)
dat[[chr_col]] <- gsub("chr", "", dat[[chr_col]])
message("Reordering")
dat <- dat[order(dat[[chr_col]], dat[[pos_col]]), ]
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.onAttach <- function(libname, pkgname) {
options(ebi_ftp_url="ftp://ftp.ebi.ac.uk/pub/databases/gwas/summary_statistics/")
options(ebi_ftp_url="http://ftp.ebi.ac.uk/pub/databases/gwas/summary_statistics/")
options(ebi_api="https://www.ebi.ac.uk/gwas/rest/api/studies/")
options(cromwell_api="http://ieu-db-interface.epi.bris.ac.uk:8001")
# options(igd_api="http://ieu-db-interface.epi.bris.ac.uk:8082/")
Expand Down

0 comments on commit 9f548f8

Please sign in to comment.