Last data update: 2014.03.03

R: Builtin queries to add additional annotation to a BuxcoDB...
Additional annotation queriesR Documentation

Builtin queries to add additional annotation to a BuxcoDB database

Description

These functions take BuxcoDB objects as input and return an SQL query (in the SQLite dialect) which results in the creation of a table containing additional annotation that is not parsed from the Buxco CSV file. These annotations are meant to be categorical labels such as whether a datapoint was part of an acclimation or experimental run which may not necessarily be encoded directly in the Buxco CSV file. A user can also specify functions in this form to add custom annotations to the database. Typically the end user does not need to call these functions directly, instead they are supplied to the code argument of the addAnnotation method. This method then calls the function internally in the process of generating the annotation table.

Currently implemented queries are:

day.infer.query: Computes the number of days past the first observed timestamp for a given sample. This day assignment should be compared to the experimental timepoint potentially recorded in the 'Phase' element of the Buxco CSV file. This value will exist as the 'Rec_Exp_date' column of the data.frame returned by retrieveData.

break.type.query: Labels each datapoint as belonging to one of several categories. Typically each datapoint would be part of the 'ACC' or 'EXP' groups corresponding to acclimation or experimental readings. The assignment of these categories is based on observations regarding the current breakpoint number relative to the number of breakpoints observed for a given sample and given day. Typically the acclimation readings are reported first followed by the experimental readings. Additionally, 'UNK' or 'ERR' indicate deviations from the expected sample-breakpoint relationships. Specifically, 'UNK' refers to the case where only one breakpoint was observed for that animal and day so the category is unknown. The presence of 'ERR' categories indicate potential issues with how the data was parsed and should be reported to the package author for investigation. NOTE: Currently, day.infer.query needs to be run prior to this query as it draws upon the computed date as opposed to the labeled date.

Usage

break.type.query(obj)
day.infer.query(obj)

Arguments

obj

A BuxcoDB object.

Value

A character string representing an SQL query.

Author(s)

Daniel Bottomly

References

http://www.sqlite.org/

See Also

BuxcoDB

Examples

	

samp.file <- sample.db.path()
new.file <- file.path(tempdir(), basename(samp.file))

stopifnot(file.copy(samp.file, new.file, overwrite=TRUE))

bux.db <- makeBuxcoDB(new.file)

head(retrieveData(bux.db))

#query used to compute experiment day relative to the initial timepoint.
day.infer.query(bux.db)

addAnnotation(bux.db, query=day.infer.query)

head(retrieveData(bux.db))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(plethy)
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/plethy/add_query_funcs.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Additional annotation queries
> ### Title: Builtin queries to add additional annotation to a BuxcoDB
> ###   database
> ### Aliases: break.type.query day.infer.query
> ### Keywords: utilities
> 
> ### ** Examples
> 	
> 
> samp.file <- sample.db.path()
> new.file <- file.path(tempdir(), basename(samp.file))
> 
> stopifnot(file.copy(samp.file, new.file, overwrite=TRUE))
> 
> bux.db <- makeBuxcoDB(new.file)
> 
> head(retrieveData(bux.db))
   Sample_Name              P_Time Break_sec_start Variable_Name Bux_table_Name
1 8034x13140_5 2012-09-28 10:07:17               0             f          WBPth
2 8034x13140_5 2012-09-28 10:07:17               0           TVb          WBPth
3 8034x13140_5 2012-09-28 10:07:17               0           MVb          WBPth
4 8034x13140_5 2012-09-28 10:07:17               0          Penh          WBPth
5 8034x13140_5 2012-09-28 10:07:17               0           PAU          WBPth
6 8034x13140_5 2012-09-28 10:07:17               0          Rpef          WBPth
  Rec_Exp_date Break_number       Value
1          D-3            1 384.3611755
2          D-3            1   0.1556593
3          D-3            1  59.8293839
4          D-3            1   0.5106936
5          D-3            1   1.6047863
6          D-3            1   0.0828647
> 
> #query used to compute experiment day relative to the initial timepoint.
> day.infer.query(bux.db)
[1] "SELECT Break_Chunk_ID, ROUND(STRFTIME('%J', P_Time) - Min_time) AS Days FROM Timepoint JOIN Chunk_Time USING (Time_ID) JOIN (SELECT Sample_ID, MIN(STRFTIME('%J', P_Time)) AS Min_time FROM Timepoint JOIN Chunk_Time USING (Time_ID) GROUP BY Sample_ID)  USING (Sample_ID)"
> 
> addAnnotation(bux.db, query=day.infer.query)
[1] TRUE
> 
> head(retrieveData(bux.db))
   Sample_Name              P_Time Break_sec_start Variable_Name Bux_table_Name
1 8034x13140_5 2012-09-28 10:07:17               0             f          WBPth
2 8034x13140_5 2012-09-28 10:07:17               0           TVb          WBPth
3 8034x13140_5 2012-09-28 10:07:17               0           MVb          WBPth
4 8034x13140_5 2012-09-28 10:07:17               0          Penh          WBPth
5 8034x13140_5 2012-09-28 10:07:17               0           PAU          WBPth
6 8034x13140_5 2012-09-28 10:07:17               0          Rpef          WBPth
  Rec_Exp_date Break_number Days       Value
1          D-3            1    0 384.3611755
2          D-3            1    0   0.1556593
3          D-3            1    0  59.8293839
4          D-3            1    0   0.5106936
5          D-3            1    0   1.6047863
6          D-3            1    0   0.0828647
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>