Skip to content
Snippets Groups Projects
Statistics_methylation.py 3.25 KiB
Newer Older
    global CpG
    motif_counts = {}  # Création d'un dictionnaire pour stocker le comptage de chaque motif
    for motif in CpG:
        motif_counts[motif] = 0

    # Boucler à travers chaque k_mer dans methylated dataset

    for kmer in methylated["k_mer"][2:]:
        sub_kmer = kmer[2:4]
        sub_kmer_str = "".join(sub_kmer)

        # Comptage des occurences de chaque motif dans sub_kmer

        for motif in CpG:
            motif_count = sub_kmer_str.count(motif)
            motif_counts[motif] += motif_count

    # Calculer le total des occurences de chaque sub_kmer
    total_len = len(methylated["k_mer"])
    total_count = sum(motif_counts.values())
    pourcentage = (total_count  * 100) / total_len

    print(f"Le pourcentage de la méthylation type CpG est  : {pourcentage: .2f}% ")



def CHG_context(methylated):
    motif_counts = {}  # Création d'un dictionnaire pour stocker le comptage de chaque motif
    global CHG
    for motif in CHG:
        motif_counts[motif] = 0

    # Boucler à travers chaque k_mer dans methylated dataset

    for kmer in methylated["k_mer"][2:]:
        sub_kmer = kmer[2:]
        sub_kmer_str = "".join(sub_kmer)

        # Comptage des occurences de chaque motif dans sub_kmer

        for motif in CHG:
            motif_count = sub_kmer_str.count(motif)
            motif_counts[motif] += motif_count

    # Calculer le total des occurences de chaque sub_kmer
    total_len = len(methylated["k_mer"])
    total_count = sum(motif_counts.values())
    pourcentage = (total_count  * 100) / total_len

    print(f"Le pourcentage de la méthylation type CHG est: {pourcentage: .2f}% ")


def CHH_context(methylated):
    global CHH
    motif_counts = {}  # Création d'un dictionnaire pour stocker le comptage de chaque motif
    for motif in CHH:
        motif_counts[motif] = 0

    # Boucler à travers chaque k_mer dans methylated dataset

    for kmer in methylated["k_mer"][2:]:
        sub_kmer = kmer[2:]
        sub_kmer_str = "".join(sub_kmer)

        # Comptage des occurences de chaque motif dans sub_kmer

        for motif in CHH:
            motif_count = sub_kmer_str.count(motif)
            motif_counts[motif] += motif_count

    # Calculer le total des occurences de chaque sub_kmer
    total_len = len(methylated["k_mer"])
    total_count = sum(motif_counts.values())
    pourcentage = (total_count  * 100) / total_len

    print(f"Le pourcentage de la méthylation type CHH est : {pourcentage: .2f}% ")


# Déclaration des trois contexte de méthylation
CpG = ["CG"]
CHG = ["CCG", "CAG", "CTG"]
CHH = ["CCC", "CAA", "CTT", "CCA", "CCT", "CAT", "CAC", "CTA", "CTC"]





# Lecture de fichier
names = ["Chromosome", "position","strand", "pos_in_strand", "readname", "read_strand", "prob_0", "prob_1", "called_label", "k_mer"]
call_mods = pd.read_csv("/home/fadwa/Téléchargements/FAS08151_fast5s.C_call_mods.tsv", sep='\t', names=names)

# Création du DataFrame
df = pd.DataFrame(call_mods)

# Extraction des reads méthylés

methylated= df[df["called_label"] == 1]
methylated=pd.DataFrame(methylated)
#methylated.to_csv("/home/fadwa/Téléchargements/FAS08151_methylated.tsv", sep='\t')

CpG_contexte(methylated)
CHG_context(methylated)
CHH_context(methylated)