<commit_before># DDA stands for disease-drug agent whose task is to
# search for targets known to be implicated in a 
# certain disease and to look for drugs that are known 
# to affect that target directly or indirectly.

import re
import os
import rdflib
import sqlite3
import numpy
from bioagents import cbio_client
import warnings
import indra.bel.processor

class DDA:
    def __init__(self):
        data_dir = os.path.dirname(os.path.realpath(__file__)) + '/data/'
        # Build an initial set of substitution statements
        bel_corpus = data_dir + 'large_corpus_direct_subs.rdf'
        g = rdflib.Graph()
        g.parse(bel_corpus, format='nt')
        bp = indra.bel.processor.BelProcessor(g)
        bp.get_activating_subs()
        self.sub_statements = bp.statements
        # Load a database of drug targets
        self.drug_db = sqlite3.connect(data_dir + 'drug_targets.db')
   
    def __del__(self):
        self.drug_db.close()

    def is_nominal_drug_target(self, drug_name, target_name):
        res = self.drug_db.execute('SELECT nominal_target FROM agent '
                           'WHERE synonyms LIKE "%%%s%%" '
                           'OR name LIKE "%%%s%%"' % (drug_name, drug_name)).fetchall()
        for r in res:
            if r[0] == target_name:
                return True
        return False

    def find_mutation_effect(self, protein_name, amino_acid_change):
        match = re.match(r'([A-Z])([0-9]+)([A-Z])', amino_acid_change)
        if match is None:
            return None
        matches = match.groups()
        wt_residue = matches[0]
        pos = matches[1]
        sub_residue = matches[2]

        for stmt in self.sub_statements:
            if stmt.monomer.name == protein_name and\
                stmt.wt_residue == wt_residue and\
                stmt.pos == pos and\
                stmt.sub_residue == sub_residue:
                if stmt.rel == 'increases':
                    return 'activate'
                else:
                    return 'deactivate'
        return None
    
    def get_mutation_statistics(self, disease_name_filter, mutation_type):
        study_ids = cbio_client.get_cancer_studies(disease_name_filter)<commit_msg>Implement find all drugs for a target in DDA<commit_after># DDA stands for disease-drug agent whose task is to
# search for targets known to be implicated in a 
# certain disease and to look for drugs that are known 
# to affect that target directly or indirectly.

import re
import os
import rdflib
import sqlite3
import numpy
from bioagents import cbio_client
import warnings
import indra.bel.processor

class DDA:
    def __init__(self):
        data_dir = os.path.dirname(os.path.realpath(__file__)) + '/data/'
        # Build an initial set of substitution statements
        bel_corpus = data_dir + 'large_corpus_direct_subs.rdf'
        g = rdflib.Graph()
        g.parse(bel_corpus, format='nt')
        bp = indra.bel.processor.BelProcessor(g)
        bp.get_activating_subs()
        self.sub_statements = bp.statements
        # Load a database of drug targets
        self.drug_db = sqlite3.connect(data_dir + 'drug_targets.db')
   
    def __del__(self):
        self.drug_db.close()

    def is_nominal_drug_target(self, drug_name, target_name):
        '''
        Return True if the drug targets the target, and False if not
        '''
        res = self.drug_db.execute('SELECT nominal_target FROM agent '
                           'WHERE synonyms LIKE "%%%s%%" '
                           'OR name LIKE "%%%s%%"' % (drug_name, drug_name)).fetchall()
        for r in res:
            if r[0] == target_name:
                return True
        return False

    def find_target_drug(self, target_name):
        '''
        Find all the drugs that nmoinally target the target.
        '''
        res = self.drug_db.execute('SELECT name, synonyms FROM agent '
                'WHERE nominal_target LIKE "%%%s%%" ' % target_name).fetchall()
        drug_names = [r[0] for r in res]
        return drug_names

    def find_mutation_effect(self, protein_name, amino_acid_change):
        match = re.match(r'([A-Z])([0-9]+)([A-Z])', amino_acid_change)
        if match is None:
            return None
        matches = match.groups()
        wt_residue = matches[0]
        pos = matches[1]
        sub_residue = matches[2]

        for stmt in self.sub_statements:
            if stmt.monomer.name == protein_name and\
                stmt.wt_residue == wt_residue and\
                stmt.pos == pos and\
                stmt.sub_residue == sub_residue:
                if stmt.rel == 'increases':
                    return 'activate'
                else:
                    return 'deactivate'
        return None
    
    def get_mutation_statistics(self, disease_name_filter, mutation_type):
        study_ids = cbio_client.get_cancer_studies(disease_name_filter)
{'fraction_non_alphanumeric': 0.09011213047910295, 'fraction_numerical': 0.0034658511722731908, 'mean_word_length': 2.1774611398963732, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6750335', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1433, 'n_words': 400}