Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding plotting utils #81

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions experiments/pdac/launcher_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
python plot_kms.py -R fedeca_dataset/fedeca_dataset/fl/\(\'ffcd\',\ \'pancan\'\)_results_2025-01-17_15-10-22_is_folfirinoxTrue_treatmentffcd_fed_kaplan_120b1807-5f28-4f26-a4aa-eddd68847dd1.pkl 2>&1 | tee -a log2
python plot_kms.py -R fedeca_dataset/fedeca_dataset/fl/\(\'ffcd\',\ \'pancan\'\)_results_2025-01-17_21-53-51_is_folfirinoxFalse_treatmentffcd_fed_kaplan_d110ed36-7a95-434f-9a60-e4f6b1484e65.pkl 2>&1 | tee -a log3
python plot_kms.py -R fedeca_dataset/fedeca_dataset/fl/\(\'ffcd\',\ \'idibigi\'\)_results_2025-01-19_18-40-01_is_folfirinoxFalse_treatmentidibigi_fed_kaplan_d21d92ba-1dc1-4940-8dee-8133da8c9008.pkl 2>&1 | tee -a log1

python plot_kms.py -R fedeca_dataset/fedeca_dataset/fl/\(\'idibigi\',\ \'ffcd\'\)_results_2025-01-17_11-58-55_is_folfirinoxTrue_treatmentidibigi_fed_kaplan_d6e19450-49f7-4d11-a759-7d281048c637.pkl 2>&1 | tee -a log4
python plot_kms.py -R fedeca_dataset/fedeca_dataset/fl/\(\'idibigi\',\ \'pancan\'\)_results_2025-01-17_10-20-54_is_folfirinoxTrue_treatmentidibigi_fed_kaplan_c605b601-1697-46cd-86be-0a5f1e574c04.pkl 2>&1 | tee -a log5
python plot_kms.py -R fedeca_dataset/fedeca_dataset/fl/\(\'pancan\',\ \'idibigi\'\)_results_2025-01-19_20-21-26_is_folfirinoxFalse_treatmentidibigi_fed_kaplan_a7e82932-ee64-469d-8b5c-34a856eebe75.pkl 2>&1 | tee -a log6
60 changes: 60 additions & 0 deletions experiments/pdac/plot_exchangeability_kms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import matplotlib.pyplot as plt
from fedeca.utils.plot_fed_kaplan import compute_ci
import pickle
import re
import argparse
from pathlib import Path


if __name__ == "__main__":

parser = argparse.ArgumentParser()
parser.add_argument('--results_name', "-R", type=str, help="Name of a file containing pairs of centers exchangeability experiments")

args = parser.parse_args()

results_name = args.results_name

with open(Path(".") / results_name, "rb") as f:
fl_results = pickle.load(f)

names_mapping = {"ffcd": "FFCD", "idibigi": "IDIBGI", "pancan": "PanCAN"}
TREATMENT = re.findall("(?<=treatment)[a-z]+", results_name)[0]

POPULATION = re.findall("(?<=is_folfirinox)[a-zA-Z]+", results_name)[0] == "True"

POPULATION = "FOLFIRINOX" if POPULATION else "GEM+NAB"

color = "blue" if POPULATION == "FOLFIRINOX" else "orange"
centers = set([name[1:-1] for name in Path(results_name).stem.split("_")[0][1:-1].split(", ")])
#breakpoint()
centers.remove(TREATMENT)
CONTROL = list(centers)[0]
TREATMENT = names_mapping[TREATMENT]
CONTROL = names_mapping[CONTROL]
fl_grid_treated, fl_s_treated, fl_var_s_treated, fl_cumsum_treated = fl_results[
"treated"
]

(
fl_grid_untreated,
fl_s_untreated,
fl_var_s_untreated,
fl_cumsum_untreated,
) = fl_results["untreated"]

lower_untreated, upper_untreated = compute_ci(fl_s_untreated, fl_var_s_untreated, fl_cumsum_untreated) # noqa: E501
lower_treated, upper_treated = compute_ci(fl_s_treated, fl_var_s_treated, fl_cumsum_treated)


ax = plt.plot(fl_grid_untreated, fl_s_untreated, label=CONTROL, color=color, linestyle='-')
plt.fill_between(fl_grid_untreated, lower_untreated, upper_untreated, alpha=0.25, linewidth=1.0, step="post", color=color) # noqa: E501

ax = plt.plot(fl_grid_treated, fl_s_treated, label=TREATMENT, color=color, linestyle='--')
plt.fill_between(fl_grid_treated, lower_treated, upper_treated, alpha=0.25, linewidth=1.0, step="post", color=color) # noqa: E501

plt.ylim(0., 1.)
plt.ylabel("Probability of survival")
plt.xlabel("Survival time (months)")
plt.legend()
plt.savefig(f"fed_km_T{TREATMENT}_C{CONTROL}_POP{POPULATION}.pdf", bbox_inches="tight", dpi=300)
Loading