<jupyter_start><jupyter_text>$P_{fix}$ for all the patients, region envPatient "p7" is not loading for some reason, "p10" excluded because its weird data (super infected + data very close and very far from one another)<jupyter_code># Inside the bin
patient_names = ["p1", "p2", "p4", "p5", "p6", "p8", "p9", "p11"]
criteria = "in"
region = "env"
fontsize = 16

plt.figure(figsize=(10,8))
plt.title(f"Proba fix region {region} " + criteria + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.plot([0, 1], [0, 1], 'k--')
for patient_name in patient_names:
    patient = Patient.load(patient_name)

    aft = patient.get_allele_frequency_trajectories(region)
    trajectories = trajectory.create_trajectory_list(patient, region, aft)
    filtered_traj = trajectories
#     filtered_traj = [traj for traj in trajectories if traj.t[-1] > 0]  # Remove 1 point only trajectories

    frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, lost_per_bin = get_proba_fix(
        filtered_traj, criteria)
    plt.plot(frequency_bins, proba_fix, '.-', label=patient_name)

plt.legend()
plt.show()

# Through the bin

patient_names = ["p1", "p2", "p4", "p5", "p6", "p8", "p9", "p11"]
criteria = "through"
region = "env"
fontsize = 16

plt.figure(figsize=(10,8))
plt.title(f"Proba fix region {region} " + criteria + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.plot([0, 1], [0, 1], 'k--')
for patient_name in patient_names:
    patient = Patient.load(patient_name)

    aft = patient.get_allele_frequency_trajectories(region)
    trajectories = trajectory.create_trajectory_list(patient, region, aft)
    filtered_traj = trajectories
#     filtered_traj = [traj for traj in trajectories if traj.t[-1] > 0]  # Remove 1 point only trajectories

    frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, lost_per_bin = get_proba_fix(
        filtered_traj, criteria)
    plt.plot(frequency_bins, proba_fix, '.-', label=patient_name)

plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>$P_{fix}$ for all the patients, region gagPatient "p7" is not loading for some reason<jupyter_code># Inside the bin
patient_names = ["p1", "p2", "p4", "p5", "p6", "p8", "p9", "p11"]
criteria = "in"
region = "gag"
fontsize = 16

plt.figure(figsize=(10,8))
plt.title(f"Proba fix region {region} " + criteria + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.plot([0, 1], [0, 1], 'k--')
for patient_name in patient_names:
    patient = Patient.load(patient_name)

    aft = patient.get_allele_frequency_trajectories(region)
    trajectories = trajectory.create_trajectory_list(patient, region, aft)
    filtered_traj = trajectories
#     filtered_traj = [traj for traj in trajectories if traj.t[-1] > 0]  # Remove 1 point only trajectories

    frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, lost_per_bin = get_proba_fix(
        filtered_traj, criteria)
    plt.plot(frequency_bins, proba_fix, '.-', label=patient_name)

plt.legend()
plt.show()

# Through the bin

patient_names = ["p1", "p2", "p4", "p5", "p6", "p8", "p9", "p11"]
criteria = "through"
region = "gag"
fontsize = 16

plt.figure(figsize=(10,8))
plt.title(f"Proba fix region {region} " + criteria + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.plot([0, 1], [0, 1], 'k--')
for patient_name in patient_names:
    patient = Patient.load(patient_name)

    aft = patient.get_allele_frequency_trajectories(region)
    trajectories = trajectory.create_trajectory_list(patient, region, aft)
    filtered_traj = trajectories
#     filtered_traj = [traj for traj in trajectories if traj.t[-1] > 0]  # Remove 1 point only trajectories

    frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, lost_per_bin = get_proba_fix(
        filtered_traj, criteria)
    plt.plot(frequency_bins, proba_fix, '.-', label=patient_name)

plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>$P_{fix}$ for all the patients, region polPatient "p7" is not loading for some reason<jupyter_code># Inside the bin
patient_names = ["p1", "p2", "p4", "p5", "p6", "p8", "p9", "p11"]
criteria = "in"
region = "pol"
fontsize = 16

plt.figure(figsize=(10,8))
plt.title(f"Proba fix region {region} " + criteria + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.plot([0, 1], [0, 1], 'k--')
for patient_name in patient_names:
    patient = Patient.load(patient_name)

    aft = patient.get_allele_frequency_trajectories(region)
    trajectories = trajectory.create_trajectory_list(patient, region, aft)
    filtered_traj = trajectories
#     filtered_traj = [traj for traj in trajectories if traj.t[-1] > 0]  # Remove 1 point only trajectories

    frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, lost_per_bin = get_proba_fix(
        filtered_traj, criteria)
    plt.plot(frequency_bins, proba_fix, '.-', label=patient_name)

plt.legend()
plt.show()

# Through the bin

patient_names = ["p1", "p2", "p4", "p5", "p6", "p8", "p9", "p11"]
criteria = "through"
region = "pol"
fontsize = 16

plt.figure(figsize=(10,8))
plt.title(f"Proba fix region {region} " + criteria + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.plot([0, 1], [0, 1], 'k--')
for patient_name in patient_names:
    patient = Patient.load(patient_name)

    aft = patient.get_allele_frequency_trajectories(region)
    trajectories = trajectory.create_trajectory_list(patient, region, aft)
    filtered_traj = trajectories
#     filtered_traj = [traj for traj in trajectories if traj.t[-1] > 0]  # Remove 1 point only trajectories

    frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, lost_per_bin = get_proba_fix(
        filtered_traj, criteria)
    plt.plot(frequency_bins, proba_fix, '.-', label=patient_name)

plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>$P_{fix}$ Averaged over all patients<jupyter_code>def average_proba_fix(patient_names, region, bin_type="uniform", nb_bin=10, remove_one_point_traj=False):
    # Combining all the trajectories
    trajectories = []
    for patient_name in patient_names:
        patient = Patient.load(patient_name)
        aft = patient.get_allele_frequency_trajectories(region)
        trajectories = trajectories + trajectory.create_trajectory_list(patient, region, aft)

    # Computing proba and error
    frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, lost_per_bin = get_proba_fix(
        trajectories, nb_bin, bin_type)

    err_proba_fix = np.array(proba_fix) * np.sqrt(1 / np.array(fixed_per_bin) + 1 / np.array(traj_per_bin))

    return frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, err_proba_fix


def plot_average_proba(freq_bin, proba_fix, err_proba_fix, region, bin_type, fontsize=16):
    plt.figure(figsize=(10, 8))
    plt.title(f"Average P_fix region {region} " + bin_type + " bin", fontsize=fontsize)
    plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
    plt.xlabel("Frequency", fontsize=fontsize)
    plt.errorbar(freq_bin, proba_fix, yerr=err_proba_fix, fmt='.-', label="Average over patients")
    plt.plot([0, 1], [0, 1], 'k--', label="neutral expectation")
    plt.legend(fontsize=fontsize)
    plt.ylim([0,1])
    plt.show()

def get_nonuniform_bins(nb_bins, type="log", bin_range=[0.05, 0.95]):
    if type not in ["quadra", "log"]:
        raise ValueError("Type of bins must be either quadra or log.")

    if type == "quadra":
        bins = np.linspace(bin_range[0], bin_range[1], nb_bins + 1)
        non_uniform_bins = bins * bins
        return non_uniform_bins
    elif type == "log":
        return np.logspace(np.log10(bin_range[0]), np.log10(bin_range[1]), nb_bins + 1)<jupyter_output><empty_output><jupyter_text>Region env<jupyter_code># Parameters
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "uniform"
region = "env"
remove_one_point_only = False
nb_bin = 20

# Function calls
frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, err_proba_fix = average_proba_fix(patient_names, region, bin_type, nb_bin, remove_one_point_only)
plot_average_proba(frequency_bins, proba_fix, err_proba_fix, region, bin_type)
# Parameters
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "nonuniform"
region = "env"
remove_one_point_only = False
nb_bin = 20

# Function calls
frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, err_proba_fix = average_proba_fix(patient_names, region, bin_type, nb_bin, remove_one_point_only)
plot_average_proba(frequency_bins, proba_fix, err_proba_fix, region, bin_type)<jupyter_output><empty_output><jupyter_text>Region pol<jupyter_code># Parameters
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "uniform"
region = "pol"
remove_one_point_only = False
nb_bin = 10

# Function calls
frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, err_proba_fix = average_proba_fix(patient_names, region, bin_type, nb_bin, remove_one_point_only)
plot_average_proba(frequency_bins, proba_fix, err_proba_fix, region, bin_type)
# Parameters
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "nonuniform"
region = "pol"
remove_one_point_only = False
nb_bin = 10

# Function calls
frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, err_proba_fix = average_proba_fix(patient_names, region, bin_type, nb_bin, remove_one_point_only)
plot_average_proba(frequency_bins, proba_fix, err_proba_fix, region, bin_type)<jupyter_output><empty_output><jupyter_text>Region gag<jupyter_code># Parameters
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "uniform"
region = "gag"
remove_one_point_only = False
nb_bin = 10

# Function calls
frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, err_proba_fix = average_proba_fix(patient_names, region, bin_type, nb_bin, remove_one_point_only)
plot_average_proba(frequency_bins, proba_fix, err_proba_fix, region, bin_type)
# Parameters
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "nonuniform"
region = "gag"
remove_one_point_only = False
nb_bin = 10

# Function calls
frequency_bins, proba_fix, traj_per_bin, fixed_per_bin, err_proba_fix = average_proba_fix(patient_names, region, bin_type, nb_bin, remove_one_point_only)
plot_average_proba(frequency_bins, proba_fix, err_proba_fix, region, bin_type)<jupyter_output><empty_output><jupyter_text>Syn VS non_syn plots<jupyter_code>patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "nonuniform"
region = "env"
remove_one_point_only = False
nb_bin = 10
fontsize = 16

trajectories = trajectory.create_all_patient_trajectories(region)
syn_traj = [traj for traj in trajectories if traj.synonymous == True]
non_syn_traj = [traj for traj in trajectories if traj.synonymous == False]

bins, proba_fix_syn, _, _, _, err_proba_fix_syn = get_proba_fix(syn_traj, nb_bin, bin_type)
bins, proba_fix_non_syn, _, _, _, err_proba_fix_non_syn = get_proba_fix(non_syn_traj, nb_bin, bin_type)

plt.figure(figsize=(10, 8))
plt.title(f"Average P_fix region {region} " + bin_type + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.errorbar(bins, proba_fix_syn, yerr=err_proba_fix_syn, fmt='.-', label="Syn")
plt.errorbar(bins, proba_fix_non_syn, yerr=err_proba_fix_non_syn, fmt='.-', label="Non_syn")
plt.plot([0, 1], [0, 1], 'k--', label="neutral expectation")
plt.legend(fontsize=fontsize)
plt.xlim([0,1])
plt.ylim([0,1])
plt.show()
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "nonuniform"
region = "pol"
remove_one_point_only = False
nb_bin = 10
fontsize = 16

trajectories = trajectory.create_all_patient_trajectories(region)
syn_traj = [traj for traj in trajectories if traj.synonymous == True]
non_syn_traj = [traj for traj in trajectories if traj.synonymous == False]

bins, proba_fix_syn, _, _, _, err_proba_fix_syn = get_proba_fix(syn_traj, nb_bin, bin_type)
bins, proba_fix_non_syn, _, _, _, err_proba_fix_non_syn = get_proba_fix(non_syn_traj, nb_bin, bin_type)

plt.figure(figsize=(10, 8))
plt.title(f"Average P_fix region {region} " + bin_type + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.errorbar(bins, proba_fix_syn, yerr=err_proba_fix_syn, fmt='.-', label="Syn")
plt.errorbar(bins, proba_fix_non_syn, yerr=err_proba_fix_non_syn, fmt='.-', label="Non_syn")
plt.plot([0, 1], [0, 1], 'k--', label="neutral expectation")
plt.legend(fontsize=fontsize)
plt.xlim([0,1])
plt.ylim([0,1])
plt.show()
patient_names = ["p1", "p2", "p3", "p4", "p5", "p6", "p8", "p9", "p11"]
bin_type = "nonuniform"
region = "gag"
remove_one_point_only = False
nb_bin = 10
fontsize = 16

trajectories = trajectory.create_all_patient_trajectories(region)
syn_traj = [traj for traj in trajectories if traj.synonymous == True]
non_syn_traj = [traj for traj in trajectories if traj.synonymous == False]

bins, proba_fix_syn, _, _, _, err_proba_fix_syn = get_proba_fix(syn_traj, nb_bin, bin_type)
bins, proba_fix_non_syn, _, _, _, err_proba_fix_non_syn = get_proba_fix(non_syn_traj, nb_bin, bin_type)

plt.figure(figsize=(10, 8))
plt.title(f"Average P_fix region {region} " + bin_type + " bin", fontsize=fontsize)
plt.ylabel(r"$P_{fix}$", fontsize=fontsize)
plt.xlabel("Frequency", fontsize=fontsize)
plt.errorbar(bins, proba_fix_syn, yerr=err_proba_fix_syn, fmt='.-', label="Syn")
plt.errorbar(bins, proba_fix_non_syn, yerr=err_proba_fix_non_syn, fmt='.-', label="Non_syn")
plt.plot([0, 1], [0, 1], 'k--', label="neutral expectation")
plt.legend(fontsize=fontsize)
plt.xlim([0,1])
plt.ylim([0,1])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14525818910027177, 'fraction_numerical': 0.02209984265484194, 'mean_word_length': 6.037242073477604, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '647070', 'license': 'MIT', 'n_tokens_mistral': 5711, 'n_tokens_neox': 5364, 'n_words': 1123, 'path': 'notebooks/pre_paper_draft/P_fix.ipynb', 'repo_name': 'neherlab/HIVEVO_recombination', 'size': '13982'}