Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #27 convert to gwasglue2 summaryset inside gwasvcf package #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Package: gwasvcf
Title: Tools for Dealing with GWAS Summary Data in VCF Format
Version: 0.1.1
Version: 0.1.2
Authors@R: c(
person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0920-1055")),
person("Tom", "Palmer", , "tom.palmer@bristol.ac.uk", role = "ctb",
comment = c(ORCID = "0000-0003-4655-4511"))
comment = c(ORCID = "0000-0003-4655-4511")),
person("Rita", "Rasteiro", , "rita.rasteiro@bristol.ac.uk", role = "ctb",
comment = c(ORCID = "0000-0002-4217-3060"))
)
Description: Tools for dealing with GWAS summary data in VCF format.
Includes reading, querying, writing, as well as helper functions such
Expand All @@ -23,6 +25,7 @@ Imports:
genetics.binaRies,
GenomeInfoDb,
GenomicRanges,
gwasglue2,
IRanges,
magrittr,
RCurl,
Expand All @@ -41,7 +44,9 @@ Suggests:
VignetteBuilder:
knitr
Remotes:
github::mrcieu/genetics.binaRies
github::mrcieu/genetics.binaRies,
github::mrcieu/gwasglue2
Encoding: UTF-8
RoxygenNote: 7.2.2
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
SystemRequirements: GNU unzip
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(create_rsidx_index_from_vcf)
export(create_rsidx_sub_index)
export(create_vcf)
export(get_ld_proxies)
export(gwasvcf_to_summaryset)
export(merge_vcf)
export(parse_chrompos)
export(proxy_match)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# gwasvcf 0.1.2

* New `gwasvcf_to_summaryset()` function to create a [gwasglue2](https://mrcieu.github.io/gwasglue2) SummarySet object from a vcf file
* Fixed error in `get_ld_proxies()` related with argument `validate`, deprecated in `as_tibble()` (tibble 2.0.0)
21 changes: 21 additions & 0 deletions R/gwasglue.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file contains the functions to create a gwasglue2 SummarySet object



#' Create a SummarySet
#'
#' Returns a gwasglue2 SummarySet object
#' @param vcf Path or URL to GWAS-VCF file or VCF object e.g. output from [VariantAnnotation::readVcf()], [create_vcf()] or [query_gwas()]
#' @export
gwasvcf_to_summaryset <- function(vcf){
# get metadata from vcf and create metadata object
md <- gwasglue2::create_metadata(id = vcf@metadata$header@samples, build = unique(VariantAnnotation::meta(header(vcf))$contig$assembly))

# get summary data and create SummarySet

s <- vcf %>%
vcf_to_tibble() %>%
gwasglue2::create_summaryset_from_gwasvcf(metadata = md)

return(s)
}
2 changes: 1 addition & 1 deletion R/manipulate.r
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ vcf_to_tibble <- function(vcf, id=NULL)
return(dplyr::tibble())
}
S4Vectors::values(a)[["rsid"]] <- names(a)
return(dplyr::as_tibble(a))
return(dplyr::as_tibble(a, .name_repair = "minimal"))
}


Expand Down
12 changes: 6 additions & 6 deletions R/proxy.r
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ get_ld_proxies <- function(rsid, bfile, searchspace=NULL, tag_kb=5000, tag_nsnp=
return(ld)
}
ld <- data.table::fread(paste0("gunzip -c ", outname), header=TRUE) %>%
dplyr::as_tibble() %>%
dplyr::as_tibble(.name_repair="minimal") %>%
dplyr::filter(.data[["R"]]^2 > tag_r2) %>%
dplyr::filter(.data[["SNP_A"]] != .data[["SNP_B"]]) %>%
dplyr::mutate(PHASE=gsub("/", "", .data[["PHASE"]])) %>%
Expand All @@ -70,9 +70,9 @@ get_ld_proxies <- function(rsid, bfile, searchspace=NULL, tag_kb=5000, tag_nsnp=
message("No proxies found")
return(ld)
}
temp <- do.call(rbind, strsplit(ld[["PHASE"]], "")) %>% dplyr::as_tibble(.data, .name_repair="minimal")
temp <- do.call(rbind, strsplit(ld[["PHASE"]], "")) %>% dplyr::as_tibble(.name_repair="minimal")
names(temp) <- c("A1", "B1", "A2", "B2")
ld <- cbind(ld, temp) %>% dplyr::as_tibble(.data, .name_repair="minimal")
ld <- cbind(ld, temp) %>% dplyr::as_tibble(.name_repair="minimal")
# ld <- dplyr::arrange(ld, desc(abs(R))) %>%
# dplyr::filter(!duplicated(SNP_A))
ld <- dplyr::arrange(ld, dplyr::desc(abs(.data[["R"]])))
Expand All @@ -99,16 +99,16 @@ sqlite_ld_proxies <- function(rsids, dbfile, tag_r2)
numid <- gsub("rs", "", rsids) %>% paste(collapse=",")
query <- paste0("SELECT DISTINCT * FROM tags WHERE SNP_A IN (", numid, ")")
ld <- RSQLite::dbGetQuery(conn, query) %>%
dplyr::as_tibble() %>%
dplyr::as_tibble(.name_repair="minimal") %>%
dplyr::filter(.data[["R"]]^2 > tag_r2) %>%
dplyr::filter(.data[["SNP_A"]] != .data[["SNP_B"]]) %>%
dplyr::mutate(PHASE=gsub("/", "", .data[["PHASE"]])) %>%
dplyr::filter(nchar(.data[["PHASE"]]) == 4) %>%
dplyr::mutate(SNP_A = paste0("rs", .data[["SNP_A"]]), SNP_B = paste0("rs", .data[["SNP_B"]]))

temp <- do.call(rbind, strsplit(ld[["PHASE"]], "")) %>% dplyr::as_tibble(.data, .name_repair="minimal")
temp <- do.call(rbind, strsplit(ld[["PHASE"]], "")) %>% dplyr::as_tibble(.name_repair="minimal")
names(temp) <- c("A1", "B1", "A2", "B2")
ld <- cbind(ld, temp) %>% dplyr::as_tibble(.data, .name_repair="minimal")
ld <- cbind(ld, temp) %>% dplyr::as_tibble(.name_repair="minimal")
ld <- dplyr::arrange(ld, dplyr::desc(abs(.data[["R"]])))
message("Found ", nrow(ld), " proxies")
RSQLite::dbDisconnect(conn)
Expand Down
2 changes: 1 addition & 1 deletion R/pval_index.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Create pval index from GWAS-VCF file
#'
#' Create a separate file called <id>.pvali which is used to speed up p-value queries
#' Create a separate file called `<id>.pvali` which is used to speed up p-value queries.
#'
#' @param vcffile VCF filename
#' @param maximum_pval Maximum p-value to include. Default = 0.05
Expand Down
2 changes: 1 addition & 1 deletion R/query.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Read in GWAS summary data with filters on datasets (if multiple datasets per file) and/or chromosome/position, rsids or pvalues. Chooses most optimal choice for the detected operating system. Typically chrompos searches are the fastest. On Windows, rsid or pvalue filters from a file will be slow.
#'
#' @param vcf Path or URL to GWAS-VCF file or VCF object e.g. output from VariantAnnotation::readVcf or gwasvcftools::query_vcf
#' @param vcf Path or URL to GWAS-VCF file or VCF object e.g. output from [VariantAnnotation::readVcf()] or [create_vcf()]
#' @param chrompos Either vector of chromosome and position ranges e.g. "1:1000" or "1:1000-2000", or data frame with columns `chrom`, `start`, `end`.
#' @param rsid Vector of rsids
#' @param pval P-value threshold (NOT -log10)
Expand Down
2 changes: 1 addition & 1 deletion man/create_pval_index_from_vcf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/gwasvcf_to_summaryset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/parse_chrompos.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/query_chrompos_bcftools.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/query_chrompos_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/query_chrompos_vcf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/query_gwas.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/vcflist_overlaps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vignettes/guide.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,19 @@ writeVcf(out, file="temp.vcf")
```

You may want to first harmonise the data so that all the non-effect alleles are aligned to the human genome reference. See the [gwasglue](https://github.com/MRCIEU/gwasglue) package on some functions to do this.

## Creating a gwasglue2 SummarySet object from a vcf file

Although still under development, if compared with its predecessor, the [gwasglue2](https://mrcieu.github.io/gwasglue2/) package has several new features, including the use of S4 R objects.

It is possible to create a `SummarySet` object from a GWAS-VCF file or VCF object e.g. output from `VariantAnnotation::readVcf()`, `create_vcf()` or `query_gwas()` using the `gwasvcf_to_summaryset()` function.


For example:

```{r, eval=FALSE}
summaryset <- readVcf(vcffile) %>%
gwasvcf_to_summaryset()
```

Once the `SummarySet` objects are created, it is possible to use `gwasglue2` to harmonise data, harmonise against a LD matrix, remap genomic coordinates to a different genome assembly, convert to other formats and more.
Loading