3 static int upperCase = 0;
9 int addlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, int skip )
11 int pos1, pos2, start1, start2, end1, end2;
20 pos1 = off1; pos2 = off2;
26 fprintf( stderr, "nlocalhom = %d in addlocalhom\n", nlocalhom );
27 fprintf( stderr, "al1 = %s, al2 = %s\n", al1, al2 );
28 fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 );
29 fprintf( stderr, "localhopt = %p, skip = %d\n", localhompt, skip );
30 fprintf( stderr, "pt1 = \n%s\n, pt2 = \n%s\n", pt1, pt2 );
35 while( --skip > 0 ) localhompt = localhompt->next;
36 localhompt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
37 localhompt = localhompt->next;
38 // fprintf( stderr, "tmppt = %p, localhompt = %p\n", tmppt, localhompt );
46 // fprintf( stderr, "In in while loop\n" );
47 // fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
48 if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
55 // fprintf( stderr, "reallocating ...\n" );
56 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
57 // fprintf( stderr, "done\n" );
61 tmppt->start1 = start1;
62 tmppt->start2 = start2;
68 sumoverlap += end2-start2+1;
70 tmppt->overlapaa = end2-start2+1;
71 tmppt->opt = score * 5.8 / 600;
72 tmppt->overlapaa = overlapaa;
73 tmppt->opt = (double)opt;
77 fprintf( stderr, "score (1)= %f\n", score );
78 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
79 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
84 else if( *pt1 != '-' && *pt2 != '-' )
88 start1 = pos1; start2 = pos2;
91 score += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]];
92 // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
94 if( *pt1++ != '-' ) pos1++;
95 if( *pt2++ != '-' ) pos2++;
100 if( nlocalhom++ > 0 )
102 // fprintf( stderr, "reallocating ...\n" );
103 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
104 // fprintf( stderr, "done\n" );
110 tmppt->start1 = start1;
111 tmppt->start2 = start2;
117 sumoverlap += end2-start2+1;
119 tmppt->overlapaa = end2-start2+1;
120 tmppt->opt = score * 5.8 / 600;
121 tmppt->overlapaa = overlapaa;
122 tmppt->opt = (double)opt;
125 fprintf( stderr, "score (2)= %f\n", score );
126 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
127 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
131 for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
133 tmppt->overlapaa = sumoverlap;
134 tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
141 int addlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, int skip )
143 int pos1, pos2, start1, start2, end1, end2;
151 pt1 = al1; pt2 = al2;
152 pos1 = off1; pos2 = off2;
158 fprintf( stderr, "nlocalhom = %d in addlocalhom\n", nlocalhom );
159 fprintf( stderr, "al1 = %s, al2 = %s\n", al1, al2 );
160 fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 );
161 fprintf( stderr, "localhopt = %p, skip = %d\n", localhompt, skip );
163 fprintf( stderr, "pt1 = \n%s\n, pt2 = \n%s\n", pt1, pt2 );
167 while( --skip > 0 ) localhompt = localhompt->next;
168 localhompt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
169 localhompt = localhompt->next;
170 fprintf( stderr, "tmppt = %p, localhompt = %p\n", tmppt, localhompt );
178 fprintf( stderr, "In in while loop\n" );
179 fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
180 if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
185 if( nlocalhom++ > 0 )
187 // fprintf( stderr, "reallocating ...\n" );
188 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
189 // fprintf( stderr, "done\n" );
193 tmppt->start1 = start1;
194 tmppt->start2 = start2;
200 sumoverlap += end2-start2+1;
202 tmppt->overlapaa = end2-start2+1;
203 tmppt->opt = score * 5.8 / 600;
204 tmppt->overlapaa = overlapaa;
205 tmppt->opt = (double)opt;
208 fprintf( stderr, "score (1)= %f\n", score );
209 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
210 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
214 else if( *pt1 != '-' && *pt2 != '-' )
218 start1 = pos1; start2 = pos2;
221 score += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]];
222 // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
224 if( *pt1++ != '-' ) pos1++;
225 if( *pt2++ != '-' ) pos2++;
227 if( nlocalhom++ > 0 )
229 // fprintf( stderr, "reallocating ...\n" );
230 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
231 // fprintf( stderr, "done\n" );
237 tmppt->start1 = start1;
238 tmppt->start2 = start2;
244 sumoverlap += end2-start2+1;
246 tmppt->overlapaa = end2-start2+1;
247 tmppt->opt = score * 5.8 / 600;
248 tmppt->overlapaa = overlapaa;
249 tmppt->opt = (double)opt;
252 fprintf( stderr, "score (2)= %f\n", score );
253 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
254 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
256 for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
258 tmppt->overlapaa = sumoverlap;
259 tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
263 void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
265 int pos1, pos2, start1, start2, end1, end2;
270 LocalHom *tmppt = localhompt;
273 pt1 = al1; pt2 = al2;
274 pos1 = off1; pos2 = off2;
284 // fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
285 if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
290 if( nlocalhom++ > 0 )
292 // fprintf( stderr, "reallocating ...\n" );
293 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
294 // fprintf( stderr, "done\n" );
298 tmppt->start1 = start1;
299 tmppt->start2 = start2;
306 tmppt->overlapaa = end2-start2+1;
307 tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
312 sumoverlap += end2-start2+1;
315 tmppt->overlapaa = overlapaa;
316 tmppt->opt = (double)opt;
320 fprintf( stderr, "score (1)= %f\n", score );
321 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
322 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
327 else if( *pt1 != '-' && *pt2 != '-' )
331 start1 = pos1; start2 = pos2;
334 score += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â
335 // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
337 if( *pt1++ != '-' ) pos1++;
338 if( *pt2++ != '-' ) pos2++;
340 if( *(pt1-1) != '-' && *(pt2-1) != '-' )
342 if( nlocalhom++ > 0 )
344 // fprintf( stderr, "reallocating ...\n" );
345 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
346 // fprintf( stderr, "done\n" );
352 tmppt->start1 = start1;
353 tmppt->start2 = start2;
360 tmppt->overlapaa = end2-start2+1;
361 tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
366 sumoverlap += end2-start2+1;
369 tmppt->overlapaa = overlapaa;
370 tmppt->opt = (double)opt;
374 fprintf( stderr, "score (2)= %f\n", score );
375 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
376 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
382 for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
384 tmppt->overlapaa = sumoverlap;
385 tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
386 // fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt );
390 void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
392 int pos1, pos2, start1, start2, end1, end2;
397 LocalHom *tmppt = localhompt;
400 pt1 = al1; pt2 = al2;
401 pos1 = off1; pos2 = off2;
411 // fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
412 if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
417 if( nlocalhom++ > 0 )
419 // fprintf( stderr, "reallocating ...\n" );
420 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
421 // fprintf( stderr, "done\n" );
425 tmppt->start1 = start1;
426 tmppt->start2 = start2;
433 tmppt->overlapaa = end2-start2+1;
434 tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
439 sumoverlap += end2-start2+1;
442 tmppt->overlapaa = overlapaa;
443 tmppt->opt = (double)opt;
447 fprintf( stderr, "score (1)= %f\n", score );
448 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
449 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
454 else if( *pt1 != '-' && *pt2 != '-' )
458 start1 = pos1; start2 = pos2;
461 score += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â
462 // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
464 if( *pt1++ != '-' ) pos1++;
465 if( *pt2++ != '-' ) pos2++;
467 if( nlocalhom++ > 0 )
469 // fprintf( stderr, "reallocating ...\n" );
470 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
471 // fprintf( stderr, "done\n" );
477 tmppt->start1 = start1;
478 tmppt->start2 = start2;
485 tmppt->overlapaa = end2-start2+1;
486 tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
491 sumoverlap += end2-start2+1;
494 tmppt->overlapaa = overlapaa;
495 tmppt->opt = (double)opt;
499 fprintf( stderr, "score (2)= %f\n", score );
500 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
501 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
506 for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
508 tmppt->overlapaa = sumoverlap;
509 tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
510 // fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt );
515 char *cutal( char *al, int al_display_start, int start, int end )
521 pos = al_display_start;
524 if( start == pos ) val = pt;
525 if( end == pos ) break;
526 // fprintf( stderr, "pos=%d, *pt=%c, val=%p\n", pos, *pt, val );
527 if( *pt != '-' ) pos++;
528 } while( *pt++ != 0 );
533 void ErrorExit( char *message )
535 fprintf( stderr, "%s\n", message );
539 void strncpy_caseC( char *str1, char *str2, int len )
541 if( dorp == 'd' && upperCase > 0 )
544 *str1++ = toupper( *str2++ );
546 else strncpy( str1, str2, len );
549 void seqUpper( int nseq, char **seq ) /* not used */
552 for( i=0; i<nseq; i++ )
554 len = strlen( seq[i] );
555 for( j=0; j<len; j++ )
556 seq[i][j] = toupper( seq[i][j] );
560 void seqLower( int nseq, char **seq )
563 for( i=0; i<nseq; i++ )
565 len = strlen( seq[i] );
566 for( j=0; j<len; j++ )
567 seq[i][j] = tolower( seq[i][j] );
571 int getaline_fp_eof( char *s, int l, FILE *fp ) /* end of file -> return 1 */
575 for( i=0; i<l && ( noteofflag = ( (c=getc(fp)) != EOF ) ) && c != '\n'; i++ )
578 return( !noteofflag );
581 int getaline_fp_eof_new(s, l, fp) /* end of file -> return 1 */
582 char s[] ; int l ; FILE *fp ;
587 if( feof( fp ) ) return( 1 );
589 for( i=0; i<l && ( noteofflag = ( (c=getc(fp)) != EOF ) ) && c != '\n'; i++ )
592 if( c != '\n' && c != EOF ) while( getc(fp) != '\n' )
594 return( !noteofflag );
597 int myfgets(s, l, fp) /* l°Ê¾å¤Ï¡¢¹ÔËö¤Þ¤ÇÆɤßÈô¤Ð¤¹ */
598 char s[] ; int l ; FILE *fp ;
602 if( feof( fp ) ) return( 1 );
604 for( i=0; i<l && ( c=getc( fp ) ) != '\n'; i++ )
608 while( getc(fp) != '\n' )
613 float input_new( FILE *fp, int d )
623 mojiretsu[i] = getc( fp );
626 return( atof( mojiretsu ) );
630 void PreRead( FILE *fp, int *locnjob, int *locnlenmax )
635 fgets( b, B-1, fp ); *locnjob = atoi( b );
641 if( !strncmp( b, "=", 1 ) )
644 fgets( b, B-1, fp ); nleni = atoi( b );
645 if( nleni > *locnlenmax ) *locnlenmax = nleni;
648 if( *locnlenmax > N )
650 fprintf( stderr, "TOO LONG SEQUENCE!\n" );
655 fprintf( stderr, "TOO MANY SEQUENCE!\n" );
656 fprintf( stderr, "%d > %d\n", njob, M );
661 int allSpace( char *str )
664 while( *str ) value *= ( !isdigit( *str++ ) );
668 void Read( char name[M][B], int nlen[M], char **seq )
670 extern void FRead( FILE *x, char y[M][B], int z[M], char **w );
671 FRead( stdin, name, nlen, seq );
674 void FRead( FILE *fp, char name[][B], int nlen[], char **seq )
681 fprintf( stderr, "b = %s\n", b );
684 if( strstr( b, "onnet" ) ) scoremtx = 1;
685 else if( strstr( b, "DnA" ) )
690 else if( strstr( b, "dna" ) )
695 else if( strstr( b, "DNA" ) )
700 else if( strstr( b, "M-Y" ) || strstr( b, "iyata" ) ) scoremtx = 2;
703 fprintf( stderr, " %s->scoremtx = %d\n", b, scoremtx );
709 if( strlen( b ) >=25 )
713 fprintf( stderr, "kimuraR = %s\n", b+20 );
715 kimuraR = atoi( b+20 );
717 if( kimuraR < 0 || 20 < kimuraR ) ErrorExit( "Illeagal kimuraR value.\n" );
718 if( allSpace( b+20 ) ) kimuraR = NOTSPECIFIED;
720 else kimuraR = NOTSPECIFIED;
722 fprintf( stderr, "kimuraR = %d\n", kimuraR );
725 if( strlen( b ) >=20 )
729 fprintf( stderr, "pamN = %s\n", b+15 );
732 if( pamN < 0 || 400 < pamN ) ErrorExit( "Illeagal pam value.\n" );
733 if( allSpace( b+15 ) ) pamN = NOTSPECIFIED;
735 else pamN = NOTSPECIFIED;
737 if( strlen( b ) >= 15 )
741 fprintf( stderr, "poffset = %s\n", b+10 );
743 poffset = atoi( b+10 );
744 if( poffset > 500 ) ErrorExit( "Illegal extending gap ppenalty\n" );
745 if( allSpace( b+10 ) ) poffset = NOTSPECIFIED;
747 else poffset = NOTSPECIFIED;
749 if( strlen( b ) >= 10 )
753 fprintf( stderr, "ppenalty = %s\n", b+5 );
755 ppenalty = atoi( b+5 );
756 if( ppenalty > 0 ) ErrorExit( "Illegal opening gap ppenalty\n" );
757 if( allSpace( b+5 ) ) ppenalty = NOTSPECIFIED;
759 else ppenalty = NOTSPECIFIED;
762 for( i=0; i<njob; i++ )
764 getaline_fp_eof_new( b, B-1, fp );
765 strcpy( name[i], b );
767 fprintf( stderr, "name[%d] = %s\n", i, name[i] );
769 fgets( b, B-1, fp ); nlen[i] = atoi( b ); /* seq i no nagasa */
771 if( nlen[i] ) for( j=0; j <= (nlen[i]-1)/C; j++ )
773 getaline_fp_eof_new( b, B-1, fp );
779 if( scoremtx == -1 && upperCase != -1 ) seqLower( njob, seq );
783 static int countKUorWA( FILE *fp )
790 while( ( c = getc( fp ) ) != EOF )
792 if( b == '\n' && ( c == '=' || c == '>' ) )
800 static void searchKUorWA( FILE *fp )
804 while( !( ( ( c = getc( fp ) ) == '>' || c == '=' || c == EOF ) && b == '\n' ) )
809 static int onlyAlpha_lower( char *str )
815 while( (tmp=*str++) )
816 if( isalpha( tmp ) || tmp == '-' || tmp == '*' || tmp == '.' )
817 *res++ = tolower( tmp );
821 static int onlyAlpha_upper( char *str )
827 while( (tmp=*str++) )
828 if( isalpha( tmp ) || tmp == '-' || tmp == '*' || tmp == '.' )
829 *res++ = toupper( tmp );
834 void kake2hiku( char *str )
837 if( *str == '*' ) *str = '-';
841 int load1SeqWithoutName_new( FILE *fpp, char *cbuf )
847 while( ( c = getc( fpp ) ) != EOF && /* by T. Nishiyama */
848 !( ( c == '>' || c == '=' || c == '(' || c == EOF ) && b == '\n' ) )
850 *cbuf++ = (char)c; /* Ť¹¤®¤Æ¤â¤·¤é¤Ê¤¤ */
856 onlyAlpha_lower( bk );
858 onlyAlpha_upper( bk );
864 void readDataforgaln( FILE *fp, char **name, int *nlen, char **seq )
867 static char *tmpseq = NULL;
871 tmpseq = AllocateCharVec( N );
877 for( i=0; i<njob; i++ )
879 name[i][0] = '='; getc( fp );
881 fgets( name[i]+1, B-2, fp );
882 j = strlen( name[i] );
883 if( name[i][j-1] != '\n' )
884 ErrorExit( "Too long name\n" );
887 myfgets( name[i]+1, B-2, fp );
890 fprintf( stderr, "name[%d] = %s\n", i, name[i] );
892 load1SeqWithoutName_new( fp, tmpseq );
893 strcpy( seq[i], tmpseq );
894 nlen[i] = strlen( seq[i] );
896 if( dorp == 'd' && upperCase != -1 ) seqLower( njob, seq );
902 void readData( FILE *fp, char name[][B], int nlen[], char **seq )
905 static char *tmpseq = NULL;
909 tmpseq = AllocateCharVec( N );
915 for( i=0; i<njob; i++ )
917 name[i][0] = '='; getc( fp );
919 fgets( name[i]+1, B-2, fp );
920 j = strlen( name[i] );
921 if( name[i][j-1] != '\n' )
922 ErrorExit( "Too long name\n" );
925 myfgets( name[i]+1, B-2, fp );
928 fprintf( stderr, "name[%d] = %s\n", i, name[i] );
930 load1SeqWithoutName_new( fp, tmpseq );
931 strcpy( seq[i], tmpseq );
932 nlen[i] = strlen( seq[i] );
934 if( dorp == 'd' && upperCase != -1 ) seqLower( njob, seq );
941 double countATGC( char *s )
954 if( c == 'a' || c == 't' || c == 'g' || c == 'c' || c == 'u' || c == 'n' )
959 return( (double)nATGC / nChar );
963 void getnumlen( FILE *fp )
968 tmpseq = AllocateCharVec( N );
969 njob = countKUorWA( fp );
973 for( i=0; i<njob; i++ )
975 fgets( tmpseq, N-1, fp );
976 load1SeqWithoutName_new( fp, tmpseq );
977 tmp = strlen( tmpseq );
978 if( tmp > nlenmax ) nlenmax = tmp;
979 atgcfreq += countATGC( tmpseq );
981 atgcfreq /= (double)njob;
982 if( dorp == NOTSPECIFIED )
984 if( atgcfreq > 0.75 )
1000 void WriteGapFill( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq )
1006 static char buff[N];
1009 fprintf( stderr, "IMAKARA KAKU\n" );
1012 for( i=0; i<locnjob; i++ )
1014 int len = strlen( aseq[i] );
1015 if( nlenmax < len ) nlenmax = len;
1018 for( i=0; i<nlenmax; i++ ) gap[i] = '-';
1021 fprintf( fp, "%5d", locnjob );
1022 fprintf( fp, "\n" );
1024 for( i=0; i<locnjob; i++ )
1026 strcpy( buff, aseq[i] );
1027 strncat( buff, gap, nlenmax-strlen( aseq[i] ) );
1029 nalen[i] = strlen( buff );
1030 fprintf( fp, "%s\n", name[i] );
1031 fprintf( fp, "%5d\n", nalen[i] );
1032 for( j=0; j<nalen[i]; j=j+C )
1034 strncpy_caseC( b, buff+j, C ); b[C] = 0;
1035 fprintf( fp, "%s\n",b );
1039 fprintf( stderr, "nalen[0] = %d\n", nalen[0] );
1042 fprintf( stderr, "KAKIOWATTA\n" );
1046 void writeDataforgaln( FILE *fp, int locnjob, char **name, int *nlen, char **aseq )
1051 for( i=0; i<locnjob; i++ )
1053 nalen = strlen( aseq[i] );
1054 fprintf( fp, ">%s\n", name[i]+1 );
1055 for( j=0; j<nalen; j=j+C )
1058 strncpy( b, aseq[i]+j, C ); b[C] = 0;
1059 fprintf( fp, "%s\n",b );
1061 fprintf( fp, "%.*s\n", C, aseq[i]+j );
1067 void writeData( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq )
1072 for( i=0; i<locnjob; i++ )
1075 fprintf( stderr, "i = %d in writeData\n", i );
1077 nalen = strlen( aseq[i] );
1078 fprintf( fp, ">%s\n", name[i]+1 );
1079 for( j=0; j<nalen; j=j+C )
1082 strncpy( b, aseq[i]+j, C ); b[C] = 0;
1083 fprintf( fp, "%s\n",b );
1085 fprintf( fp, "%.*s\n", C, aseq[i]+j );
1095 void readhat2_int( FILE *fp, int nseq, char name[M][B], int **mtx )
1101 fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
1103 for( i=0; i<nseq; i++ )
1106 getaline_fp_eof( b, B, fp );
1108 myfgets( b, B-2, fp );
1111 j = MIN( strlen( b+6 ), 10 );
1112 if( strncmp( name[i], b+6 , j ) )
1114 fprintf( stderr, "Error in hat2\n" );
1115 fprintf( stderr, "%s != %s\n", b, name[i] );
1120 for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
1122 mtx[i][j] = (int)( input_new( fp, D ) * INTMTXSCALE );
1125 void readhat2( FILE *fp, int nseq, char name[M][B], double **mtx )
1131 fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
1133 for( i=0; i<nseq; i++ )
1136 getaline_fp_eof( b, B, fp );
1138 myfgets( b, B-2, fp );
1141 j = MIN( strlen( b+6 ), 10 );
1142 if( strncmp( name[i], b+6 , j ) )
1144 fprintf( stderr, "Error in hat2\n" );
1145 fprintf( stderr, "%s != %s\n", b, name[i] );
1150 for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
1152 mtx[i][j] = (double)input_new( fp, D);
1156 void WriteFloatHat2( FILE *hat2p, int locnjob, char name[M][B], float **mtx )
1160 for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
1162 fprintf( hat2p, "%5d\n", 1 );
1163 fprintf( hat2p, "%5d\n", locnjob );
1164 fprintf( hat2p, " %#6.3f\n", max * 2.5 );
1166 for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
1167 for( i=0; i<locnjob-1; i++ )
1169 for( j=i+1; j<locnjob; j++ )
1171 fprintf( hat2p, "%#6.3f", mtx[i][j] );
1172 if( (j-i) % 12 == 0 || j == locnjob-1 ) fprintf( hat2p, "\n" );
1177 void WriteHat2_int( FILE *hat2p, int locnjob, char name[M][B], int **mtx )
1181 for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
1184 fprintf( hat2p, "%5d\n", 1 );
1185 fprintf( hat2p, "%5d\n", locnjob );
1186 fprintf( hat2p, " %#6.3f\n", max * 2.5 );
1188 for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
1189 for( i=0; i<locnjob-1; i++ )
1191 for( j=i+1; j<locnjob; j++ )
1193 fprintf( hat2p, "%#6.3f", (float)mtx[i][j] / INTMTXSCALE );
1194 if( (j-i) % 12 == 0 || j == locnjob-1 ) fprintf( hat2p, "\n" );
1198 void WriteHat2( FILE *hat2p, int locnjob, char name[M][B], double **mtx )
1202 for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
1204 fprintf( hat2p, "%5d\n", 1 );
1205 fprintf( hat2p, "%5d\n", locnjob );
1206 fprintf( hat2p, " %#6.3f\n", max * 2.5 );
1208 for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
1209 for( i=0; i<locnjob-1; i++ )
1211 for( j=i+1; j<locnjob; j++ )
1213 fprintf( hat2p, "%#6.3f", mtx[i][j] );
1214 if( (j-i) % 12 == 0 || j == locnjob-1 ) fprintf( hat2p, "\n" );
1219 int ReadFasta_sub( FILE *fp, double *dis, int nseq, char name[M][B] )
1226 for( i=0; i<10000000 && count<nseq; i++ )
1228 fgets( b, B-1, fp );
1229 if( !strncmp( "+==========+", b, 12 ) )
1231 junban[count] = atoi( b+12 );
1236 for( i=0; i<nseq; i++ ) dis[i] = 0.0;
1238 for( i=0; i<100000 && count<nseq; i++ )
1240 if( fgets( b, B-1, fp ) ) break;
1241 if( !strncmp( name[junban[count]], b, 20 ) )
1243 fgets( b, B-1, fp );
1244 dis[junban[count]] = atof( b );
1252 int ReadSsearch( FILE *fp, double *dis, int nseq, char name[M][B] )
1260 for( i=0; i<10000000 && count<nseq; i++ )
1262 fgets( b, B-1, fp );
1263 if( !strncmp( "+==========+", b, 12 ) )
1265 junban[count] = atoi( b+12 );
1266 sscanf( b+75, "%d", &opt );
1267 dis[junban[count]] = (double)opt;
1274 for( i=0; i<100000 && count<nseq; i++ )
1276 fgets( b, B-1, fp );
1277 if( !strncmp( name[junban[count]], b, 20 ) )
1279 dis[junban[count]] = atof( b+65 );
1287 int ReadBlastm7( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
1292 static int junban[M];
1294 double score, sumscore;
1295 int qstart, qend, tstart, tend;
1297 int qal_display_start, tal_display_start;
1298 static char qal[N], tal[N], al[N];
1300 int c, i, nlocalhom;
1310 if( feof( fp ) ) break;
1312 while( fgets( b, B-1, fp ) )
1314 if( !strncmp( " <Hit_def>", b, 19 ) || !strncmp( " <Hsp_num>", b, 23 ) ) break;
1317 if( !strncmp( " <Hit_def>", b, 19 ) )
1319 junban[count] = atoi( b+31 );
1324 while( fgets( b, B-1, fp ) )
1325 if( !strncmp( " <Hsp_score>", b, 25 ) ) break;
1331 while( fgets( b, B-1, fp ) )
1332 if( !strncmp( " <Hsp_query-from>", b, 30 ) ) break;
1334 qstart = atoi( pt ) - 1;
1337 while( fgets( b, B-1, fp ) )
1338 if( !strncmp( " <Hsp_query-to>", b, 28 ) ) break;
1340 qend = atoi( pt ) - 1;
1343 while( fgets( b, B-1, fp ) )
1344 if( !strncmp( " <Hsp_hit-from>", b, 28 ) ) break;
1346 tstart = atoi( pt ) - 1;
1349 while( fgets( b, B-1, fp ) )
1350 if( !strncmp( " <Hsp_hit-to>", b, 26 ) ) break;
1352 tend = atoi( pt ) - 1;
1355 while( fgets( b, B-1, fp ) )
1356 if( !strncmp( " <Hsp_align-len>", b, 29 ) ) break;
1358 overlapaa = atoi( pt );
1361 while( fgets( al, N-100, fp ) )
1362 if( !strncmp( " <Hsp_qseq>", al, 24 ) ) break;
1364 strcpy( qal, al+24 );
1366 while( *++pt != '<' )
1371 while( fgets( al, N-100, fp ) )
1372 if( !strncmp( " <Hsp_hseq>", al, 24 ) ) break;
1374 strcpy( tal, al+24 );
1376 while( *++pt != '<' )
1381 // fprintf( stderr, "t=%d, score = %f, qstart=%d, qend=%d, tstart=%d, tend=%d, overlapaa=%d\n", junban[count], score, qstart, qend, tstart, tend, overlapaa );
1383 nlocalhom += addlocalhom( qal, tal, localhomlist+junban[count], qstart, tstart, score, overlapaa, nlocalhom );
1385 while( fgets( b, B-1, fp ) )
1386 if( !strncmp( " </Hsp>:", b, 18 ) ) break;
1389 fgets( b, B-1, fp );
1392 if( !strncmp( " </Hit_hsps>", b, 21 ) )
1394 dis[junban[count++]] = sumscore;
1396 fgets( b, B-1, fp );
1397 fgets( b, B-1, fp );
1398 if( !strncmp( " </Iteration_hits>", b, 23 ) ) break;
1404 int ReadFasta34noalign( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
1409 static int junban[M];
1411 int opt, qstart, qend, tstart, tend;
1413 int qal_display_start, tal_display_start;
1414 static char qal[N], tal[N];
1421 for( i=0; i<10000000 && count<nseq; i++ )
1423 while( !feof( fp ) )
1426 fgets( b, B-1, fp );
1427 if( !strncmp( "+==========+", b, 12 ) )
1429 junban[count] = atoi( b+12 );
1431 pt = strchr( b, ')' ) + 1;
1432 sscanf( pt, "%d %lf %lf", &opt, &bits, &z );
1433 dis[junban[count]] = (double)opt;
1441 int ReadFasta34m10_nuc( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
1446 static int junban[M];
1448 int opt, qstart, qend, tstart, tend;
1450 int qal_display_start, tal_display_start;
1451 static char qal[N], tal[N];
1458 for( i=0; i<10000000 && count<nseq; i++ )
1460 while( !feof( fp ) )
1463 fgets( b, B-1, fp );
1464 if( !strncmp( "+==========+", b, 12 ) )
1466 junban[count] = atoi( b+12 );
1468 if( strchr( b, 'r' ) ) continue;
1470 pt = strchr( b, ']' ) + 1;
1471 sscanf( pt, "%d %lf %lf", &opt, &bits, &z );
1472 dis[junban[count]] = (double)opt;
1476 else if( 0 == strncmp( ">>+==========+", b, 14 ) )
1482 if( !count ) return -1;
1487 if( strncmp( ">>+==========+", b, 14 ) )
1489 fgets( b, B-1, fp );
1490 if( feof( fp ) ) break;
1493 junban[count++] = atoi( b+14 );
1494 // fprintf( stderr, "t = %d\n", atoi( b+14 ) );
1495 while( fgets( b, B-1, fp ) )
1496 if( !strncmp( "; fa_opt:", b, 9 ) || !strncmp( "; sw_s-w opt:", b, 13 ) ) break;
1497 pt = strstr( b, ":" ) +1;
1501 while( fgets( b, B-1, fp ) )
1502 if( !strncmp( "_overlap:", b+4, 9 ) ) break;
1503 pt = strstr( b, ":" ) +1;
1504 overlapaa = atoi( pt );
1506 while( fgets( b, B-1, fp ) )
1507 if( !strncmp( "_start:", b+4, 7 ) ) break;
1508 pt = strstr( b, ":" ) +1;
1509 qstart = atoi( pt ) - 1;
1511 while( fgets( b, B-1, fp ) )
1512 if( !strncmp( "_stop:", b+4, 6 ) ) break;
1513 pt = strstr( b, ":" ) +1;
1514 qend = atoi( pt ) - 1;
1516 while( fgets( b, B-1, fp ) )
1517 if( !strncmp( "_display_start:", b+4, 15 ) ) break;
1518 pt = strstr( b, ":" ) +1;
1519 qal_display_start = atoi( pt ) - 1;
1522 while( c = fgetc( fp ) )
1529 if( isalpha( c ) || c == '-' )
1534 while( fgets( b, B-1, fp ) )
1535 if( !strncmp( "_start:", b+4, 7 ) ) break;
1536 pt = strstr( b, ":" ) + 1;
1537 tstart = atoi( pt ) - 1;
1539 while( fgets( b, B-1, fp ) )
1540 if( !strncmp( "_stop:", b+4, 6 ) ) break;
1541 pt = strstr( b, ":" ) + 1;
1542 tend = atoi( pt ) - 1;
1544 while( fgets( b, B-1, fp ) )
1545 if( !strncmp( "_display_start:", b+4, 15 ) ) break;
1546 pt = strstr( b, ":" ) + 1;
1547 tal_display_start = atoi( pt ) - 1;
1550 while( c = fgetc( fp ) )
1557 if( isalpha( c ) || c == '-' )
1562 // fprintf( stderr, "(%d-%d:%d-%d)\n", qstart, qend, tstart, tend );
1563 // fprintf( stderr, "qal_display_start = %d, tal_display_start = %d\n", qal_display_start, tal_display_start );
1565 // fprintf( stderr, "qal = %s\n", qal );
1566 // fprintf( stderr, "tal = %s\n", tal );
1568 qal2 = cutal( qal, qal_display_start, qstart, qend );
1569 tal2 = cutal( tal, tal_display_start, tstart, tend );
1571 // fprintf( stderr, "qal2 = %s\n", qal2 );
1572 // fprintf( stderr, "tal2 = %s\n", tal2 );
1574 // fprintf( stderr, "putting %d - %d, opt = %d\n", qmem, junban[count-1], opt );
1575 putlocalhom( qal2, tal2, localhomlist+junban[count-1], qstart, tstart, opt, overlapaa );
1577 // fprintf( stderr, "count = %d\n", count );
1580 int ReadFasta34m10( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
1585 static int junban[M];
1587 int opt, qstart, qend, tstart, tend;
1589 int qal_display_start, tal_display_start;
1590 static char qal[N], tal[N];
1597 for( i=0; i<10000000 && count<nseq; i++ )
1599 while( !feof( fp ) )
1602 fgets( b, B-1, fp );
1603 if( !strncmp( "+==========+", b, 12 ) )
1605 junban[count] = atoi( b+12 );
1607 pt = strchr( b, ')' ) + 1;
1608 sscanf( pt, "%d %lf %lf", &opt, &bits, &z );
1609 dis[junban[count]] = (double)opt;
1613 else if( 0 == strncmp( ">>+==========+", b, 14 ) )
1619 if( !count ) return -1;
1624 if( strncmp( ">>+==========+", b, 14 ) )
1626 fgets( b, B-1, fp );
1627 if( feof( fp ) ) break;
1630 junban[count++] = atoi( b+14 );
1631 // fprintf( stderr, "t = %d\n", atoi( b+14 ) );
1632 while( fgets( b, B-1, fp ) )
1633 if( !strncmp( "; fa_opt:", b, 9 ) || !strncmp( "; sw_s-w opt:", b, 13 ) ) break;
1634 pt = strstr( b, ":" ) +1;
1638 while( fgets( b, B-1, fp ) )
1639 if( !strncmp( "_overlap:", b+4, 9 ) ) break;
1640 pt = strstr( b, ":" ) +1;
1641 overlapaa = atoi( pt );
1643 while( fgets( b, B-1, fp ) )
1644 if( !strncmp( "_start:", b+4, 7 ) ) break;
1645 pt = strstr( b, ":" ) +1;
1646 qstart = atoi( pt ) - 1;
1648 while( fgets( b, B-1, fp ) )
1649 if( !strncmp( "_stop:", b+4, 6 ) ) break;
1650 pt = strstr( b, ":" ) +1;
1651 qend = atoi( pt ) - 1;
1653 while( fgets( b, B-1, fp ) )
1654 if( !strncmp( "_display_start:", b+4, 15 ) ) break;
1655 pt = strstr( b, ":" ) +1;
1656 qal_display_start = atoi( pt ) - 1;
1659 while( c = fgetc( fp ) )
1666 if( isalpha( c ) || c == '-' )
1671 while( fgets( b, B-1, fp ) )
1672 if( !strncmp( "_start:", b+4, 7 ) ) break;
1673 pt = strstr( b, ":" ) + 1;
1674 tstart = atoi( pt ) - 1;
1676 while( fgets( b, B-1, fp ) )
1677 if( !strncmp( "_stop:", b+4, 6 ) ) break;
1678 pt = strstr( b, ":" ) + 1;
1679 tend = atoi( pt ) - 1;
1681 while( fgets( b, B-1, fp ) )
1682 if( !strncmp( "_display_start:", b+4, 15 ) ) break;
1683 pt = strstr( b, ":" ) + 1;
1684 tal_display_start = atoi( pt ) - 1;
1687 while( c = fgetc( fp ) )
1694 if( isalpha( c ) || c == '-' )
1699 // fprintf( stderr, "(%d-%d:%d-%d)\n", qstart, qend, tstart, tend );
1700 // fprintf( stderr, "qal_display_start = %d, tal_display_start = %d\n", qal_display_start, tal_display_start );
1702 // fprintf( stderr, "qal = %s\n", qal );
1703 // fprintf( stderr, "tal = %s\n", tal );
1705 qal2 = cutal( qal, qal_display_start, qstart, qend );
1706 tal2 = cutal( tal, tal_display_start, tstart, tend );
1708 // fprintf( stderr, "qal2 = %s\n", qal2 );
1709 // fprintf( stderr, "tal2 = %s\n", tal2 );
1711 // fprintf( stderr, "putting %d - %d, opt = %d\n", qmem, junban[count-1], opt );
1712 putlocalhom( qal2, tal2, localhomlist+junban[count-1], qstart, tstart, opt, overlapaa );
1714 // fprintf( stderr, "count = %d\n", count );
1717 int ReadFasta34( FILE *fp, double *dis, int nseq, char name[M][B], LocalHom *localhomlist )
1722 static int junban[M];
1724 int opt, qstart, qend, tstart, tend;
1730 for( i=0; i<10000000 && count<nseq; i++ )
1732 while( !feof( fp ) )
1735 fgets( b, B-1, fp );
1736 if( !strncmp( "+==========+", b, 12 ) )
1738 junban[count] = atoi( b+12 );
1740 pt = strchr( b, ')' ) + 1;
1741 sscanf( pt, "%d %lf %lf", &opt, &bits, &z );
1742 dis[junban[count]] = (double)opt;
1746 else if( 0 == strncmp( ">>+==========+", b, 14 ) )
1752 if( !count ) return -1;
1755 while( !feof( fp ) )
1757 if( !strncmp(">>+==========+", b, 14 ) )
1759 junban[count] = atoi( b+14 );
1761 fgets( b, B-1, fp ); // initn:
1762 pt = strstr( b, "opt: " ) + 5;
1763 localhomlist[junban[count-1]].opt = atof( pt );
1764 fgets( b, B-1, fp ); // Smith-Waterman score
1765 pt = strstr( b, "ungapped) in " ) + 13;
1766 sscanf( pt, "%d", &overlapaa );
1767 fprintf( stderr, "pt = %s, overlapaa = %d\n", pt, overlapaa );
1768 pt = strstr( b, "overlap (" ) + 8;
1769 sscanf( pt, "(%d-%d:%d-%d)", &qstart, &qend, &tstart, &tend );
1770 localhomlist[junban[count-1]].overlapaa = overlapaa;
1771 localhomlist[junban[count-1]].start1 = qstart-1;
1772 localhomlist[junban[count-1]].end1 = qend-1;
1773 localhomlist[junban[count-1]].start2 = tstart-1;
1774 localhomlist[junban[count-1]].end2 = tend-1;
1776 fgets( b, B-1, fp );
1778 fprintf( stderr, "count = %d\n", count );
1782 int ReadFasta3( FILE *fp, double *dis, int nseq, char name[M][B] )
1788 int initn, init1, opt;
1793 for( i=0; i<10000000 && count<nseq; i++ )
1795 while( !feof( fp ) )
1798 fgets( b, B-1, fp );
1799 if( !strncmp( "+==========+", b, 12 ) )
1801 junban[count] = atoi( b+12 );
1803 pt = strchr( b, ')' ) + 1;
1804 sscanf( pt, "%d %d %d %lf", &initn, &init1, &opt, &z );
1805 dis[junban[count]] = (double)opt;
1812 int ReadFasta( FILE *fp, double *dis, int nseq, char name[M][B] )
1817 int initn, init1, opt;
1820 for( i=0; i<nseq; i++ ) dis[i] = 0.0;
1821 for( i=0; !feof( fp ) && count<nseq; i++ )
1823 fgets( b, B-1, fp );
1824 if( !strncmp( "+==========+", b, 12 ) )
1826 junban[count] = atoi( b+12 );
1828 sscanf( b+50, "%d %d %d", &initn, &init1, &opt );
1829 dis[junban[count]] = (double)opt;
1836 for( i=0; i<100000 && count<nseq; i++ )
1838 fgets( b, B-1, fp );
1839 if( !strncmp( name[junban[count]], b, 20 ) )
1841 dis[junban[count]] = atof( b+65 );
1850 int ReadOpt( FILE *fp, int opt[M], int nseq, char name[M][B] )
1855 int optt, initn, init1;
1858 for( i=0; i<10000000 && count<nseq; i++ )
1860 fgets( b, B-1, fp );
1861 if( !strncmp( "+==========+", b, 12 ) )
1863 junban[count] = atoi( b+12 );
1864 sscanf( b+50, "%d %d %d", &initn, &init1, &optt );
1865 opt[junban[count]] = (double)optt;
1872 int ReadOpt2( FILE *fp, int opt[M], int nseq, char name[M][B] )
1879 for( i=0; i<10000000 && count<nseq; i++ )
1881 fgets( b, B-1, fp );
1882 if( !strncmp( "+==========+", b, 12 ) )
1884 junban[count] = atoi( b+12 );
1885 opt[junban[count]] = atoi( b+65 );
1894 int writePre( int nseq, char name[][B], int nlen[M], char **aseq, int force )
1903 if( devide ) dvWrite( prep_g, nseq, name, nlen, aseq );
1905 else WriteGapFill( prep_g, nseq, name, nlen, aseq );
1907 else writeData( prep_g, nseq, name, nlen, aseq );
1912 for( i=0; i<10; i++ )
1915 fprintf( stderr, "SEMAPHORE = %d\n", signalSM[SEMAPHORE] );
1917 if( signalSM[SEMAPHORE]-- > 0 )
1919 #if 0 /* /tmp/pre ¤Î´Ø·¸¤Ç¤Ï¤º¤·¤¿ */
1920 if( ferror( prep_g ) ) prep_g = fopen( "pre", "w" );
1921 if( !prep_g ) ErrorExit( "Cannot re-open pre." );
1924 signalSM[STATUS] = IMA_KAITERU;
1926 if( force ) fprintf( stderr, "FINAL " );
1928 if( devide ) dvWrite( prep_g, nseq, name, nlen, aseq );
1929 else WriteGapFill( prep_g, nseq, name, nlen, aseq );
1931 fprintf( prep_g, '\EOF' );
1934 if( force ) signalSM[STATUS] = OSHIMAI;
1935 else signalSM[STATUS] = KAKIOWATTA;
1937 signalSM[SEMAPHORE]++;
1939 fprintf( stderr, "signalSM[STATUS] = %c\n", signalSM[STATUS] );
1946 fprintf( stderr, "YONDERUKARA_AKIRAMERU\n" );
1949 signalSM[SEMAPHORE]++;
1952 fprintf( stderr, "MATSU\n" );
1957 if( force && !value ) ErrorExit( "xced ga pre wo hanasanai \n" );
1963 writeData( prep_g, nseq, name, nlen, aseq );
1970 void readOtherOptions( int *ppidptr, int *fftThresholdptr, int *fftWinSizeptr )
1974 FILE *fp = fopen( "pre", "r" );
1976 if( !fp ) ErrorExit( "Cannot open pre.\n" );
1977 fgets( b, B-1, fp );
1978 sscanf( b, "%d %d %d", ppidptr, fftThresholdptr, fftWinSizeptr );
1981 fprintf( stderr, "b = %s\n", b );
1982 fprintf( stderr, "ppid = %d\n", ppid );
1983 fprintf( stderr, "fftThreshold = %d\n", fftThreshold );
1984 fprintf( stderr, "fftWinSize = %d\n", fftWinSize );
1990 *fftThresholdptr = FFT_THRESHOLD;
1992 *fftWinSizeptr = FFT_WINSIZE_D;
1994 *fftWinSizeptr = FFT_WINSIZE_P;
1997 fprintf( stderr, "fftThresholdptr=%d\n", *fftThresholdptr );
1998 fprintf( stderr, "fftWinSizeptr=%d\n", *fftWinSizeptr );
2002 void initSignalSM( void )
2007 if( ppid ) fprintf( stderr, "PID of xced = %d\n", ppid );
2016 signalsmid = shmget( (key_t)ppid, 3, IPC_ALLOC | 0666 );
2017 if( signalsmid == -1 ) ErrorExit( "Cannot get Shared memory for signal.\n" );
2018 signalSM = shmat( signalsmid, 0, 0 );
2019 if( (int)signalSM == -1 ) ErrorExit( "Cannot attatch Shared Memory for signal!\n" );
2020 signalSM[STATUS] = IMA_KAITERU;
2021 signalSM[SEMAPHORE] = 1;
2025 void initFiles( void )
2029 sprintf( pname, "/tmp/pre.%d", ppid );
2031 sprintf( pname, "pre" );
2032 prep_g = fopen( pname, "w" );
2033 if( !prep_g ) ErrorExit( "Cannot open pre" );
2035 trap_g = fopen( "trace", "w" );
2036 if( !trap_g ) ErrorExit( "cannot open trace" );
2037 fprintf( trap_g, "PID = %d\n", getpid() );
2042 void WriteForFasta( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq )
2048 for( i=0; i<locnjob; i++ )
2050 nalen[i] = strlen( aseq[i] );
2051 fprintf( fp, ">%s\n", name[i] );
2052 for( j=0; j<nalen[i]; j=j+C )
2054 strncpy( b, aseq[i]+j, C ); b[C] = 0;
2055 fprintf( fp, "%s\n",b );
2060 void readlocalhomtable( FILE*fp, int njob, LocalHom **localhomtable )
2063 static char buff[B];
2064 int i, j, overlapaa, start1, end1, start2, end2;
2065 int **nlocalhom = NULL;
2066 LocalHom *tmpptr1, *tmpptr2;
2068 nlocalhom = AllocateIntMtx( njob, njob );
2069 for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) nlocalhom[i][j] = 0;
2071 while ( NULL != fgets( buff, B-1, fp ) )
2073 // fprintf( stderr, "\n" );
2074 sscanf( buff, "%d %d %d %lf %d %d %d %d", &i, &j, &overlapaa, &opt, &start1, &end1, &start2, &end2 );
2077 if( start1 == end1 || start2 == end2 ) continue; //mondai ari
2081 if( nlocalhom[i][j]++ > 0 )
2083 // fprintf( stderr, "reallocating, nlocalhom[%d][%d] = %d\n", i, j, nlocalhom[i][j] );
2084 tmpptr1->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
2085 tmpptr1 = tmpptr1->next;
2086 tmpptr1->next = NULL;
2090 tmpptr1 = localhomtable[i]+j;
2091 // fprintf( stderr, "nlocalhom[%d][%d] = %d\n", i, j, nlocalhom[i][j] );
2094 tmpptr1->start1 = start1;
2095 tmpptr1->start2 = start2;
2096 tmpptr1->end1 = end1;
2097 tmpptr1->end2 = end2;
2098 // tmpptr1->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600;
2099 // tmpptr1->opt = opt;
2100 tmpptr1->opt = ( opt + 0.00 ) / 5.8 * 600;
2101 tmpptr1->overlapaa = overlapaa;
2103 // fprintf( stderr, "i=%d, j=%d, opt = %f\n", i, j, opt );
2105 if( nlocalhom[j][i]++ > 0 )
2107 tmpptr2->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
2108 tmpptr2 = tmpptr2->next;
2109 tmpptr2->next = NULL;
2112 tmpptr2 = localhomtable[j]+i;
2114 tmpptr2->start2 = start1;
2115 tmpptr2->start1 = start2;
2116 tmpptr2->end2 = end1;
2117 tmpptr2->end1 = end2;
2118 // tmpptr2->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600;
2119 // tmpptr2->opt = opt;
2120 tmpptr2->opt = ( opt + 0.00 ) / 5.8 * 600;
2121 tmpptr2->overlapaa = overlapaa;
2124 FreeIntMtx( nlocalhom );
2127 void outlocalhom( LocalHom **localhom, int nseq )
2131 for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ )
2133 tmpptr = localhom[i]+j;
2134 fprintf( stderr, "%d-%d\n", i, j );
2137 fprintf( stderr, "reg1=%d-%d, reg2=%d-%d, imp=%f, opt=%f\n", tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->importance, tmpptr->opt );
2139 while( tmpptr=tmpptr->next );
2143 void outlocalhompt( LocalHom ***localhom, int n1, int n2 )
2147 for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
2149 tmpptr = localhom[i][j];
2150 fprintf( stderr, "%d-%d\n", i, j );
2153 fprintf( stderr, "reg1=%d-%d, reg2=%d-%d, imp=%f, opt=%f, wimp=%f\n", tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->importance, tmpptr->opt, tmpptr->wimportance );
2155 while( tmpptr=tmpptr->next );
2159 void FreeLocalHomTable( LocalHom **localhomtable, int n )
2162 LocalHom *ppp, *tmpptr;
2163 fprintf( stderr, "freeing localhom\n" );
2164 for( i=0; i<n; i++ )
2166 for( j=0; j<n; j++ )
2168 tmpptr=localhomtable[i]+j;
2170 for( ; tmpptr; tmpptr=ppp )
2173 fprintf( stderr, "i=%d, j=%d\n", i, j );
2176 if( tmpptr!=localhomtable[i]+j )
2179 fprintf( stderr, "freeing %p\n", tmpptr );
2186 fprintf( stderr, "freeing localhomtable[%d]\n", i );
2188 free( localhomtable[i] );
2191 fprintf( stderr, "freeing localhomtable\n" );
2193 free( localhomtable );
2195 fprintf( stderr, "freed\n" );
2199 char *progName( char *str )
2202 if( ( value = strrchr( str, '/' ) ) != NULL )
2208 static char *extractfirstword( char *str )
2214 if( val == str && *str == ' ' )
2218 else if( *str != ' ' )
2222 else if( *str == ' ' )
2231 void clustalout( FILE *fp, int nseq, int maxlen, char **seq, char name[][B], char *mark, char *comment, int *order )
2235 if( comment == NULL )
2236 fprintf( fp, "CLUSTAL (-like) formatted alignment by MAFFT (v%s)\n\n", VERSION );
2238 fprintf( fp, "CLUSTAL (-like) formatted alignment by MAFFT %s (v%s)\n\n", comment, VERSION );
2240 while( pos < maxlen )
2242 fprintf( fp, "\n" );
2243 for( j=0; j<nseq; j++ )
2245 fprintf( fp, "%-15.15s ", extractfirstword( name[order[j]]+1 ) );
2246 fprintf( fp, "%.60s\n", seq[order[j]]+pos ); // Ťµ¤¬°ã¤¦¤È¤À¤á¡£
2248 fprintf( fp, "%-15.15s ", "" );
2249 fprintf( fp, "%.60s\n", mark + pos ); // Ťµ¤¬°ã¤¦¤È¤À¤á¡£
2254 void writeData_reorder( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq, int *order )
2259 for( i=0; i<locnjob; i++ )
2263 fprintf( stderr, "i = %d in writeData\n", i );
2265 nalen = strlen( aseq[k] );
2266 fprintf( fp, ">%s\n", name[k]+1 );
2267 for( j=0; j<nalen; j=j+C )
2270 strncpy( b, aseq[k]+j, C ); b[C] = 0;
2271 fprintf( fp, "%s\n",b );
2273 fprintf( fp, "%.*s\n", C, aseq[k]+j );
2279 void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
2281 int pos1, pos2, start1, start2, end1, end2;
2287 LocalHom *subnosento;
2291 pt1 = al1; pt2 = al2;
2292 pos1 = off1; pos2 = off2;
2297 subnosento = localhompt;
2298 while( subnosento->next ) subnosento = subnosento->next;
2301 saisho = ( localhompt->nokori == 0 );
2303 fprintf( stderr, "localhompt = %p\n", localhompt );
2304 fprintf( stderr, "tmppt = %p\n", tmppt );
2305 fprintf( stderr, "subnosento = %p\n", subnosento );
2311 // fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
2312 if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
2317 if( localhompt->nokori++ > 0 )
2319 // fprintf( stderr, "reallocating ...\n" );
2320 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
2321 // fprintf( stderr, "done\n" );
2322 tmppt = tmppt->next;
2325 tmppt->start1 = start1;
2326 tmppt->start2 = start2;
2327 tmppt->end1 = end1 ;
2328 tmppt->end2 = end2 ;
2333 tmppt->overlapaa = end2-start2+1;
2334 tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
2339 sumoverlap += end2-start2+1;
2342 tmppt->overlapaa = overlapaa;
2343 tmppt->opt = (double)opt;
2347 fprintf( stderr, "score (1)= %f\n", score );
2348 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
2349 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
2354 else if( *pt1 != '-' && *pt2 != '-' )
2358 start1 = pos1; start2 = pos2;
2361 score += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â
2362 // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
2364 if( *pt1++ != '-' ) pos1++;
2365 if( *pt2++ != '-' ) pos2++;
2367 if( *(pt1-1) != '-' && *(pt2-1) != '-' )
2369 if( localhompt->nokori++ > 0 )
2371 // fprintf( stderr, "reallocating ...\n" );
2372 tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
2373 // fprintf( stderr, "done\n" );
2374 tmppt = tmppt->next;
2380 tmppt->start1 = start1;
2381 tmppt->start2 = start2;
2382 tmppt->end1 = end1 ;
2383 tmppt->end2 = end2 ;
2389 tmppt->overlapaa = end2-start2+1;
2390 tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
2395 sumoverlap += end2-start2+1;
2398 tmppt->overlapaa = overlapaa;
2399 tmppt->opt = (double)opt;
2403 fprintf( stderr, "score (2)= %f\n", score );
2404 fprintf( stderr, "al1: %d - %d\n", start1, end1 );
2405 fprintf( stderr, "al2: %d - %d\n", start2, end2 );
2409 fprintf( stderr, "sumscore = %f\n", sumscore );
2413 if( !saisho ) subnosento = subnosento->next;
2414 for( tmppt=subnosento; tmppt; tmppt=tmppt->next )
2416 tmppt->overlapaa = sumoverlap;
2417 tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
2418 fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt );
2422 void readlocalhomtable2( FILE*fp, int njob, LocalHom **localhomtable )
2425 static char buff[B];
2426 int i, j, overlapaa, start1, end1, start2, end2;
2427 LocalHom *tmpptr1, *tmpptr2;
2429 // for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) nlocalhom[i][j] = 0;
2431 while ( NULL != fgets( buff, B-1, fp ) )
2433 // fprintf( stderr, "\n" );
2434 sscanf( buff, "%d %d %d %lf %d %d %d %d", &i, &j, &overlapaa, &opt, &start1, &end1, &start2, &end2 );
2437 if( start1 == end1 || start2 == end2 ) continue; //mondai ari
2440 if( localhomtable[i][j].nokori++ > 0 )
2442 tmpptr1 = localhomtable[i][j].last;
2443 // fprintf( stderr, "reallocating, localhomtable[%d][%d].nokori = %d\n", i, j, localhomtable[i][j].nokori );
2444 tmpptr1->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
2445 tmpptr1 = tmpptr1->next;
2446 tmpptr1->extended = -1;
2447 tmpptr1->next = NULL;
2448 localhomtable[i][j].last = tmpptr1;
2449 // fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", i, j, localhomtable[i][j].nokori );
2453 tmpptr1 = localhomtable[i]+j;
2454 // fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", i, j, localhomtable[i][j].nokori );
2457 tmpptr1->start1 = start1;
2458 tmpptr1->start2 = start2;
2459 tmpptr1->end1 = end1;
2460 tmpptr1->end2 = end2;
2461 // tmpptr1->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600;
2462 // tmpptr1->opt = opt;
2463 tmpptr1->opt = ( opt + 0.00 ) / 5.8 * 600;
2464 tmpptr1->overlapaa = overlapaa;
2466 // fprintf( stderr, "i=%d, j=%d, st1=%d, en1=%d, opt = %f\n", i, j, tmpptr1->start1, tmpptr1->end1, opt );
2468 if( localhomtable[j][i].nokori++ > 0 )
2470 tmpptr2 = localhomtable[j][i].last;
2471 tmpptr2->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
2472 tmpptr2 = tmpptr2->next;
2473 tmpptr2->extended = -1;
2474 tmpptr2->next = NULL;
2475 localhomtable[j][i].last = tmpptr2;
2476 // fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", j, i, localhomtable[j][i].nokori );
2480 tmpptr2 = localhomtable[j]+i;
2481 // fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", j, i, localhomtable[j][i].nokori );
2484 tmpptr2->start2 = start1;
2485 tmpptr2->start1 = start2;
2486 tmpptr2->end2 = end1;
2487 tmpptr2->end1 = end2;
2488 // tmpptr2->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600;
2489 // tmpptr2->opt = opt;
2490 tmpptr2->opt = ( opt + 0.00 ) / 5.8 * 600;
2491 tmpptr2->overlapaa = overlapaa;