Learn R Programming

Overview

This package allows users to easily call the GA4GH API from R.

The functions are typically split into get_* and search_*. The get_* functions retrive an object from the API with a specified ID and the search_* functions post JSON to the API and retrieve the results.

Usage

The ga4gh_client function should be used to create a client to interact with the API.

client <- ga4gh_client("http://localhost", 9001)

This can then be used in the get and search functions. The %>% function from magrittr can simulate to some degree the client having methods, each method being one of the get or search functions. At the moment these functions return response objects from the httr package. Use content() to extract the content of the response as a list.

client %>% get_dataset("id") %>% content()

## find all the datasets in the Server
d <- client %>% search_datasets() %>% content()

## find all the variant sets in a dataset
var_sets <- client %>% search_variant_sets(d$datasets[[1]]$id) %>% content

## find the first 100 variants from a variant set in chromosome 1
variants <- client %>% search_variants(var_sets$variantSets[[1]]$id, reference_name = "1", page_size = 100) %>% content

Further work could include a way to parse these into a data.frame or similar R object that is easier to work with. For example:


vars_to_df <- function(vars) {
  
  l <- lapply(vars, function(x) c(unlist(x["referenceName"])[[1]], unlist(x["names"])[[1]], unlist(x["start"])[[1]], unlist(x["end"])[[1]],
                                  unlist(x["referenceBases"])[[1]], unlist(x["alternateBases"])[[1]]))
  
  df <- do.call(rbind, l) %>% data.frame(stringsAsFactors = FALSE)
  names(df) <- c("reference_name", "id", "start", "end", "reference_bases", "alternate_bases")
  df$start <- as.numeric(df$start)
  df$end <- as.numeric(df$end)
  df
}

This will turn the content of a search_variants response into a data.frame containing some of the fields. Ideally this should be more general. Work could be done to formalise each of the response objects returned from the various get and search functions. These are detailed in the interactive documentation on the GA4GH reference server http://1kgenomes.ga4gh.org/static/index.html

Copy Link

Version

Install

install.packages('Rga4gh')

Monthly Downloads

12

Version

0.1.1

License

GPL-2

Maintainer

Harry Peaker

Last Published

November 7th, 2016

Functions in Rga4gh (0.1.1)

get_feature

GET a Feature
get_ga4gh

GET an Object
get_variant_annotation_set

GET a Variant Annotation Set
get_call_set

GET a Call Set
get_dataset

GET a Dataset
get_read_group_set

GET a Read Group Set
get_rna_quantification

GET an RNA Quantification
search_bio_samples

Search for Bio Samples
get_individual

GET an Individual
post_ga4gh

POST to a GA4GH Server
get_reference_set

GET a Reference Set
get_rna_quantification_set

GET an RNA Quantification Set
ga4gh_client

GA4GH Client
get_bio_sample

GET a Bio Sample
get_variant_set

GET a Variant Set
get_expression_level

GET an Expression Level
get_variant

GET a Variant
get_feature_set

GET a Feature Set
search_call_sets

Search for Call Sets
search_datasets

Search for Datasets
search_expression_levels

Search for Expression Levels
search_feature_phenotype_associations

Search for Feature Phenotype Associations
search_feature_sets

Search for Feature Sets
search_features

Search for Features
get_read_group

GET a Read Group
search_ga4gh

Search
get_reference_id

GET a Reference
search_individuals

Search for Individuals
search_phenotype_association_sets

Search for Phenotype Association Sets
search_phenotypes

Search for Phenotypes
search_rna_quantifications

Search for RNA Quantifications
search_variant_annotation_sets

Search for Variant Annotation Sets
search_variant_annotations

Search for Variant Annotations
search_variant_sets

Search for Variant Sets
search_references

Search for References
search_read_group_sets

Search for Read Group Sets
search_rna_quantification_sets

Search for RNA Quantification Sets
search_reads

Search for Reads
search_reference_bases

Search for Reference Bases
search_reference_sets

Search for Reference Sets
search_variants

Search for Variants