I have a dataset that contains IDs and associated Gene Ontology (GO) IDs. Some of the IDs have multiple GO IDs assigned to them, and I'm unsure how to handle this situation. I would like to determine whether Should I split all Go id or I should use the first or last GO ID in the hierarchy when assigning the GO ID to the ID.
Here is an example of my data:
3667 FEHLGCFF_05007 GO:0006637|GO:0047617
3673 FEHLGCFF_05919 GO:0016020|GO:0022857|GO:0055085
3684 FEHLGCFF_00369 GO:0022857|GO:0055085
3695 FEHLGCFF_00369 GO:0016020|GO:0022857|GO:0055085
3696 FEHLGCFF_00369 GO:0022857
3702 FEHLGCFF_06641 GO:0016627
3707 FEHLGCFF_06641 GO:0003995
3721 FEHLGCFF_04414 GO:0046872
3725 FEHLGCFF_02968 GO:0003700|GO:0006352|GO:0006355
How should I handle cases where an ID has multiple GO IDs assigned to it? Should I split all Go id or Should I use the first GO ID, the last GO ID, or is there another approach I should consider?
Any guidance or best practices would be greatly appreciated. Thank you!
Here is My code using R, it it Ok
library(tidyverse)
# Read the go-basic.obo file
go_data <- readLines("go-basic.obo")
# Extract the GO ID and Gene ID from the unique_data dataframe
unique_data <- unique_data %>%
separate_rows(GO_ID, sep = "\\|") %>%
select(V1, GO_ID) # Replace with the correct column names from your unique_data dataframe
# Create an empty dataframe to store the results
result <- data.frame(Gene_ID = character(), GO_ID = character(), Name = character(), Namespace = character(), stringsAsFactors = FALSE)
# Process each line in the go-basic.obo file
for (i in 1:(length(go_data) - 1)) {
line <- go_data[i]
if (grepl("^id:", line)) {
go_id <- strsplit(line, " ")[[1]][2]
# Check if the current GO ID exists in the unique_data dataframe
if (go_id %in% unique_data$GO_ID) {
# Filter the unique_data dataframe for the current GO ID
filtered_data <- unique_data %>% filter(GO_ID == go_id)
# Extract the name and namespace information
name <- ""
namespace <- ""
while (!grepl("^is_a:", go_data[i])) {
if (grepl("^name:", go_data[i])) {
name <- strsplit(go_data[i], "name: ")[[1]][2]
} else if (grepl("^namespace:", go_data[i])) {
namespace <- strsplit(go_data[i], "namespace: ")[[1]][2]
}
i <- i + 1
}
# Add the information to the result dataframe
temp_df <- data.frame(Gene_ID = filtered_data$V1, GO_ID = go_id, Name = name, Namespace = namespace, stringsAsFactors = FALSE) # Replace with the correct column names
result <- bind_rows(result, temp_df)
}
}
}
# Print the result dataframe
result
nrow(result)