Created
July 22, 2021 17:28
-
-
Save thanhleviet/cf12bfcdae56ccfea88d78769a6de660 to your computer and use it in GitHub Desktop.
R script to manipulate data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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