예제 #1
0
파일: logic.c 프로젝트: mbelicki/theseus.f
static void die(State * const state)
{
    change_state( state, STATE_LOST );
    reset_player_position( state );
    reset_entities( state );
    clean_map( & state->map );
}
예제 #2
0
void			ft_clean_all(t_hall **hall, t_ants **ants)
{
    t_hall		*tmp;
    t_hall		*tmp2;
    t_map		*map;

    tmp = *hall;
    tmp2 = NULL;
    map = NULL;
    clean_ants(ants);
    while (tmp)
    {
        tmp->id = tmp->x = tmp->y = tmp->stat = tmp->nbr_ants = 0;
        tmp->nbr_move = 0;
        map = tmp->map;
        clean_map(&map);
        tmp->map = NULL;
        tmp->myats = NULL;
        ft_clean_str(&tmp->name);
        if (tmp->note)
            ft_clean_str(&tmp->note);
        tmp2 = tmp->next;
        free(tmp);
        tmp = tmp2;
    }
}
예제 #3
0
파일: struct.c 프로젝트: msikic/struct_v2
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;

}