Example #1
0
def term_types_in_paper(paper):
    """For each paper, count how often different term types appear.
    Possible term types:
    biological_process
    molecular_function
    cellular_component
    """
    # term types (ontologies) in a given paper
    tt_count = {}
    go_con = mysqlConnect()
    go_cursor = go_con.cursor()
    for prec in paper:
        go_id = prec['go_id']
        try:
            term_type = gu.go_acc_to_term_type(go_id, go_cursor)
        except IndexError:
            print go_id, "may be deprecated"
            continue
        # tt_count[term_type] = count of that term
        tt_count[term_type] = tt_count.get(term_type, 0) + 1
    go_con.close()
    return tt_count  # count of term types
Example #2
0
def term_types_in_paper(paper):
    """For each paper, count how often different term types appear.
    Possible term types:
    biological_process
    molecular_function
    cellular_component
    """
    # term types (ontologies) in a given paper
    tt_count = {}
    go_con = mysqlConnect()
    go_cursor = go_con.cursor()
    for prec in paper:
        go_id = prec['go_id']
        try:
            term_type = gu.go_acc_to_term_type(go_id, go_cursor)
        except IndexError:
            print go_id,"may be deprecated"
            continue
        # tt_count[term_type] = count of that term
        tt_count[term_type] = tt_count.get(term_type,0) + 1
    go_con.close()
    return tt_count # count of term types
Example #3
0
outfile = sys.stdout
for o, a in opts:
    if o in ('-i','--infile'):
        infile = a
    elif o in ('-o','--outfile'):
        outfile = open(a,"w")
    elif o in ('-f','--field'):
        go_acc_field = int(a)
print "infile", infile
if infile:
    for inline in file(infile):
        sp_id = inline.strip().split()[3]
        go_acc = inline.strip().split()[go_acc_field-1]
        go_level = gu.go_level(go_acc,goc)
        try:
            go_term_type = gu.go_acc_to_term_type(go_acc, goc)
        except IndexError:
            outfile.write("%s\t%s\t%.1f\t%s\n" % (go_acc, "NOTERMTYPE",
                                                  go_level, sp_id))
            continue
        outfile.write("%s\t%s\t%.1f\t%s\n" % (go_acc, go_term_type, go_level, sp_id))
    
else:
    go_acc = args[0]
    go_level = gu.go_level(go_acc,goc)
    go_term_type = gu.go_acc_to_term_type(go_acc, goc)
    outfile.write("%s\t%s\t%.1f\n" % (go_acc, go_term_type, go_level))
gocon.close()
if outfile != sys.stdout:
    outfile.close()