示例#1
0
    def normalize(self):
        term = MySQLdb.escape_string(self.text)
        # adjust - adjust the final score
        match = ()
        cur = db.cursor()
        # synonym
        query = """SELECT DISTINCT t.acc, t.name, s.term_synonym
                       FROM term t, term_synonym s
                       WHERE s.term_synonym LIKE %s and s.term_id = t.id
                       ORDER BY t.ic ASC
                       LIMIT 1;""" # or DESC
        # print "QUERY", query

        cur.execute(query, ("%" + term + "%", ))

        res = cur.fetchone()
        if res is not None:
            print res
        else:
            query = """SELECT DISTINCT t.acc, t.name, p.name
                       FROM term t, prot p, prot_GOA_BP a
                       WHERE p.name LIKE %s and p.id = a.prot_id and a.term_id = t.id
                       ORDER BY t.ic ASC
                       LIMIT 1;""" # or DESC
            cur.execute(query, (term, ))
            res = cur.fetchone()
            print res
示例#2
0
文件: ssm.py 项目: lasigeBioTM/IBEnt
def simui_hindex_go(id1, id2, h=4):
    cur = dbwebgo.cursor()
    query = """SELECT (
			SELECT COUNT(y.id)
			FROM  (
				SELECT DISTINCT t3.id
				FROM graph_path p1, graph_path p2, term t1, term t2, term t3
                WHERE t1.acc = %s AND t2.acc = %s AND
                t1.id = p1.term2_id AND t2.id = p2.term2_id
				AND p1.term1_id=p2.term1_id
				AND p1.term1_id=t3.id AND t3.hindex >= %s)
			AS y )
		 /(
		 	SELECT COUNT(x.id)
		 	FROM (
                SELECT t2.id
                FROM graph_path p1, term t1, term t2
                WHERE t1.acc = %s AND t1.id = p1.term2_id
                AND p1.term1_id = t2.id AND t2.hindex >= %s
                UNION
                SELECT t4.id
                FROM graph_path p2, term t3, term t4
                WHERE t3.acc = %s AND t3.id = p2.term2_id
                AND p2.term1_id = t4.id AND t4.hindex >= %s)
		 	AS x )"""
    cur.execute(query, (id1,id2,h,id1,h,id2,h))
    res = cur.fetchone()[0]
    if res is None:
        res = '0'
    return float(res)
示例#3
0
文件: ssm.py 项目: lasigeBioTM/IBEnt
def simgic_hindex_go(id1, id2, h=4):
    cur = dbwebgo.cursor()
    cur.execute("""SELECT (
            SELECT SUM(y.ic)
            FROM  (
                SELECT DISTINCT f.id, f.ic
                FROM graph_path p1, graph_path p2, term f, term f1, term f2
                WHERE p1.term2_id = f1.id AND f1.acc = %s
                AND p2.term2_id = f2.id AND f2.acc = %s
                AND p1.term1_id=p2.term1_id
                AND p1.term1_id=f.id
                AND f.hindex >= %s)
            AS y )
         /(
            SELECT SUM(x.ic)
            FROM (
                SELECT f1.id, f1.ic
                FROM graph_path p1, term f1, term f3
                WHERE p1.term2_id  = f3.id and f3.acc = %s
                AND p1.term1_id = f1.id
                AND f1.hindex >= %s
                UNION
                SELECT f2.id, f2.ic
                FROM graph_path p2, term f2, term f4
                WHERE p2.term2_id = f4.id and f4.acc = %s
                AND p2.term1_id = f2.id
                AND f2.hindex >= %s)
            AS x )""", (id1,id2,h,id1,h,id2,h))
    res = cur.fetchone()[0]
    if res is None:
        res = '0'
    return float(res)
示例#4
0
文件: ssm.py 项目: lasigeBioTM/IBEnt
def resnik_go(id1, id2):
    cur = dbwebgo.cursor()
    query = """SELECT MAX(t3.ic) 
		FROM graph_path p1, graph_path p2, term t1, term t2, term t3 
        WHERE t1.acc = %s AND t2.acc = %s AND t1.id = p1.term2_id AND t2.id = p2.term2_id
		AND p1.term1_id = p2.term1_id 
		AND p1.term1_id = t3.id;"""
    cur.execute(query, (id1, id2))
    #r = cur.store_result()
    res = cur.fetchone()[0]
    #print id1, id2, res
    if res is None:
        res = '0'
    return float(res)
示例#5
0
    def get_best_go(self):
        cur = db.cursor()
        # synonym

        query = """SELECT DISTINCT t.acc, t.name, t.ic
                       FROM term t
                       WHERE t.acc IN (%s)
                       ORDER BY t.ic ASC
                       LIMIT 1;"""  # or DESC
        # print "QUERY", query

        format_strings = ','.join(['%s'] * len(self.go_ids))
        cur.execute(query % format_strings, (self.go_ids))
        res = cur.fetchone()
        if res is not None:
            # print self.text, res[1:]
            logging.info("best GO for {} ({}): {}".format(
                self.text, len(self.go_ids), " ".join([str(r) for r in res])))
            self.best_go = res[0]
        else:
            logging.info("NO GO")
            self.best_go = ""
示例#6
0
    def get_best_go(self):
        cur = db.cursor()
        # synonym

        query = """SELECT DISTINCT t.acc, t.name, t.ic
                       FROM term t
                       WHERE t.acc IN (%s)
                       ORDER BY t.ic ASC
                       LIMIT 1;"""  # or DESC
        # print "QUERY", query


        format_strings = ','.join(['%s'] * len(self.go_ids))
        cur.execute(query % format_strings, (self.go_ids))
        res = cur.fetchone()
        if res is not None:
            # print self.text, res[1:]
            logging.info("best GO for {} ({}): {}".format(self.text, len(self.go_ids), " ".join([str(r) for r in res])))
            self.best_go = res[0]
        else:
            logging.info("NO GO")
            self.best_go = ""