| 12
 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
 
 |  
#include <stdio.h>
#include <stdlib.h>
 
struct FASTA {
char * comment ;
char * sequence ;
};
 
typedef struct FASTA  tfa ;
 
char* readfasta(char* name){
 
FILE *FIC;
char *chaine,chaine2;
tfa sequence;
int i,j,k,indcom,indseq;
int length,curpos;
char **tab1;
char **tab2;
 
 
length=0;
FIC=fopen(name,"w+");
 
curpos=ftell(FIC); /* je positionne mon curseur */
fseek(FIC,0,SEEK_END); /*je me place à la fin de mon fichier*/
length=ftell(FIC);/*et hop la taille du fichier*/
fseek(FIC,curpos,SEEK_SET);/*je me replace au début*/
 
chaine=(char*)malloc(length*sizeof(char)); /*j'allou pas trop de mémoir puisqu'après je libère*/
fread(chaine,length,1,FIC);
fclose(FIC);
 
sequence.comment=(char*)malloc(length*sizeof(char));/*allocation obligatoire non ? */
sequence.sequence=(char*)malloc(length*sizeof(char));
 
k=0;
 
 
tab1=(char**)malloc(length*sizeof(char*));
tab2=(char**)malloc(length*sizeof(char*));
 
 while(k<length){
 
 while(chaine[i]!='\n'){
sequence.comment[i]=chaine[i];
i++;
}
 
tab1[k]=sequence.comment;
 
 
sequence.comment[i]='\0';
i=i+1;
j=0;
 
 while(i<length && chaine[i]!='>'){
   if (chaine[i]!='\n'){
sequence.sequence[j]=chaine[i];
j++;
   }
i++;
 }
 
tab2[k]=sequence.sequence;
sequence.sequence[j]='\0';
 
k++;
 
 }
tab1[k]='\0';
tab2[k]='\0';
 
 
 for (i=0;i<=k;i++){
 
printf("%s \n",tab1[i]);
printf("%s \n",tab2[i]);
 
 }
/* READ, ALLOCATE AND PUT SEQUENCES IN CHAINE */
 
printf("%d",length);
 
}
 
int main (int argc,char **argv){
 
char* seq;
 
seq = readfasta(argv[1]);
 
return 0;
 
} | 
Partager