Exemplo n.º 1
0
static void cleanup_state(state_t* status)
{
    if (!status) return;
    if (status->unaccounted_header) bam_hdr_destroy(status->unaccounted_header);
    if (status->unaccounted_file) sam_close(status->unaccounted_file);
    sam_close(status->merged_input_file);
    size_t i;
    for (i = 0; i < status->output_count; i++) {
        bam_hdr_destroy(status->rg_output_header[i]);
        sam_close(status->rg_output_file[i]);
        free(status->rg_id[i]);
    }
    bam_hdr_destroy(status->merged_input_header);
    free(status->rg_output_header);
    free(status->rg_output_file);
    kh_destroy_c2i(status->rg_hash);
    free(status->rg_id);
    free(status);
}
Exemplo n.º 2
0
static int cleanup_state(state_t* status, bool check_close)
{
    int ret = 0;

    if (!status) return 0;
    if (status->unaccounted_header) bam_hdr_destroy(status->unaccounted_header);
    if (status->unaccounted_file) {
        if (sam_close(status->unaccounted_file) < 0 && check_close) {
            fprintf(pysam_stderr, "Error on closing unaccounted file\n");
            ret = -1;
        }
    }
    sam_close(status->merged_input_file);
    size_t i;
    for (i = 0; i < status->output_count; i++) {
        if (status->rg_output_header && status->rg_output_header[i])
            bam_hdr_destroy(status->rg_output_header[i]);
        if (status->rg_output_file && status->rg_output_file[i]) {
            if (sam_close(status->rg_output_file[i]) < 0 && check_close) {
                fprintf(pysam_stderr, "Error on closing output file '%s'\n",
                        status->rg_output_file_name[i]);
                ret = -1;
            }
        }
        if (status->rg_id) free(status->rg_id[i]);
        if (status->rg_output_file_name) free(status->rg_output_file_name[i]);
    }
    if (status->merged_input_header)
        bam_hdr_destroy(status->merged_input_header);
    free(status->rg_output_header);
    free(status->rg_output_file);
    free(status->rg_output_file_name);
    kh_destroy_c2i(status->rg_hash);
    free(status->rg_id);
    free(status);

    return ret;
}