knitr::opts_chunk$set(echo = TRUE)

Connect DSLite (for writing purposes)

library(dsBase)
library(dsBaseClient)
library(resourcer)
library(DSLite)
library(dsOmics)
library(dsOmicsClient)

ceneca <- newResource(
  name = "ceneca",
  url = "file://C:/Users/Gerard/OneDrive/ISGlobal/PhD/obiba-home/opal/seed/data/chr22.vcf.gz",
  format = 'VCF2GDS'
)
ceneca_covars <- newResource(
  name = "ceneca_covars",
  url = "https://raw.githubusercontent.com/isglobal-brge/brgedata/master/data/ega_synthetic_data_phenotypes.tsv",
  format = "tsv"
)
dslite.server <- newDSLiteServer(resources=list(ceneca = ceneca, ceneca_covars = ceneca_covars),
                                 config = DSLite::defaultDSConfiguration(include=c("dsBase", "resourcer", "dsOmics")))

builder <- DSI::newDSLoginBuilder()
builder$append(server = "server1", url = "dslite.server", resource = "ceneca", driver = "DSLiteDriver")
logindata.dslite.cnsim <- builder$build()

conns <- datashield.login(logindata.dslite.cnsim, assign=T, symbol = "resource")
datashield.assign.resource(conns, "resource_covars", "ceneca_covars")
datashield.assign.expr(conns = conns, symbol = "ceneca_vcf", expr = quote(as.resource.object(resource)))
datashield.assign.expr(conns = conns, symbol = "ceneca_feno", expr = quote(as.resource.data.frame(resource_covars)))

Connect Opal + Resource creation (????) For release version

library(DSI)
library(DSOpal)
library(dsBaseClient)
library(dsOmicsClient)

builder <- newDSLoginBuilder()
builder$append(server = "study1", url = "http://localhost:9980/", 
               user = "dsuser", password = "password", 
               resource = "RSRC.ceneca_vcf")

logindata <- builder$build()

conns <- datashield.login(logins = logindata, assign = TRUE, 
                          symbol = "resource")
datashield.assign.resource(conns, "resource_covars", "RSRC.ceneca_covars")
datashield.assign.expr(conns = conns, symbol = "ceneca_vcf", expr = quote(as.resource.object(resource)))
datashield.assign.expr(conns = conns, symbol = "ceneca_feno", expr = quote(as.resource.data.frame(resource_covars)))

We need to specify:

ds.colnames("ceneca_feno")

We can see IDcol = 51 and sexcol = 62

Let's search for the sex encoding

ds.table("ceneca_feno$sex")$output.list$TABLES.COMBINED_all.sources_counts

Now we have the information to assemble the GenotypeData structure on the server

ds.GenotypeData(x='ceneca_vcf', covars = 'ceneca_feno', columnId = 51, sexId = 62, 
                male_encoding = "male", female_encoding = "female", newobj.name = 'gds.Data')

PCA

ds.PCASNPS("ceneca_vcf")

Allele Frequency

al_freq <- ds.alleleFrequency("gds.Data")

Association SNP to Phenotype

ds.varLabels('gds.Data')
ds.glmSNP('rs587703534', 'Energy ~  sex', 'gds.Data', family = 'gaussian')

Stratified Association SNP to Phenotype

ds.glmSNP('rs12008773', "asthma ~ sex", 'gds.Data', family = 'binomial', strata = 'smoke')

Same pero amb regiĆ³ (Genomic Ranges)

ds.glmSNP(gr2, "asthma ~ sex", 'gds.Data', family = 'binomial')
ds.glmSNP(gr2, "asthma ~ sex", 'gds.Data', family = 'binomial', strata = 'smoke')

GWAS

ds.GWAS('gds.Data', model = asthma ~  age+country, family = 'binomial')
datashield.logout(conns)


isglobal-brge/dsOmicsClient documentation built on March 20, 2023, 3:52 p.m.