Answers.Body: <p>You might want to look at <a href="http://revigo.irb.hr" rel="nofollow noreferrer">Revigo</a> to simplify multiple GO terms into their parent terms. I've used <a href="https://bioconductor.org/packages/release/bioc/html/rrvgo.html" rel="nofollow noreferrer">rrvgo</a> extensively to simplify enrichment results - this is the R implementation of Revigo.</p>
  <p>It's not clear how exactly you are obtaining these GO assignments. If these are the significant hits for each feature, I'd take the union of all significant GO terms (i.e. everything in your second column combined) and pass it to rrvgo. Then, you can select the parent term associated with each row. I don't guarantee each row will be collapsed to a single term, but it should make whatever you are doing downstream much more tractable.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-18T21:04:43.447Z
Answers.LastActivityDate: 2023-07-18T21:07:41.477Z
Answers.LastEditDate: 2023-07-18T21:07:41.477Z
Answers.UserDisplayName: Ricardo A.
Body: <p>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.</p>
  <p>Here is an example of my data:</p>
  <pre><code>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
  </code></pre>
  <p>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?</p>
  <p>Any guidance or best practices would be greatly appreciated. Thank you!</p>
  <p>Here is My code using R, it it Ok</p>
  <pre><code>library(tidyverse)
  
  # Read the go-basic.obo file
  go_data &lt;- readLines(&quot;go-basic.obo&quot;)
  
  # Extract the GO ID and Gene ID from the unique_data dataframe
  unique_data &lt;- unique_data %&gt;%
    separate_rows(GO_ID, sep = &quot;\\|&quot;) %&gt;%
    select(V1, GO_ID) # Replace with the correct column names from your unique_data dataframe
  
  # Create an empty dataframe to store the results
  result &lt;- 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 &lt;- go_data[i]
    
    if (grepl(&quot;^id:&quot;, line)) {
      go_id &lt;- strsplit(line, &quot; &quot;)[[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 &lt;- unique_data %&gt;% filter(GO_ID == go_id)
        
        # Extract the name and namespace information
        name &lt;- &quot;&quot;
        namespace &lt;- &quot;&quot;
        
        while (!grepl(&quot;^is_a:&quot;, go_data[i])) {
          if (grepl(&quot;^name:&quot;, go_data[i])) {
            name &lt;- strsplit(go_data[i], &quot;name: &quot;)[[1]][2]
          } else if (grepl(&quot;^namespace:&quot;, go_data[i])) {
            namespace &lt;- strsplit(go_data[i], &quot;namespace: &quot;)[[1]][2]
          }
          i &lt;- i + 1
        }
        
        # Add the information to the result dataframe
        temp_df &lt;- data.frame(Gene_ID = filtered_data$V1, GO_ID = go_id, Name = name, Namespace = namespace, stringsAsFactors = FALSE) # Replace with the correct column names
        result &lt;- bind_rows(result, temp_df)
      }
    }
  }
  
  # Print the result dataframe
  result
  nrow(result)
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-07-06T07:25:05.523Z
Comments.Text: What do you want to do with this data? GO terms of deep down the hierarchy also imply the upper nodes (genes annotated in the olfactory sensors term are also part of the biological process term).
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-07-06T07:50:27.250Z
Comments.Text: @ I I have seen in papers, they classify in GO terms and give good bar graphs with frequency, whith three terms, but I got this kind of confusing, so I am confused which one is correct, for publishing paper
Comments.UserDisplayName: Umar
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-07-06T08:39:05.890Z
Comments.Text: There are three branches of GO terms, BP, biological process, CC, cellular components and MF molecular functions. All three are correct, for publishing, it only depends on what do you want to focus on. They are independent of each other, that's why they are split/classified in three terms.
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-07-10T08:25:13.463Z
Comments.Text: I think I should delete this question
Comments.UserDisplayName: Umar
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-07-23T12:44:49.397Z
Comments.Text: Dear @umar I am afraid that deleting a question with an upvoted answer is not permitted. It is fair to point out both llrs and RicardoA.'s answer are reasonable contributions. Also RicardoA's comment about how you obtain GO assignments is good.
Comments.UserDisplayName: M__
Tags: <r><gene-ontology>
Title: Assigning multiple GO IDs to an ID: Should I split or use the first or last ID in the hierarchy?
ThreadText: # Assigning multiple GO IDs to an ID: Should I split or use the first or last ID in the hierarchy?
  
  (Asked by: username_0 on 2023-07-05)
  
  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)
  
  ```
  
  **Tags:** r, gene-ontology
  
  > **Comments:**
  > **username_1**: What do you want to do with this data? GO terms of deep down the hierarchy also imply the upper nodes (genes annotated in the olfactory sensors term are also part of the biological process term).  
  > **username_0**: @ I I have seen in papers, they classify in GO terms and give good bar graphs with frequency, whith three terms, but I got this kind of confusing, so I am confused which one is correct, for publishing paper  
  > **username_1**: There are three branches of GO terms, BP, biological process, CC, cellular components and MF molecular functions. All three are correct, for publishing, it only depends on what do you want to focus on. They are independent of each other, that's why they are split/classified in three terms.  
  > **username_0**: I think I should delete this question  
  > **username_2**: Dear @username_0 I am afraid that deleting a question with an upvoted answer is not permitted. It is fair to point out both username_1 and RicardoA.'s answer are reasonable contributions. Also RicardoA's comment about how you obtain GO assignments is good.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2023-07-18. Score: 2 | Accepted answer
  
  You might want to look at [Revigo](http://revigo.irb.hr) to simplify multiple GO terms into their parent terms. I've used [rrvgo](https://bioconductor.org/packages/release/bioc/html/rrvgo.html) extensively to simplify enrichment results - this is the R implementation of Revigo.
  
  It's not clear how exactly you are obtaining these GO assignments. If these are the significant hits for each feature, I'd take the union of all significant GO terms (i.e. everything in your second column combined) and pass it to rrvgo. Then, you can select the parent term associated with each row. I don't guarantee each row will be collapsed to a single term, but it should make whatever you are doing downstream much more tractable.
  
  
  ---
  
  