Ejemplo n.º 1
0
            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 = []
    patientIDs = []
    count = 0
Ejemplo n.º 2
0
                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 = []
    patientIDs = []
    for withheldPatientHash in withheldPatientHashes:
Ejemplo n.º 3
0
                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'))
    patientsMutationDrugEvidence = []
    patientIDs = []
    for withheldPatientHash in withheldPatientHashes:
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)

#-- Set the patient data file
reasoner.set_src_metadata(patient_data_file)
#reasoner.collapsed_bkb.makeGraph()
Ejemplo n.º 5
0
                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(',')

    patientDict = pickle.load(open(patient_data_file, 'rb'))
    patientsMutationPathEvidence = []
Ejemplo n.º 6
0
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)
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('Got Evidence')
                        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)
    '''
    #demo_evidence_static = [('Drug_Name(s)', '==', 'TAMOXIFEN')]
Ejemplo n.º 9
0
                        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)
    demo_evidence = ('Age_Of_Diagnosis', '>=')
    demo_evidence_val = 20000
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

    #print('Got Evidence')