Book Image

R Bioinformatics Cookbook - Second Edition

By : Dan MacLean
Book Image

R Bioinformatics Cookbook - Second Edition

By: Dan MacLean

Overview of this book

The updated second edition of R Bioinformatics Cookbook takes a recipe-based approach to show you how to conduct practical research and analysis in computational biology with R. You’ll learn how to create a useful and modular R working environment, along with loading, cleaning, and analyzing data using the most up-to-date Bioconductor, ggplot2, and tidyverse tools. This book will walk you through the Bioconductor tools necessary for you to understand and carry out protocols in RNA-seq and ChIP-seq, phylogenetics, genomics, gene search, gene annotation, statistical analysis, and sequence analysis. As you advance, you'll find out how to use Quarto to create data-rich reports, presentations, and websites, as well as get a clear understanding of how machine learning techniques can be applied in the bioinformatics domain. The concluding chapters will help you develop proficiency in key skills, such as gene annotation analysis and functional programming in purrr and base R. Finally, you'll discover how to use the latest AI tools, including ChatGPT, to generate, edit, and understand R code and draft workflows for complex analyses. By the end of this book, you'll have gained a solid understanding of the skills and techniques needed to become a bioinformatics specialist and efficiently work with large and complex bioinformatics datasets.
Table of Contents (16 chapters)

Working with lists in purrr

Lists are incredibly useful data structures that allow you to store and organize various types of objects, such as vectors, matrices, dataframes, and even other lists. Unlike vectors, matrices, or dataframes, lists can accommodate different data types and structures within a single object. This flexibility makes them a powerful tool for data manipulation and analysis in R.

As a result the purrr package provides lots of functions for working with lists, and in this short recipe, we’ll look at a few for summarizing, simplifying, and extracting data.

Getting ready

We’ll just need the purrr package.

How to do it…

We can manipulate lists in purrr using the following functions:

  1. Filter a list of elements:
    set.seed(2345)l <- list(  a = rnorm(10, mean = 1),  b = rnorm(10, mean = 10),  c = rnorm(10, mean = 20))library(purrr)keep(l, function(x) mean(x) >= 10)keep(l, ~ mean(.x) >= 10)detect_index...