Exemplo n.º 1
0
static float callmxscarna( char **mseq1, char **mseq2, int alloclen )
{
	FILE *fp;
	int res;
	static char com[10000];
	float value;


	t2u( *mseq1 );
	t2u( *mseq2 );
	fp = fopen( "_mxscarnain", "w" );
	if( !fp )
	{
		fprintf( stderr, "Cannot open _mxscarnain\n" );
		exit( 1 );
	}
	fprintf( fp, ">1\n" );
	fprintf( fp, "%s\n", *mseq1 );
	fprintf( fp, ">2\n" );
	fprintf( fp, "%s\n", *mseq2 );
	fclose( fp );

	sprintf( com, "env PATH=%s mxscarna _mxscarnain > _mxscarnaout 2>/dev/null", whereispairalign );
	res = system( com );
	if( res )
	{
		fprintf( stderr, "Error in mxscarna\n" );
		exit( 1 );
	}

	fp = fopen( "_mxscarnaout", "r" );
	if( !fp )
	{
		fprintf( stderr, "Cannot open _mxscarnaout\n" );
		exit( 1 );
	}

	fgets( com, 999, fp );
	load1SeqWithoutName_new( fp, *mseq1 );
	fgets( com, 999, fp );
	load1SeqWithoutName_new( fp, *mseq2 );

	fclose( fp );

//	fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
//	fprintf( stderr, "*mseq2 = %s\n", *mseq2 );

	value = (float)naivepairscore11( *mseq1, *mseq2, penalty );

	return( value );
}
Exemplo n.º 2
0
static void pairalign( char **name, int nlen[M], char **seq, double *effarr, int alloclen )
{
	FILE *tmpfp;
	static char dumm1[B], dumm0[B];
	int i, j;
	char *res;
	FILE *hat3p;
	static double *effarr1 = NULL;
	static double *effarr2 = NULL;
	static char **pseq;
	LocalHom **localhomtable, *tmpptr;
	float pscore = 0.0; // by D.Mathog, aguess
	char *aseq = NULL; // by D.Mathog
	char **usedseqs = NULL; // by D.Mathog
	char **usednames = NULL; // by D.Mathog
	int nused;
	double tsuyosa;

	tsuyosa = (double)nhomologs * (nhomologs-1) / njob * TSUYOSAFACTOR;
	fprintf( stderr, "tsuyosa = %f\n", tsuyosa );
	localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
	for( i=0; i<njob; i++)
	{
		localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
		for( j=0; j<njob; j++)
		{
			localhomtable[i][j].start1 = -1;
			localhomtable[i][j].end1 = -1;
			localhomtable[i][j].start2 = -1; 
			localhomtable[i][j].end2 = -1; 
			localhomtable[i][j].opt = -1.0;
			localhomtable[i][j].next = NULL;
		}
	}

	if( effarr1 == NULL ) 
	{
		effarr1 = AllocateDoubleVec( njob );
		effarr2 = AllocateDoubleVec( njob );
		pseq = AllocateCharMtx( 2, nlenmax*9+1 );
		aseq = AllocateCharVec( nlenmax*9+1 );
		usedseqs = AllocateCharMtx( njob, nlenmax*9+1 );
		usednames = AllocateCharMtx( njob, B );
#if 0
#else
#endif
	}

#if 0
	fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
#endif

#if 0
	for( i=0; i<njob; i++ )
		fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
#endif


//	writePre( njob, name, nlen, aseq, 0 );

	fprintf( stderr, "opening %s\n", pairfile  );
	tmpfp = fopen( pairfile, "r" );
	if( !tmpfp )
	{
		fprintf( stderr, "Cannot open %s\n", pairfile );
		exit( 1 );
	}
	searchKUorWA( tmpfp );
	hat3p = fopen( "hat3", "w" );
	if( !hat3p ) ErrorExit( "Cannot open hat3." );
	nused = 0;
	while( 1 )
	{
		res = fgets( dumm0, B-1, tmpfp );
		strip( dumm0 );
		if( res == NULL )
		{
			break;
		}
		load1SeqWithoutName_new( tmpfp, pseq[0] );
		gappick0( aseq, pseq[0] );
		i =  searchused( aseq, usedseqs, nused );
		if( i == -1 )
		{
			strcpy( usednames[nused], dumm0+1 );
			strcpy( usedseqs[nused], aseq );
			i = nused;
			nused++;
		}
		fprintf( stderr, "i = %d\n", i );

		res = fgets( dumm1, B-1, tmpfp );
		strip( dumm1 );
		if( res == NULL )
		{
			fprintf( stderr, "ERROR: The number of sequences in %s must be even.\n", pairfile );
			exit( 1 );
		}
		load1SeqWithoutName_new( tmpfp, pseq[1] );
		gappick0( aseq, pseq[1] );
		j =  searchused( aseq, usedseqs, nused );
		if( j == -1 )
		{
			strcpy( usednames[nused], dumm1+1 );
			strcpy( usedseqs[nused], aseq );
			j = nused;
			nused++;
		}
		fprintf( stderr, "j = %d\n", j );

		if( strlen( pseq[0] ) != strlen( pseq[1] ) )
		{
			fprintf( stderr, "Not aligned,  %s - %s\n", dumm0, dumm1 );
			exit( 1 );
		}


		fprintf( stderr, "adding %d-%d\n", i, j );
		putlocalhom2( pseq[0], pseq[1], localhomtable[i]+j, 0, 0, (int)pscore, strlen( pseq[0] ) );
		for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
		{
			if( tmpptr->opt == -1.0 ) continue;
			fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt * tsuyosa, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next ); 
		}
	}
	fclose( tmpfp );
	fclose( hat3p );

	for( i=0; i<nused; i++ )
		fprintf( stdout, ">%s\n%s\n", usednames[i], usedseqs[i] );


#if 0
	fprintf( stderr, "##### writing hat3\n" );
	hat3p = fopen( "hat3", "w" );
	if( !hat3p ) ErrorExit( "Cannot open hat3." );
	ilim = njob-1;	
	for( i=0; i<ilim; i++ ) 
	{
		for( j=i+1; j<njob; j++ )
		{
			for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
			{
				if( tmpptr->opt == -1.0 ) continue;
				fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt * tsuyosa, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->next ); 
			}
		}
	}
	fclose( hat3p );
#endif
#if DEBUG
	fprintf( stderr, "calling FreeLocalHomTable\n" );
#endif
	FreeLocalHomTable( localhomtable, njob );
#if DEBUG
	fprintf( stderr, "done. FreeLocalHomTable\n" );
#endif
}