#include "mltaln.h" static void strncpy0( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } #if 0 static void strncpy0x( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0b0( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0b1( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0b2( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0n0( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0n1( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0n2( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0a0( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0a1( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0a2( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0o0( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0o1( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } static void strncpy0o2( char *s1, char *s2, int n ) { while( n-- ) *s1++ = *s2++; *s1 = 0; } #endif static void eqpick( char *aseq, char *seq ) { for( ; *seq != 0; seq++ ) { if( *seq != '=' ) *aseq++ = *seq; } *aseq = 0; } void profilealignment2( int n0, int n2, char **aln0, char **aln2, int alloclen, char alg ) // n1 ha allgap { int i, newlen; double *effarr0, *effarr2; int *allgap0, *allgap2; double dumdb; int alcount0, alcount2; if( aln0[0][1] == 0 && aln2[0][1] == 0 ) return; // --allowshift no tokiha... // reporterr( "profilealignment!\n" ); commongappick( n0, aln0 ); commongappick( n2, aln2 ); effarr0 = AllocateDoubleVec( n0 ); effarr2 = AllocateDoubleVec( n2 ); allgap0 = AllocateIntVec( n0 ); allgap2 = AllocateIntVec( n2 ); #if 1 // new weight 2015/Jun alcount0 = 0; for( i=0; ialn0[%d] = \n%s\n", i, aln0[i] ); for( i=0; ialn1[%d] = \n%s\n", i, aln1[i] ); for( i=0; ialn2[%d] = \n%s\n", i, aln2[i] ); #endif free( effarr0 ); free( effarr2 ); free( allgap0 ); free( allgap2 ); } static void profilealignment( int n0, int n1, int n2, char **aln0, char **aln1, char **aln2, int alloclen, char alg ) // n1 ha allgap { int i, j, newlen; double *effarr0 = NULL, *effarr2 = NULL; int *allgap0 = NULL, *allgap2 = NULL; double dumdb; int alcount0, alcount2; char *cptr; // effarr0 = AllocateDoubleVec( n0 ); // effarr2 = AllocateDoubleVec( n2 ); // allgap0 = AllocateIntVec( n0 ); // allgap2 = AllocateIntVec( n2 ); // if( aln0[0][1] == 0 && aln2[0][1] == 0 ) return; // --allowshift no tokiha... // reporterr( "In profilealignment(), strlen( aln0[0] ) %d\n", strlen( aln0[0] ) ); // reporterr( "In profilealignment(), strlen( aln2[0] ) %d\n", strlen( aln2[0] ) ); commongappick( n0, aln0 ); commongappick( n2, aln2 ); // reporterr( "after commongappick, strlen( aln0[0] ) %d\n", strlen( aln0[0] ) ); // reporterr( "after commongappick, strlen( aln2[0] ) %d\n", strlen( aln2[0] ) ); // reporterr( "\n\n\n" ); if( aln2[0][0] == 0 ) { newlen = j = strlen( aln0[0] ); cptr = aln2[0]; while( j-- ) *cptr++ = '-'; *cptr = 0; cptr = aln2[0]; for( i=1; ialn0[%d] = %s\n", i, aln0[i] ); for( i=0; ialn1[%d] = %s\n", i, aln1[i] ); for( i=0; ialn2[%d] = %s\n", i, aln2[i] ); #endif #if 0 fprintf( stderr, "in profilealignment, after commongappick\n" ); for( i=0; ialn0[%d] = %s\n", i, aln0[i] ); for( i=0; ialn1[%d] = %s\n", i, aln1[i] ); for( i=0; ialn2[%d] = %s\n", i, aln2[i] ); #endif free( effarr0 ); free( effarr2 ); free( allgap0 ); free( allgap2 ); } void eq2dashmatomete( char **s, int n ) { int i, j; char sj; for( j=0; (sj=s[0][j]); j++ ) { if( sj == '=' ) { for( i=0; i0; i-- ) // break ari no baai, migihajiha saigo { if( ref[i-1] == '+' && ( ref[i] != '+' && ref[i] != '=' ) && ref[i+1] == '=' ) { // reporterr( "hit! i=%d, len=%d\n", i, len ); hit = realloc( hit, (nhit+1) * sizeof( int ) ); hit[nhit] = i; nhit += 1; // break; } } if( nhit == 0 ) return( 0 ); for( k=0; k 1 ) exit( 1 ); return( val ); } static int smoothing1leftmulti( int len, char *ref ) // osoi! { int i, j, k; int shiftfrom = -1; int shiftto = -1; int *hit; int val = 0, nhit = 0; hit = NULL; // reporterr( "ref (1leftmulti) = %s\n", ref ); for( i=1, nhit=0; i0; i-- ) // break ari no baai, migihajiha saigo { if( ref[i-1] == '=' && ( ref[i] != '+' && ref[i] != '=' ) && ref[i+1] == '+' ) { // reporterr( "hit! i=%d, len=%d\n", i, len ); hit = realloc( hit, (nhit+1) * sizeof( int ) ); hit[nhit] = i; nhit += 1; // break; } } if( nhit == 0 ) return( 0 ); for( k=0; k-1; j-- ) { if( ref[j] != '=' ) { shiftto = j+1; break; } } if( j == -1 && ref[0] == '=' ) { reporterr( "hit[i].end = %d, j = -1, skip!\n" ); continue; } if( shiftto > 0 && ref[shiftto-1] == '+' ) continue; // muda dakara val += 1; shiftfrom = hit[k]; if( ref[shiftto] != '=' ) // atode sakujo { reporterr( "Error in smoothing1left!\n" ); exit( 1 ); } ref[shiftto] = ref[shiftfrom]; ref[shiftfrom] = '='; } free( hit ); // reporterr( "ref (1leftmulti) = %s\n", ref ); reporterr( " %d out of %d have been smoothed (left).\n", val, nhit ); // if( nhit > 1 ) exit( 1 ); return( val ); } void restorecommongapssmoothly( int njob, int n0, char **seq, int *ex1, int *ex2, int *gapmap, int alloclen, char gapchar ) { int *mem; char *tmpseq; char *cptr; int *iptr; int *tmpgapmap; int i, j, k, len, rep1, rep2, len1, klim, leninserted; int totalres; if( n0 == 0 ) return; mem = calloc( njob+1, sizeof( int ) ); // +1 ha iranai. intcpy( mem, ex1 ); intcat( mem, ex2 ); // tmpseq = calloc( alloclen+2, sizeof( char ) ); // tmpgapmap = calloc( alloclen+2, sizeof( int ) ); #if 0 // iranai for( i=0; (k=mem[i])!=-1; i++ ) // iranai reporterr( "mem[%d] = %d\n", i, k ); // iranai if( i == njob ) // iranai { fprintf( stderr, "Error in restorecommongaps()\n" ); free( mem ); exit( 1 ); } #endif rep1 = ex1[0]; rep2 = ex2[0]; len = strlen( seq[rep1] ); len1 = len+1; tmpseq = calloc( alloclen, sizeof( char ) ); tmpgapmap = calloc( alloclen, sizeof( int ) ); #if 0 reporterr( "\n" ); reporterr( "seq[rep1] = %s\n", seq[rep1] ); reporterr( "seq[rep2] = %s\n", seq[rep2] ); #endif for( k=0; (i=mem[k])!=-1; k++ ) { cptr = tmpseq; for( j=0; j\n" ); reporterr( "seq[rep1] = \n%s\n", seq[rep1] ); reporterr( "seq[rep2] = \n%s\n", seq[rep2] ); #endif leninserted = strlen( seq[rep1] ); #if 0 reporterr( "gapmap =\n" ); for(j=0; j0; i-- ) reporterr( "-" ); } reporterr( "\n" ); #endif #if 0 resprev = 10000; // tekitou while( 1 ) { res = 0; // reporterr( "\nsmoothing1right..\n" ); res = (0= resprev ) break; // if( res == 0 ) break; resprev = res; } #else totalres = 0; totalres += smoothing1rightmulti( leninserted, seq[rep1] ); totalres += smoothing1leftmulti( leninserted, seq[rep1] ); if( totalres ) reflectsmoothing( seq[rep1], ex1, seq, leninserted ); totalres = 0; totalres += smoothing1rightmulti( leninserted, seq[rep2] ); totalres += smoothing1leftmulti( leninserted, seq[rep2] ); if( totalres ) reflectsmoothing( seq[rep2], ex2, seq, leninserted ); #endif for( k=0; (i=mem[k])!=-1; k++ ) plus2gapchar( seq[i], gapchar ); #if 0 reporterr( "->\n" ); reporterr( "seq[rep1] = \n%s\n", seq[rep1] ); reporterr( "seq[rep2] = \n%s\n", seq[rep2] ); reporterr( "gapmap =\n" ); for(j=0; j0; i-- ) reporterr( "-" ); } reporterr( "\n" ); #endif iptr = tmpgapmap; for( j=0; j _ no tame fprintf( fp, ">%s\n", nameptr ); fprintf( fp, "# letter, position in the original sequence, position in the reference alignment\n" ); #if 0 // reporterr( "addbk[%d] = %s\n", i, addbk[i] ); for( j=0; (p=deletelist[i][j])!=-1; j++ ) { // reporterr( "deleting %d, %c\n", p, addbk[i][p] ); gapped[p] = '-'; } #else // reporterr( "addbk[%d] = %s\n", i, addbk[i] ); for( j=0; (p=deletelist[i][j].pos)!=-1; j++ ) { // reporterr( "deleting %d, %c\n", p, addbk[i][p] ); gaplen = deletelist[i][j].len; while( gaplen-- ) gapped[p++] = '-'; } #endif // reporterr( "addbk = %s\n", addbk[i] ); // reporterr( "gapped = %s\n", gapped ); for( j=0,p=0; j Position in reference\n" ); for( i=0; i _ no tame status = 0; #if 0 // reporterr( "addbk[%d] = %s\n", i, addbk[i] ); for( j=0; (p=deletelist[i][j])!=-1; j++ ) { // reporterr( "deleting %d, %c\n", p, addbk[i][p] ); gapped[p] = '-'; status = 1; } #else // reporterr( "addbk[%d] = %s\n", i, addbk[i] ); for( j=0; (p=deletelist[i][j].pos)!=-1; j++ ) { // reporterr( "deleting %d-%d, %c\n", p, p+deletelist[i][j].len, addbk[i][p] ); gaplen = deletelist[i][j].len; while( gaplen-- ) gapped[p++] = '-'; // origin??????????? 2022/Jan status = 1; } #endif // reporterr( "addbk = %s\n", addbk[i] ); // reporterr( "gapped = %s\n", gapped ); if( status == 0 ) { free( gapped ); continue; } fprintf( fp, ">%s\n", nameptr ); status = -1; #if MODIFYNAME insstr[0] = 0; nins = 0; #endif for( j=0,p=0; j %dv%d\n", j, addbk[i][j-1], p, p+1 ); // 1origin #if MODIFYNAME if( nins == 1 ) sprintf( insstr+strlen(insstr), "%d%c,", j, addbk[i][j-1] ); #endif } status = 0; // fprintf( fp, "%c, %d, %d\n", addbk[i][j], j+1, p+1 ); // 1origin p++; } } if( status == 1 ) { fprintf( fp, "%d%c > %dv%d\n", j, addbk[i][j-1], p, p+1 ); // 1origin #if MODIFYNAME if( nins == 1 ) sprintf( insstr+strlen(insstr), "%d%c,", j, addbk[i][j-1] ); #endif } free( gapped ); #if MODIFYNAME insstr[strlen(insstr)-1] = 0; strcpy( newname, name[i] ); sprintf( newname+(nameptr-name[i]), "%dins:%s|%s", nins, insstr, nameptr ); newname[B] = 0; strcpy( name[i], newname ); #endif } #if MODIFYNAME free( newname ); free( insstr ); #endif }