Manipulating GDCQuery filters
The filter
is simply a safe accessor for
the filter element in GDCQuery
objects.
The get_filter
is simply a safe accessor for
the filter element in GDCQuery
objects.
Usage
filter(x, expr)
# S3 method for GDCQuery
filter(x, expr)
get_filter(x)
# S3 method for GDCQuery
get_filter(x)
Arguments
- x
the object on which to set the filter list member
- expr
a filter expression in the form of the right hand side of a formula, where bare names (without quotes) are allowed if they are available fields associated with the GDCQuery object,
x
Value
A GDCQuery
object with the filter
field replaced by specified filter expression
Examples
# make a GDCQuery object to start
#
# Projects
#
pQuery = projects()
# check for the default fields
# so that we can use one of them to build a filter
default_fields(pQuery)
#> [1] "dbgap_accession_number" "disease_type" "intended_release_date"
#> [4] "name" "primary_site" "project_autocomplete"
#> [7] "project_id" "releasable" "released"
#> [10] "state"
pQuery = filter(pQuery,~ project_id == 'TCGA-LUAC')
get_filter(pQuery)
#> $op
#> [x] "="
#>
#> $content
#> $content$field
#> [1] "project_id"
#>
#> $content$value
#> [1] "TCGA-LUAC"
#>
#>
#
# Files
#
fQuery = files()
default_fields(fQuery)
#> [1] "access" "acl"
#> [3] "average_base_quality" "average_insert_size"
#> [5] "average_read_length" "channel"
#> [7] "chip_id" "chip_position"
#> [9] "contamination" "contamination_error"
#> [11] "created_datetime" "data_category"
#> [13] "data_format" "data_type"
#> [15] "error_type" "experimental_strategy"
#> [17] "file_autocomplete" "file_id"
#> [19] "file_name" "file_size"
#> [21] "imaging_date" "magnification"
#> [23] "md5sum" "mean_coverage"
#> [25] "msi_score" "msi_status"
#> [27] "pairs_on_diff_chr" "plate_name"
#> [29] "plate_well" "platform"
#> [31] "proc_internal" "proportion_base_mismatch"
#> [33] "proportion_coverage_10X" "proportion_coverage_10x"
#> [35] "proportion_coverage_30X" "proportion_coverage_30x"
#> [37] "proportion_reads_duplicated" "proportion_reads_mapped"
#> [39] "proportion_targets_no_coverage" "read_pair_number"
#> [41] "revision" "stain_type"
#> [43] "state" "state_comment"
#> [45] "submitter_id" "tags"
#> [47] "total_reads" "tumor_ploidy"
#> [49] "tumor_purity" "type"
#> [51] "updated_datetime"
fQuery = filter(fQuery,~ data_format == 'VCF')
# OR
# with recent GenomicDataCommons versions:
# no "~" needed
fQuery = filter(fQuery, data_format == 'VCF')
get_filter(fQuery)
#> $op
#> [1] "and"
#>
#> $content
#> $content[[1]]
#> $content[[1]]$op
#> [x] "="
#>
#> $content[[1]]$content
#> $content[[1]]$content$field
#> [1] "data_format"
#>
#> $content[[1]]$content$value
#> [1] "VCF"
#>
#>
#>
#> $content[[2]]
#> $content[[2]]$op
#> [x] "="
#>
#> $content[[2]]$content
#> $content[[2]]$content$field
#> [1] "data_format"
#>
#> $content[[2]]$content$value
#> [1] "VCF"
#>
#>
#>
#>
fQuery = filter(fQuery,~ data_format == 'VCF'
& experimental_strategy == 'WXS'
& type == 'simple_somatic_mutation')
files() %>% filter(~ data_format == 'VCF'
& experimental_strategy=='WXS'
& type == 'simple_somatic_mutation') %>% count()
#> [1] 63175
files() %>% filter( data_format == 'VCF'
& experimental_strategy=='WXS'
& type == 'simple_somatic_mutation') %>% count()
#> [1] 63175
# Filters may be chained for the
# equivalent query
#
# When chained, filters are combined with logical AND
files() %>%
filter(~ data_format == 'VCF') %>%
filter(~ experimental_strategy == 'WXS') %>%
filter(~ type == 'simple_somatic_mutation') %>%
count()
#> [1] 63175
# OR
files() %>%
filter( data_format == 'VCF') %>%
filter( experimental_strategy == 'WXS') %>%
filter( type == 'simple_somatic_mutation') %>%
count()
#> [1] 63175
# Use str() to get a cleaner picture
str(get_filter(fQuery))
#> List of 2
#> $ op : chr "and"
#> $ content:List of 2
#> ..$ :List of 2
#> .. ..$ op : chr "and"
#> .. ..$ content:List of 2
#> .. .. ..$ :List of 2
#> .. .. .. ..$ op : 'scalar' chr "="
#> .. .. .. ..$ content:List of 2
#> .. .. .. .. ..$ field: chr "data_format"
#> .. .. .. .. ..$ value: chr "VCF"
#> .. .. ..$ :List of 2
#> .. .. .. ..$ op : 'scalar' chr "="
#> .. .. .. ..$ content:List of 2
#> .. .. .. .. ..$ field: chr "data_format"
#> .. .. .. .. ..$ value: chr "VCF"
#> ..$ :List of 2
#> .. ..$ op : 'scalar' chr "and"
#> .. ..$ content:List of 2
#> .. .. ..$ :List of 2
#> .. .. .. ..$ op : 'scalar' chr "and"
#> .. .. .. ..$ content:List of 2
#> .. .. .. .. ..$ :List of 2
#> .. .. .. .. .. ..$ op : 'scalar' chr "="
#> .. .. .. .. .. ..$ content:List of 2
#> .. .. .. .. .. .. ..$ field: chr "data_format"
#> .. .. .. .. .. .. ..$ value: chr "VCF"
#> .. .. .. .. ..$ :List of 2
#> .. .. .. .. .. ..$ op : 'scalar' chr "="
#> .. .. .. .. .. ..$ content:List of 2
#> .. .. .. .. .. .. ..$ field: chr "experimental_strategy"
#> .. .. .. .. .. .. ..$ value: chr "WXS"
#> .. .. ..$ :List of 2
#> .. .. .. ..$ op : 'scalar' chr "="
#> .. .. .. ..$ content:List of 2
#> .. .. .. .. ..$ field: chr "type"
#> .. .. .. .. ..$ value: chr "simple_somatic_mutation"