annotate pangenomeCogAnalysis_V1.pl @ 10:ccb38fd085b2 draft

Uploaded
author mgarnier
date Mon, 05 Jul 2021 12:52:58 +0000
parents 9132bdc6ce8b
children b36506d26a43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
1 #!/usr/bin/perl
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
2
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
3 use strict;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
4 use warnings;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
5
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
6 my $num_args = $#ARGV + 1;
6
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
7 if ($num_args != 9) {
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
8 print "Il n'y a pas le bon nombre d'arguments !\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
9 exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
10 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
11
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
12 # INPUT_
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
13 my $matrix_file = $ARGV[0]; # fichier tabulé : une liste d'orthogroupes qui se retrouvent ou non dans les différentes souches
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
14 my $species_file = $ARGV[1]; # association de chaque souche à son espèce (fichier tabulé également)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
15 my $annotation = $ARGV[2]; # collection de fichiers tabulés qui contiennent pour chaque gène la ou les catégories de COG associée(s)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
16 my $order = $ARGV[3]; # cette entrée correspond simplement au nom des souches qui sont rentrées dans le même ordre que les fichiers d'annotation : cela permet de savoir pour un fichier COG à quelle souche et donc plus tard à quelle espèce il correspond
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
17 my $annotation_GFF = $ARGV[4]; # fichiers avec les GFF
6
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
18 # my $order_GFF = $ARGV[5];
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
19
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
20 # OUTPUT_
6
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
21 my $output = $ARGV[5]; # liste des espèces avec leurs orthogroupes (présence-absence)
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
22 my $output2 = $ARGV[6]; # fichier des moyennes
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
23 my $output3 = $ARGV[7]; # fichier de la liste des valeurs pour chaque catégorie de COG et pour chaque espèce
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
24 my $output4 = $ARGV[8]; # fichier avec les catégories de COG pour core-génome / génome accessoire / gènes spé
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
25
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
26
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
27 # print "ok\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
28 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
29
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
30 my @list_gff = split(',', $annotation_GFF); # liste des différents fichiers GFF (qui se retrouvent dans le dossier Annotation Maker)
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
31 my %hSpecies = (); # HASH -> key: N_Id (ex NF_AR12) ; val: nom de l'esp (ex Naegleria Fowleri)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
32
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
33 ######################## LE SPECIES_FILE ###########################
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
34 open (S, $species_file);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
35 while (my $line = <S>){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
36
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
37 $line =~s/\n//g; $line =~s/\r//g;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
38 my @sp = split('\t', $line);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
39 # print "$line\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
40 # exit;
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
41 $hSpecies{$sp[0]} = $sp[1]; # HASH -> key: N_Id ; val: name
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
42
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
43 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
44 my $nbr = keys (%hSpecies); #compter le nombre de souches max
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
45 # = taille de la table de hash
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
46 # print "J'ai $nbr clés\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
47 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
48
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
49 close (S);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
50
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
51 #///////////////////////////////////////////////////////////////////////////////////////////////////
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
52
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
53 ############################################ LA MATRICE ############################################
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
54
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
55 open(M, $matrix_file);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
56
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
57 my $first_line = <M>;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
58 $first_line =~s/\n//g; $first_line =~s/\r//g; # ne garder que la première ligne du tableau
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
59 my @samples = split(/\t/,$first_line); # mettre dans une liste (@samples) chaque intitulé de colonne = N_Id
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
60 # print "$first_line\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
61 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
62
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
63 # Le but ici est de récupérer les combinaisons associées à chaque espèce : NF, NG et NL
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
64 my %hCombination =(); # HASH -> key: N_Id ; val: combinaison
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
65
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
66 for (my $i=1; $i <= $#samples; $i++){ # on parcourt chaque colonne ($i) mais on ne regarde que le N_Id
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
67 my $header = $samples[$i]; # on récupère le N_Id dans $header (soit le nom de la colonne i)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
68 my $species = $hSpecies{$header}; # on regarde dans la table avec N_Id => Nom esp et on attribue à chaque header (qui est ici une clé) sa valeur donc son nom d'esp correspondant
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
69 $hCombination{$species} .= "_".$i; # à chaque tour de boucle, pour une $species spé va ajouter le n° de colonne $i pour avoir la combinaison spé à chaque esp
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
70 # print "$header\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
71 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
72 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
73
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
74
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
75 # foreach my $species (keys (%hCombination)){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
76 # my $combination = $hCombination{$species};
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
77 # # print "$species $combination\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
78 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
79
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
80
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
81 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
82
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
83 # orthogrp présents :
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
84 my %hCombination_prs = (); # HASH -> key: combinaison ; val: liste des orthogroupes
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
85 # orthogrp absents :
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
86 my %hCombination_abs = (); # idem
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
87
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
88
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
89
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
90 my %coregenes = (); # HASH -> key: gene ; val: orthogroupe (pour core-genome)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
91 my %specificgenes = (); # HASH -> key: gene ; val: orthogroupe (pour gènes spécifiques)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
92 my %accessorygenes = (); # HASH -> key: gene ; val: orthogroupe (pour génome accessoire)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
93
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
94 my $coregene_line;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
95 my %coregenes2 = (); # HASH -> key1: colonne i ; key2: gène ; val: orthogroupe
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
96
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
97 my %Genes_of_OG = (); # HASH -> key1: orthogroupe ; key2: colonne i ; val: gène
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
98
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
99
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
100 while(<M>) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
101
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
102 my $line = $_;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
103 $line =~s/\n//g; $line =~s/\r//g;
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
104 my $nb_found = 0;
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
105 my @infos = split(/\t/,$line);
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
106 my $orthogroup = $infos[0]; # on récupère le nom de l'orthogroupe dans $orthogroup
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
107 my $first_column = $infos[1]; # ici on récupère les gènes de la première colonne qui vont nous servir pour le core-génome
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
108 my $combi_prs = "";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
109 my $combi_abs = "";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
110 my $val;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
111 my $gene_random;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
112
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
113
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
114 for (my $i=1; $i <= $#infos; $i++){ # on travaille par ligne puis dans chaque ligne (while(<M>)), cellule par cellule (cette boucle for)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
115
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
116 $val = $infos[$i]; # on récupère l'information contenue dans la case $i
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
117
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
118 if ($val =~/\w/){ # s'il cette cellule contient qq chose...
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
119 $combi_prs .= "_".$i; # ...on va concaténer notre chaine $combi_prs pour que cela forme une combinaison
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
120 $nb_found++; # on incrémente le compteur qui permet de savoir cb de fois notre orthogroupe est présent (le but sera de l'utiliser quand nb_found == 9)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
121 $gene_random=$val; # on récupère la valeur de la case (les gènes)
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
122
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
123 my @table_genes = split (',', $val);
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
124 my $premier_gene = $table_genes[0];
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
125 $Genes_of_OG{$i}{$orthogroup} = $premier_gene; # pour chaque orthorgoupe de chaque colonne, on récupère le premier gène
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
126 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
127
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
128 else { # si jamais il n'y a rien dans la cellule...
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
129 $combi_abs .= "_".$i; # ... on fait la même chose mais avec $combi_abs
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
130 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
131
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
132 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
133
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
134 # $hCount{$combi}++;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
135 $hCombination_prs{$combi_prs}.=$orthogroup."\n"; # à la fin de chaque ligne, on va ajouter notre orthogroupe à la combinaison qui lui correspond
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
136 $hCombination_abs{$combi_abs}.=$orthogroup."\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
137
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
138
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
139
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
140 if ($nb_found == $#infos){ # si nb_found = au nombre de souche, c'est qu'on a à faire à un core-génome
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
141 # print "$orthogroup\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
142 # print "$nb_found\n=================\n";
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
143 for (my $i=1; $i <= $#infos; $i++){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
144 my @list_of_genes = split (',', $infos[$i]); # ici va séparer tous les gènes (qui se présentent comme une liste, séparés par des ',')
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
145 my $first_gene = $list_of_genes[0]; # prend la valeur du premier gène uniquement !
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
146 $coregenes{$first_gene}= $orthogroup; # on va récupérer ce premier gène qu'on met dans un hash (pour y avoir accès facilement, d'où val = 1, ici ça n'a pas d'importance)
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
147 $coregenes2{$i}{$first_gene}= $orthogroup;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
148
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
149
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
150
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
151
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
152 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
153 if (!$coregene_line){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
154 $coregene_line = $line;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
155 }
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
156 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
157 elsif ($nb_found == 1) { # si on a un gène spé
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
158 my @list_of_genes = split (',', $gene_random); # idem, on ne veut qu'un seul gène donc on crée la liste
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
159 my $first_gene = $list_of_genes[0]; # on ne prend que le premier
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
160 $specificgenes{$first_gene}= $orthogroup; # et pareil on crée la table de hash
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
161 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
162
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
163 else { # là c'est le génome accessoire, i.e tout le reste !
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
164 my @list_of_genes = split (',', $gene_random);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
165 my $first_gene = $list_of_genes[0];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
166 $accessorygenes{$first_gene}= $orthogroup;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
167 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
168
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
169 }
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
170
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
171 my %hCol_Annotated = (); # HASH -> key: colonne ; val: 1 (colonnes pour lesquelles les GFF sont présents)
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
172
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
173 # Le but ici est de ne garder que les colonnes (donc les souches) qui ont un fichier GFF associé
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
174 my @list_column = split ('\t', $coregene_line);
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
175 for (my $i=1; $i <= $#list_column; $i++){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
176 my @list_genes = split (', ', $list_column[$i]);
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
177 my $premier_gene = $list_genes[0];
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
178 my $strain = $samples[$i]; # récupérer le nom de la souche
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
179
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
180
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
181 foreach my $gff (@list_gff){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
182 my $result_grep = `grep $premier_gene $gff`;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
183
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
184 if ($result_grep){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
185 $hCol_Annotated{$i}=$strain;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
186
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
187 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
188 # print "$result_grep\n";
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
189 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
190 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
191 # exit;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
192 # foreach my $i (sort keys (%coregenes2)){ # parcours de la table %hCount2 au niveau des catégories
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
193 # foreach my $gene (keys %{$coregenes2{$i} }){ # parcours de la table %hCount2 au niveau des espèces
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
194 # print "$i\t$gene\t".$coregenes2{$i}{$gene}."\n";
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
195 # }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
196 # }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
197
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
198 # while (my ($k,$v) = each(%strain_specie)) {
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
199 # print "i=$k strain=$v\n";
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
200 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
201 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
202 # foreach my $oups (keys (%coregenes)) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
203 # print "$oups\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
204 # }
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
205 # exit;
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
206
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
207 close (M);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
208
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
209 my %Hash_Specific = ();
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
210
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
211 open (OUT, '>', $output) or die $!;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
212 print OUT "$annotation\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
213 foreach my $species (keys (%hCombination)){ # parcours de la table de hash %hCombination (key: nom esp ; val: combi)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
214 my $combination = $hCombination{$species}; # on récupère dans la variable $combination la valeur de chaque clé {species} (= nom esp) de la table de hash %hCombination
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
215 my $ortho_presents = $hCombination_prs{$combination}; # $ortho_presents prend la valeur de chaque clé {combination} (récupérée juste au-dessus) de la table de hash %hCombination
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
216 my $ortho_absents = $hCombination_abs{$combination}; # en somme on a 3 combi possibles (_1_2_3_4_5 | _6 | _7_8_9) donc pour ces 3 combi-là, qui sont les clés de %hCombination_prs ou_abs, on va retrouver la liste des orthogroupes qui correspondent
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
217
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
218 # open (OUT,">results.list.txt");
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
219
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
220 if ($ortho_presents){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
221 print OUT "> $species - present\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
222 print OUT "$ortho_presents\n";
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
223 my @orthogroups_name = split ('\n', $ortho_presents);
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
224 foreach my $ortho (@orthogroups_name){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
225 $Hash_Specific{$ortho} = $species;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
226 }
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
227 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
228
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
229 if ($ortho_absents){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
230 # open (OUT2,">$species.$combination.absents.list.txt");
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
231 print OUT "> $species - absent\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
232 print OUT "$ortho_absents\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
233 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
234
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
235 # close(OUT2);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
236 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
237
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
238 close(OUT);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
239
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
240 #//////////////////////////////////////////////////////////////////////////////////////////////////
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
241
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
242 ############################################### COG ###############################################
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
243
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
244 # STEP 1 : CORRESPONDANCE ENTRE LES DIFFERENTS FICHIERS DE COG ET L'ORDRE --------------------------------------------
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
245 my @files = split(',', $annotation); # liste des différents fichiers COG (qui se retrouvent dans le dossier Naegleria)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
246 my @list = split(',', $order); # liste de l'ordre des souches
5
3d565ddc7b95 Uploaded
mgarnier
parents: 4
diff changeset
247 #my ($f,$l);
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
248
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
249 my %hCorrespondance = (); #HASH -> key: un fichier COG ; val: un nom de souche (ces 2 données sont entrées en input = $annotation et $order)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
250
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
251 # ++++++++++++ parcours de 2 listes en même temps ++++++++++++ #
8
9132bdc6ce8b Uploaded
mgarnier
parents: 6
diff changeset
252 my $l = 1;
5
3d565ddc7b95 Uploaded
mgarnier
parents: 4
diff changeset
253 foreach my $f (@files){
3d565ddc7b95 Uploaded
mgarnier
parents: 4
diff changeset
254 $hCorrespondance{$f} = $list[$l]; # on fait correspondre pour chaque fichier de COG, un nom de souche
3d565ddc7b95 Uploaded
mgarnier
parents: 4
diff changeset
255 $l++;
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
256 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
257
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
258 # #Affichage du hash
5
3d565ddc7b95 Uploaded
mgarnier
parents: 4
diff changeset
259 # foreach my $f (keys %hCorrespondance){
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
260 # print $f."=>".$hCorrespondance{$f}."\n"
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
261 # }
5
3d565ddc7b95 Uploaded
mgarnier
parents: 4
diff changeset
262 # exit;
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
263
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
264 # STEP 2 : POUR CHAQUE FICHIER DE COG, FAIRE CORRESPONDRE L'ESPECE (ET NON LA SOUCHE) -------------------------------------
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
265 my %hCorresp_file_species = (); # HASH -> key: un fichier de COG ; val: une espèce
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
266 my %species_names; # HASH -> key: nom d'espèce ; val: 1
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
267
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
268 foreach my $h (keys (%hCorrespondance)){ # parcours de la table de hash {fichier COG => nom souche}
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
269 my $smpl = $hCorrespondance{$h}; # $smpl prend la valeur de la clé (donc d'un nom de souche)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
270 my $espece = $hSpecies{$smpl}; # on regarde la correspondance entre ce $smpl et les nom qu'on a dans notre table de hash %hSpecies (fichier "species.txt") pour avoir le nom de l'espèce dans $espece
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
271 $species_names{$espece} = 1; # on garde sous le coude nos nom d'espèce dans cette nouvelle table de hash
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
272 $hCorresp_file_species{$h} = $espece; # BUT ATTEINT : on donne pour chaque fichier de COG le nom de l'espèce qui lui correspond
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
273 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
274 # while (my ($k,$v) = each(%hCorresp_file_species)) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
275 # print "file=$k sp=$v\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
276 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
277 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
278
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
279 # STEP 3 : COMPTAGE DES CATEGORIES DE COG ------------------------------------------------------------------------------
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
280 my %hCount2 = (); # HASH -> key1: catégorie de COG ; key2: espèce associée ; val: comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
281
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
282 # comptage du core-genome / des gènes spé / du génome accessoire
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
283 my %hCore_Count = (); # HASH -> key: catégorie de COG ; val: comptage (ce hash ne sera utilisé que pour le core-genome)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
284 my %hSpecific_Count = (); # HASH -> key: catégorie de COG ; val: comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
285 my %hAccessory_Count = (); # HASH -> key: catégorie de COG ; val: comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
286
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
287 # hash pour récupérer le gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
288 my %hCore_Cat = (); # HASH -> key: catégorie de COG ; val: gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
289 my %hAccessory_Cat = (); # HASH -> key: catégorie de COG ; val: gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
290 my %hSpecific_Cat = (); # HASH -> key: catégorie de COG ; val: gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
291
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
292 # hash pour récupérer le gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
293 my %hCore_Cat_Esp = (); # HASH -> key1: catégorie de COG ; key2: espèce ; val: gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
294 my %hAccessory_Cat_Esp = (); # HASH -> key1: catégorie de COG ; key2: espèce ; val: gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
295 my %hSpecific_Cat_Esp = (); # HASH -> key1: catégorie de COG ; key2: espèce ; val: gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
296
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
297 my %Cog_of_gene = (); # HASH -> key: gène ; val: cat de COG
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
298 my %Specie_of_gene = (); # HASH -> key: gène ; val: souche
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
299
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
300 foreach my $file(@files){ # parcours de la liste des fichiers
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
301 my $esp = $hCorresp_file_species{$file}; # on récupère l'espèce pour chaque fichier de COG dans $esp
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
302 # print $esp."\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
303 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
304
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
305 my %hCount = (); # HASH -> key: catégorie de COG ; val: comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
306
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
307
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
308 open (A, $file); # on va parcourir maintenant chaque fichier un à un
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
309
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
310 while (my $line2 = <A>){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
311
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
312 $line2 =~s/\n//g; $line2 =~s/\r//g; # on procède ligne par ligne
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
313 my @Genes = split('\t', $line2);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
314 my $gene = $Genes[0];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
315 my $first_cat = $Genes[2];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
316 $Cog_of_gene{$gene} = $first_cat;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
317
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
318 for (my $j=2; $j <= $#Genes; $j++) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
319 my $cat = $Genes[$j]; # on récupère la ou les catégorie(s) de COG
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
320 $hCount{$cat}++; # pour la catégorie donnée, on incrémente son nb d'occurences
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
321
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
322 if ($coregenes{$gene}){ # si le $gene fait bien partie du core-genome (donc de notre table de hash %coregenes)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
323 $hCore_Count{$cat}++; # on incrémente le hash
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
324 $hCore_Cat{$cat}=$gene; # on récupère le nom du gène
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
325 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
326 if ($accessorygenes{$gene}){ # s'il fait partie des gènes accessoires
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
327 $hAccessory_Count{$cat}++;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
328 $hAccessory_Cat{$cat}=$gene;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
329 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
330 if ($specificgenes{$gene}){ # s'il fait partie des gènes spécifiques
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
331 $hSpecific_Count{$cat}++;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
332 $hSpecific_Cat{$cat}=$gene;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
333 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
334 # $hCount2{$cat}{$esp}++; # TABLE DE HASH AVEC CLES=CAT DE COG + ESPECE VAL=COMPTAGE
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
335 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
336
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
337 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
338 close (A);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
339
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
340 # print "$file $esp\n=============\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
341 while (my ($k,$v) = each(%hCount)) { # parcours de la table de hash de comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
342 # print "cat=$k nb=$v\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
343 $hCount2{$k}{$esp}.= "$v,"; # pour un $k (= une catégorie de COG) on lui associe son espèce et on donne la valeur du comptage qui vient de %hCount
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
344 # le but ici est en fait pour une espèce et une catégorie données on veut le nombre d'occurences par souche (pour NF par ex on aura 5 valeurs car il y a 5 souches)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
345 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
346
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
347 # Récupérer les gènes du core-génome
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
348 while (my ($cat_core,$gene_core) = each(%hCore_Cat)) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
349 $hCore_Cat_Esp{$cat_core}{$esp}=$gene_core;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
350 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
351 # Récupérer les gènes du génome-accessoire
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
352 while (my ($cat_acc,$gene_acc) = each(%hAccessory_Cat)) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
353 $hAccessory_Cat_Esp{$cat_acc}{$esp}=$gene_acc;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
354 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
355 # Récupérer les gènes spécifique
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
356 while (my ($cat_spe,$gene_spe) = each(%hSpecific_Cat)) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
357 $hSpecific_Cat_Esp{$cat_spe}{$esp}=$gene_spe;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
358 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
359
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
360 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
361 # foreach my $category (sort keys (%hSpecific_Cat_Esp)) { # parcours au niveau de la 1ere clé
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
362
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
363 # foreach my $especeee (keys %{$hSpecific_Cat_Esp{$category} }) { # parcours au niveau de la 2e clé pour la $category donnée
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
364
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
365 # print "$category\t$especeee\t$hSpecific_Cat_Esp{$category}{$especeee}\n"; # on crée une sortie qui affiche en somme notre hash %hCount2
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
366 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
367 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
368 # exit;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
369
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
370 # STEP 4 : AFFICHAGE DANS LE FICHIER DE SORTIE ------------------------------------------------------------------------------
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
371 open (OUT4, ">$output4") or die $!;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
372
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
373 print OUT4 "Species"."\t"."COG categories"."\t"."Core-genome"."\t"."Accessory genome"."\t"."Specific genes"."\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
374
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
375 foreach my $category (sort keys (%hCount2)){ # parcours de la table %hCount2 au niveau des catégories
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
376 foreach my $especeee (keys %{$hCount2{$category} }){ # parcours de la table %hCount2 au niveau des espèces
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
377 print OUT4 "$especeee\t$category\t"; # affichage des esp puis des cat
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
378
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
379 # if ($hCore_Cat_Esp{$category}{$especeee}) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
380 # print OUT4 "$hCore_Cat_Esp{$category}{$especeee}\t";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
381 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
382 my $c = 0;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
383 if ($hCore_Count{$category}){ # si cette catégorie existe dans le core-génome
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
384 $c = ($hCore_Count{$category}/scalar keys (%coregenes))*100; # calcul du % du comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
385 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
386 print OUT4 "$c\t"; # affichage du %
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
387
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
388 # if ($hAccessory_Cat_Esp{$category}{$especeee}) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
389 # print OUT4 "$hAccessory_Cat_Esp{$category}{$especeee}\t";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
390 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
391 my $acc = 0;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
392 if ($hAccessory_Count{$category}){ # si cette catégorie existe dans le génome accessoire
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
393 $acc = ($hAccessory_Count{$category}/scalar keys (%accessorygenes))*100; # calcul du % du comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
394 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
395 print OUT4 "$acc\t"; # affichage du %
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
396
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
397 # if ($hSpecific_Cat_Esp{$category}{$especeee}) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
398 # print OUT4 "$hSpecific_Cat_Esp{$category}{$especeee}\t";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
399 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
400 my $s = 0;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
401 if ($hSpecific_Count{$category}){ # si cette catégorie existe dans les gènes spécifiques
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
402 $s = ($hSpecific_Count{$category}/scalar keys (%specificgenes))*100; # calcul du % du comptage
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
403 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
404 print OUT4 "$s\n"; # affichage du %
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
405 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
406 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
407 close (OUT4);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
408
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
409 open (OUT3, ">$output3") or die $!;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
410 foreach my $category (sort keys (%hCount2)) { # parcours au niveau de la 1ere clé
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
411
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
412 foreach my $especeee (keys %{$hCount2{$category} }) { # parcours au niveau de la 2e clé pour la $category donnée
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
413
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
414 print OUT3 "$category\t$especeee\t$hCount2{$category}{$especeee}\n"; # on crée une sortie qui affiche en somme notre hash %hCount2
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
415 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
416 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
417
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
418 close (OUT3);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
419
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
420
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
421 open (OUT2, ">$output2") or die $!;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
422
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
423 print OUT2 "category";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
424 foreach my $e (sort keys (%species_names)){ # on parcours le hash d'espèces...
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
425 print OUT2 "\t".$e; #... où on récupère le nom de celles-ci
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
426 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
427 print OUT2 "\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
428
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
429 foreach my $category (sort keys (%hCount2)) { # on parcourt de nouveau les catégories de notre hash à 2 clés
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
430 print OUT2 $category;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
431
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
432 foreach my $especes (sort keys (%species_names)) { # on parcourt également le hash d'espèces
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
433
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
434 my $nbr = 0;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
435 if ($hCount2{$category}{$especes}) { # si pour une catégorie et une espèce données, on a un nombre : $nbr prend la valeur de ce dernier
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
436 $nbr = $hCount2{$category}{$especes};
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
437 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
438 # $nbr =~s/\n//g; $nbr =~s/\r//g;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
439
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
440
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
441 my @liste = split(',', $nbr); # vu qu'il peut y avoir plusieurs nombres on les dissocie
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
442
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
443 my $somme=0;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
444 my $n=0;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
445 my $moyenne=0;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
446 #print "\nma liste de $nbr: ".join("%",@liste)."\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
447 foreach my $x (@liste) { # on parcourt nos nombres
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
448 $somme=$somme+$x;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
449 $n=$n+1;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
450 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
451
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
452 if ($n>0){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
453 $moyenne = $somme/$n; # on fait le calcul de la moyenne
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
454 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
455 # print "$category, $especes: $hCount2{$category}{$especes}\t";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
456 # print "moyenne = $moyenne\n=============\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
457
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
458 print OUT2 "\t".$moyenne; # fichier de sortie
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
459 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
460 print OUT2 "\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
461 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
462
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
463 close (OUT2);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
464
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
465 # foreach my $cat (keys (%hCore_Cat)){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
466 # print OUT4 $c_gene."\t";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
467 # }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
468
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
469
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
470 #//////////////////////////////////////////////////////////////////////////////////////////////////
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
471
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
472 ############################################### GFF ###############################################
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
473
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
474
6
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
475 # my @order_gff = split(',', $order_GFF); # liste de l'ordre des souches
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
476 my ($g,$o);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
477
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
478 my %hgff_order = (); #HASH -> key: un fichier GFF ; val: un nom de souche (ces 2 données sont entrées en input = $annotation_GFF et $order_GFF)
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
479 my %Gene_position = ();
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
480 my %Cat_genes = ();
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
481
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
482 my %hash_of_genes = ();
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
483
6
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
484
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
485 foreach $g (@list_gff){
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
486 # print "$g\n";
6
cf9da93e4145 Uploaded
mgarnier
parents: 5
diff changeset
487 # $hgff_order{$g} = $order_gff[$o++]; # on fait correspondre pour chaque fichier GFF, un nom de souche
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
488 open (G, $g);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
489 while (<G>) {
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
490 my @table_gff = split (/\t/, $_);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
491 my $chr = $table_gff[0];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
492 my $start = $table_gff[3];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
493 my $end = $table_gff[4];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
494 my $gene_name = $table_gff[8];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
495 my $type = $table_gff[2];
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
496
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
497
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
498
10
ccb38fd085b2 Uploaded
mgarnier
parents: 8
diff changeset
499 if ($type && ($type eq "mRNA" or $type eq "CDS") && $gene_name =~ /ID=([^;]+);/){
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
500 my $gene = $1;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
501 # print $gene."\n";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
502 # exit;
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
503 $hash_of_genes{$gene}=1;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
504
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
505 foreach my $cog (keys (%hCore_Cat)){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
506 if ($hCore_Cat{$cog} eq $gene){
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
507 $Cat_genes{$gene}=$cog;
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
508 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
509 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
510
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
511 $Gene_position{$gene}="$chr\t$start\t$end";
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
512 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
513
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
514 # foreach my $gene (keys (%hash_of_genes)){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
515 # my $orthogrp = $hGene_OG{$gene};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
516 # print "$orthogrp\n";
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
517 # }
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
518 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
519
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
520 close (G);
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
521 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
522
4
db4e1e6850b0 Uploaded
mgarnier
parents: 2
diff changeset
523 my %Hash_Convert = ( "A"=>1, "B"=>2, "C"=>3, "D"=>4, "E"=>5, "F"=>6, "G"=>7, "H"=>8, "I"=>9, "J"=>10, "K"=>11, "L"=>12, "M"=>13, "N"=>14, "O"=>15, "P"=>16, "Q"=>17, "R"=>18,"S"=>19, "T"=>20, "U"=>21, "V"=>22, "W"=>23, "X"=>24, "Y"=>25, "Z"=>26, "unknown"=>27);
db4e1e6850b0 Uploaded
mgarnier
parents: 2
diff changeset
524
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
525 mkdir("Core");
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
526 foreach my $i (keys (%coregenes2)){
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
527
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
528 if (!$hCol_Annotated{$i}) { # si le fichier GFF n'existe pas
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
529 next;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
530 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
531
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
532
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
533 my $strain_name = $hCol_Annotated{$i};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
534
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
535 my $specie_name = $hSpecies{$strain_name};
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
536
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
537
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
538
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
539 open (OUT5, "> Core/$strain_name.$specie_name.txt") or die "Cannot create file $!\n";
8
9132bdc6ce8b Uploaded
mgarnier
parents: 6
diff changeset
540 print OUT5 "Orthogroup\tGene\tChromosome\tStart\tEnd\tCOG categories\tNumber assigned\n";
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
541
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
542 my $refcoregenes2 = $coregenes2{$i};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
543 my %subhash = %$refcoregenes2;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
544 foreach my $gene (keys (%subhash)){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
545 # print "$gene\n";
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
546 my $cat = "unknown";
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
547 if ($Cog_of_gene{$gene}){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
548 $cat = $Cog_of_gene{$gene};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
549 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
550 # if (!$Gene_position{$gene}){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
551 # print "$gene\n coucou"; exit;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
552 # }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
553
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
554 # if (!$subhash{$gene}){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
555 # print "$gene\n";
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
556 # }
4
db4e1e6850b0 Uploaded
mgarnier
parents: 2
diff changeset
557 print OUT5 $subhash{$gene}."\t"."$gene\t".$Gene_position{$gene}."\t".$cat."\t".$Hash_Convert{$cat}."\n";
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
558
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
559 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
560
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
561 close (OUT5);
0
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
562 }
731fb6cb324b Uploaded
mgarnier
parents:
diff changeset
563
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
564
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
565 mkdir("GroupSpecific");
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
566 foreach my $i (keys (%Genes_of_OG)){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
567 if (!$hCol_Annotated{$i}) { # si le fichier GFF n'existe pas
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
568 next;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
569 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
570
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
571 my $strain_name = $hCol_Annotated{$i};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
572
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
573 my $specie_name = $hSpecies{$strain_name};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
574
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
575 open (OUT6, "> GroupSpecific/$strain_name.$specie_name.txt") or die "Cannot create file $!\n";
8
9132bdc6ce8b Uploaded
mgarnier
parents: 6
diff changeset
576 print OUT6 "Orthogroup\tGene\tChromosome\tStart\tEnd\tCOG categories\tNumber assigned\n";
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
577
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
578 my $refGenes_of_OG = $Genes_of_OG{$i};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
579 my %subhash = %$refGenes_of_OG;
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
580
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
581 foreach my $orthogroup (keys (%subhash)){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
582 if ($Hash_Specific{$orthogroup} && $Hash_Specific{$orthogroup} eq $specie_name){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
583 my $gene = $subhash{$orthogroup};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
584
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
585 my $cat = "unknown";
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
586 if ($Cog_of_gene{$gene}){
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
587 $cat = $Cog_of_gene{$gene};
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
588 }
4
db4e1e6850b0 Uploaded
mgarnier
parents: 2
diff changeset
589 print OUT6 $orthogroup."\t".$subhash{$orthogroup}."\t".$Gene_position{$gene}."\t".$cat."\t".$Hash_Convert{$cat}."\n";
2
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
590 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
591
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
592 }
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
593 close (OUT6);
0428ce25da81 Uploaded
mgarnier
parents: 1
diff changeset
594 }