Newer
Older
fadwael.khaddar_ird.fr
committed
import re
import pandas as pd
fadwael.khaddar_ird.fr
committed
def CpG_context(methylated):
fadwael.khaddar_ird.fr
committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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)