Skip to contents

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 class 'GDCQuery'
filter(x, expr)

get_filter(x)

# S3 method for class '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"            "cancer_dna_fraction"           
#>  [7] "channel"                        "chip_id"                       
#>  [9] "chip_position"                  "contamination"                 
#> [11] "contamination_error"            "created_datetime"              
#> [13] "data_category"                  "data_format"                   
#> [15] "data_type"                      "error_type"                    
#> [17] "experimental_strategy"          "file_autocomplete"             
#> [19] "file_id"                        "file_name"                     
#> [21] "file_size"                      "genome_doubling"               
#> [23] "imaging_date"                   "magnification"                 
#> [25] "md5sum"                         "mean_coverage"                 
#> [27] "msi_score"                      "msi_status"                    
#> [29] "pairs_on_diff_chr"              "plate_name"                    
#> [31] "plate_well"                     "platform"                      
#> [33] "proc_internal"                  "proportion_base_mismatch"      
#> [35] "proportion_coverage_10x"        "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] "subclonal_genome_fraction"      "submitter_id"                  
#> [47] "tags"                           "total_reads"                   
#> [49] "tumor_ploidy"                   "tumor_purity"                  
#> [51] "type"                           "updated_datetime"              
#> [53] "wgs_coverage"                  

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] 74575
                   
                   
files() |> filter( data_format == 'VCF'
                   & experimental_strategy=='WXS'
                   & type == 'simple_somatic_mutation') |> count()
#> [1] 74575

# 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] 74575

# OR

files() |>
  filter( data_format == 'VCF') |>
  filter( experimental_strategy == 'WXS') |>
  filter( type == 'simple_somatic_mutation') |>
  count()
#> [1] 74575

# 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"