Трудно ответить без дополнительной информации о ваших данных и желаемом выводе, но он гибкий и должен помочь вам начать. Предполагается, что у вас есть несколько генов, у вашего гена всегда есть |
, отделяющий его от столбца GO
, а столбцы GO
разделены запятыми. Удачи!
library(stringi)
text <- "Bcin01g00010| GO:0016491 (MF: oxidoreductase activity),GO:0003824 (MF: catalytic activity),GO:0050662^MF^coenzyme binding"
# Removing spaces
normal_spaces <- stri_replace_all_regex(text, replacement = " ", pattern = "\\s+")
# Separating the gene name
split_on_vbar <- stri_split_regex(normal_spaces, "\\|", simplify = T)
# Removing white space from the string
split_on_vbar <- trimws(split_on_vbar)
# Pasting the gene name onto the "go" anf the output is a vector
formatted_vector <- paste(split_on_vbar[,1], stri_split_fixed(split_on_vbar[,2], ",", simplify = T), sep = "|")
formatted_vector
[1] "Bcin01g00010|GO:0016491 (MF: oxidoreductase activity)" "Bcin01g00010|GO:0003824 (MF: catalytic activity)"
[3] "Bcin01g00010|GO:0050662^MF^coenzyme binding"
# Assuming you want a dataframe...
df1 <- as.data.frame(stri_split_fixed(formatted_vector, "|", simplify = T))
names(df1) <- c("Gene", "GO")
df1
Gene GO
1 Bcin01g00010 GO:0016491 (MF: oxidoreductase activity)
2 Bcin01g00010 GO:0003824 (MF: catalytic activity)
3 Bcin01g00010 GO:0050662^MF^coenzyme binding