Skip to content

Instantly share code, notes, and snippets.

@thanhleviet
Created July 22, 2021 17:28
Show Gist options
  • Save thanhleviet/cf12bfcdae56ccfea88d78769a6de660 to your computer and use it in GitHub Desktop.
Save thanhleviet/cf12bfcdae56ccfea88d78769a6de660 to your computer and use it in GitHub Desktop.
R script to manipulate data
library(tidyverse)
library(data.table)
library(janitor)
csv <- fread("Ebenn_code_data_21Jul21_18.08.csv")
features <- names(csv)[-c(1,2,4)]
sample_names <- csv$Name %>%
gsub("_flye_[a-z\\_]*|_hybrid","",.) %>%
unique()
compare_list <- list()
i <- 0
for (sample in sample_names) {
pilot_sample <- csv %>%
filter(grepl(sample, Name)) %>%
select(-2,-4) %>%
transpose() %>%
row_to_names(row_number = 1) %>%
mutate(features = features) %>%
select(features, contains("hybrid"), everything()) %>%
mutate_all(.funs = toupper) %>%
mutate(across(contains("flye"), .fns = function(x) x == cur_data()[2])) %>%
summarise(across(contains("flye"), sum)) %>%
mutate(sample = sample) %>%
select(sample, everything()) %>%
setNames(c("sample","flye_accurate","flye_accurate_medaka","flye_accurate_medaka_pilon","flye_fast","flye_fast_medaka"))
print(pilot_sample)
i = i + 1
compare_list[[i]] <- pilot_sample
}
compare_df <- bind_rows(compare_list) %>%
mutate(across(contains("flye"), .fns = function(x) x/99))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment