-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added getVariantPopData & convertVariantIds
- Loading branch information
1 parent
a71fdc7
commit f5f8e34
Showing
11 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#' @title Get variant IDs for alternate reference genome | ||
#' @inheritParams pkgParams | ||
#' @param genomes The genome associated with the given variant_id | ||
#' @description | ||
#' Returns the variant_id(s) for the alternate reference genome | ||
#' | ||
#' @return variant_id(s) | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' convertVariantIds(varids = '1-89388944-A-C', genomes = "GRCh37") | ||
#' } | ||
#' | ||
#' @import ghql | ||
#' @importFrom glue glue glue_collapse | ||
#' @importFrom jsonlite fromJSON | ||
#' @export | ||
|
||
convertVariantIds <- function(varids, genomes) { | ||
stopifnot(validGenomes(genomes)) | ||
gmCon <- GraphqlClient$new(url = apiUrl()) | ||
datasets <- getDatasets(genomes) | ||
idnames <- getLiftoverIdName(genomes) | ||
tmp <- | ||
' | ||
{genomes}_{gsub("-", "_", varids)}: | ||
liftover({idnames}: "{varids}", reference_genome: {genomes}) {{ | ||
source {{ | ||
variant_id | ||
reference_genome | ||
}} | ||
liftover {{ | ||
variant_id | ||
reference_genome | ||
}} | ||
}} | ||
' | ||
qryBody <- glue_collapse(glue(tmp), sep = "\n") | ||
qry <- Query$new()$query('convertIds', | ||
glue('query convertIds {{ {qryBody} }}')) | ||
tryres <- try(jsn <- gmCon$exec(qry$convertIds), silent = TRUE) | ||
if (is(tryres, 'try-error')) stop(qfailmessage) | ||
res <- fromJSON(jsn, flatten = TRUE)$data | ||
res | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#' @title Get variant population data | ||
#' @inheritParams pkgParams | ||
#' @param genomes The genome(s) associated with the given variant_id | ||
#' @description | ||
#' Returns the variant_id(s) for the alternate reference genome | ||
#' | ||
#' @return List of population data for the given variant_id(s) | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' getVariantPopData(varids = '1-88923261-A-C', genomes = "GRCh38") | ||
#' } | ||
#' | ||
#' @import ghql | ||
#' @importFrom glue glue glue_collapse | ||
#' @importFrom jsonlite fromJSON | ||
#' @export | ||
|
||
getVariantPopData <- function(varids, genomes) { | ||
stopifnot(validGenomes(genomes)) | ||
gmCon <- GraphqlClient$new(url = apiUrl()) | ||
datasets <- getDatasets(genomes) | ||
tmp <- | ||
' | ||
{genomes}_{gsub("-", "_", varids)}: | ||
variant(variantId: "{varids}", dataset: {datasets}) {{ | ||
variantId | ||
chrom | ||
pos | ||
genome {{ | ||
populations {{ | ||
id | ||
ac | ||
an | ||
homozygote_count | ||
hemizygote_count | ||
}} | ||
}} | ||
}} | ||
' | ||
qryBody <- glue_collapse(glue(tmp), sep = "\n") | ||
qry <- Query$new()$query('convertIds', | ||
glue('query convertIds {{ {qryBody} }}')) | ||
tryres <- try(jsn <- gmCon$exec(qry$convertIds), silent = TRUE) | ||
if (is(tryres, 'try-error')) stop(qfailmessage) | ||
resLst <- fromJSON(jsn, flatten = TRUE)$data | ||
procPopData <- function(x) { | ||
cbind(varid = x$variantId, | ||
chrom = x$chrom, | ||
pos = x$pos, | ||
x$genome$populations) | ||
} | ||
res <- lapply(resLst, procPopData) | ||
res | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.