Analysis of pairwise competition

Author

Shane Hogle

Published

July 4, 2025

Abstract
Here we compile the amplicon sequencing outputs from all the different batches for later analysis.

1 Setup

1.1 Libraries

Show/hide code
library(tidyverse)
library(here)

1.2 Global variables

Show/hide code
data_raw <- here::here("_data_raw", "communities")
data <- here::here("data", "communities")
# make processed data directory if it doesn't exist
fs::dir_create(data)

2 Read data

2.1 Compiled pairs data

Show/hide code
bind_rows(read_tsv(here::here(data, "20240711_BTK_illumina_v3", "pairs_counts.tsv"), col_types = "cccddddddccc"),
          read_tsv(here::here(data, "20241024_BTK_illumina_v3", "pairs_counts.tsv"), col_types = "cccddddddccc"),
          ) %>% 
  # these steps ensure we don't get duplicates of some masterplate samples sequenced again in the second batch
  # filtering to keep samples closest to the target f value
  mutate(del_f = abs(f_thresh-target_f_masterplate)) %>% 
  group_by(sample, strainID) %>% 
  filter(if_else(community_type == "masterplate", del_f == min(del_f), TRUE )) %>% 
  ungroup() %>% 
  dplyr::select(-del_f) %>% 
  write_tsv(here::here(data, "2sps_compiled_9010.tsv"))
  
read_tsv(here::here(data, "20250502_BTK_illumina_v3", "pairs_counts.tsv"), col_types = "cccddddddccc") %>% 
  write_tsv(here::here(data, "2sps_compiled_5050.tsv"))

2.2 Compiled trios data

Show/hide code
bind_rows(read_tsv(here::here(data, "20240711_BTK_illumina_v3", "trios_counts.tsv"), col_types = "cccddddddccc"),
          read_tsv(here::here(data, "20241024_BTK_illumina_v3", "trios_counts.tsv"), col_types = "cccddddddccc"),
          read_tsv(here::here(data, "20250127_BTK_illumina_v3", "trios_counts.tsv"), col_types = "cccddddddccc"),
          read_tsv(here::here(data, "20250502_BTK_illumina_v3", "trios_counts.tsv"), col_types = "cccddddddccc")) %>% 
  write_tsv(here::here(data, "3sps_compiled.tsv"))

2.3 Compiled quartets data

Show/hide code
bind_rows(read_tsv(here::here(data, "20241024_BTK_illumina_v3", "quartets_counts.tsv"), col_types = "cccddddddccc"),
          read_tsv(here::here(data, "20250127_BTK_illumina_v3", "quartets_counts.tsv"), col_types = "cccddddddccc")) %>% 
  write_tsv(here::here(data, "4sps_compiled.tsv"))

2.4 Compiled octets data

Show/hide code
read_tsv(here::here(data, "20250502_BTK_illumina_v3", "octets_counts.tsv"), col_types = "ccdddcdddddccc") %>% 
  write_tsv(here::here(data, "8sps_compiled.tsv"))