Excellent. Thanks for the solutions. The perl one liner worked perfectly. Thank you
• 0 views
•
link
Hi,
I have done annotation on a denovo transcriptome for which I want to do GO term enrichment. Here's the format for the list of GO terms I get:
TR17386 GO:0005737 GO:0005634
TR27677 GO:0005737 GO:0005524 GO:0006457
TR24529 GO:0005737 GO:0004332 GO:0006096
But I went them in a list with just 2 columns like this:
TR17386 GO:0005737
TR17386 GO:0005634
TR27677 GO:0005737
TR27677 GO:0005524
TR27677 GO:0006457
TR27677 GO:0006950
TR24529 GO:0005737
TR24529 GO:0004332
TR24529 GO:0006096
Is there a script that can help me achieve this?
Thanks,
Davis
This should work:
perl -lane '$id = shift(@F); foreach $GO (@F) {print "$id\t$GO"} ' your_file.tab
# Solution using R
# Packages
# You might need to install them
library(data.table)
library(reshape2)
# Read in
df <- read.table("original.txt", header=FALSE, fill=TRUE)
# Format as wanted
res <- melt(df, id="V1")
# Remove empty row
setDT(res)
res <- res[value != "", list(V1, value)]
# Save as a text file
write.table(res, "wanted.txt", col.names=FALSE, row.names=FALSE, quote=FALSE)
Log in to answer this question.