def __main__():
    """
    Perform substructure searches on the selected db based on Fingerprint descriptors.
    """
    args = parse_command_line(sys.argv)
    db_conn = cheminfolib.db_connect(args)

    if args.istyle == "pattern":
        mol = pybel.readstring("smi", args.input)
        cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
        cur.execute(create_query(args, mol))
        rows = cur.fetchall()
    else:
        old_rows = []
        for mol in pybel.readfile("smi", args.input):
            cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
            cur.execute(create_query(args, mol))
            old_rows.append(cur.fetchall())

        # TODO: if i have a testing env, try to not append the cur.fetchall ... + it and save the one loop here
        rows = []
        for first_row in old_rows:
            for row in first_row:
                rows.append(row)

    cheminfolib.print_output(args, rows)
Beispiel #2
0
def __main__():
    """
    Query the database and retrieve the requested compounds. A unique identifier for the molecules must be provided in a tab file
    """
    args = parse_command_line(sys.argv)
    identifiers = [
        line.split("\t")[args.column - 1].strip() for line in open(args.input, "r")
    ]

    db_conn = cheminfolib.db_connect(args)

    query = """SELECT *
                FROM %(libname)s.tbl_molecule molec
                LEFT JOIN %(libname)s.tbl_molecule_synonym syn
                ON molec.id = syn.fk_molecule_id
                WHERE syn.synonym IN ('%(id)s')
            """ % {
        "libname": args.lib,
        "id": ("', '").join(identifiers),
    }

    cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(query)
    rows = cur.fetchall()

    cheminfolib.print_output(args, rows)
Beispiel #3
0
def __main__():
    """
        Filter a db using user-selected physico-chemical properties
    """

    args = parse_command_line(sys.argv)
    db_conn = cheminfolib.db_connect(args)
    filters = json.loads((args.filters).replace(" ", "").replace(",}", "}"))

    query = """SELECT can_smiles, synonym
                FROM %(libname)s.tbl_molecule molec
                LEFT JOIN (SELECT fk_molecule_id, MAX(synonym) as synonym FROM %(libname)s.tbl_molecule_synonym GROUP BY fk_molecule_id) syn
                ON molec.id = syn.fk_molecule_id
                WHERE %(filter_query)s
             """ % {
        "libname": args.lib,
        "filter_query": " AND ".join(
            [("%s BETWEEN %s AND %s" % (key, elem[0], elem[1])) for key, elem in filters.items()]
        ),
    }

    cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(query)
    rows = cur.fetchall()

    # Only fetch smiles from the database since SDF retrieval takes ages
    args.oformat = "can_smiles"

    cheminfolib.print_output(args, rows)
Beispiel #4
0
def __main__():
    """
    Filter a db using user-selected physico-chemical properties
    """

    args = parse_command_line(sys.argv)
    db_conn = cheminfolib.db_connect(args)
    filters = json.loads((args.filters).replace(" ", "").replace(",}", "}"))

    query = """SELECT can_smiles, synonym
                FROM %(libname)s.tbl_molecule molec
                LEFT JOIN (SELECT fk_molecule_id, MAX(synonym) as synonym FROM %(libname)s.tbl_molecule_synonym GROUP BY fk_molecule_id) syn
                ON molec.id = syn.fk_molecule_id
                WHERE %(filter_query)s
             """ % {
        "libname":
        args.lib,
        "filter_query":
        " AND ".join([("%s BETWEEN %s AND %s" % (key, elem[0], elem[1]))
                      for key, elem in filters.items()]),
    }

    cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(query)
    rows = cur.fetchall()

    # Only fetch smiles from the database since SDF retrieval takes ages
    args.oformat = "can_smiles"

    cheminfolib.print_output(args, rows)
def __main__():
    """
        Perform substructure searches on the selected db based on Fingerprint descriptors.
    """
    args = parse_command_line(sys.argv)
    db_conn = cheminfolib.db_connect(args)

    if args.istyle == "pattern":
        mol = pybel.readstring("smi", args.input)
        cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
        cur.execute(create_query(args, mol))
        rows = cur.fetchall()
    else:
        old_rows = []
        for mol in pybel.readfile("smi", args.input):
            cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
            cur.execute(create_query(args, mol))
            old_rows.append(cur.fetchall())

        ### TODO: if i have a testing env, try to not append the cur.fetchall ... + it and save the one loop here
        rows = []
        for first_row in old_rows:
            for row in first_row:
                rows.append(row)

    cheminfolib.print_output(args, rows)
Beispiel #6
0
def __main__():
    """
        Query the database and retrieve the requested compounds. A unique identifier for the molecules must be provided in a tab file
    """
    args = parse_command_line(sys.argv)
    identifiers = [ line.split('\t')[args.column - 1].strip() for line in open(args.input, 'r') ]

    db_conn = cheminfolib.db_connect(args)

    query = ("""SELECT *
                FROM %(libname)s.tbl_molecule molec
                LEFT JOIN %(libname)s.tbl_molecule_synonym syn
                ON molec.id = syn.fk_molecule_id
                WHERE syn.synonym IN ('%(id)s')
            """
            % { 'libname' : args.lib, 'id' : ("', '").join(identifiers) } )

    cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(query)
    rows = cur.fetchall()

    cheminfolib.print_output(args, rows)
Beispiel #7
0
def __main__():
    """
    Perform similarity searches on the selected db based on Tanimoto similarity of Fingerprint descriptors.
    """

    args = parse_command_line(sys.argv)
    db_conn = cheminfolib.db_connect(args)

    if args.istyle == "pattern":
        mol = pybel.readstring("smi", args.input)

        cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
        cur.execute(create_query(args, mol))

        rows = cur.fetchall()

    else:
        old_rows = []
        for mol in pybel.readfile("smi", args.input):

            cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
            cur.execute(create_query(args, mol))

            old_rows.append(cur.fetchall())

        rows = []
        # this crap deletes one level from the list...
        for first_row in old_rows:
            for row in first_row:
                rows.append(row)

    if args.oformat in ["table", "sdf"]:
        # Add the Tanimoto coefficient as output for the tabular and sdf selections in similarity searches
        args.fetch += ", %s" % "tani"

    cheminfolib.print_output(args, rows)