def get_protein_domain_data(uniprot_id):
    query_tpl = 'SELECT interpro_id, name, database, start, end ' \
                'FROM {interpro_table} ' \
                'WHERE uniprot_accession=?'
    query = query_tpl.format(interpro_table=INTERPRO_TABLE)

    log.debug("INTERPRO SQL: " + query)

    values = [uniprot_id]

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))

    items = []
    for row in cursor.fetchall():
        res = {k: row[k] for k in row.keys()}
        items.append(res)

    cursor.close()
    db.close()

    if len(items) == 0:
        raise InterProEntryNotFound(uniprot_id)

    return items
def get_mutation_data(tumor_type_array, gene):
    # Generate the 'IN' statement string: (%s, %s, ..., %s)
    tumor_stmt = ', '.join(['?' for tumor in tumor_type_array])

    query_tpl = 'SELECT Cancer AS tumor_type, gene, protein_ID, tumor_sample AS patient_id, mutation_type, aa_change, aa_location, aa1, aa2 ' \
                'FROM {mutation_table} ' \
                'WHERE gene=? AND Cancer IN ({tumor_stmt})'
    query = query_tpl.format(mutation_table=MUTATION_TABLE,
                             tumor_stmt=tumor_stmt)

    log.debug("MUTATION SQL: " + query)

    values = [gene]
    values.extend(tumor_type_array)

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))
    items = []
    for row in cursor.fetchall():
        cluster = parse_cluster(row)
        items.append(cluster)

    cursor.close()
    db.close()

    log.debug("Found mutation rows: {num}".format(num=len(items)))
    return items
def get_protein_domain_data(uniprot_id):
    query_tpl = 'SELECT interpro_id, name, database, start, end ' \
                'FROM {interpro_table} ' \
                'WHERE uniprot_accession=?'
    query = query_tpl.format(interpro_table=INTERPRO_TABLE)

    log.debug("INTERPRO SQL: " + query)

    values = [uniprot_id]

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))

    items = []
    for row in cursor.fetchall():
        res = {k: row[k] for k in row.keys()}
        items.append(res)

    cursor.close()
    db.close()

    if len(items) == 0:
        raise InterProEntryNotFound(uniprot_id)

    return items
Esempio n. 4
0
def get_uniprot_data(uniprot_id):
    """

    :param uniprot_id:
    :return:
    """
    query_tpl = 'SELECT primary_accession, entry_name, length, protein_name ' \
                'FROM {uniprot_table} ' \
                'WHERE primary_accession=?'
    query = query_tpl.format(uniprot_table=UNIPROT_TABLE)

    _log.debug("UNIPROT SQL: " + query)

    values = [uniprot_id]

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))

    items = []
    for row in cursor.fetchall():
        res = {k: row[k] for k in row.keys()}
        items.append(res)

    cursor.close()
    db.close()

    if len(items) == 0:
        return None

    return items[0]
Esempio n. 5
0
def get_cluster_data(tumor_type_array, gene):
    # Generate the 'IN' statement string: (%s, %s, ..., %s)
    tumor_stmt = ', '.join(['?' for tumor in tumor_type_array])

    query_tpl = 'SELECT cancer as tumor_type, ct.gene, ct.cluster, missense_mutations, nonsense_mutations, silent_mutations, cs.cluster_score '\
                'FROM {cluster_table} ct ' \
                'LEFT OUTER JOIN {cluster_score_table} cs ON ct.gene = cs.gene AND ct.cluster = cs.cluster ' \
                'WHERE ct.gene=? AND ct.cancer IN ({tumor_stmt}) '

    query = query_tpl.format(cluster_table=CLUSTER_TABLE,
                             cluster_score_table=CLUSTER_SCORE_TABLE,
                             tumor_stmt=tumor_stmt)

    log.debug("CLUSTER SQL: " + query)

    values = [gene]
    values.extend(tumor_type_array)

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))

    items = []
    for row in cursor.fetchall():
        cluster = parse_cluster(row)
        items.append(cluster)

    cursor.close()
    db.close()
    return items
def get_mutation_data(tumor_type_array, gene):
    # Generate the 'IN' statement string: (%s, %s, ..., %s)
    tumor_stmt = ', '.join(['?' for tumor in tumor_type_array])

    query_tpl = 'SELECT Cancer AS tumor_type, gene, protein_ID, tumor_sample AS patient_id, mutation_type, aa_change, aa_location, aa1, aa2 ' \
                'FROM {mutation_table} ' \
                'WHERE gene=? AND Cancer IN ({tumor_stmt})'
    query = query_tpl.format(mutation_table=MUTATION_TABLE, tumor_stmt=tumor_stmt)

    log.debug("MUTATION SQL: " + query)

    values = [gene]
    values.extend(tumor_type_array)

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))
    items = []
    for row in cursor.fetchall():
        cluster = parse_cluster(row)
        items.append(cluster)

    cursor.close()
    db.close()

    log.debug("Found mutation rows: {num}".format(num=len(items)))
    return items
def get_cluster_data(tumor_type_array, gene):
    # Generate the 'IN' statement string: (%s, %s, ..., %s)
    tumor_stmt = ', '.join(['?' for tumor in tumor_type_array])

    query_tpl = 'SELECT cancer as tumor_type, ct.gene, ct.cluster, missense_mutations, nonsense_mutations, silent_mutations, cs.cluster_score '\
                'FROM {cluster_table} ct ' \
                'LEFT OUTER JOIN {cluster_score_table} cs ON ct.gene = cs.gene AND ct.cluster = cs.cluster ' \
                'WHERE ct.gene=? AND ct.cancer IN ({tumor_stmt}) '

    query = query_tpl.format(cluster_table=CLUSTER_TABLE, cluster_score_table=CLUSTER_SCORE_TABLE, tumor_stmt=tumor_stmt)

    log.debug("CLUSTER SQL: " + query)

    values = [gene]
    values.extend(tumor_type_array)

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))

    items = []
    for row in cursor.fetchall():
        cluster = parse_cluster(row)
        items.append(cluster)

    cursor.close()
    db.close()
    return items
def get_mutation_data_summary_for_gene(gene):
    query_tpl = 'SELECT Cancer as tumor_type, gene, protein_ID, tumor_sample AS patient_id, mutation_type, aa_change, aa_location, aa1, aa2 ' \
                'FROM {mutation_table} ' \
                'WHERE gene=?'
    query = query_tpl.format(mutation_table=MUTATION_TABLE)

    log.debug("MUTATION SUMMARY SQL: " + query)

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, (gene, ))

    items = []
    for row in cursor.fetchall():
        cluster = parse_cluster(row)
        items.append(cluster)

    cursor.close()
    db.close()

    log.debug("Found mutation summary rows: {num}".format(num=len(items)))
    return items
def get_mutation_data_summary_for_gene(gene):
    query_tpl = 'SELECT Cancer as tumor_type, gene, protein_ID, tumor_sample AS patient_id, mutation_type, aa_change, aa_location, aa1, aa2 ' \
                'FROM {mutation_table} ' \
                'WHERE gene=?'
    query = query_tpl.format(mutation_table=MUTATION_TABLE)

    log.debug("MUTATION SUMMARY SQL: " + query)

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, (gene, ))

    items = []
    for row in cursor.fetchall():
        cluster = parse_cluster(row)
        items.append(cluster)

    cursor.close()
    db.close()

    log.debug("Found mutation summary rows: {num}".format(num=len(items)))
    return items
def get_pathway_data(tumor_type, gene, cluster):
    query_tpl = 'SELECT cancer as tumor_type, gene, cluster, pathway_name, pval, fdr, wl.url ' \
                'FROM {pathway_assoc_table} a ' \
                'LEFT OUTER JOIN pathway_web_links wl ON a.pathway_name=wl.pathway ' \
                'WHERE a.gene=? AND a.cancer=? AND a.cluster=? '
    query = query_tpl.format(pathway_assoc_table=PATHWAY_ASSOC_TABLE)

    log.debug("PATHWAY_ASSOC SQL: " + query)

    values = [gene, tumor_type, cluster]

    db = sql_connection()
    cursor = db.cursor()
    cursor.execute(query, tuple(values))

    items = []
    for row in cursor.fetchall():
        items.append(row)

    log.debug("Found {0} pathway associations.".format(len(items)))

    cursor.close()
    db.close()
    return items