holdoutResults[idx][indexTrue]) print(probOne, probTwo) if holdoutResults[idx][indexFalse][2] > holdoutResults[idx][ indexTrue][2]: print("\tfalse -", targetVal, "CORRECT") numCorrect += 1 else: print("\tfalse -", targetVal, "WRONG") numWrong += 1 print("Number correct:", numCorrect) print("Number wrong:", numWrong) if __name__ == '__main__': fused_bkb = BKB() fused_bkb.load('/home/public/data/ncats/660Pats6Holdout/fusion.bkb') patient_data_file = '/home/public/data/ncats/660Pats6Holdout/patient_data.pk' withheld_patients_file = '/home/public/data/ncats/660Pats6Holdout/withheldPatients.csv' #fused_bkb.load('/home/public/data/ncats/660Pats5PercentHoldout/fusion.bkb') #patient_data_file = '/home/public/data/ncats/660Pats5PercentHoldout/patient_data.pk' #withheld_patients_file = '/home/public/data/ncats/660Pats5PercentHoldout/withheldPatients.csv' compNames = fused_bkb.getAllComponentNames() f = open(withheld_patients_file, 'r') withheldPatientHashes = f.read().split(',') patientDict = pickle.load(open(patient_data_file, 'rb')) patientsMutationVariantEvidence = []
import sys import os from pybkb import bayesianKnowledgeBase as BKB from pybkb.core.python_base.reasoning import checkMutex #!!!!!!!!!! Change to your local bkb-pathway-core directory. #sys.path.append('/home/ghyde/bkb-pathway-provider/core') sys.path.append( '/home/cyakaboski/src/python/projects/bkb-pathway-provider/core') from reasoner import Reasoner from query import Query #-- Initalize a BKB fused_bkb = BKB() #-- Load in the fused bkb from our datafiles fused_bkb.load( '/home/public/data/ncats/AxleBKBS/AxleDemoBKB3-14-20/fusion.bkb') #-- Here are the associated patient data files patient_data_file = '/home/public/data/ncats/AxleBKBS/AxleDemoBKB3-14-20/patient_data.pk' withheld_patients_file = '/home/public/data/ncats/AxleBKBS/AxleDemoBKB3-14-20/withheldPatients.csv' gene_var_direct_file = '/home/public/data/ncats/AxleBKBS/AxleDemoBKB3-14-20/geneFreqAnal.csv' #-- Instaniate reasoner reasoner = Reasoner(fused_bkb=fused_bkb, gene_var_direct=gene_var_direct_file, max_new_ev=2)
print(holdoutResults[idx][indexFalse], holdoutResults[idx][indexTrue]) print(probOne, probTwo) if holdoutResults[idx][indexFalse][2] > holdoutResults[idx][ indexTrue][2]: print("\tfalse -", targetVal, "CORRECT") numCorrect += 1 else: print("\tfalse -", targetVal, "WRONG") numWrong += 1 print("Number correct:", numCorrect) print("Number wrong:", numWrong) if __name__ == '__main__': fused_bkb = BKB() fused_bkb.load('/home/ghyde/bkb-pathway-provider/core/AXLEBKB/fusion.bkb') patient_data_file = '/home/ghyde/bkb-pathway-provider/core/AXLEBKB/patient_data.pk' withheld_patients_file = '/home/ghyde/bkb-pathway-provider/core/AXLEBKB/withheldPatients.csv' freq_file = '/home/ghyde/bkb-pathway-provider/core/AXLEBKB/geneFreqAnal.csv' maxNewEv = 20 #fused_bkb.load('/home/public/data/ncats/660Pats5PercentHoldout/fusion.bkb') #patient_data_file = '/home/public/data/ncats/660Pats5PercentHoldout/patient_data.pk' #withheld_patients_file = '/home/public/data/ncats/660Pats5PercentHoldout/withheldPatients.csv' compNames = fused_bkb.getAllComponentNames() f = open(withheld_patients_file, 'r') withheldPatientHashes = f.read().split(',')
AGE_RANGE_YRS = (20, 90) SURIVAL_YRS = (0, 10) patient_data = { patient: { 'Gender': random.choice(GENDER_OPTIONS), 'Age': random.randrange(AGE_RANGE_YRS[0], AGE_RANGE_YRS[1]), 'Survival': random.randrange(SURIVAL_YRS[0], SURIVAL_YRS[1]) } for patient in PATIENTS } bkfs = list() #-- Make BKB frags for patient in PATIENTS: bkf = BKB() for gene in GENES: if random.choice([True, False]): #-- Setup Gene i component. comp_idx = bkf.addComponent('mut_{}'.format(gene)) stateTrue_idx = bkf.addComponentState(comp_idx, 'True') bkf.addSNode( BKB_S_node(init_component_index=comp_idx, init_state_index=stateTrue_idx, init_probability=1)) variant_comp_idx = bkf.addComponent('mut-var_{}'.format(gene)) random_variant = random.choice(GENE_VARIANTS) variant_state_idx = bkf.addComponentState(variant_comp_idx, random_variant)
priors[gene] = float(count / len(PATIENTS)) #--Pairs Calculate Correlations counts = dict() for gene1 in GENES: for gene2 in GENES: count = 0 for patient in PATIENTS: if patient_data[patient]['Genes'][gene1] and patient_data[patient][ 'Genes'][gene2]: count += 1 counts[(gene1, gene2)] = float(count / len(PATIENTS)) / priors[gene2] #-- Make BKB Patient frags for patient in PATIENTS: bkf = BKB() for gene in patient_data[patient]['Genes']: #-- Setup Gene i component. geneComp_idx = bkf.addComponent(gene) geneStateTrue_idx = bkf.addComponentState(geneComp_idx, 'True') s_node_prior = BKB_S_node(init_component_index=geneComp_idx, init_state_index=geneStateTrue_idx, init_probability=1) bkf.addSNode(s_node_prior) patient_bkfs.append(bkf) #-- Define Sample Pathway PATHWAYS = ['Pathway{}'.format(i) for i in range(1)]
def processPathwayBKF(self, exhaustiveOr=False): assert len(self.pathways) > 0, "Have not processed pathways yet" for pathway in tqdm.tqdm(self.pathways, desc='Processing pathway BKFs'): bkf = BKB(name=pathway.pathwayID) pathwayActiveComp_idx = bkf.addComponent('{}_active='.format( pathway.pathwayID)) pathwayActiveTrue_idx = bkf.addComponentState( pathwayActiveComp_idx, 'True') if exhaustiveOr: print("not implemented") else: geneSelectorComp_idx = bkf.addComponent("Gene_combo=") for gene in pathway.genes: #gene[0] = geneName, gene[1] = low value gene[2] = high value geneCombo_idx = bkf.addComponentState( geneSelectorComp_idx, gene[0]) statConditionComp_idx = bkf.addComponent( 'mu-STD<={}<=mu+STD='.format(gene[0])) statConditionTrue_idx = bkf.addComponentState( statConditionComp_idx, 'True') bkf.addSNode( BKB_S_node(statConditionComp_idx, statConditionTrue_idx, 1.0)) bkf.addSNode( BKB_S_node( geneSelectorComp_idx, geneCombo_idx, 1.0, [(statConditionComp_idx, statConditionTrue_idx)])) bkf.addSNode( BKB_S_node(pathwayActiveComp_idx, pathwayActiveTrue_idx, 1.0, [(geneSelectorComp_idx, geneCombo_idx)])) self.bkfs.append(bkf) assert len(self.pathways) > 0, "Have not processed pathways yet"
from pybkb.core.python_base.fusion import fuse sys.path.append( '/home/cyakaboski/src/python/projects/bkb-pathway-provider/core') from reasoner import Reasoner, _constructSNodesByHead from query import Query PATIENTS = ['Patient_{}'.format(i) for i in range(10)] NUM_GENES = 5 bkfs = list() #-- Make BKB frags for j, _ in enumerate(PATIENTS): bkf = BKB() for i in range(NUM_GENES): #-- Setup Gene i component. comp_idx = bkf.addComponent('Gene{}_mutated'.format(i)) stateTrue_idx = bkf.addComponentState(comp_idx, 'True') if random.choice([True, False]): bkf.addSNode( BKB_S_node(init_component_index=comp_idx, init_state_index=stateTrue_idx, init_probability=1)) bkfs.append(bkf) #-- Fuse patients together. fused_bkb = fuse(bkfs, [1 for _ in range(len(PATIENTS))],
def read_expression_snodes(self, expression_levels_dict, tcga_expression_file, react_gene_file, pathways_file): #-- Process all gene_reaction s_nodes and assume there is a header with gene names. with open(react_gene_file, 'r') as csv_file: reader = csv.reader(csv_file) rows = [row for row in reader] #-- Process Gene Names from header: print(rows[0]) genes = rows[0][1:] genes = [genes[i][:-4] for i in range(0,len(genes),2)] print(genes) for row in rows[1:]: bkf = BKB(name=row[0] + ' BKF') reaction_head_name = row[0] react_component = BKB_component(reaction_head_name) i_node_true = BKB_I_node('True', react_component) i_node_false = BKB_I_node('False', react_component) react_component.addINode(i_node_true) react_component.addINode(i_node_false) bkf.addComponent(react_component) #-- Extract and Make I-nodes for gene_j, row_i in enumerate(range(1,len(row), 2)): gene_name = genes[gene_j] gene_low = row[row_i] gene_high = row[row_i + 1] if gene_low != '': print(gene_low, gene_high) num_levels = expression_levels_dict[gene_name] levels = [rag for rag in np.linspace(int(gene_low), int(gene_high), num_levels)] component_states = ['{} | {}'.format(levels[i], levels[i+1]) for i in range(len(levels)-1)] component = BKB_component(gene_name + ' ExpressionLv') for state in component_states: i_node = BKB_I_node(state, component) component.addINode(i_node) bkf.addComponent(component) for idx in range(bkf.findComponent(component.name).getNumberStates()): i_node = component.getState(idx) bkf.addSNode(BKB_S_node(component, i_node, random.random())) bkf.addSNode(BKB_S_node(react_component, i_node_true, random.random(), [(component, i_node)])) bkf.addSNode(BKB_S_node(react_component, i_node_false, random.random(), [(component, i_node)])) self.bkfs.append(bkf) print('Done') #-- Process Pathway BKFs with open(pathways_file, 'r') as csv_file: reader = csv.reader(csv_file) bkf = BKB() for row in reader: tail = row[0] head = row[1] states = ['True', 'False'] if bkf.findComponent(tail) == -1: component_tail = BKB_component(tail) for state in states: component_tail.addINode(BKB_I_node(state, component_tail)) bkf.addComponent(component_tail) else: component_tail = bkf.findComponent(tail) if bkf.findComponent(head) == -1: component_head = BKB_component(head) for state in states: component_head.addINode(BKB_I_node(state, component_head)) bkf.addComponent(component_head) else: component_head = bkf.findComponent(head) for state1 in states: for state2 in states: bkf.addSNode(BKB_S_node(component_head, component_head.findState(state1), random.random(), [(component_tail, component_tail.findState(state2))]) ) self.bkfs.append(bkf) print('Complete')
state_name)].append(prob) except: results[('Updates', comp_name, state_name)] = [prob] del query print('Complete Patient {}.'.format(i)) return self.results_to_dataframe(results), title def results_to_dataframe(self, results): print(results) df = pd.DataFrame(data=results) df.to_csv('crossValid-results-1000.csv') return df if __name__ == '__main__': fused_bkb = BKB() fused_bkb.load( '/home/public/data/ncats/90PERCENTValidationAllPatientsWithDrug/set1/fusion.bkb' ) #print(fused_bkb.getAllComponentNames()) patient_data_file = '/home/public/data/ncats/90PERCENTValidationAllPatientsWithDrug/set1/patient_data.pk' test_patient_hashes = read_withheldPatientFile( '/home/public/data/ncats/90PERCENTValidationAllPatientsWithDrug/set1/withheldPatients.csv' ) #print(test_patient_hashes) ''' fused_bkb = BKB() fused_bkb.load('10pat.bkb') patient_data_file = 'patient_data.pk' test_patient_hashes = None #print(test_patient_hashes)
def processPatientBKF(self): assert len( self.patients) > 0, "Have not processed Patient and gene data yet." #print("Forming Patient BKFs...") allGenes = list() for pat in tqdm.tqdm(self.patients, desc='Forming patient BKFs'): bkf = BKB(name=pat.patientID) variantCompIndices = list() variantCompNames = list() variantCompStateIndices = list() for idx, gene in enumerate(pat.mutatedGenes): allGenes.append(gene) # gene mutGeneComp_idx = bkf.addComponent('mut_{}='.format(gene)) iNodeGeneMut_idx = bkf.addComponentState( mutGeneComp_idx, 'True') # form SNode o---->[mut_<genename>=True] bkf.addSNode(BKB_S_node(mutGeneComp_idx, iNodeGeneMut_idx, 1.0)) if 'var_' + pat.variants[idx] + '=' in variantCompNames: cIdx = variantCompNames.index('var_{}='.format( pat.variants[idx])) #mut_var combo mutVarComp_idx = bkf.addComponent('mut-var_{}='.format( pat.mutatedGeneVariants[idx])) iNodeMutVar_idx = bkf.addComponentState( mutVarComp_idx, 'True') #mut_var s-node bkf.addSNode( BKB_S_node(mutVarComp_idx, iNodeMutVar_idx, 1.0, [(mutGeneComp_idx, iNodeGeneMut_idx), (variantCompIndices[cIdx], variantCompStateIndices[cIdx])])) else: #var variantComp_idx = bkf.addComponent('var_{}='.format( pat.variants[idx])) iNodeVariant_idx = bkf.addComponentState( variantComp_idx, 'True') #var s-node bkf.addSNode( BKB_S_node(variantComp_idx, iNodeVariant_idx, 1.0)) variantCompIndices.append(variantComp_idx) variantCompStateIndices.append(iNodeGeneMut_idx) variantCompNames.append( bkf.getComponentName(variantComp_idx)) #mut_var combo mutVarComp_idx = bkf.addComponent('mut-var_{}='.format( pat.mutatedGeneVariants[idx])) iNodeMutVar_idx = bkf.addComponentState( mutVarComp_idx, 'True') #mut_var s-node bkf.addSNode( BKB_S_node(mutVarComp_idx, iNodeMutVar_idx, 1.0, [(mutGeneComp_idx, iNodeGeneMut_idx), (variantComp_idx, iNodeVariant_idx)])) self.bkfs.append(bkf)
def processPathwayBKF(self, exhaustiveOr=False): assert len(self.pathways) > 0, "Have not processed pathways yet" for pathway in tqdm.tqdm(self.pathways, desc='Processing pathway BKFs'): bkf = BKB(name=pathway.ID) if "_hier" in pathway.ID: #head pathwayParentComp_idx = bkf.addComponent('{}_active='.format( pathway.head)) pathwayParentTrue_idx = bkf.addComponentState( pathwayParentComp_idx, 'True') #tail - should only be 1 for _hier bkfs pathwayChildComp_idx = bkf.addComponent('{}_active='.format( pathway.tails[0])) pathwayChildTrue_idx = bkf.addComponentState( pathwayChildComp_idx, 'True') #S-node bkf.addSNode( BKB_S_node(pathwayChildComp_idx, pathwayChildTrue_idx, 1.0)) bkf.addSNode( BKB_S_node(pathwayParentComp_idx, pathwayParentTrue_idx, 1.0, [(pathwayChildComp_idx, pathwayChildTrue_idx)])) else: ''' #head pathwayHierComp_idx = bkf.addComponent('{}_active='.format(pathway.head)) pathwayHierTrue_idx = bkf.addComponentState(pathwayHierComp_idx, 'True') #tails for tail in pathway.tails: statConditionComp_idx = bkf.addComponent('mu-STD<={}<=mu+STD'.format(tail)) statConditionTrue_idx = bkf.addComponentState(statConditionComp_idx, 'True') bkf.addSNode(BKB_S_node(statConditionComp_idx, statConditionTrue_idx, 1.0)) bkf.addSNode(BKB_S_node(pathwayHierComp_idx, pathwayHierTrue_idx, 1.0, [(statConditionComp_idx, statConditionTrue_idx)])) self.bkfs.append(bkf) ''' #======= if exhaustiveOr: print("not implemented") else: # pathway pathwayReactionComp_idx = bkf.addComponent(pathway.head + "_active=") pathwayReactionTrue_idx = bkf.addComponentState( pathwayReactionComp_idx, 'True') # gene slector geneSelectorComp_idx = bkf.addComponent("Gene_combo=") #tails for tail in pathway.tails: geneCombo_idx = bkf.addComponentState( geneSelectorComp_idx, tail) statConditionComp = BKB_component("mu-STD>=" + tail + "<=mu+STD=") statConditionTrue = BKB_I_node('True', statConditionComp) statConditionComp_idx = bkf.addComponent("mu-STD>=" + tail + "<=mu+STD=") statConditionTrue_idx = bkf.addComponentState( statConditionComp_idx, 'True') bkf.addSNode( BKB_S_node(statConditionComp_idx, statConditionTrue_idx, 1.0)) bkf.addSNode( BKB_S_node(geneSelectorComp_idx, geneCombo_idx, 1.0, [(statConditionComp_idx, statConditionTrue_idx)])) bkf.addSNode( BKB_S_node( pathwayReactionComp_idx, pathwayReactionTrue_idx, 1.0, [(geneSelectorComp_idx, geneCombo_idx)])) self.bkfs.append(bkf)
import sys from pybkb import bayesianKnowledgeBase as BKB from pybkb.core.python_base.reasoning import checkMutex #!!!!!!!!!! Change to your local bkb-pathway-core directory. #sys.path.append('/home/ghyde/bkb-pathway-provider/core') sys.path.append( '/home/cyakaboski/src/python/projects/bkb-pathway-provider/core') from reasoner import Reasoner from query import Query #-- 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' #-- Instaniate reasoner reasoner = Reasoner(fused_bkb=fused_bkb) #-- Set the patient data file reasoner.set_src_metadata(patient_data_file) #reasoner.collapsed_bkb.makeGraph()
state_name)].append(prob) except: results[('Updates', comp_name, state_name)] = [prob] del query print('Complete Patient {}.'.format(i)) return self.results_to_dataframe(results), title def results_to_dataframe(self, results): print(results) df = pd.DataFrame(data=results) df.to_csv('crossValid-results-1.csv') return df if __name__ == '__main__': fused_bkb = BKB() fused_bkb.load( '/home/public/data/ncats/90PERCENTValidation200Patients40Validation/set1/fusion.bkb' ) #print(fused_bkb.getAllComponentNames()) patient_data_file = '/home/public/data/ncats/90PERCENTValidation200Patients40Validation/set1/patient_data.pk' test_patient_hashes = read_withheldPatientFile( '/home/public/data/ncats/90PERCENTValidation200Patients40Validation/set1/withheldPatients.csv' ) #print(test_patient_hashes) ''' fused_bkb = BKB() fused_bkb.load('10pat.bkb') patient_data_file = 'patient_data.pk' test_patient_hashes = None #print(test_patient_hashes)
import os import sys import random from pybkb import bayesianKnowledgeBase as BKB #-- Change to your local data folder NCATS_DIR = '/home/cyakaboski/src/python/projects/bkb-pathway-provider' sys.path.append(os.path.join(NCATS_DIR, 'core')) from query import Query from reasoner import Reasoner if __name__ == '__main__': bkb = BKB() bkb.load('/home/public/data/ncats/fullBKFs/patientBKFs/fusion.bkb') g = bkb.makeGraph(show=False, layout='neato') ##-- Select Random Evidence #num_evidence = 1 #evidence = dict() #for _ in range(num_evidence): # rand_rv = random.choice(bkb.components) # while rand_rv.name in evidence: # rand_rv = random.choice(bkb.components) # #-- Get a random state # rand_state = random.choice(rand_rv.states) # evidence[rand_rv.name] = rand_state.name
else: print(patID) print(holdoutResults[idx][indexFalse],holdoutResults[idx][indexTrue]) print(probOne, probTwo) if holdoutResults[idx][indexFalse][2] > holdoutResults[idx][indexTrue][2]: print("\tfalse -",targetVal, "CORRECT") numCorrect += 1 else: print("\tfalse -",targetVal, "WRONG") numWrong += 1 print("Number correct:", numCorrect) print("Number wrong:", numWrong) if __name__ == '__main__': fused_bkb = BKB() fused_bkb.load('/home/public/data/ncats/BabelBKBs/collapsedAll/fusion.bkb') patient_data_file = '/home/public/data/ncats/BabelBKBs/collapsedAll/patient_data.pk' withheld_patients_file = '/home/public/data/ncats/BabelBKBs/collapsedAll/withheldPatients.csv' #fused_bkb.load('/home/public/data/ncats/660Pats5PercentHoldout/fusion.bkb') #patient_data_file = '/home/public/data/ncats/660Pats5PercentHoldout/patient_data.pk' #withheld_patients_file = '/home/public/data/ncats/660Pats5PercentHoldout/withheldPatients.csv' compNames = fused_bkb.getAllComponentNames() f = open(withheld_patients_file, 'r') withheldPatientHashes = f.read().split(',') patientDict = pickle.load(open(patient_data_file, 'rb')) patientsMutationVariantEvidence = []
if __name__ == '__main__': processor = ReactomePathwayProcessor() processor.processGenePathways(reactome_g2r_file) processor.processHierarchyPathways(reactome_p2p_file) processor.processPathwayBKF() bkf_files, source_names = processor.BKFsToFile('/tmp/') bkfs = processor.bkfs fuse(bkfs, reliabilities=[random.random() for _ in range(len(bkfs))], source_names=source_names, file_prefix='react_only-') fused_bkb = BKB() fused_bkb.load('/tmp/react_only-fusion.bkb') #g = fused_bkb.makeGraph(show=True, layout='neato') ##-- Select Random Evidence #num_evidence = 1 #evidence = dict() #for _ in range(num_evidence): # rand_rv = random.choice(bkb.components) # while rand_rv.name in evidence: # rand_rv = random.choice(bkb.components) # #-- Get a random state # rand_state = random.choice(rand_rv.states) # evidence[rand_rv.name] = rand_state.name
print(holdoutResults[idx][indexFalse], holdoutResults[idx][indexTrue]) print(probOne, probTwo) if holdoutResults[idx][indexFalse][2] > holdoutResults[idx][ indexTrue][2]: print("\tfalse -", targetVal, "CORRECT") numCorrect += 1 else: print("\tfalse -", targetVal, "WRONG") numWrong += 1 print("Number correct:", numCorrect) print("Number wrong:", numWrong) if __name__ == '__main__': fused_bkb = BKB() fused_bkb.load( '/home/public/data/ncats/AxleBKBS/660Pats6HoldoutSTAGING/fusion.bkb') patient_data_file = '/home/public/data/ncats/AxleBKBS/660Pats6HoldoutSTAGING/patient_data.pk' withheld_patients_file = '/home/public/data/ncats/AxleBKBS/660Pats6HoldoutSTAGING/withheldPatients.csv' #fused_bkb.load('/home/public/data/ncats/660Pats5PercentHoldout/fusion.bkb') #patient_data_file = '/home/public/data/ncats/660Pats5PercentHoldout/patient_data.pk' #withheld_patients_file = '/home/public/data/ncats/660Pats5PercentHoldout/withheldPatients.csv' compNames = fused_bkb.getAllComponentNames() f = open(withheld_patients_file, 'r') withheldPatientHashes = f.read().split(',') patientDict = pickle.load(open(patient_data_file, 'rb'))
import os import sys from pybkb import bayesianKnowledgeBase as BKB #-- Change to your local data folder NCATS_DIR = '/home/cyakaboski/src/python/pojects/bkb-pathway-provider' sys.path.append(os.path.join(NCATS_DIR, 'core')) from query import Query from reasoner import Reasoner if __name__ == '__main__': bkb = BKB() bkb.load('/home/public/data/ncats/fusedPatientBKBSmall/fusion.bkb') reasoner = Reasoner(bkb) query0 = Query(evidence={ '_sourceFusion_14_02_2020_16:35:04__mut_CACNA1H=': '[0]_-7750956075882572850' }, targets=['mut_CACNA1H=', 'mu-STD>=CACNA1H<=mu+STD='], type='updating') result = reasoner.analyze_query(query0)
query = self.reasoner.analyze_query( copy.deepcopy(query), preprocessed_bkb=self.processed_bkb) summary = query.result.summary() #query.result.summary() for update, prob in query.result.updates.items(): comp_idx, state_idx = update comp_name = query.bkb.getComponentName(comp_idx) state_name = query.bkb.getComponentINodeName( comp_idx, state_idx) probs.append((comp_name, state_name, prob)) return (probs[0], probs[1]), summary if __name__ == '__main__': fused_bkb = BKB() fused_bkb.load('/home/public/data/ncats/663Pats6Holdouts/fusion.bkb') patient_data_file = '/home/public/data/ncats/663Pats6Holdouts/patient_data.pk' withheld_patients_file = '/home/public/data/ncats/663Pats6Holdouts/withheldPatients.csv' #fused_bkb.load('/home/public/data/ncats/90PERCENTValidation50Patients10Validation/set1/fusion.bkb') #patient_data_file = '/home/public/data/ncats/90PERCENTValidation50Patients10Validation/set1/patient_data.pk' #withheld_patients_file = '/home/public/data/ncats/90PERCENTValidation50Patients10Validation/set1/withheldPatients.csv' compNames = fused_bkb.getAllComponentNames() f = open(withheld_patients_file, 'r') withheldPatientHashes = f.read().split(',') patientDict = pickle.load(open(patient_data_file, 'rb')) patientsDynamicEvidence = []
import sys from pybkb import bayesianKnowledgeBase as BKB from pybkb.core.python_base.reasoning import checkMutex #!!!!!!!!!! Change to your local bkb-pathway-core directory. #sys.path.append('/home/ghyde/bkb-pathway-provider/core') sys.path.append('/home/cyakaboski/src/python/projects/bkb-pathway-provider/core') from reasoner import Reasoner from query import Query #-- Initalize a BKB fused_bkb = BKB() #-- Load in the fused bkb from our datafiles fused_bkb.load('/home/public/data/ncats/BabelBKBs/collapsedAll/fusion.bkb') #-- Here are the associated patient data files patient_data_file = '/home/public/data/ncats/BabelBKBs/collapsedAll/patient_data.pk' withheld_patients_file = '/home/public/data/ncats/BabelBKBS/collapsedAll/withheldPatients.csv' #-- Instaniate reasoner reasoner = Reasoner(fused_bkb=fused_bkb) #-- Set the patient data file reasoner.set_src_metadata(patient_data_file) #reasoner.collapsed_bkb.makeGraph() #-- If you want to see what genetic or demographic evidence is avaliable, uncomment the line below #print(reasoner.metadata_ranges)