2
$\begingroup$

I have a gene ontology obo file, and would like to rearrange the obo format file in a single column to a text file in three columns comprised of 'parent (id:GO:xxxxxxx)', 'child (is_a: GO:xxxxxxx, part_of GO:xxxxxxx, or positively/negatively_regulates GO:xxxxxxx. For example...

Thank you for your help in advance!

Original file:

[Term]
id: GO:0000001 # parent
name: mitochondrion inheritance
namespace: biological_process
def: "The distribution of mitochondria, including the mitochondrial genome, into daughter cells after mitosis or meiosis, mediated by interactions between mitochondria and the cytoskeleton." [GOC:mcc, PMID:10873824, PMID:11389764]
synonym: "mitochondrial inheritance" EXACT []
is_a: GO:0048308 ! organelle inheritance # child
is_a: GO:0048311 ! mitochondrion distribution # child

[Term]
id: GO:0000015 # parent
name: phosphopyruvate hydratase complex
namespace: cellular_component
def: "A multimeric enzyme complex, usually a dimer or an octamer, that catalyzes the conversion of 2-phospho-D-glycerate to phosphoenolpyruvate and water." [GOC:jl, ISBN:0198506732]
subset: goslim_metagenomics
synonym: "enolase complex" EXACT []
is_a: GO:1902494 ! catalytic complex # child
relationship: part_of GO:0005829 ! cytosol # child

[Term]
id: GO:0000122 # parent
name: negative regulation of transcription by RNA polymerase II
namespace: biological_process
alt_id: GO:0010553
alt_id: GO:0045816
def: "Any process that stops, prevents, or reduces the frequency, rate or extent of transcription mediated by RNA polymerase II." [GOC:go_curators, GOC:txnOH]
synonym: "down regulation of global transcription from RNA polymerase II promoter" RELATED []
synonym: "down regulation of transcription from RNA polymerase II promoter" EXACT []
synonym: "down-regulation of global transcription from RNA polymerase II promoter" RELATED []
synonym: "down-regulation of transcription from RNA polymerase II promoter" EXACT []
synonym: "downregulation of global transcription from RNA polymerase II promoter" RELATED []
synonym: "downregulation of transcription from RNA polymerase II promoter" EXACT []
synonym: "inhibition of global transcription from RNA polymerase II promoter" RELATED []
synonym: "inhibition of transcription from RNA polymerase II promoter" EXACT []
synonym: "negative regulation of gene-specific transcription from RNA polymerase II promoter" RELATED []
synonym: "negative regulation of global transcription from Pol II promoter" RELATED []
synonym: "negative regulation of transcription from Pol II promoter" EXACT []
synonym: "negative regulation of transcription from RNA polymerase II promoter" EXACT []
synonym: "negative regulation of transcription from RNA polymerase II promoter, global" RELATED []
is_a: GO:0006357 ! regulation of transcription by RNA polymerase II # child
is_a: GO:0045892 ! negative regulation of DNA-templated transcription # child
relationship: negatively_regulates GO:0006366 ! transcription by RNA polymerase II # child

Desired format:

Parent       Child       Relationship
GO:0000001   GO:0048308  is_a
GO:0000001   GO:0048311  is_a
GO:0000015   GO:1902494  is_a
GO:0000015   GO:0005829  part_of
GO:0000122   GO:0006357  is_a
GO:0000122   GO:0045892  is_a
GO:0000122   GO:0006366  negatively_regulates
$\endgroup$
1
  • 1
    $\begingroup$ Thank you for the advice. I've just reformatted the example file. $\endgroup$
    – ojikj2023
    Jul 11 at 15:40

1 Answer 1

2
$\begingroup$

One potential solution using awk:

awk 'BEGIN {
    OFS = "\t"
    print "Parent", "Child", "Relationship"
}

/GO:[[:digit:]]{1,}/ {
    if ($1 ~ /^id:/) {
    parent_id = $2
} else if ($1 ~ /^is_a:/) {
        gsub(":", "", $1)
    print parent_id, $2, $1
} else if ($1 ~ /^relationship:/) {
        print parent_id, $3, $2
    }
}' test.txt
Parent      Child       Relationship
GO:0000001  GO:0048308  is_a
GO:0000001  GO:0048311  is_a
GO:0000015  GO:1902494  is_a
GO:0000015  GO:0005829  part_of
GO:0000122  GO:0006357  is_a
GO:0000122  GO:0045892  is_a
GO:0000122  GO:0006366  negatively_regulates

Including comments:

awk 'BEGIN {                      # before processing the first line
    OFS = "\t"                    # set the output field separator to tab
    print "Parent", "Child", "Relationship"    # and print the header
}

/GO:[[:digit:]]{1,}/ {    # for any line that contains a GO term
    if ($1 ~ /^id:/) {            # if the line starts with id:
    parent_id = $1                # set the parent id
} else if ($1 ~ /^is_a/) {        # then, for lines that start with is_a 
        gsub(":", "", $1)         # remove the colon
    print parent_id, $2, $1       # and print the parent, child and relationship
} else if ($1 ~ /^relationship:/) {  # then, for lines that start with relationship
        print parent_id, $3, $2   # print the parent, child, and relationship
    }
}' test.txt
$\endgroup$
2
  • $\begingroup$ You're welcome - I'm glad you solved your problem @ojikj2023 - but comments are not the right place to say 'thank you'; please see What should I do when someone answers my question?. $\endgroup$ Jul 12 at 23:21
  • 1
    $\begingroup$ It's my first time to post a question and get help. I've just done voting following your comment! $\endgroup$
    – ojikj2023
    Jul 13 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.