Tool:TidyWrappers : an R package to deal with an object tbl
Entering edit mode
3.8 years ago
Chirag Parsania ★ 2.0k

Dear Biostarians,

As we all know that tidyverse has shifted the paradigm the way R was being used then and now. And therefore, it has become necessary to learn tidyverse to do efficient programming in R. For newcomers, it takes time to become familiar with tools given in tidyverse and to apply efficiently to handle genomics data. While handling the genomics data (especially feature matrix obtained from RNA-seq and ChIP-seq) on a day to day basis using several functions from tidyverse in R, I realized that one needs to write some code, again and again, to prepare the data for final plot. To overcome this, I wrote an R package TidyWrappers which help users to deal with object tbl, which is the core data structure behind tidyverse tools. TidyWrappers provides handy wrapper functions on top of dplyr verbs to get, count, convert, keep, remove and replace data from a tbl object. It contains more than 35 functions grouped into 8 different categories.

  1. tbl_convert_*
  2. tbl_count_vars_*
  3. tbl_get_vars_*
  4. tbl_keep_rows_*
  5. tbl_keep_vars_*
  6. tbl_remove_rows_*
  7. tbl_remove_vars_*
  8. tbl_replace_*

You can find TidyWrappers here

Here, I want your inputs/comments/criticisms/suggestions to improve TidyWrappers.

Here are some tricks from TidyWrappers which saves little from writing a bit of code.

 tbl <- tibble::tibble(a = letters[1:6], b = NA_character_, x = c(0,1,2,0,0,NA) , y = c(0,1,2,0,3,5) , z = c(0,1,2,0,3,5) )

  ## keep rows having  0 across all numeric columns. 

  # using dplyr
  tbl %>% dplyr::filter_if(is.numeric , dplyr::all_vars( . == 0) )

  # using TidyWrappers
  tbl %>% TidyWrappers::tbl_keep_rows_zero_all()

  ## remove rows having  0 across all numeric columns. 

  # using dplyr 
  tbl %>% dplyr::filter_if(is.numeric , dplyr::any_vars( . > 0) )

  # using TidyWrappers 
  tbl %>% TidyWrappers::tbl_remove_rows_zero_all()

  ## Convert log2 to all numeric columns optionally adding numeric fraction to original values. 

  # using dplyr 
  tbl %>% dplyr::mutate_if(is.numeric , ~ log2 (. +  1))

  # using TidyWrappers
  tbl %>% TidyWrappers::tbl_convert_log2(frac = 1)

  ## Remove columns / variables  having atleaset one NA

  # using dplyr
  tbl %>% dplyr::select_if( ~ ( ( %>% any(., na.rm = T)  %>% `!`) ) 

  # using TidyWrappers
  tbl %>% TidyWrappers::tbl_remove_vars_NA_any()

  ## Remove columns / variables  having all values are NA

  # using dplyr
  tbl %>% dplyr::select_if( ~ ( ( %>% all(., na.rm = T)  %>% `!`) ) 

  # using TidyWrappers
  tbl %>% TidyWrappers::tbl_remove_vars_NA_all()
ChIP-Seq wrappers R RNA-Seq gene-expression • 1.1k views

Login before adding your answer.

Traffic: 1761 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6