-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonction_gene_seq.c
174 lines (148 loc) · 4.05 KB
/
fonction_gene_seq.c
1
2
3
4
5
6
7
8
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include "fonction_gene_seq.h"
char genBases() //Génération aléatoire de bases
{
int Random= rand() % 4;
char c;
switch(Random)
{
case 0 : c = 'a';break;
case 1 : c = 't';break;
case 2 : c = 'g';break;
case 3 : c = 'c';break;
}
return c;
}
//***********************************************************************
void calculPSSM(float** PSSM, char nuc, int i)
{
//printf("%f\n", PSSM[i][0]);
switch (nuc)
{
case 'a' : PSSM[i][0]++; break;
case 't' : PSSM[i][1]++; break;
case 'g' : PSSM[i][2]++; break;
case 'c' : PSSM[i][3]++; break;
default : printf("Probleme calculPSSM\n");
}
}
//***********************************************************************
void freqPSSM(float** PSSM, int nbMotifs, int tailleMotif)
{
int i;
for ( i = 0; i < tailleMotif ; i++)
{
printf("%d\n", i);
PSSM[i][0] /= nbMotifs;
PSSM[i][1] /= nbMotifs;
PSSM[i][2] /= nbMotifs;
PSSM[i][3] /= nbMotifs;
}
}
//***********************************************************************
char* substMotif(char* motif, int nomSubs, FILE* Seqfile, float** PSSM)
{
int tailleMotif = strlen(motif);
char* motif2 = NULL;
if((motif2 = (char*)malloc(sizeof(char)*(tailleMotif + 1))) == NULL){
exit(1);
}
strcpy(motif2, motif);
char subst = '\0', nuc = '\0';
int i = 0;
int k = 0;
//InfoSubst* info=NULL;
while(i < tailleMotif)
{
int j = chanceSubst();
subst = genBases();
nuc = motif2[i];
if (j && (subst != nuc) && k < nomSubs)
{
fprintf(Seqfile, "\n\tSubstitution du nucléotide numéro %i (%c) en %c", i+1, motif2[i], subst);
//printf("Substitution de %c en %c\n",motif2[i],subst[0] );
motif2[i] = subst;
k++;
//printf("%s\n",motif2);
}
calculPSSM(PSSM,motif2[i],i);
i++;
}
//printf("motif 2 : %s\n",motif2);
//info = (InfoSubst*)malloc(sizeof(InfoSubst));
//strcpy(motif,motif2);
//info->_nbSub=k;
motif2[tailleMotif] = '\0';
return motif2;
}
//************************************************************************
char* genSeq(int tailleSeq, int tailleMotif, int subst, char* motif, FILE* Seqfile, float** PSSM, int* nbMotifs)
{
char* Seq = NULL;
if((Seq = (char*) calloc(tailleSeq + 1, sizeof(char))) == NULL){
exit(1);
}
int i=0;
int pos;
int occ=0;
char* motif2 = NULL; // = (char*) calloc(tailleMotif + 1, sizeof(char));
//PtrMotifs listeMotifs = NULL;
//listeMotifs = (PtrMotifs)malloc(sizeof(Motifs));
//PtrListeSeq listeSeq = NULL;
fprintf(Seqfile, "Position(s) : ");
if (tailleMotif <= tailleSeq) //Si la taille du motif est inférieure à la taille de la séquence
{
while(i < tailleSeq) //Tant qu'on est dans la séquence
{
int j = chanceMotif(); //Chance d'apparition du motif
if(j && ((tailleSeq-i) > tailleMotif)) // Si le motif doit apparaitre et qu'il reste assez de nucléotides dans la séquence pour l'apparition du motif
{
//int substmotif = 0;
pos=i+1;
fprintf(Seqfile,"\n%i ",pos );
//if (chanceSubst()) // S'il y a une substitution et qu'on a pas encore atteint le nombre max de substitutions
//{
motif2 = substMotif(motif, subst, Seqfile, PSSM);
strncat(Seq,motif2,tailleMotif);
//printf("%i\n",(int) strlen(motif2) );
//printf("%i\n",strlen(substMotif(motif,subst,Seqfile,PSSM)) );
//printf("#\n");
i=i+tailleMotif;
occ = occ +1;
//printf("%s\n",motif2 );
//}
/*else
{
strncat(Seq,motif,tailleMotif);
printf("$\n");
//printf("%s\n", motif);
i=i+tailleMotif;
occ = occ +1;
//printf("%s\n", motif );
}*/
*nbMotifs = 1 + *nbMotifs;
}
else
{
//strcat(Seq,genBases());
Seq[i] = genBases();
i++;
}
}
//fprintf(Fastafile,"%s\n",Seq );
fprintf(Seqfile, "\nOccurence(s) : %i\n\n", occ);
Seq[tailleSeq] = '\0';
}
else
{
printf("Erreur, la taille de la séquence doit être plus grande que celle du motif\n");
}
//printf("%s",Seq);
//listeMotifs->_listeSeq->next = NULL;
return Seq;
}
//***********************************************************************