Last active
February 21, 2023 05:13
-
-
Save siero5335/bb1e39df80d6e222b40dc2eb33109ef6 to your computer and use it in GitHub Desktop.
This file contains 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) | |
ms_dial_filter <- function(df, adduct, annotatelevel, cv) { | |
df %>% dplyr::select(`Metabolite name`, `Adduct type`, `Annotation tag (VS1.0)`, `Total score`, | |
`RT similarity`, `Average Rt(min)`, INCHIKEY , 33:ncol(df)) %>% | |
filter(`Annotation tag (VS1.0)` %in% annotatelevel) %>% | |
filter(`Adduct type` %in% adduct) %>% | |
mutate(qc_mean = rowMeans(dplyr::select(., contains("QC")))) %>% | |
filter(qc_mean != 0) %>% | |
mutate(qc_cv = apply(dplyr::select(., contains("QC")), 1, sd)/ qc_mean * 100) %>% | |
group_by(`Metabolite name`, qc_mean) %>% | |
arrange(desc(qc_mean)) %>% | |
ungroup() %>% | |
distinct(`Metabolite name`, .keep_all = T) %>% | |
group_by(INCHIKEY, qc_mean) %>% | |
arrange(desc(qc_mean)) %>% | |
ungroup() %>% | |
distinct(INCHIKEY, .keep_all = T) %>% | |
filter(qc_cv < cv) | |
} | |
### Demo | |
# df <- read_tsv("hoge.txt", skip = 4) #exported file from MS-dial | |
# posi_adduct <- unique(df1$`Adduct type`) | |
# annotate_level <- c(400, 410, 420, 430) | |
# tmp <- ms_dial_filter(df, annotatelevel = annotate_level, adduct = posi_adduct, cv = 30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a function to filter aligned text output from MS-dial (Ver4.8.0).
Requires tidyverse package.
File name for QC must contain "QC"