Exemplo n.º 1
0
    def test_igf_intervention_on_mek(self):

        bel_file_path = "data/igf.json"
        config_file_path = "data/COVID-19-config.json"
        data_file_path = "data/observational_igf.csv"
        output_pickle_object_file = "igf_scm.pkl"

        scm = SCM(bel_file_path, config_file_path, data_file_path)

        exogenous_noise = scm.exogenous_dist_dict
        condition_data = scm.model(exogenous_noise)
        print(condition_data)
        # target = "a(p(Erk))"
        intervention_data = {"a(p(Mek))": 40.0}

        do_model = scm.intervention(intervention_data)
        samples = [do_model(exogenous_noise) for _ in range(5000)]
        df = pd.DataFrame(samples)
        for col in df.columns:
            for i in range(len(df)):
                if torch.is_tensor(df[col][i]):
                    df[col][i] = df[col][i].item()
        df2 = pd.read_csv("data/bel2scm_samples_igf.csv")
        erk_diff = df["a(p(Erk))"] - df2["a(p(Erk))"]
        erk_diff.to_csv("data/erk_do_mek_40_minus_erk.csv")
        df.to_csv("data/intervention_mek_40_samples_igf.csv")
        self.assertTrue(True, True)
Exemplo n.º 2
0
    def test_covid_direct_simulation_causal_effect(self):
        torch.manual_seed(23)
        time1 = time.time()
        bel_file_path = os.path.join(DATA, "covid_input.json")
        config_file_path = os.path.join(DATA, "COVID-19-config.json")
        data_file_path = os.path.join(
            DATA, "observational_samples_from_sigmoid_known_parameters.csv")
        scm = SCM(bel_file_path, config_file_path, data_file_path)

        exogenous_noise = scm.exogenous_dist_dict
        condition_data = scm.model(exogenous_noise)
        intervention_data = {"a(TOCI)": 0.0}

        do_model = scm.intervention(intervention_data)
        samples = [do_model(exogenous_noise) for _ in range(5000)]
        df = pd.DataFrame(samples)
        for col in df.columns:
            for i in range(len(df)):
                if torch.is_tensor(df[col][i]):
                    df[col][i] = df[col][i].item()
        df2 = pd.read_csv(os.path.join(DATA, "bel2scm_samples_covid.csv"))
        cytokine_diff = df["a(cytokine)"] - df2["a(cytokine)"]
        cytokine_diff.to_csv(
            os.path.join(DATA, "cytokine_do_toci_0_minus_cytokine.csv"))
        df.to_csv(os.path.join(DATA, "intervention_toci_0_samples_covid.csv"))
Exemplo n.º 3
0
    def test_igf_intervention_on_ras(self):
        """
        Description: This experiment gets causal effect on erk by
                    intervening on mek for igf graph using bel2scm algorithm
        """

        bel_file_path = "data/igf.json"
        config_file_path = "data/COVID-19-config.json"
        data_file_path = "data/observational_igf.csv"

        scm = SCM(bel_file_path, config_file_path, data_file_path)

        exogenous_noise = scm.exogenous_dist_dict
        condition_data = scm.model(exogenous_noise)
        print(condition_data)
        intervention_data = {"a(p(Ras))": 30.0}

        do_model = scm.intervention(intervention_data)
        samples = [do_model(exogenous_noise) for _ in range(5000)]
        df = pd.DataFrame(samples)
        for col in df.columns:
            for i in range(len(df)):
                if torch.is_tensor(df[col][i]):
                    df[col][i] = df[col][i].item()
        df2 = pd.read_csv("data/bel2scm_samples_igf.csv")
        erk_diff = df["a(p(Erk))"] - df2["a(p(Erk))"]
        erk_diff.to_csv("data/erk_do_ras_30_minus_erk.csv")
        df.to_csv("data/intervention_samples_igf.csv")
        self.assertTrue(True, True)
Exemplo n.º 4
0
    def test_igf_intervention_on_mek(self):
        torch.manual_seed(23)

        bel_file_path = os.path.join(DATA, "igf.json")
        config_file_path = os.path.join(DATA, "COVID-19-config.json")
        data_file_path = os.path.join(DATA, "observational_igf.csv")
        output_pickle_object_file = "../../../igf_scm.pkl"

        scm = SCM(bel_file_path, config_file_path, data_file_path)

        exogenous_noise = scm.exogenous_dist_dict
        condition_data = scm.model(exogenous_noise)
        print(condition_data)
        # target = "a(p(Erk))"
        intervention_data = {"a(p(Mek))": 40.0}

        do_model = scm.intervention(intervention_data)
        samples = [do_model(exogenous_noise) for _ in range(5000)]
        df = pd.DataFrame(samples)
        for col in df.columns:
            for i in range(len(df)):
                if torch.is_tensor(df[col][i]):
                    df[col][i] = df[col][i].item()
        df2 = pd.read_csv(os.path.join(DATA, "bel2scm_samples_igf.csv"))
        erk_diff = df["a(p(Erk))"] - df2["a(p(Erk))"]
        erk_diff.to_csv(os.path.join(DATA, "erk_do_mek_40_minus_erk.csv"))
        df.to_csv(os.path.join(DATA, "intervention_mek_40_samples_igf.csv"))
Exemplo n.º 5
0
    def test_mapk_erk_samples(self):
        bel_file_path = os.path.join(DATA, "mapk.json")
        config_file_path = os.path.join(DATA, "COVID-19-config.json")
        data_file_path = os.path.join(DATA, "mapk3000.csv")
        # output_pickle_object_file = os.path.join(HERE, "../mapk_scm.pkl"

        scm = SCM(bel_file_path, config_file_path, data_file_path)
        exogenous_noise = scm.exogenous_dist_dict
        samples = [scm.model(exogenous_noise) for i in range(3000)]
        print(samples)
Exemplo n.º 6
0
    def test_covid_toci0_bel2scm_causal_effect(self):
        torch.manual_seed(23)
        bel_file_path = os.path.join(DATA, "covid_input.json")
        config_file_path = os.path.join(DATA, "COVID-19-config.json")
        data_file_path = os.path.join(
            DATA, "observational_samples_from_sigmoid_known_parameters.csv")

        scm = SCM(bel_file_path, config_file_path, data_file_path)
        condition_data = {
            # 'a(SARS_COV2)': tensor(67.35032),
            # 'a(PRR)': tensor(89.7037),
            # 'a(ACE2)': tensor(29.747593),
            # 'a(AngII)': tensor(68.251114),
            # 'a(AGTR1)': tensor(90.96106999999999),
            # 'a(ADAM17)': tensor(86.84893000000001),
            # 'a(TOCI)': tensor(40.76684),
            # 'a(TNF)': tensor(76.85005),
            # 'a(sIL_6_alpha)': tensor(87.99491),
            # 'a(EGF)': tensor(84.55391),
            # 'a(EGFR)': tensor(79.94534),
            # 'a(IL6_STAT3)': tensor(83.39896),
            # 'a(NF_xB)': tensor(82.79433399999999),
            # 'a(IL6_AMP)': tensor(81.38015),
            # 'a(cytokine)': tensor(80.21895)
            'a(SARS_COV2)': tensor(61.631156999999995),
            'a(PRR)': tensor(87.76389),
            'a(ACE2)': tensor(39.719845),
            'a(AngII)': tensor(59.212959999999995),
            'a(AGTR1)': tensor(84.39899399999999),
            'a(ADAM17)': tensor(85.84442),
            'a(TOCI)': tensor(67.33063),
            'a(TNF)': tensor(77.83915),
            'a(sIL_6_alpha)': tensor(57.584044999999996),
            'a(EGF)': tensor(86.26822),
            'a(EGFR)': tensor(81.4849),
            'a(IL6_STAT3)': tensor(69.57323000000001),
            'a(NF_xB)': tensor(83.75941),
            'a(IL6_AMP)': tensor(77.52906),
            'a(cytokine)': tensor(79.07555)
        }
        target = "a(cytokine)"
        intervention_data = {"a(TOCI)": 0.0}

        causal_effects1, counterfactual_samples1 = scm.counterfactual_inference(
            condition_data, intervention_data, target, True)
        samples_df = pd.DataFrame(causal_effects1)
        samples_df.to_csv(os.path.join(
            DATA,
            "causal_effect_bel2scm_hardcoded_sigmoid_moderately_ill.csv"),
                          index=False)
Exemplo n.º 7
0
    def test_igf(self):
        torch.manual_seed(101)

        bel_file_path = os.path.join(DATA, "igf.json")
        config_file_path = os.path.join(DATA, "COVID-19-config.json")
        data_file_path = os.path.join(DATA, "observational_igf.csv")
        # output_pickle_object_file = "../../igf_scm.pkl"

        scm = SCM(bel_file_path, config_file_path, data_file_path)
        # save_scm_object(output_pickle_object_file, scm)
        exogenous_noise = scm.exogenous_dist_dict
        samples = [scm.model(exogenous_noise) for i in range(5000)]
        df = pd.DataFrame(samples)
        for col in df.columns:
            for i in range(len(df)):
                if torch.is_tensor(df[col][i]):
                    df[col][i] = df[col][i].item()
        df.to_csv(os.path.join(DATA, "bel2scm_samples_igf.csv"))
Exemplo n.º 8
0
    def test_covid_noisy_model_samples(self):
        torch.manual_seed(23)
        time1 = time.time()
        bel_file_path = os.path.join(DATA, "covid_input.json")
        config_file_path = os.path.join(DATA, "COVID-19-config.json")
        data_file_path = os.path.join(DATA,
                                      "covid_noisy_reparameterized_data.csv")

        scm = SCM(bel_file_path, config_file_path, data_file_path)

        exogenous_noise = scm.exogenous_dist_dict
        samples = torch.tensor([
            list(scm.model(exogenous_noise).values()) for _ in range(5500)
        ]).detach().numpy()
        np.savetxt(os.path.join(
            DATA, "covid_bel2scm_noisy_reparameterized_samples.csv"),
                   samples,
                   delimiter=',')
Exemplo n.º 9
0
    def test_covid(self):
        torch.manual_seed(23)

        bel_file_path = os.path.join(DATA, "covid_input.json")
        config_file_path = os.path.join(DATA, "COVID-19-config.json")
        data_file_path = os.path.join(
            DATA, "observational_samples_from_sigmoid_known_parameters.csv")
        output_pickle_object_file = "../../../covid_scm.pkl"

        scm = SCM(bel_file_path, config_file_path, data_file_path)
        exogenous_noise = scm.exogenous_dist_dict
        samples = [scm.model(exogenous_noise) for i in range(5000)]
        df = pd.DataFrame(samples)
        for col in df.columns:
            for i in range(len(df)):
                if torch.is_tensor(df[col][i]):
                    df[col][i] = df[col][i].item()
        df.to_csv(os.path.join(DATA, "bel2scm_samples_covid.csv"))
        save_scm_object(output_pickle_object_file, scm)
Exemplo n.º 10
0
    def test_covid_causal_effect_with_estimated_parameters_datapoint1(self):

        torch.manual_seed(23)
        time1 = time.time()
        bel_file_path = "data/covid_input.json"
        config_file_path = "data/COVID-19-config.json"
        data_file_path = "data/observational_samples_from_sigmoid_known_parameters.csv"

        scm = SCM(bel_file_path, config_file_path, data_file_path)
        condition_data = {
            'a(SARS_COV2)': tensor(67.35032),
            'a(PRR)': tensor(89.7037),
            'a(ACE2)': tensor(29.747593),
            'a(AngII)': tensor(68.251114),
            'a(AGTR1)': tensor(90.96106999999999),
            'a(ADAM17)': tensor(86.84893000000001),
            'a(TOCI)': tensor(40.76684),
            'a(TNF)': tensor(76.85005),
            'a(sIL_6_alpha)': tensor(87.99491),
            'a(EGF)': tensor(84.55391),
            'a(EGFR)': tensor(79.94534),
            'a(IL6_STAT3)': tensor(83.39896),
            'a(NF_xB)': tensor(82.79433399999999),
            'a(IL6_AMP)': tensor(81.38015),
            'a(cytokine)': tensor(80.21895)
        }
        target = "a(cytokine)"
        intervention_data = {"a(TOCI)": 0.0}

        causal_effects1, counterfactual_samples1 = scm.counterfactual_inference(
            condition_data, intervention_data, target, True)
        print("time required for causal effects", time.time() - time1)
        samples_df = pd.DataFrame(causal_effects1)
        samples_df.to_csv(
            "data/causal_effect_sigmoid_with_estimated_parameters_datapoint1.csv",
            index=False)
Exemplo n.º 11
0
    def test_covid_causal_effect_with_estimated_parameters_datapoint2(self):

        torch.manual_seed(23)
        time1 = time.time()
        bel_file_path = "data/covid_input.json"
        config_file_path = "data/COVID-19-config.json"
        data_file_path = "data/observational_samples_from_sigmoid_known_parameters.csv"

        scm = SCM(bel_file_path, config_file_path, data_file_path)
        condition_data = {
            'a(SARS_COV2)': 61.631156999999995,
            'a(PRR)': 87.76389,
            'a(ACE2)': 39.719845,
            'a(AngII)': 59.212959999999995,
            'a(AGTR1)': 84.39899399999999,
            'a(ADAM17)': 85.84442,
            'a(TOCI)': 67.33063,
            'a(TNF)': 77.83915,
            'a(sIL_6_alpha)': 57.584044999999996,
            'a(EGF)': 86.26822,
            'a(EGFR)': 81.4849,
            'a(IL6_STAT3)': 69.57323000000001,
            'a(NF_xB)': 83.75941,
            'a(IL6_AMP)': 77.52906,
            'a(cytokine)': 79.07555
        }
        target = "a(cytokine)"
        intervention_data = {"a(TOCI)": 0.0}

        causal_effects1, counterfactual_samples1 = scm.counterfactual_inference(
            condition_data, intervention_data, target, True)
        print("time required for causal effects", time.time() - time1)
        samples_df = pd.DataFrame(causal_effects1)
        samples_df.to_csv(
            "data/causal_effect_sigmoid_with_estimated_parameters_datapoint2.csv",
            index=False)