Search code examples
rtransposegenetics

Transposing PCR 96 well plate to single column format


PCR plates work on a coordinate system similar to an X-Y coordinate system. I would like to convert a 96-well PCR plate from this X-Y coordinate system (row and column format) to a single column only format, combining the x-y system together (i.e Row B and Column 12 = B12).

The first dataset provided below, called "pcr_plate", is the format of a 96-well PCR plate.

The second dataset, called "sample_transposed_plate" is an example of the desired outcome.

I've tried classical approaches to transposing data, using code from the follwing packages:

library(dplyr) library(tidyr)

In addition to transform(data.frame, ... )

However, I am confused how to write a code that starts from Row A column 1:12, followed by Row B column 1:12, etc.. while keeping the respective sample (aka well) in an adjacent column

two sample working data sets:

pcr_plate <- read.table ("https://pastebin.com/raw/bGhzj5dU", header = T, sep = "")


sample_transposed_plate <- read.table ("https://pastebin.com/raw/xyzv9cvH", header=T, sep = "") # example of desired outcome

Logically, given there are 96-wells, I should have 96 lines of data in the end (97 with a header). First column would be "location", and second column would be "sample"


Solution

  • You can just use a typical gather to convert from wide to long data:

    library(tidyverse)
    pcr_plate <- read.table ("https://pastebin.com/raw/bGhzj5dU", header = T, sep = "")
    sample_transposed_plate <- read.table ("https://pastebin.com/raw/xyzv9cvH", header=T, sep = "")
    
    pcr_plate_long = pcr_plate %>%
      gather(number, content, -pcr.plate) %>%
      mutate(number = str_remove(number, "^X"),
             well_ID = paste0(pcr.plate, number)) %>%
      select(content, well_ID)