Thank you so much for this code. I tried it. It works wonderfully. Some of the GO terms are repeating (present in multiple rows_ in the output table (GO:0003735,GO:0019843). Also, can we add corresponding UniprotKBs in one more column? Thank you again.
Help with R code to get a unique list
Hi,
I have gene ontology data that looks like this (sample data). I manually downloaded the gene ontology data from the Uniprot website.
I want to:
- Make a list of unique GO terms from the column 'Gene Ontology(molecular function)
- Make the list of genes associated with each GO term
- Also make the list of GO term descriptions in the next column
- Make the list of number of gene associated to a GO term
The output data would look like this
Please note that GO terms do not repeat in a specific cell, however, they repeat in other rows. Kindly help me to do this in R.
I did several unsuccessful trials. Hope to get help from someone. I will highly appreciate your help. Thank you so much.
• 3,329 views
•
link
1 answer
Tidyverse answer
library("tidyverse")
df %>%
select(gene_id, `Gene ontology (molecular function)`) %>%
distinct %>%
group_by(`Gene ontology (molecular function)`) %>%
summarize(gene_id=str_c(gene_id, collapse=", "), `No. of Genes`=n(), .groups="drop") %>%
separate_rows(`Gene ontology (molecular function)`, sep="; ") %>%
separate(
`Gene ontology (molecular function)`, sep="\\s(?=\\[GO)",
into=c("Gene ontology (molecular function)", "Gene Ontology IDs"))
• 0 views
•
link
Log in to answer this question.
df[!duplicated(df$'Gene Ontology (molecular function)'),]will work, and it will only keep the first entry of the duplicated values.See this SO post as a start:
group by GO IDs, collapse gene_id column, expand GO IDs, group by GO IDs, and count genes.