1 /* Tree-dependent-iteration */
2 /* Devide to segments */
12 void arguments( int argc, char *argv[] )
32 divWinSize = 20; /* 70 */
46 use_fft = 0; // CHUUI dochira demo mafft.tmpl deha F
48 alg = 'A'; /* chuui */
55 ppenalty = NOTSPECIFIED;
56 ppenalty_ex = NOTSPECIFIED;
57 poffset = NOTSPECIFIED;
58 kimuraR = NOTSPECIFIED;
61 fftWinSize = NOTSPECIFIED;
62 fftThreshold = NOTSPECIFIED;
63 RNAppenalty = NOTSPECIFIED;
64 RNAppenalty_ex = NOTSPECIFIED;
65 RNApthr = NOTSPECIFIED;
67 consweight_multi = 1.0;
70 while( --argc > 0 && (*++argv)[0] == '-' )
72 while ( (c = *++argv[0]) )
78 fprintf( stderr, "inputfile = %s\n", inputfile );
82 niter = atoi( *++argv );
83 fprintf( stderr, "niter = %d\n", niter );
87 RNApthr = (int)( atof( *++argv ) * 1000 - 0.5 );
91 RNAppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
95 ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
96 // fprintf( stderr, "ppenalty = %d\n", ppenalty );
100 ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
101 // fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
105 poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
106 fprintf( stderr, "poffset = %d\n", poffset );
110 kimuraR = atoi( *++argv );
111 fprintf( stderr, "kappa = %d\n", kimuraR );
115 nblosum = atoi( *++argv );
117 fprintf( stderr, "blosum %d / kimura 200\n", nblosum );
121 pamN = atoi( *++argv );
124 fprintf( stderr, "jtt/kimura %d\n", pamN );
128 pamN = atoi( *++argv );
131 fprintf( stderr, "tm %d\n", pamN );
135 fastathreshold = atof( *++argv );
140 consweight_rna = atof( *++argv );
145 consweight_multi = atof( *++argv );
257 fftThreshold = atoi( *++argv );
261 fftWinSize = atoi( *++argv );
265 fprintf( stderr, "illegal option %c\n", c );
275 cut = atof( (*argv) );
280 fprintf( stderr, "options : Check source file!\n" );
284 if( alg == 'A' && weight == 0 )
285 ErrorExit( "ERROR : Algorithm A+ and un-weighted\n" );
290 int main( int argc, char *argv[] )
294 static char name[M][B], **seq, **aseq, **bseq;
295 static Segment *segment = NULL;
296 static int anchors[MAXSEG];
309 LocalHom **localhomtable = NULL; // by D.Mathog
310 RNApair ***singlerna;
313 static char *kozoarivec;
316 arguments( argc, argv );
320 infp = fopen( inputfile, "r" );
323 fprintf( stderr, "Cannot open %s\n", inputfile );
331 PreRead( stdin, &njob, &nlenmax );
341 fprintf( stderr, "At least 2 sequences should be input!\n"
342 "Only %d sequence found.\n", njob );
348 segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
349 topol = AllocateIntCub( njob, 2, njob );
350 len = AllocateDoubleMtx( njob, 2 );
351 eff = AllocateDoubleMtx( njob, njob );
352 seq = AllocateCharMtx( njob, nlenmax*9+1 );
353 seq_g = AllocateCharMtx( njob, nlenmax*9+1 );
354 res_g = AllocateCharMtx( njob, nlenmax*9+1 );
355 aseq = AllocateCharMtx( njob, nlenmax*9+1 );
356 bseq = AllocateCharMtx( njob, nlenmax*9+1 );
357 nogap1seq = AllocateCharMtx( 1, nlenmax*1+1 );
358 alloclen = nlenmax * 9;
359 seq_g_bk = AllocateCharMtx( njob, 0 );
360 for( i=0; i<njob; i++ ) seq_g_bk[i] = seq_g[i];
361 kozoarivec = AllocateCharVec( njob );
365 localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
366 for( i=0; i<njob; i++)
368 localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
369 for( j=0; j<njob; j++)
371 localhomtable[i][j].start1 = -1;
372 localhomtable[i][j].end1 = -1;
373 localhomtable[i][j].start2 = -1;
374 localhomtable[i][j].end2 = -1;
375 localhomtable[i][j].overlapaa = -1.0;
376 localhomtable[i][j].opt = -1.0;
377 localhomtable[i][j].importance = -1.0;
378 localhomtable[i][j].next = NULL;
379 localhomtable[i][j].nokori = 0;
380 localhomtable[i][j].extended = -1;
381 localhomtable[i][j].last = localhomtable[i]+j;
382 localhomtable[i][j].korh = 'h';
385 fprintf( stderr, "Loading 'hat3' ... " );
386 prep = fopen( "hat3", "r" );
387 if( prep == NULL ) ErrorExit( "Make hat3." );
388 readlocalhomtable2( prep, njob, localhomtable, kozoarivec );
390 // for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
391 // fprintf( stdout, "%d %d %d %d %d %d %d\n", i, j, localhomtable[i][j].opt, localhomtable[i][j].start1, localhomtable[i][j].end1, localhomtable[i][j].start2, localhomtable[i][j].end2 );
392 fprintf( stderr, "done.\n" );
394 fprintf( stderr, "Extending localhom ... " );
395 extendlocalhom( njob, localhomtable );
396 fprintf( stderr, "done.\n" );
399 for( i=0; i<njob; i++ ) if( kozoarivec[i] ) nkozo++;
403 if( nlenmax > 30000 )
408 fprintf( stderr, "\nnlenmax=%d, nagasugi!\n", nlenmax );
413 fprintf( stderr, "\nnevermemsave=1, nlenmax=%d, nagasugi!\n", nlenmax );
417 if( !constraint && !nevermemsave && alg != 'M' )
419 fprintf( stderr, "\nnlenmax=%d, Switching to the memsave mode\n", nlenmax );
425 Read( name, nlen, seq_g );
427 readData( infp, name, nlen, seq_g );
432 for( i=0; i<njob; i++ )
438 for( i=0; i<njob; i++ )
440 identity *= ( nlen[i] == nlen[0] );
444 fprintf( stderr, "Input pre-aligned data\n" );
447 constants( njob, seq_g );
450 fprintf( stderr, "penalty = %d\n", penalty );
451 fprintf( stderr, "penalty_ex = %d\n", penalty_ex );
452 fprintf( stderr, "offset = %d\n", offset );
462 writePre( njob, name, nlen, seq_g, 1 );
474 c = seqcheck( seq_g );
477 fprintf( stderr, "Illegal character %c\n", c );
480 commongappick( njob, seq_g );
482 if( rnakozo && rnaprediction == 'm' )
484 singlerna = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
485 prep = fopen( "hat4", "r" );
486 if( prep == NULL ) ErrorExit( "Make hat4 using mccaskill." );
487 fprintf( stderr, "Loading 'hat4' ... " );
488 for( i=0; i<njob; i++ )
490 gappick0( nogap1seq[0], seq_g[i] );
491 nogaplen = strlen( nogap1seq[0] );
492 singlerna[i] = (RNApair **)calloc( nogaplen, sizeof( RNApair * ) );
493 for( j=0; j<nogaplen; j++ )
495 singlerna[i][j] = (RNApair *)calloc( 1, sizeof( RNApair ) );
496 singlerna[i][j][0].bestpos = -1;
497 singlerna[i][j][0].bestscore = -1.0;
499 readmccaskill( prep, singlerna[i], nogaplen );
502 fprintf( stderr, "\ndone.\n" );
511 prep = fopen( "hat2", "r" );
512 if( !prep ) ErrorExit( "Make hat2." );
513 readhat2( prep, njob, name, eff );
516 for( i=0; i<njob-1; i++ )
518 for( j=i+1; j<njob; j++ )
520 printf( " %f", eff[i][j] );
526 veryfastsupg_double_loadtree( njob, eff, topol, len );
527 else if( intop ) // v6.528 deha if( intop ) dattanode intree ga mukou datta.
528 veryfastsupg_double_loadtop( njob, eff, topol, len );
529 else if( treemethod == 'X' || treemethod == 'E' || treemethod == 'q' )
530 // veryfastsupg_double( njob, eff, topol, len );
531 veryfastsupg_double_outtree( njob, eff, topol, len, name );
532 else if( treemethod == 'n' )
533 nj( njob, eff, topol, len );
534 else if( treemethod == 's' )
535 spg( njob, eff, topol, len );
536 else if( treemethod == 'p' )
537 upg2( njob, eff, topol, len );
538 else ErrorExit( "Incorrect treemethod.\n" );
541 printf( "utree = %d\n", utree );
544 if( ( !utree && kobetsubunkatsu ) || constraint || !bunkatsu )
548 anchors[1] =strlen( seq_g[0] );
553 nseg = searchAnchors( njob, seq_g, segment );
555 fprintf( stderr, "### nseg = %d\n", nseg );
556 fprintf( stderr, "### seq_g[0] = %s\n", seq_g[0] );
557 fprintf( stderr, "### nlenmax = %d\n", nlenmax );
558 fprintf( stderr, "### len = %d\n", strlen( seq_g[0] ) );
563 for( i=0; i<nseg; i++ ) anchors[i+1] = segment[i].center;
564 anchors[nseg+1] = strlen( seq_g[0] );
568 for( i=0; i<nseg; i++ )
569 fprintf( stderr, "anchor[%d] = %d\n", i, anchors[i] );
573 for( i=0; i<njob; i++ ) res_g[i][0] = 0;
575 for( iseg=0; iseg<nseg-1; iseg++ )
577 int tmplen = anchors[iseg+1]-anchors[iseg];
578 int pos = strlen( res_g[0] );
579 for( j=0; j<njob; j++ )
581 strncpy( seq[j], seq_g[j], tmplen );
586 fprintf( stderr, "Segment %3d/%3d %4d-%4d\n", iseg+1, nseg-1, pos+1, pos+1+tmplen );
587 fprintf( trap_g, "Segment %3d/%3d %4d-%4d\n", iseg+1, nseg-1, pos+1, pos+1+tmplen );
590 returnvalue = TreeDependentIteration( njob, name, nlen, seq, bseq, topol, len, alloclen, localhomtable, singlerna, nkozo, kozoarivec );
592 for( i=0; i<njob; i++ )
593 strcat( res_g[i], bseq[i] );
595 FreeCharMtx( seq_g_bk );
597 FreeDoubleMtx( len );
598 FreeDoubleMtx( eff );
599 fprintf( stderr, "constraint = %d\n", constraint );
600 if( constraint ) FreeLocalHomTable( localhomtable, njob );
603 Write( stdout, njob, name, nlen, bseq );
606 fprintf( stderr, "done\n" );
607 fprintf( trap_g, "done\n" );
612 writePre( njob, name, nlen, res_g, 1 );
614 writeData( stdout, njob, name, nlen, res_g, 1 );
623 signed int main( int argc, char *argv[] )
630 gets( b ); njob = atoi( b );
634 if( strstr( b, "ayhoff" ) ) scoremtx = 1;
635 else if( strstr( b, "dna" ) || strstr( b, "DNA" ) ) scoremtx = -1;
636 else if( strstr( b, "M-Y" ) || strstr( b, "iyata" ) ) scoremtx = 2;
639 if( strstr( b, "constraint" ) ) cnst = 1;
646 if( !strncmp( b, a, 1 ) )
648 gets( b ); nlen[i] = atoi( b );
649 if( nlen[i] > nlenmax ) nlenmax = nlen[i];
653 if( nlenmax > N || njob > M )
655 fprintf( stderr, "ERROR in main\n" );
662 value = main1( nlen, argc, argv );