def __init__(self, hosts_filename=None, num_processes_per_host=0, bkb_handler=None, joint_reasoner=None, dynamic_reasoner=None, max_results=10): # Instantiate handler is one was not passed if bkb_handler is None: self.bkb_data_handler = BkbDataHandler( bkb_major_version='darwin', bkb_minor_version='2.0', disease='tcga', ) else: self.bkb_data_handler = bkb_handler # Save off other attributes self.hosts_filename = hosts_filename self.num_processes_per_host = num_processes_per_host self.max_results = max_results self.joint_reasoner = joint_reasoner self.dynamic_reasoner = dynamic_reasoner # Run specific handler setup self._setup_handler() # Read in curies with open(self.bkb_data_handler.curies_path, 'r') as f_: self.curies = json.load(f_)
class ChpBrainApiConfig(AppConfig): logger.warning('Running CHP Brain API Configuration. May take a minute.') name = 'chp_core_brain' # Used for distrbuted reasoning # Get Hosts File if it exists #parent_dir = os.path.dirname(os.path.realpath(__file__)) #HOSTS_FILENAME = os.path.join(parent_dir, 'hosts') #NUM_PROCESSES_PER_HOST = multiprocessing.cpu_count() #if not os.path.exists(HOSTS_FILENAME): hosts_filename = None num_processes_per_host = 0 # Instantiate BKB handler bkb_handler = BkbDataHandler(disease='tcga_gbm', bkb_major_version='darwin', bkb_minor_version='2.0') logger.info('Instantiating reasoners.') # Instantiate Reasoners dynamic_reasoner = ChpDynamicReasoner( bkb_handler=bkb_handler, hosts_filename=hosts_filename, num_processes_per_host=num_processes_per_host) joint_reasoner = ChpJointReasoner( bkb_handler=bkb_handler, hosts_filename=hosts_filename, num_processes_per_host=num_processes_per_host)
def __init__(self, query, hosts_filename=None, num_processes_per_host=0, max_results=100, bkb_handler=None, joint_reasoner=None, dynamic_reasoner=None): # Save initial passed query(s) self.init_query = query # Instantiate handler is one was not passed if bkb_handler is None: self.bkb_data_handler = BkbDataHandler(bkb_major_version='coulomb', bkb_minor_version='1.0') else: self.bkb_data_handler = bkb_handler # Save off other attributes self.hosts_filename = hosts_filename self.num_processes_per_host = num_processes_per_host self.max_results = max_results self.joint_reasoner = joint_reasoner self.dynamic_reasoner = dynamic_reasoner # Run specific handler setup self._setup_handler() # Read in curies with open(self.bkb_data_handler.curies_path, 'r') as f_: self.curies = json.load(f_)
def setUpClass(cls): super(TestOneHopHandler, cls).setUpClass() # load in sample query graphs with open('query_samples/onehop/standard_queries.json', 'r') as f_: cls.standard_queries = json.load(f_) with open('query_samples/onehop/wildcard_queries.json', 'r') as f_: cls.wildcard_queries = json.load(f_) cls.bkb_handler = BkbDataHandler() cls.dynamic_reasoner = ChpDynamicReasoner(cls.bkb_handler) cls.joint_reasoner = ChpJointReasoner(cls.bkb_handler)
def __init__(self, query, hosts_filename=None, num_processes_per_host=0, max_results=100): # query graph components self.query = query self.max_results = max_results self.qg = self.query['query_graph'] if 'knowledge_graph' not in list(self.query.keys()): self.kg = { "edges": {}, "nodes": {} } else: self.kg = self.query['knowledge_graph'] if 'results' not in list(self.query.keys()): self.results = [] else: self.results = self.query['results'] self.op = '>=' self.value = 970 # Instiatate Reasoner self.bkb_data_handler = BkbDataHandler(dataset_version='1.4') self.reasoner = Reasoner(bkb_data_handler=self.bkb_data_handler, hosts_filename=hosts_filename, num_processes_per_host=num_processes_per_host) # prepare curie gene dict self.true_gene_contrib = dict() self.false_gene_contrib = dict() self.gene_curie_dict = dict() self.gene_to_curie = dict() with open(self.bkb_data_handler.gene_curie_path, 'r') as gene_file: reader = csv.reader(gene_file) next(reader) for row in reader: self.gene_curie_dict[row[1]] = row[0] self.true_gene_contrib[row[1]] = 0 self.false_gene_contrib[row[1]] = 0 self.gene_to_curie[row[0]] = row[1] # prepare curie drug dict self.drug_curie_dict = dict() with open(self.bkb_data_handler.drug_curie_path, 'r') as drug_file: reader = csv.reader(drug_file) next(reader) for row in reader: self.drug_curie_dict[row[1]] = row[0] # default query specification self.target_strategy = 'explicit' self.interpolation = 'standard'
def __init__(self, query, hosts_filename=None, num_processes_per_host=0): self.query = query self.qg = self.query['query_graph'] self.kg = self.query['knowledge_graph'] self.results = self.query['results'] self.probability_targets = self.query['probability_targets'] #-- Instiatate Reasoner self.bkb_data_handler = BkbDataHandler() self.reasoner = Reasoner(bkb_data_handler=self.bkb_data_handler, hosts_filename=hosts_filename, num_processes_per_host=num_processes_per_host) self.gene_curie_dict = dict() with open(self.bkb_data_handler.gene_curie_path, 'r') as gene_file: reader = csv.reader(gene_file) next(reader) for row in reader: self.gene_curie_dict[row[1]] = row[0] self.target_strategy = 'chain' self.interpolation = 'standard'
def __init__(self, query, hosts_filename=None, num_processes_per_host=0): # query graph components self.query = query self.bkb_data_handler = BkbDataHandler(dataset_version='1.1') # Only do the rest of this if a query is passed if self.query is not None: self.qg = self.query['query_graph'] if 'knowledge_graph' not in list(self.query.keys()): self.kg = {"edges": [], "nodes": []} else: self.kg = self.query['knowledge_graph'] if 'results' not in list(self.query.keys()): self.results = {"node_bindings": [], "edge_bindings": []} else: self.results = self.query['results'] # Instiatate Reasoner self.reasoner = Reasoner( bkb_data_handler=self.bkb_data_handler, hosts_filename=hosts_filename, num_processes_per_host=num_processes_per_host) # prepare curie gene dict self.gene_curie_dict = dict() with open(self.bkb_data_handler.gene_curie_path, 'r') as gene_file: reader = csv.reader(gene_file) next(reader) for row in reader: self.gene_curie_dict[row[1]] = row[0] # prepare curie drug dict self.drug_curie_dict = dict() with open(self.bkb_data_handler.drug_curie_path, 'r') as drug_file: reader = csv.reader(drug_file) next(reader) for row in reader: self.drug_curie_dict[row[1]] = row[0] # default query specification self.target_strategy = 'explicit' self.interpolation = 'standard'
def setUp(self): self.bkb_handler = BkbDataHandler( bkb_major_version='coulomb', bkb_minor_version='1.0', ) self.dynamic_reasoner = ChpDynamicReasoner(self.bkb_handler)
def setUp(self): self.bkb_handler = BkbDataHandler() self.joint_reasoner = ChpJointReasoner(self.bkb_handler)
from chp.query import Query from chp_data.bkb_handler import BkbDataHandler #-- Initalize a BKB fused_bkb = BKB() ''' #-- Load in the fused bkb from our datafiles fused_bkb.load('/home/public/data/ncats/AxleBKBS/660Pats6HoldoutSTAGING/fusion.bkb') #-- Here are the associated patient data files patient_data_file = '/home/public/data/ncats/AxleBKBS/660Pats6HoldoutSTAGING/patient_data.pk' withheld_patients_file = '/home/public/data/ncats/AxleBKBS/660Pats6HoldoutSTAGING/withheldPatients.csv' ''' bkb_data_handler = BkbDataHandler(bkb_version='special', dataset_version='babel-small-problem') #-- Instiante reasoner reasoner = Reasoner(bkb_data_handler=bkb_data_handler) #-- If you want to see what genetic or demographic evidence is avaliable, uncomment the line below #print(reasoner.metadata_ranges) ''' #-- Make a query (evidence is for genetic info, and meta_ is for demographic info) query0 = Query(evidence={'mut_TMEM245=': 'True'}, targets=list(), meta_evidence=[('Age_of_Diagnosis', '>=',20000)], meta_targets=[('Survival_Time', '>=', 300)]) ''' query0 = Query(evidence={'_mut_AADAC': 'True'}, targets=list(),
def setUpClass(cls): super(TestBaseHandler, cls).setUpClass() cls.bkb_handler = BkbDataHandler() cls.dynamic_reasoner = ChpDynamicReasoner(cls.bkb_handler) cls.joint_reasoner = ChpJointReasoner(cls.bkb_handler)
def setUpClass(cls): super(TestDynamicReasoner, cls).setUpClass() cls.bkb_handler = BkbDataHandler(disease='tcga_brca') cls.dynamic_reasoner = ChpDynamicReasoner(cls.bkb_handler)
def setUpClass(cls): super(TestJointReasoner, cls).setUpClass() cls.bkb_handler = BkbDataHandler() cls.joint_reasoner = ChpJointReasoner(cls.bkb_handler)