#!/bin/bash
# Parses the go terms out of an input file

set -o pipefail -e

terms="http://geneontology.org/ontology/go-basic.obo"

wget -q "$terms" -O - | <<<CMD_AWK>>> '
BEGIN {
    OFS = "	"
}
/^\[.*\]$/ { # start of a record
    type = $0
    split("", record, ":")
    next
}
!/^$/ { # a field in a record
    key = $0;   sub(":.*", "", key)
    value = $0; sub("[^ ]*: ", "", value)
    record[key] = value
}
/^$/ { # end of a record
    if (id != 0 && type == "[Term]") {
        sub("_", " ", record["namespace"])
        print id, record["id"], record["namespace"], record["name"]
    }
    id++
    type = ""
}'

#!/bin/bash
# Parses the go terms out of an input file

set -o pipefail -e

terms="http://geneontology.org/ontology/go-basic.obo"

wget -q "$terms" -O - | <<<CMD_AWK>>> '
BEGIN {
    OFS = "	"
    id=1
}
/^\[.*\]$/ { # start of a record
    type = $0
    alt_ctr = 0
    split("", record, ":")
    split("", ids, ":")
    next
}
/^(alt_id|id).*$/ { # a id or alt_id field in a record
    value = $0; sub("[^ ]*: ", "", value)
    record["id"][alt_ctr] = value
    alt_ctr++
    next
}
!/^$/ { # a field in a record
    key = $0;   sub(":.*", "", key)
    value = $0; sub("[^ ]*: ", "", value)
    record[key] = value
}
/^$/ { # end of a record
    if (type == "[Term]") {
        sub("_", " ", record["namespace"])
        for(i in record["id"]){
            print id, record["id"][i], record["namespace"], record["name"]
            id++
        }
    }
    type = ""
}'

Duplicate go_terms enteries that have alternative id's
Duplicate go_terms enteries that have alternative id's
