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
|
typedef struct pos_id_chained
{
char* id;
int pos;
struct pos_id_chained * next;
} pos_id_chained_t;
typedef struct {
char* Kmer;
uint32_t hashvalue;
struct pos_id_chained * positions;
}Thash;
Thash* CreerTableHash(size_t nbEntrees)
{
Thash def = {NULL, 0, NULL};
size_t i;
Thash* TThash = malloc(nbEntrees * sizeof(Thash));
if(TThash == NULL)
return NULL;
for(i=0 ; i<nbEntrees ; i++)
TThash[i] = def;
return TThash;
}
pos_id_chained_t * ajoute(pos_id_chained_t *pListe, char const *id, int pos)
{
pos_id_chained_t * newelem= malloc(sizeof(pos_id_chained_t));
strcpy(newelem->id,id);
newelem->pos=pos;
newelem->next = NULL;
if(pListe == NULL)
{
return newelem;
}
else
{
pos_id_chained_t * temp=pListe;
while(temp->next != NULL)
{
temp= temp->next;
}
temp->next=newelem;
return pListe;
}
}
void display ( pos_id_chained_t *p_head)
{
pos_id_chained_t *p = p_head;
while (p != NULL)
{
/* afficher les données courantes */
printf ("sequence: %s \n", p->id);
printf("position: %d \n", p->pos);
/* pointer sur le suivant */
p = p->next;
}
/* afficher la fin */
printf ("NIL\n");
}
int main()
{
int k=3;int i=0;int j=0;
char *sequence = NULL;
sequence = malloc(sizeof(char) * 200000);int TAILLE_MAX=200001;
char *Kmer = NULL;
Kmer = malloc(sizeof(char) * k);
int longseq=0; int nbKmer=0;
Thash* TThash;
TThash=CreerTableHash(20000);
while(fgets(sequence,TAILLE_MAX, fichier1)!= NULL)
{
nbKmer=0;
longseq=strlen(sequence)-1; printf("\nlongeur= %d\n", longseq);
if(sequence[0]!='>' && strlen(sequence)>50)
{
for(i=0;i<=longseq-k;i++)
{
nbKmer++;
strncpy(Kmer,sequence+i,k);
Value= hash(Kmer);
TThash[j].Kmer=Kmer;
TThash[j].hashvalue=Value;
TThash[j].positions= ajoute(TThash[j].positions,sequence1,1000);
printf("TThash[%d].Kmer= %s \n",j,TThash[j].Kmer);
printf("TThash[%d].hashvalue= %d \n",j,TThash[j].hashvalue);
display(TThash[j].positions);
j++;
}
printf("\n%d",nbKmer);
}
}
if (fichier == NULL)
{
printf("File not found"); // perror(msg);
}
return 0;
} |
Partager