예제 #1
0
파일: maintestOLD.c 프로젝트: vsteffen/FDF
int		key_press(int keycode, data_t *data)
{
	//printf("key event %d\n", keycode);
	if (keycode == 53 || keycode == 12)
		exitProg("Key \"escape\" or \"Q\" detected, end of the process.\n");
	return (0);
}
예제 #2
0
void *monrealloc(void *in, long size) {
	void *point;
	if(size<0 || !(point = realloc(in, size))) {
		char tmp[200];
		sprintf(tmp, "Try to reallocate %ld bytes\n", size);
		exitProg(ErrorMemory, tmp);
	}
	return point;
}
예제 #3
0
파일: maintest.c 프로젝트: vsteffen/FDF
int		main(int ac, char **av)
{
	t_d		d;

	if (ac != 2)
		exitProg("Please, add one file after fdf.\n");
	if (analyzeFile(ac, av, &d))
		exitProg("Map specify may have incorrect values or error when reading file.\n");
/*	if ((d.mlx = mlx_init()) == NULL)
		exitProg("Fail to init the minilibx library.\n");
	if ((d.win = mlx_new_window(d.mlx, 500, 500, av[1])) == NULL)
		exitProg("Fail to open a new window.\n");
	mlx_mouse_hook(d.win, mouse_click, &d);
	mlx_key_hook(d.win, key_press, &d);
	//mlx_expose_hook(d.win, expose_hook, &d);
	mlx_loop(d.mlx);
*/	return (EXIT_SUCCESS);
}
예제 #4
0
파일: maintest.c 프로젝트: vsteffen/FDF
int		key_press(int keycode, t_d *d)
{
	//printf("key event %d\n", keycode);
	if (keycode == 53 || keycode == 12)
	{
		free(d->map);
		exitProg("Key \"escape\" or \"Q\" detected, end of the process.\n");
	}
	return (0);
}
예제 #5
0
TypeTimeInterval toFossilInt(char *s) {
    int i, ind;
    TypeTimeInterval fossilInt;
    char tmp[MAX_NAME_SIZE];
    for(i=0; s[i] != '\0'; i++)
		if(s[i] == ',')
			s[i] = '.';
    for(i=0; s[i] != '\0' && isspace(s[i]); i++);
    if(s[i] == '(' || s[i] == '[') {
        i++;
        for(; s[i] != '\0' && isspace(s[i]); i++);
        ind = 0;
        for(; s[i] != '\0' && s[i] != ':' && s[i] != ';' && !isspace(s[i]); i++)
            tmp[ind++] = s[i];
        tmp[ind] = '\0';
        fossilInt.inf =	atof(tmp);
        for(; s[i] != '\0' && isspace(s[i]); i++);
        if(s[i] != ':' && s[i] != ';')
            exitProg(ErrorReading, "Missing ':' or ';' while reading a fossilInt time interval.");
        i++;
        for(; s[i] != '\0' && isspace(s[i]); i++);
        ind = 0;
        for(; s[i] != '\0' && s[i] != ')' && s[i] != ']' && !isspace(s[i]); i++)
            tmp[ind++] = s[i];
        tmp[ind] = '\0';
        fossilInt.sup =	atof(tmp);
        for(; s[i] != '\0' && isspace(s[i]); i++);
        if(s[i] != ')' && s[i] != ']')
            exitProg(ErrorReading, "Missing ')' or ']' while reading a fossilInt time interval.");
        if(fossilInt.sup<fossilInt.inf) {
            double tmp = fossilInt.sup;
            fossilInt.sup = fossilInt.inf;
            fossilInt.inf = tmp;
        }
    } else {
        fossilInt.inf = atof(s);
        fossilInt.sup = fossilInt.inf;
    }
    return fossilInt;
}
예제 #6
0
파일: maintest.c 프로젝트: vsteffen/FDF
int		expose_hook(t_d *d)
{
	int		x = 0;
	int		y = 0;
	int		pos;

	printf("Enter in expose\n");
	if ((d->img = mlx_new_image(d->mlx, 500, 500)) == NULL)
		exitProg("Fail to init a new image in minilibx.\n");	
	d->strimg = mlx_get_data_addr(d->img, &(d->bpp), &(d->size_line), &(d->endian));
	d->color = mlx_get_color_value(d->mlx, 0xFFFAFA);
	while (x < 250)
	{
		put_pixel_in_img(d, x, y);
		x++;
		if (x == 250 && y < 250)
		{
			x = 0;
			y++;
		}
		/* == CA MARCHE
		   y = 0;
		   while (y < 250)
		   {
		   pos = y * d->size_line + 4 * x;
		   d->strimg[pos] = 255;
		   y++;

		   }
		   x++;*/
	}
	mlx_put_image_to_window(d->mlx, d->win, d->img, 0, 0);
	//mlx_destroy_image(d->mlx, d->img);
	printf("End of expose\n");
	return (0);
}
예제 #7
0
int main(int argc, char **argv) {
	TypePosition orderstart=1, orderend=10;
	char option[256], inputFileName[SIZE_BUFFER_CHAR], outputFileName[SIZE_BUFFER_CHAR], bufferOutput[SIZE_BUFFER_CHAR], *table, 
	outputFormat = 'r', typeDec = 'l', typeAlphabet = '?', typeCalc = 'g';
	TypeSetOfSequences *set;
	TypeAlignment aln, atmp;
	int fixed = 0;
	double threshold = 0.001, tmin = 0.00000000001, tmax=0.1, tstep = 0.00001;
	double thre;
	TypeNumber n;
	TypeDistance distA, distB, distC;
	TypePosition l, tot;
	double corrAB, corrAC;
	TypeSetOfSequences *dec;
	TypeMarkovModel *model;
		
	FILE *fi, *fo;
	int i = 1, typeDist = 0;

	for(i=0; i<256; i++)
		option[i] = 0;
	for(i=1; i<argc && *(argv[i]) == '-'; i++) {
		int j;
		for(j=1; argv[i][j] != '\0'; j++)
			option[argv[i][j]] = 1;
		if(option['f']) {
			option['f'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &outputFormat) == 1)
				i++;
		}
		if(option['s']) {
			option['s'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeAlphabet) == 1)
				i++;
		}
		if(option['c']) {
			option['c'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeCalc) == 1)
				i++;
		}
		if(option['m']) {
			option['m'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%d", &typeDist) == 1)
				i++;
			if(typeDist >= MAX_FUNC)
				typeDist = 0;
		}
		if(option['t']) {
			option['t'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%lf", &threshold) == 1)
				i++;
		}
		if(option['h']) {
			printf("%s\n", HELPMESSAGE);
			exitProg(ExitOk, NULL);
		}
	}
	if (i>=argc || sscanf(argv[i++], "%s", inputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);
	if (i>=argc || sscanf(argv[i++], "%s", outputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);

	switch(typeAlphabet) {
		case 'd':
			table = (char*) monmalloc((strlen(DNA)+1)*sizeof(char));
			strcpy(table, DNA);
			break;
		case 'r':
			table = (char*) monmalloc((strlen(RNA)+1)*sizeof(char));
			strcpy(table, RNA);
			break;
		case 'p':
			table = (char*) monmalloc((strlen(PRO)+1)*sizeof(char));
			strcpy(table, PRO);
			break;
		case '?':
		default:
			table = (char*) monmalloc(sizeof(char));
			table[0] = '\0';
	}
	if(fi = fopen(inputFileName, "r")) {
		aln = readAlignement(fi, table, typeAlphabet == '?');
		switch(typeAlphabet) {
			case 'd':
			case 'r':
				aln.ambiguity = getXNAAmbiguity();
				break;
			case 'p':
				aln.ambiguity = getProteinAmbiguity();
				break;
			case '?':
			default:
				aln.ambiguity.number = 0;
		}
		aln.cardinal -= aln.ambiguity.number;
		fclose(fi);
	} else {
		exitProg(ErrorReading, inputFileName);
	}
	if(!(fo = fopen(outputFileName, "w")))
		exitProg(ErrorWriting, outputFileName);
	fixAlignmentAmbiguity(&aln);
	set=toSequences(&aln);
	model = estimateMarkovModel(set);
	distA = computeWholeDistancePairAln(aln, computeNorm1Aln);
	dec = getDecodedFromThreshold(set, threshold, model);
	distB = computeWholeDistanceDec(dec);
	corrAB = computeCorrelation(distA, distB);
//printf("%lE\n", corrAB);
	monfree((void*)distB.table);
	for(n=0; n<dec->number; n++)
		monfree((void*) dec->sequence[n]);
	monfree((void*) dec->sequence);
	monfree((void*) dec->size);
	monfree((void*) dec);
	distC = computeMSMDistance(set);
	corrAC = computeCorrelation(distA, distC);
	monfree((void*)distC.table);
	monfree((void*)distA.table);
	fprintf(fo, "%lE\t%lE\n", corrAB, corrAC);
	fprintf(stdout, "%lE\t%lE\n", corrAB, corrAC);
	monfree((void*)set->size);
	for(n=0; n<set->number; n++)
		monfree((void*)set->sequence[n]);
	monfree((void*)set->sequence);
	monfree((void*)set);
	fclose(fo);
/*	sprintf(bufferOutput, "%s_Ali.nex", outputFileName);
	if(!(fo = fopen(bufferOutput, "w")))
		exitProg(ErrorWriting, bufferOutput);
	printDistanceNexus(fo, distA);
	fclose(fo);
	sprintf(bufferOutput, "%s_New.nex", outputFileName);
	if(!(fo = fopen(bufferOutput, "w")))
		exitProg(ErrorWriting, bufferOutput);
	printDistanceNexus(fo, distB);
	fclose(fo);
*/

	exitProg(ExitOk,NULL);
	return 0;
}
예제 #8
0
int main(int argc, char **argv) {		
	TypePosition orderstart=1, orderend=10;
	char option[256], inputFileName[SIZE_BUFFER_CHAR], outputFileName[SIZE_BUFFER_CHAR], bufferOutput[SIZE_BUFFER_CHAR], *table, 
	outputFormat = 'r', typeDec = 'l', typeAlphabet = '?', typeCalc = 'g';
	TypeSetOfSequences set;
	int fixed = 0;
	double threshold = 0.001;
/*	TypeDistFunction *distfunc[MAX_FUNC]=
	{computeProba, computeKullbackLeiber1, computePham, computeCommon, computeCommonBis, computeGillesPham, computeMatchesBis, computeMatches, computeAlex, computeAlexBis};
*/		
	FILE *fi, *fo;
	int i = 1, typeDist = 0;

	for(i=0; i<256; i++)
		option[i] = 0;
	for(i=1; i<argc && *(argv[i]) == '-'; i++) {
		int j;
		for(j=1; argv[i][j] != '\0'; j++)
			option[argv[i][j]] = 1;
		if(option['f']) {
			option['f'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &outputFormat) == 1)
				i++;
		}
		if(option['s']) {
			option['s'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeAlphabet) == 1)
				i++;
		}
		if(option['c']) {
			option['c'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeCalc) == 1)
				i++;
		}
		if(option['m']) {
			option['m'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%d", &typeDist) == 1)
				i++;
			if(typeDist >= MAX_FUNC)
				typeDist = 0;
		}
		if(option['t']) {
			option['t'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%lf", &threshold) == 1)
				i++;
		}
		if(option['h']) {
			printf("%s\n", HELPMESSAGE);
			exitProg(ExitOk, NULL);
		}
	}
	if (i>=argc || sscanf(argv[i++], "%s", inputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);
	if (i>=argc || sscanf(argv[i++], "%s", outputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);

	switch(typeAlphabet) {
		case 'd':
			table = (char*) monmalloc((strlen(DNA)+1)*sizeof(char));
			strcpy(table, DNA);
			break;
		case 'r':
			table = (char*) monmalloc((strlen(RNA)+1)*sizeof(char));
			strcpy(table, RNA);
			break;
		case 'p':
			table = (char*) monmalloc((strlen(PRO)+1)*sizeof(char));
			strcpy(table, PRO);
			break;
		case '?':
		default:
			table = (char*) monmalloc(sizeof(char));
			table[0] = '\0';
	}
	if(fi = fopen(inputFileName, "r")) {
		set = readSequencesFasta(fi, table, typeAlphabet == '?');
		switch(typeAlphabet) {
			case 'd':
			case 'r':
				set.ambiguity = getXNAAmbiguity();
				break;
			case 'p':
				set.ambiguity = getProteinAmbiguity();
				break;
			case '?':
			default:
				set.ambiguity.number = 0;
		}
		set.cardinal -= set.ambiguity.number;
		fclose(fi);
	} else {
		exitProg(ErrorReading, inputFileName);
	}
	
	if(fo = fopen(outputFileName, "w")) {
		TypeDistance dist;
		fixSequencesAmbiguity(&set);
		dist = computeMSMDistance(&set);
		switch(outputFormat) {
			case 't':
				printDistanceTable(fo, dist);
				break;
			case 'r':
				printDistanceRaw(fo, dist);
				break;
			case 'p':
				printDistancePhylip(fo, dist);
				break;
			case 'n':
				printDistanceNexus(fo, dist);
		}
		fclose(fo);
	} else {
		exitProg(ErrorWriting, outputFileName);
	}
	exitProg(ExitOk,NULL);
	return 0;
}
예제 #9
0
/*read partition in Clustnsee format*/
TypePartition readPartition(FILE *f, char***name) {
    char c;
    TypePartition part;
    int sizeBufItem = INC_SIZE_ITEM_BUF, index;
    TypeLexiTree *dict;
    dict = newLexiTree();

    part.sizeAtom = -1;
    part.sizeItem = 0;
    part.atom = (int*) malloc(sizeBufItem*sizeof(int));
    for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f));
    while(c != EOF) {
        char tmp[MAX_NAME_SIZE+1];
        int i;
        if(c == '\'' || c == '"') {
            c = fgetc(f);
            for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
            if(c == '\'' || c == '"')
                c = fgetc(f);
            else
                exitProg(ErrorReading, "Missing closing \" or '...");
        } else {
            for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
        }
/*		if(i == 0)
            exitProg(ErrorExec, "Empty name...");
*/		if(i == MAX_NAME_SIZE)
            exitProg(ErrorExec, "Name too much long...");
        if(i>0) {
            tmp[i++] = '\0';
//printf("%s\n", tmp);
            if(tmp[0] == '#') {
                for(; c != EOF && !isline(c); c = fgetc(f));
            } else {
                if(strncmp(tmp, CLUSTERID, strlen(CLUSTERID)) == 0) {
//	printf("Class\n");
                    part.sizeAtom++;
                    for(; c != EOF && !isline(c); c = fgetc(f));
                } else {
//	printf("Ident\n");
                    if(findWordLexi(tmp, dict) >= 0) {
                        printf("Duplicate identifier %s(%d)\n", tmp, findWordLexi(tmp, dict));
                        fprintLexiTree(stdout, dict);
                        exit(1);
                    }
                    index = addWordLexiTree(tmp, dict);
                    if(index>part.sizeItem)
                        part.sizeItem = index;
                    if(index>=sizeBufItem) {
                        sizeBufItem += INC_SIZE_ITEM_BUF;
                        part.atom = (int*) realloc((void*)part.atom, sizeBufItem*sizeof(int));
                    }
                    part.atom[index] = part.sizeAtom;
                }
            }
        }
        for(; c != EOF && issepline(c); c = fgetc(f));
    }
    part.sizeItem++;
    part.sizeAtom++;
    part.atom = (int*) realloc((void*)part.atom, part.sizeItem*sizeof(int));
    *name = (char**) malloc(part.sizeItem*sizeof(char*));
    fillLexiTree(*name, dict);
    freeLexiTree(dict);
    return part;
}
예제 #10
0
/*read partition in Line Number format*/
TypePartition readPartitionNumber(FILE *f) {
    char c;
    TypePartition part;
    int sizeBufItem = INC_SIZE_ITEM_BUF, index;
    TypeLexiTree *dict;
    dict = newLexiTree();

    part.sizeAtom = 0;
    part.sizeItem = 0;
    part.atom = (int*) malloc(sizeBufItem*sizeof(int));
    for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f));
    while(c != EOF) {
        char tmp[MAX_NAME_SIZE+1];
        int i;
        while(c != EOF && !isline(c)) {
            if(c == '\'' || c == '"') {
                c = fgetc(f);
                for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
                    tmp[i] = c;
                    c = fgetc(f);
                }
                if(c == '\'' || c == '"')
                    c = fgetc(f);
                else
                    exitProg(ErrorReading, "Missing closing \" or '...");
            } else {
                for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issep(c); i++) {
                    tmp[i] = c;
                    c = fgetc(f);
                }
            }
            if(i == MAX_NAME_SIZE)
                exitProg(ErrorExec, "Name too much long...");
            if(i>0) {
                tmp[i++] = '\0';
                index = atoi(tmp);
				if(index>part.sizeItem)
                    part.sizeItem = index;
                if(index>=sizeBufItem) {
                    sizeBufItem += INC_SIZE_ITEM_BUF;
                    part.atom = (int*) realloc((void*)part.atom, sizeBufItem*sizeof(int));
                }
				for(; c != EOF && issep(c); c = fgetc(f));
				if(c == '\'' || c == '"') {
					c = fgetc(f);
					for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
						tmp[i] = c;
						c = fgetc(f);
					}
					if(c == '\'' || c == '"')
						c = fgetc(f);
					else
						exitProg(ErrorReading, "Missing closing \" or '...");
				} else {
					for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
						tmp[i] = c;
						c = fgetc(f);
					}
				}
				if(i == MAX_NAME_SIZE)
					exitProg(ErrorExec, "Name too much long...");
				if(i>0) {
					tmp[i++] = '\0';
					part.atom[index] = atoi(tmp);
					if(part.atom[index]>=part.sizeAtom)
						part.sizeAtom = part.atom[index]+1;
				}
            }
            for(; c != EOF && issep(c); c = fgetc(f));
        }
        for(; c != EOF && issepline(c); c = fgetc(f));
    }
    part.sizeItem++;
    part.atom = (int*) realloc((void*)part.atom, part.sizeItem*sizeof(int));
    return part;
}
예제 #11
0
/*compare part1 vs part2*/
double comparePart(TypePartitionCompareIndex type, TypePartition *part1, TypePartition *part2) {
    int i,ii, j,jj, k, ci, cj, common, appar1, appar2, clasmax=0, NbR, NbS, cas, kas, *card1, *card2, **inter;
    double Max, Exp;

    if(part1->sizeItem != part2->sizeItem)
        exitProg(ErrorExec, "Trying to compare two partitions not on the same set");
    switch(type) {
        case correctedRandIndex:
            //  Indice de inter corrigé
        default:
            clasmax = UTILS_MAX(part1->sizeAtom, part2->sizeAtom); // Nb. max de atomes dans le fichier des partitions
            card1 = (int*) malloc(clasmax*sizeof(int));		// Somme Ligne de inter
            card2 = (int*) malloc(clasmax*sizeof(int));		// Somme colonne
            inter = (int**) malloc(clasmax*sizeof(int *));
            assert(card1 != NULL && card2 != NULL && inter != NULL);
            for(i=0; i<clasmax; i++) {
                inter[i] = (int*) malloc(clasmax*sizeof(int));
                assert(inter[i] != NULL);
            }
            //  Initialisation du tableau de contingence des atomes
            for(i=0; i<clasmax; i++) {
                card1[i]=0; card2[i]=0; //cardinal de la atome i dans la partition 1, cardinal de la atome j dans la partition 2
                for(j=0; j<clasmax; j++)
                    inter[i][j]=0; //intersection de la atome i de la partition 1 et de la atome j de la partition 2
            }
            // Table des cardinaux des intersections des atomes
            for(k=0; k<part1->sizeItem; k++) {
                inter[part1->atom[k]][part2->atom[k]]++;
                card1[part1->atom[k]]++;
                card2[part2->atom[k]]++;
            }
            common=0; //nombre de paires communes entre les deux partitions
            for(i=0; i<part1->sizeAtom; i++)
                for(j=0; j<part2->sizeAtom; j++)
                    common += (inter[i][j]*(inter[i][j]-1))/2;
            appar1=0; //nombre de paires appariées dans la partition 1
            appar2=0; //nombre de paires appariées dans la partition 2
            for(i=0; i<part1->sizeAtom; i++)
                appar1 += (card1[i]*(card1[i]-1))/2;
            for(j=0; j<part2->sizeAtom; j++)
                appar2 += (card2[j]*(card2[j]-1))/2;
            free((void*)card1);
            free((void*)card2);
            for(i=0; i<clasmax; i++)
                free((void*)inter[i]);
            free((void*)inter);
//if((1.-((double)((part1->sizeItem*(part1->sizeItem-1))*common-2.*appar1*appar2))/((double)(((part1->sizeItem*(part1->sizeItem-1))*(appar1+appar2))/2.-2.*appar1*appar2)))>1.) {
//printf("size %d, common %d, appar1 %d, appar2 %d\n", part1->sizeItem, common, appar1, appar2);
//printf("%.3lf/%.3lf\n", ((double)(((double)part1->sizeItem*((double)part1->sizeItem-1.))*((double)common)-2.*((double)appar1)*((double)appar2))), ((double)(((((double)part1->sizeItem)*((double)part1->sizeItem-1.))*(((double)appar1)+((double)appar2)))/2.-2.*((double)appar1)*((double)appar2))));
//}
            return ((double)(((double)part1->sizeItem*((double)part1->sizeItem-1.))*((double)common)-2.*((double)appar1)*((double)appar2)))/((double)(((((double)part1->sizeItem)*((double)part1->sizeItem-1.))*(((double)appar1)+((double)appar2)))/2.-2.*((double)appar1)*((double)appar2)));
            //((double)((part1->sizeItem*(part1->sizeItem-1))*common-2.*appar1*appar2))/((double)(((part1->sizeItem*(part1->sizeItem-1))*(appar1+appar2))/2.-2.*appar1*appar2));
    case standardJacquardIndex: // indice de Jaccard
            NbR=0; NbS=0;
            for(i=1; i<part1->sizeItem; i++)
                for(j=0; j<i; j++) {
                    if(part1->atom[i]==part1->atom[j])
                        cas=1;
                    else
                        cas=0;
                    if(part2->atom[i]==part2->atom[j])
                        kas=1;
                    else
                        kas=0;
                    if(cas==1 && kas==1)
                        NbR++;
                    else
                        if(cas==1 || kas==1)
                            NbS++; // Reunies au moins une fois
                }
                return 1.*NbR/(NbS+NbR);
    case standardRandIndex: // Taux de paires simultanement reunies ou separees - Indice de inter
            NbR=0;
            for(i=1; i<part1->sizeItem; i++)
                for(j=0; j<i; j++) {
                    cas = (part1->atom[i]==part1->atom[j])?1:0;
                    kas = (part2->atom[i]==part2->atom[j])?1:0;
                    if(cas==kas)
                        NbR++;
                }
            return 2.*NbR/part1->sizeItem/(part1->sizeItem-1);
    }
}
예제 #12
0
TypeAnnotation *readAnnotation(FILE *f) {
    char c, tmpS[MAX_NAME_SIZE+1];
    int sizeBufferG, sizeBufferL, indexG, indexA, indexL, i;
	TypeAnnotation *an;
	TypeAnnotationList *list;
	int *start;
	TypeLexiTree *dictG, *dictA;
	
	dictG = newLexiTree();
	dictA = newLexiTree();
	an = (TypeAnnotation*) malloc(sizeof(TypeAnnotation));
	indexG = 0;
	indexL = 0;
	sizeBufferG = BASIC_INC_BUFFER_G;
	sizeBufferL = BASIC_INC_BUFFER_L;
	start = (int*) malloc(sizeBufferG*sizeof(int));
	list = (TypeAnnotationList*) malloc(sizeBufferL*sizeof(TypeAnnotationList));
	for(i=0; i<sizeBufferG; i++)
		start[i] = -1;
	for(c=getc(f); c!=EOF && issepline(c); c = fgetc(f));
	while(c != EOF) { //read first line
        int i, indexG;
		if(c == '\'' || c == '"') {
			c = fgetc(f);
			for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
				tmpS[i] = c;
				c = fgetc(f);
			}
			if(c == '\'' || c == '"')
				c = fgetc(f);
			else
				exitProg(ErrorReading, "Missing closing \" or '...");			
		} else {
			for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
				tmpS[i] = c;
				c = fgetc(f);
			}
		}
		if(i == 0)
			exitProg(ErrorExec, "Empty name ...");
		if(i == MAX_NAME_SIZE)
			exitProg(ErrorExec, "Name too much long...");
		tmpS[i++] = '\0';
		indexG = addWordLexiTree(tmpS, dictG);
		if(indexG >= sizeBufferG) {
			int i;
			sizeBufferG += BASIC_INC_BUFFER_G;
			start = (int*) realloc((void *) start, sizeBufferG*sizeof(int));
			for(i=sizeBufferG-BASIC_INC_BUFFER_G; i<sizeBufferG; i++)
				start[i] = -1;
		}
		for(; c != EOF && issepX(c); c = fgetc(f));
		while(!issepline(c)) {
			if(c == '\'' || c == '"') {
				c = fgetc(f);
				for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
					tmpS[i] = c;
					c = fgetc(f);
				}
				if(c == '\'' || c == '"')
					c = fgetc(f);
				else
					exitProg(ErrorReading, "Missing closing \" or '...");			
			} else {
				for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
					tmpS[i] = c;
					c = fgetc(f);
				}
			}
			if(i == 0)
				exitProg(ErrorExec, "Empty name ...");
			if(i == MAX_NAME_SIZE)
				exitProg(ErrorExec, "Name too much long...");
			tmpS[i++] = '\0';
			if(!((i != 2) && (tmpS[0] == 'N') && (tmpS[1] == 'A'))) {
				indexA = addWordLexiTree(tmpS, dictA);
				if(indexL >= sizeBufferL) {
					sizeBufferL += BASIC_INC_BUFFER_L;
					list = (TypeAnnotationList*) realloc((void *) list, sizeBufferL*sizeof(double*));
				}
				list[indexL].annot = indexA;
				list[indexL].next = start[indexG];
				start[indexG] = indexL;
				indexL++;
			}
			for(; c != EOF && issepX(c); c = fgetc(f));
		}
		for(; c!=EOF && issepline(c); c = fgetc(f));
	}
	an->sizeG = dictG->sizeWord;
	an->sizeA = dictA->sizeWord;
	start = (int*) realloc((void *) start, an->sizeG*sizeof(int));
	an->mat = (int**) malloc( an->sizeG*sizeof(int*));
	for(i=0; i<an->sizeG; i++) {
		int j;
		an->mat[i] = (int*) malloc(an->sizeA*sizeof(int));
		for(j=0; j<an->sizeA; j++)
			an->mat[i][j] = 0;
		for(j=start[i]; j>=0; j=list[j].next)
			an->mat[i][list[j].annot] = 1;
	}
	free((void*) start);
	free((void*) list);
	an->nameG = (char**) malloc(an->sizeG*sizeof(char*));
	fillLexiTree(an->nameG, dictG);
	an->nameA = (char**) malloc(an->sizeA*sizeof(char*));
	fillLexiTree(an->nameA, dictA);
	freeLexiTree(dictG);
	freeLexiTree(dictA);
	return an;
}
예제 #13
0
int main(int argc, char **argv) {		
	TypePosition orderstart=1, orderend=10, length = 10;
	char option[256], inputFileName[SIZE_BUFFER_CHAR], outputFileName[SIZE_BUFFER_CHAR], bufferOutput[SIZE_BUFFER_CHAR], *table, 
	outputFormat = 'r', typeDec = 'l', typeAlphabet = 'd', typeCalc = 'g';
	TypeSetOfSequences set;
	int fixed = 0, flagThre = 1;
	double threshold = 0.001, tmin = -25, tmax = -3, tprec = 0.5;
/*	TypeDistFunction *distfunc[MAX_FUNC]=
	{computeProba, computeKullbackLeiber1, computePham, computeCommon, computeCommonBis, computeGillesPham, computeMatchesBis, computeMatches, computeAlex, computeAlexBis};
*/		
	FILE *fi, *fo;
	int i = 1, typeDist = 0;

	for(i=0; i<256; i++)
		option[i] = 0;
	for(i=1; i<argc && *(argv[i]) == '-'; i++) {
		int j;
		for(j=1; argv[i][j] != '\0'; j++)
			option[argv[i][j]] = 1;
		if(option['f']) {
			option['f'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &outputFormat) == 1)
				i++;
		}
		if(option['s']) {
			option['s'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeAlphabet) == 1)
				i++;
		}
		if(option['c']) {
			option['c'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeCalc) == 1)
				i++;
		}
		if(option['m']) {
			option['m'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%d", &typeDist) == 1)
				i++;
			if(typeDist >= MAX_FUNC)
				typeDist = 0;
		}
		if(option['t']) {
			option['t'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%lf", &threshold) == 1)
				i++;
			flagThre = 1;
		}
		if(option['l']) {
			option['l'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%ld", &length) == 1)
				i++;
			flagThre = 0;
		}
		if(option['h']) {
			printf("%s\n", HELPMESSAGE);
			exitProg(ExitOk, NULL);
		}
	}
	if (i>=argc || sscanf(argv[i++], "%s", inputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);
	if (i>=argc || sscanf(argv[i++], "%s", outputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);

	switch(typeAlphabet) {
		case 'd':
			table = (char*) monmalloc((strlen(DNA)+1)*sizeof(char));
			strcpy(table, DNA);
			break;
		case 'r':
			table = (char*) monmalloc((strlen(RNA)+1)*sizeof(char));
			strcpy(table, RNA);
			break;
		case 'p':
			table = (char*) monmalloc((strlen(PRO)+1)*sizeof(char));
			strcpy(table, PRO);
			break;
		case '?':
		default:
			table = (char*) monmalloc(sizeof(char));
			table[0] = '\0';
	}
	if(fi = fopen(inputFileName, "r")) {
		set = readSequencesFasta(fi, table, typeAlphabet == '?');
		switch(typeAlphabet) {
			case 'd':
			case 'r':
				set.ambiguity = getXNAAmbiguity();
				break;
			case 'p':
				set.ambiguity = getProteinAmbiguity();
				break;
			case '?':
			default:
				set.ambiguity.number = 0;
		}
		set.cardinal -= set.ambiguity.number;
		fclose(fi);
	} else {
		exitProg(ErrorReading, inputFileName);
	}
	
	if(fo = fopen(outputFileName, "w")) {
		TypeSetOfSequences *dec;
		TypeDistance dist;
		double tmid, t, smax, tres, sc,  scl, scr;
		TypeNumber n;
		TypeCodeScheme *scheme;
		TypeMarkovModel *model;

		fixSequencesAmbiguity(&set);
		scheme = (TypeCodeScheme*) monmalloc(sizeof(TypeCodeScheme));
		scheme->suffixTree = getSuffixTree(&set);
		scheme->code = (TypePosition*) monmalloc(scheme->suffixTree->size*sizeof(TypePosition));
		scheme->buffSize = INC_SIZE_CODE;
		scheme->lengthCode = (TypePosition*) monmalloc(scheme->buffSize*sizeof(TypePosition));
		model = estimateMarkovModel(&set);
		while((tmax-tmin)>4*tprec) {
			tmid = (tmax+tmin)/2.;
			scheme->cardCode = 0;
			buildCodeThreshold(exp(tmid-3.*tprec/2.), scheme->suffixTree->root, 0, 1., model, scheme);
			dec = getDecodedFromScheme(scheme);
			scl = score(dec);
			for(n=0; n<dec->number; n++)
				monfree((void*) dec->sequence[n]);
			monfree((void*) dec->sequence);
			monfree((void*) dec->size);
			monfree((void*) dec);
			scheme->cardCode = 0;
			buildCodeThreshold(exp(tmid+3.*tprec/2.), scheme->suffixTree->root, 0, 1., model, scheme);
			dec = getDecodedFromScheme(scheme);
			scr = score(dec);
			for(n=0; n<dec->number; n++)
				monfree((void*) dec->sequence[n]);
			monfree((void*) dec->sequence);
			monfree((void*) dec->size);
				monfree((void*) dec);
			if(scl>scr)
				tmax = tmid+3.*tprec/2.;
			else
				tmin = tmid-3.*tprec/2.;
		}
		if(scl>scr) {
			smax = scl;
			tres = exp(tmid-3.*tprec/2.);
		} else {
			smax = scr;
			tres = exp(tmid+3.*tprec/2.);
		}
		scheme->cardCode = 0;
		buildCodeThreshold(exp(tmid), scheme->suffixTree->root, 0, 1., model, scheme);
		dec = getDecodedFromScheme(scheme);
		sc = score(dec);
		for(n=0; n<dec->number; n++)
			monfree((void*) dec->sequence[n]);
		monfree((void*) dec->sequence);
		monfree((void*) dec->size);
		monfree((void*) dec);
		if(sc>smax) {
			smax = scl;
			tres = exp(tmid);
		}
printf("%.4lE\t%lf\n", tres, smax);
		scheme->cardCode = 0;
		buildCodeThreshold(tres, scheme->suffixTree->root, 0, 1., model, scheme);
		dec = getDecodedFromScheme(scheme);
		freeModel(model);
		freeScheme(scheme);
		dist = computeWholeDistanceDec(dec);
		switch(outputFormat) {
			case 't':
				printDistanceTable(fo, dist);
				break;
			case 'r':
				printDistanceRaw(fo, dist);
				break;
			case 'p':
				printDistancePhylip(fo, dist);
				break;
			case 'n':
				printDistanceNexus(fo, dist);
		}
		fclose(fo);
	} else {
		exitProg(ErrorWriting, outputFileName);
	}
	exitProg(ExitOk,NULL);
	return 0;
}
예제 #14
0
int main(int argc, char **argv) {
	TypePosition orderstart=1, orderend=10;
	char option[256], inputFileName[SIZE_BUFFER_CHAR], outputFileName[SIZE_BUFFER_CHAR], bufferOutput[SIZE_BUFFER_CHAR], *table, 
	outputFormat = 'r', typeDec = 'l', typeAlphabet = '?', typeCalc = 'g', type = 't';
	TypeSetOfSequences *set, seq;
	TypeAlignment aln, atmp;
	int fixed = 0;
	double threshold = 0.001, tmin = 1E-20, tmax=0.1, tstep = 0.00001, qmin = -25, qmax = -3, qprec = 0.5;
	double thre;
	TypeNumber n;
	TypeDistance distA, distB;
	TypePosition l, tot, lmax = 50;
	TypeSuffixTree *suffixTree;
	TypeMarkovModel *model;
	TypeCodeScheme *scheme;
/*	TypeDistFunction *distfunc[MAX_FUNC]=
	{computeProba, computeKullbackLeiber1, computePham, computeCommon, computeCommonBis, computeGillesPham, computeMatchesBis, computeMatches, computeAlex, computeAlexBis};
*/		
	FILE *fi, *fo;
	int i = 1, typeDist = 0;

	for(i=0; i<256; i++)
		option[i] = 0;
	for(i=1; i<argc && *(argv[i]) == '-'; i++) {
		int j;
		for(j=1; argv[i][j] != '\0'; j++)
			option[argv[i][j]] = 1;
		if(option['f']) {
			option['f'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &outputFormat) == 1)
				i++;
		}
		if(option['s']) {
			option['s'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeAlphabet) == 1)
				i++;
		}
		if(option['c']) {
			option['c'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &typeCalc) == 1)
				i++;
		}
		if(option['m']) {
			option['m'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%lf", &tmin) == 1)
				i++;
			if(typeDist >= MAX_FUNC)
				typeDist = 0;
		}
		if(option['t']) {
			option['t'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%lf", &threshold) == 1)
				i++;
		}
		if(option['y']) {
			option['y'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%c", &type) == 1)
				i++;
		}
	if(option['h']) {
			printf("%s\n", HELPMESSAGE);
			exitProg(ExitOk, NULL);
		}
	}
	if (i>=argc || sscanf(argv[i++], "%s", inputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);
	if (i>=argc || sscanf(argv[i++], "%s", outputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE);

	switch(typeAlphabet) {
		case 'd':
			table = (char*) monmalloc((strlen(DNA)+1)*sizeof(char));
			strcpy(table, DNA);
			break;
		case 'r':
			table = (char*) monmalloc((strlen(RNA)+1)*sizeof(char));
			strcpy(table, RNA);
			break;
		case 'p':
			table = (char*) monmalloc((strlen(PRO)+1)*sizeof(char));
			strcpy(table, PRO);
			break;
		case '?':
		default:
			table = (char*) monmalloc(sizeof(char));
			table[0] = '\0';
	}
	if(fi = fopen(inputFileName, "r")) {
		aln = readAlignement(fi, table, typeAlphabet == '?');
		switch(typeAlphabet) {
			case 'd':
			case 'r':
				aln.ambiguity = getXNAAmbiguity();
				break;
			case 'p':
				aln.ambiguity = getProteinAmbiguity();
				break;
			case '?':
			default:
				aln.ambiguity.number = 0;
		}
		aln.cardinal -= aln.ambiguity.number;
		fclose(fi);
	} else {
		exitProg(ErrorReading, inputFileName);
	}
	fixAlignmentAmbiguity(&aln);
	set=toSequences(&aln);

	if(!(fo = fopen(outputFileName, "w")))
		exitProg(ErrorWriting, outputFileName);
	distA = computeWholeDistancePairAln(aln, computeNorm1Aln);
	scheme = (TypeCodeScheme*) monmalloc(sizeof(TypeCodeScheme));
	scheme->suffixTree = getSuffixTree(set);
	scheme->code = (TypePosition*) monmalloc(scheme->suffixTree->size*sizeof(TypePosition));
	scheme->buffSize = INC_SIZE_CODE;
	scheme->lengthCode = (TypePosition*) monmalloc(scheme->buffSize*sizeof(TypePosition));
	if(type == 't') {
		int l;
		model = estimateMarkovModel(set);
//		for(thre=tmin; thre<=tmax; thre *= 10.0) {
		for(l=tmin; l<=-1; l++) {
			double t;
			int k;
			thre = pow(10.0, (double) l);
			for(k=0; k<10; k++) {
//			for(t=thre; t<thre*10; t+=thre) {
				double corr, sc;
				TypeSetOfSequences *dec;
				t = ((double)k+1.)*thre;
				scheme->cardCode = 0;
				buildCodeThreshold(t, scheme->suffixTree->root, 0, 1., model, scheme);
//printLengthDistribution(stdout, scheme->lengthCode,scheme->cardCode);
				dec = getDecodedFromScheme(scheme);
//printf("cardinal dec = %ld\n", dec->cardinal);
				distB = computeWholeDistanceDec(dec);
				corr = computeCorrelation(distA, distB);
				monfree((void*)distB.table);
				sc = score(dec);
				printf("%lE\t%lf\t%.2lf\n", t, corr, sc);
				fprintf(fo, "%lE\t%lf\t%.2lf\n", t, corr, sc);
				for(n=0; n<dec->number; n++)
					monfree((void*) dec->sequence[n]);
				monfree((void*) dec->sequence);
				monfree((void*) dec->size);
				monfree((void*) dec);
			}
		}
		fprintf(stdout, "\n\n%.4lE\n\n", findMode(set, qmin, qmax, qprec, scheme, model));
		freeModel(model);
	} else {
		for(l = lmax; l>=1; l--) {
			double corr;
			TypeSetOfSequences *dec;
			scheme->cardCode = 0;
			buildCodeLength(l, scheme->suffixTree->root, 0, scheme);
//printLengthDistribution(stdout, scheme->lengthCode,scheme->cardCode);
			dec = getDecodedFromScheme(scheme);
//printf("cardinal dec = %ld\n", dec->cardinal);
			distB = computeWholeDistanceDec(dec);
			corr = computeCorrelation(distA, distB);
			monfree((void*)distB.table);
			fprintf(fo, "%ld\t%lf\n", l, corr);
			fprintf(stdout, "%ld\t%lf\n", l, corr);
			for(n=0; n<dec->number; n++)
				monfree((void*) dec->sequence[n]);
			monfree((void*) dec->sequence);
			monfree((void*) dec->size);
			monfree((void*) dec);
		}
	}
		
	freeScheme(scheme);
	monfree((void*)distA.table);
	fprintf(stdout, "\n\n%ld\n\n", totalLength(*set));
	monfree((void*)set->size);
	for(n=0; n<set->number; n++)
		monfree((void*)set->sequence[n]);
	monfree((void*)set->sequence);
	monfree((void*)set);
	fclose(fo);
/*	sprintf(bufferOutput, "%s_Ali.nex", outputFileName);
	if(!(fo = fopen(bufferOutput, "w")))
		exitProg(ErrorWriting, bufferOutput);
	printDistanceNexus(fo, distA);
	fclose(fo);
	sprintf(bufferOutput, "%s_New.nex", outputFileName);
	if(!(fo = fopen(bufferOutput, "w")))
		exitProg(ErrorWriting, bufferOutput);
	printDistanceNexus(fo, distB);
	fclose(fo);
*/
;
	exitProg(ExitOk,NULL);
	return 0;
}
예제 #15
0
TypeNameFossilIntTab *readFossilIntTab(FILE *f) {
    int sizeBuf;
    char c;
    TypeNameFossilIntTab *res;

    res = (TypeNameFossilIntTab *) malloc(sizeof(TypeNameFossilIntTab));
    sizeBuf = INC_FOSSIL_ITEM;
    res->name = (char**) malloc(sizeBuf*sizeof(char*));
    res->fossilIntTab = (TypeFossilIntTab*) malloc(sizeBuf*sizeof(TypeFossilIntTab));
    res->size = 0;
    do {
        char *tmp;
        int i;
        tmp = (char*) malloc((MAX_NAME_SIZE+1)*sizeof(char));
        for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f));
        if(c == '\'' || c == '"') {
            c = fgetc(f);
            for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
            if(c == '\'' || c == '"')
                c = fgetc(f);
        } else {
            for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issep(c); i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
        }
        if(i == MAX_NAME_SIZE)
            exitProg(ErrorExec, "Name too much long...");
        tmp[i++] = '\0';
        if(i>1) {
            char bof[MAX_NAME_SIZE+1];
            int sizeFossilIntBuf = INC_FOSSIL_ITEM;
            if(res->size >= sizeBuf) {
                sizeBuf += INC_FOSSIL_ITEM;
                res->name = (char**) realloc((void*) res->name, sizeBuf*sizeof(char*));
                res->fossilIntTab = (TypeFossilIntTab*) realloc((void*) res->fossilIntTab, sizeBuf*sizeof(TypeFossilIntTab));
            }
            res->name[res->size] = (char *) realloc((void*) tmp, i*sizeof(char));
            fixSpace(res->name[res->size]);
            res->fossilIntTab[res->size].size = 0;
            res->fossilIntTab[res->size].fossilInt = (TypeTimeInterval*) malloc(sizeFossilIntBuf*sizeof(TypeTimeInterval));
            for(; c != EOF && issep(c); c = fgetc(f));
            while(c != EOF && !isline(c)) {
                for(i=0; c != EOF && !issepline(c) && i<MAX_NAME_SIZE; i++) {
                    bof[i] = c;
                    c = fgetc(f);
                }
                bof[i++] = '\0';
                if(res->fossilIntTab[res->size].size>=sizeFossilIntBuf) {
                    sizeFossilIntBuf += INC_FOSSIL_ITEM;
                    res->fossilIntTab[res->size].fossilInt = (TypeTimeInterval*) realloc((void*) res->fossilIntTab[res->size].fossilInt, sizeFossilIntBuf*sizeof(TypeTimeInterval));
                }
                res->fossilIntTab[res->size].fossilInt[res->fossilIntTab[res->size].size++] = toFossilInt(bof);
DEBUG(
    printf("\"%s\"\t%s\t", tmp, bof);
    fprintFossilInt(stdout, res->fossilIntTab[res->size].fossilInt[res->fossilIntTab[res->size].size-1]);
    printf("\n");
)
                for(; c != EOF && issep(c); c = fgetc(f));
            }
            res->size++;
        } else
예제 #16
0
int main(int argc, char **argv) {		
	char **inputNameTable, **name, inputFileName[STRING_SIZE], outputFileName[STRING_SIZE], effectifFileName[STRING_SIZE], outputPrefix[STRING_SIZE], outputFileNameRand[STRING_SIZE], buffer[STRING_SIZE], inputFileNameModel[STRING_SIZE], *tmp, option[256];
	FILE *fi, *fo, *fs;
	int i, j, t, sizeTable, singleF = 0;
	TypeMultiGraph *graph, *gtmp;
	TypeGraph **tableGraph, *g;
	TypePartition  part, *tablePart;
	double alpha = 1.;

	for(i=0; i<256; i++)
		option[i] = 0;
	   
	sprintf(outputFileName, "%s.%s", NAME_OUTPUT, EXT_OUTPUT);
	tableGraph = (TypeGraph**) malloc((argc+3)*sizeof(TypeGraph*));
	inputNameTable = (char**) malloc((argc+3)*sizeof(char*));
	sizeTable = 0;
	for(i=1; i<argc && *(argv[i]) == '-'; i++) {
		for(j=1; argv[i][j] != '\0'; j++)
			option[argv[i][j]] = 1;
		if(option['o']) {
			option['o'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%s", outputFileName) == 1)
				i++;
			else
				exitProg(ErrorArgument, "a file name is required after option -f");
		}
		if(option['s']) {
			option['s'] = 0;
			singleF = 1;
		}
		if(option['p']) {
			option['p'] = 0;
			if((i+1)<argc && sscanf(argv[i+1], "%lf", &alpha) == 1)
				i++;
			else
				exitProg(ErrorArgument, "a real number is required after option -p");
		}
		if(option['m']) {
			option['m'] = 0;
			if(!(sscanf(argv[i+1], "%s", inputFileName) == 1))
				exitProg(ErrorArgument, "wrong file name");
			i++;
			inputNameTable[sizeTable] = (char*) malloc((strlen(inputFileName)+1)*sizeof(char));
			strcpy(inputNameTable[sizeTable], inputFileName);
			printf("Reading file %s\n", inputNameTable[sizeTable]);
			if(fi = fopen(inputNameTable[sizeTable], "r")) {
				tableGraph[sizeTable++] = readMatrixGraph(fi);
				fclose(fi);
			} else
				exitProg(ErrorReading, inputNameTable[sizeTable]);
		}
		if(option['h']) {
			option['h'] = 0;
			printf("%s\n", HELPMESSAGE);
			exit(0);
		}
	}
	for(j=i; j<argc; j++) {
		if(!(sscanf(argv[j], "%s", inputFileName) == 1))
			exitProg(ErrorArgument, "wrong file name");
		inputNameTable[sizeTable] = (char*) malloc((strlen(inputFileName)+1)*sizeof(char));
		strcpy(inputNameTable[sizeTable], inputFileName);
printf("Reading file %s\n", inputNameTable[sizeTable]);
		if(fi = fopen(inputNameTable[sizeTable], "r")) {
			tableGraph[sizeTable] = readGraph(fi);
			fclose(fi);
		} else
			exitProg(ErrorReading, inputNameTable[sizeTable]);
		fixEdgeGraph(tableGraph[sizeTable]);
printf("%d nodes\n", tableGraph[sizeTable]->sizeGraph);
		sizeTable++;
	}
	if(sizeTable <= 0)
		exitProg(ErrorArgument, "at least one graph is required.");
	strcpy(outputPrefix, outputFileName);
	if((tmp = strrchr(outputPrefix, '.')) != NULL)
		tmp[0] = '\0';
	graph = toMultiGraph(tableGraph, sizeTable);
	part = getPartition(graph, LouvainType, &alpha);
	tableGraph[sizeTable] = sumMultiGraph(graph);
	inputNameTable[sizeTable] = (char*) malloc((strlen("Sum")+1)*sizeof(char));
	strcpy(inputNameTable[sizeTable], "Sum");
	sizeTable++;
	tableGraph[sizeTable] = unionMultiGraph(graph);
	inputNameTable[sizeTable] = (char*) malloc((strlen("Union")+1)*sizeof(char));
	strcpy(inputNameTable[sizeTable], "Union");
	sizeTable++;
	tableGraph[sizeTable] = interMultiGraph(graph);
	inputNameTable[sizeTable] = (char*) malloc((strlen("Intersection")+1)*sizeof(char));
	strcpy(inputNameTable[sizeTable], "Intersection");
	sizeTable++;
	name = (char**) malloc(sizeTable*sizeof(char*));
	for(t=0; t<sizeTable; t++) {
		char *tmp;
		if((tmp = strrchr(inputNameTable[t], '.')) != NULL)
			tmp[0] = '\0';
		if((tmp=strrchr(inputNameTable[t], '/')) == NULL)
			tmp = inputNameTable[t];
		else
			tmp++;
		name[t] = (char*) malloc((strlen(tmp)+1)*sizeof(char));
		strcpy(name[t], tmp);
//		printf("name[%d]\t%s\n", t, name[t]);
	}
	tablePart = (TypePartition*) malloc(sizeTable*sizeof(TypePartition));
	if(singleF) {
		TypeMultiGraph *gtmp;
		gtmp = (TypeMultiGraph*) malloc(sizeof(TypeMultiGraph));
		gtmp->sizeTable = 1;
		gtmp->edge = (TypeEdgeG***) malloc(sizeof(TypeEdgeG**));
		gtmp->present = (int**) malloc(sizeof(int*));
		gtmp->present[0] = (int*) malloc(graph->sizeGraph*sizeof(int));
		for(i=0; i<graph->sizeGraph; i++)
			gtmp->present[0][i] = 1;
		for(t=0; t<sizeTable; t++) {
			char output[STRING_SIZE], *tmp;
			fillMultiOne(tableGraph[t], gtmp);
			sprintf(output, "%s_%s.%s", outputPrefix, name[t], EXT_OUTPUT);
printf("Computing %s\n", output);
			tablePart[t] = getPartition(gtmp, LouvainType, &alpha);
			if(fo = fopen(output, "w")) {
				fprintPartitionClustNSee(fo, &(tablePart[t]), gtmp->name);
				fclose(fo);
			} else
				exitProg(ErrorWriting, output);
		}
		free((void*)gtmp->present[0]);
		free((void*)gtmp->present);
		free((void*)gtmp->edge);
		free((void*)gtmp);
	}
	if(fo = fopen(outputFileName, "w")) {
		fprintPartitionClustNSee(fo, &part, graph->name);
		fclose(fo);
	} else
		exitProg(ErrorWriting, outputFileName);
	sprintf(effectifFileName, "%s_effectif.csv", outputPrefix);
	if(fo = fopen(effectifFileName, "w")) {
		int **eff, c, t, *cs;
		eff = getEdgesNumbers(&part, graph);
		cs = getClassSize(&part);
		fprintf(fo, "\tSize");
		for(t=0; t<graph->sizeTable; t++)
			fprintf(fo, "\t%s", name[t]);
		fprintf(fo, "\n");
		for(c=0; c<part.sizeAtom; c++) {
			fprintf(fo, "ClusterID:%d", c+1);
			fprintf(fo, "\t%d", cs[c]);
			for(t=0; t<graph->sizeTable; t++) {
				fprintf(fo, "\t%d", eff[c][t]);
			}
			fprintf(fo, "\n");
		}
		fclose(fo);
		for(c=0; c<part.sizeAtom; c++)
			free((void*)eff[c]);
		free((void*)eff);
		free((void*)cs);
	} else
		exitProg(ErrorWriting, effectifFileName);
		
	if(singleF) {
		for(t=sizeTable-3; t<sizeTable; t++) {
			sprintf(effectifFileName, "%s_%s_effectif.csv", outputPrefix, name[t]);
			if((fo = fopen(effectifFileName, "w"))) {
				int **eff, c, t, *cs;
				eff = getEdgesNumbers(&(tablePart[sizeTable-1]), graph);
				cs = getClassSize(&(tablePart[sizeTable-1]));
				fprintf(fo, "\tSize");
				for(t=0; t<graph->sizeTable; t++)
					fprintf(fo, "\t%s", name[t]);
				fprintf(fo, "\n");
				for(c=0; c<tablePart[sizeTable-1].sizeAtom; c++) {
					fprintf(fo, "ClusterID:%d", c+1);
					fprintf(fo, "\t%d", cs[c]);
					for(t=0; t<graph->sizeTable; t++) {
						fprintf(fo, "\t%d", eff[c][t]);
					}
					fprintf(fo, "\n");
				}
				fclose(fo);
				for(c=0; c<tablePart[sizeTable-1].sizeAtom; c++)
					free((void*)eff[c]);
				free((void*)eff);
				free((void*)cs);
			} else
				exitProg(ErrorWriting, effectifFileName);
			sprintf(effectifFileName, "%s_%s_graph.csv", outputPrefix, name[t]);
			if((fo = fopen(effectifFileName, "w"))) {
				fprintGraph(fo, tableGraph[t]);
			} else
				exitProg(ErrorWriting, effectifFileName);
		}
	}
	if(singleF) {
		int tl, tc;
		char *tmp;
		sprintf(outputFileNameRand, "%s_Rand.csv", outputPrefix);
		if(fo = fopen(outputFileNameRand, "w")) {
			char *tmp;
			fprintf(fo,"All\t%lf\n", comparePartDiff(correctedRandIndex, &(part), graph->name, &(part), graph->name));
			for(tl=0; tl<sizeTable; tl++) {
				fprintf(fo, "%s\t%lf", name[tl], comparePartDiff(correctedRandIndex, &(part), graph->name, &(tablePart[tl]), tableGraph[tl]->name));
				for(tc=0; tc<=tl; tc++)
					fprintf(fo, "\t%lf", comparePartDiff(correctedRandIndex, &(tablePart[tc]),  tableGraph[tc]->name, &(tablePart[tl]), tableGraph[tl]->name));
				fprintf(fo, "\n");
			}
			fprintf(fo, "\tAll");
			for(tl=0; tl<sizeTable; tl++) {
				fprintf(fo, "\t%s", name[tl]);
			}
			fprintf(fo, "\n");
			fclose(fo);
		} else
			exitProg(ErrorWriting, outputFileNameRand);
	}
	for(t=0; t<sizeTable; t++) {
		freeGraph(tableGraph[t]);
		free((void*) name[t]);
		free((void*) inputNameTable[t]);
	}
	free((void*) tableGraph);
	free((void*) name);
	free((void*) inputNameTable);
	exit(0);
	return 0;
}