Question: How to convert between gene ontology file formats
0
gravatar for dgimode
3.9 years ago by
dgimode60
dgimode60 wrote:

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

rna-seq • 1.2k views
ADD COMMENTlink modified 10 months ago by Biostar ♦♦ 20 • written 3.9 years ago by dgimode60
3
gravatar for Fidel
3.9 years ago by
Fidel1.9k
Germany
Fidel1.9k wrote:

This should work:

perl -lane '$id = shift(@F); foreach $GO (@F) {print "$id\t$GO"} ' your_file.tab
ADD COMMENTlink written 3.9 years ago by Fidel1.9k

Excellent. Thanks for the solutions. The perl one liner worked perfectly. Thank you

ADD REPLYlink written 3.9 years ago by dgimode60

Cool. If the solution worked for you, then accept it  ;)

ADD REPLYlink written 3.9 years ago by Fidel1.9k
1
gravatar for PoGibas
3.9 years ago by
PoGibas4.8k
Vilnius
PoGibas4.8k wrote:
# 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)
ADD COMMENTlink modified 3.9 years ago • written 3.9 years ago by PoGibas4.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 827 users visited in the last hour