Exemple #1
0
int write_maps (FILE * fptr, Descr *descr1, Descr *descr2, List_of_maps *list) {

    int map_id, rank_ctr;
    int recursive_map_out (Map * map,  Descr * descr1, Descr * descr2, 
			   Protein *protein1, Protein *protein2, int depth);
    
    for (rank_ctr=0; rank_ctr<list->no_maps_used && rank_ctr < options.number_maps_out; rank_ctr++) {
	map_id = list->map_best[rank_ctr];
	recursive_map_out (list->map+map_id, descr1, descr2, NULL, NULL, 0);
    }

    return 0;
}
Exemple #2
0
int recursive_map_out (Map * map, 
		       Descr * descr1, Descr * descr2,
		       Protein *protein1, Protein *protein2,
		       int depth) {
    
    int  ctr;
    
    if ( ! depth) {
	printf ("\n####################################\n");
	printf ("**  %s   %s ", descr1->name, descr2->name);
	if (map->submatch_best && map->submatch_best[0] > -1) {
	    printf ("  with submap (%d)", map->submatch_best[0]+1);
	}
	printf ("\n");
    } else {
	for (ctr=0; ctr < depth; ctr++) printf ("\t");
    }
    
    printf ("   geometric z_score: %6.3lf ",  map->z_score);
    if ( options.postprocess )  {
	 printf ("   alignment score:  %6.3lf ", map->aln_score);
    }
    printf ("\n");
    
    print_map (stdout, map, descr1, descr2,   protein1, protein2,  depth);
    
    if (map->submatch_best && map->submatch_best[0] > -1 ) {
	
	int sub_best_ctr, sub_map_ctr;
	sub_best_ctr = 0;
	while ( sub_best_ctr < options.number_maps_cpl &&
		(sub_map_ctr = map->submatch_best[sub_best_ctr] ) > -1 ) {
	    for (ctr=0; ctr < depth; ctr++) printf ("\t");
	    printf ("map %3d   submatch  complementarity z-score:  %6.3lf \n",
		    sub_map_ctr+1, map->compl_z_score); 
	    recursive_map_out (map+sub_map_ctr, descr1, descr2,
			       protein1, protein2, depth+1); 
	    sub_best_ctr ++;
	    if (sub_best_ctr==1) break; /*output only the best */
	} 
    }
    return 0; 
}
Exemple #3
0
int compare(Descr * descr1, Descr *descr2, Score *score, Score *score_hung) {
    /* descr 1 is db or target, descr2 is query - important in postprocessing*/
    int retval, retval1, retval2;
    int map_ctr, map_ctr_hung, best_ctr;
    int NX, NY; //NX_eff, NY_eff;
    Representation X_rep = {0}, Y_rep = {0};

    //static Map * map = NULL;
    Map * map = NULL;
    //static int map_max = MAP_MAX * 9;
    int map_max = MAP_MAX * 9;
    //static int best_max = MAP_MAX;
    int best_max = MAP_MAX;
    // static int *map_best = NULL;
    int *map_best = NULL;
    // static int NX_allocated = 0, NY_allocated = 0;
    
    /* TODO: go back to map lineage description */

    int construct_representation(double ** x, int *x_type, int *x_length,
            int * NX_effective, Descr * descr,
            int ** represents, int * is_rep_by);
    int match_clustering(Representation* X_rep, Representation* Y_rep,
            Map * map, int map_max,
            int * map_ctr, int * map_best, int best_max, int parent_map);
    int recursive_map_out(Map * map, int map_ctr,
            Descr * descr1, Descr * descr2,
            Protein *protein1, Protein *protein2,
            int depth);
    int rec_map_out_for_postproc(Map * map, int map_ctr,
            Representation *X_rep, Representation *Y_rep, int depth);


    /****************************************/
    /*  arrays for immediate consumption    */
    /****************************************/
    /* needs to come first to figure out NX */
    rep_initialize(&X_rep, descr1);
    rep_initialize(&Y_rep, descr2);


    /****************************************/
    /*  initialization                      */
    /****************************************/
    /*  shorthands   */
    NX = X_rep.N_full;
  //  NX_eff = X_rep.N_compact;
    NY = Y_rep.N_full;
//    NY_eff = Y_rep.N_compact;


    if ((map = init_map(NX, NY, map_max)) == NULL) return 1;
    
    map_best = emalloc(map_max * sizeof (int));
    if (!map_best) return 1;
    


    /****************************************/
    /*  look for complementary maps         */
    /****************************************/
    map_ctr = 0;
    map_ctr_hung = 0;
    retval = 1;
    
    Map * map_hung;
    if ((map_hung = init_map(NX, NY, map_max)) == NULL) return 1;
    int *map_best_hung = NULL;
    map_best_hung =  emalloc(map_max * sizeof (int));
    
    /*
     * Structure matching based on secondary structure orientation
     * Two algorithms used:
     * - Smith Waterman
     * - Hungarian
     */
    
    retval1 = complement_match(&X_rep, &Y_rep, map, map_max,
                &map_ctr, map_best, best_max, -1);
    options.sw_score = 0;
    retval2 = complement_match(&X_rep, &Y_rep, map_hung, map_max,
                &map_ctr_hung, map_best_hung, best_max, -1);
    
    
    if (retval1 || retval2) {
        rep_shutdown(&X_rep);
        rep_shutdown(&Y_rep);
    // added by Mile
        clean_map(map, map_max);
        free(map_best);
        
        clean_map(map_hung, map_max);
        free(map_best_hung);
        
    //added by Mile
        
        
        return retval1;
    }

    /****************************************/
    /*   output the best case stats         */
    /****************************************/
    memset(score, 0, sizeof (Score));
    memset(score_hung, 0, sizeof (Score));
    
    best_ctr = 0;
    while (map_best[best_ctr] > -1) {
        best_ctr++;
    } // TODO - check cases when hungarian returns score and SW does not

    if (best_ctr) {
        assign_score(map, map_best, &X_rep, &Y_rep, score);
        assign_score(map_hung, map_best_hung, &X_rep, &Y_rep, score_hung);

        /****************************************/
        /*     postprocess - find the actual tf */
        /* 	   & mapping on the bb level    */
        /****************************************/
        if (options.postprocess) {
            Protein qry_structure = {0};
            Protein tgt_structure = {0};
            /* input CA coordinates for the vectors
               -- for now the input should be a little different
               if we are expecting to postprocess -- we will use the
               original pdb */
            /* the last arg is 1 in postprocessing */
            retval = read_pdb(options.pdbf_qry, options.chain_qry, &qry_structure, 1);
            if (retval) {
                fprintf(stderr, "Error reading %s, chain %c; retval %d\n",
                        options.pdbf_qry, options.chain_qry, retval);
                return 1;
            }
            retval = read_pdb(options.pdbf_tgt, options.chain_tgt, &tgt_structure, 1);
            if (retval) {
                fprintf(stderr, "Error reading %s, chain %c; retval %d\n",
                        options.pdbf_tgt, options.chain_tgt, retval);
                return 1;
            }
            /* for now,  we will just postprocess the  best map */

            best_ctr = 0;
            map_ctr = map_best[best_ctr];
            int map_ctr_hung = map_best[best_ctr];

            postprocess(descr1, &tgt_structure, &X_rep, descr2, &qry_structure, 
                    &Y_rep, map + map_ctr, score);
            postprocess(descr1, &tgt_structure, &X_rep, descr2, &qry_structure, 
                    &Y_rep, map_hung + map_ctr_hung, score_hung);
            
            
            rec_map_out_for_postproc(map, map_ctr, &X_rep, &Y_rep, 0); 
            rec_map_out_for_postproc(map_hung, map_ctr_hung, &X_rep, &Y_rep, 0);
            
            if(score_hung->total_assigned_score > score->total_assigned_score) {
                options.score_out = 1;
            }

            if (options.verbose) {
                if (options.score_out == 0){
                    recursive_map_out(map, map_ctr, descr1, descr2,
                                &qry_structure, & tgt_structure, 0);
                }
                else {
                    recursive_map_out(map_hung, map_ctr_hung, descr1, descr2,
                                &qry_structure, & tgt_structure, 0);
                } 
            }
            protein_shutdown(&qry_structure);
            protein_shutdown(&tgt_structure);

        } else {

            /****************************************/
            /*     output the maps                  */
            /****************************************/
            if (options.verbose) {
                best_ctr = 0;
                while (best_ctr < options.number_maps_out && best_ctr < map_max
                        && (map_ctr = map_best[best_ctr]) > -1
                        && map[map_best[best_ctr]].z_score < options.z_max_out) {
                    recursive_map_out(map, map_ctr, descr1, descr2, NULL, NULL, 0);
                    best_ctr++;
                }
            }
            // TODO - do something for Hungarian too. Currently without maps
        }
    } /* end if best_ctr */

    /****************************************/
    /*  shutting down                       */
    /****************************************/
    rep_shutdown(&X_rep);
    rep_shutdown(&Y_rep);

    // added by Mile
    free(map_best);
    clean_map(map, map_max); 
    
    clean_map(map_hung, map_max);
    free(map_best_hung);
    //added by Mile
        
    return 0;

}