From 9ffb3c98f23189b08c71d51798945c83cb4b67d0 Mon Sep 17 00:00:00 2001 From: fafa13 Date: Wed, 16 Jan 2019 11:21:07 +0100 Subject: [PATCH] print_bed is back --- command/free_gtf_data.c | 3 --- command/print_bed.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 command/print_bed.c diff --git a/command/free_gtf_data.c b/command/free_gtf_data.c index a62df4f..737f1ef 100644 --- a/command/free_gtf_data.c +++ b/command/free_gtf_data.c @@ -65,9 +65,6 @@ int free_gtf_data(GTF_DATA *gtf_data) { free(row->field); for (j = 0; j < row->attributes.nb; j++) { - //if (row->attributes.attr[j]->key != NULL) free(row->attributes.attr[j]->key); - //if (row->attributes.attr[j]->value != NULL) free(row->attributes.attr[j]->value); - //free(row->attributes.attr[j]); if ((row->attributes.attr + j)->key != NULL) free((row->attributes.attr + j)->key); if ((row->attributes.attr + j)->value != NULL) free((row->attributes.attr + j)->value); } diff --git a/command/print_bed.c b/command/print_bed.c new file mode 100644 index 0000000..c0bca13 --- /dev/null +++ b/command/print_bed.c @@ -0,0 +1,30 @@ +/* + * write_bed.c + * + * Created on: December 7, 2018 + * Author: puthier (based on Fafa code...) + * Objective: print a gtf obj in bed format + */ + +#include "libgtftk.h" + +extern void print_row_bed(FILE *output, GTF_ROW *r, char delim, int add_chr, char *keys, char *sep, char *more_info); + +__attribute__ ((visibility ("default"))) +void *print_bed(GTF_DATA *gtf_data, char *output, int add_chr, char *keys, char *sep, char *more_info) { + int i; + FILE *out = stdout; + + if (gtf_data != NULL) { + if (*output != '-') out = fopen(output, "w"); + if (out == NULL) out = stdout; + for (i = 0; i < gtf_data->size; i++){ + print_row_bed(out, gtf_data->data[i], '\t', add_chr, keys, sep, more_info); + } + if (out != stdout) { + fflush(out); + fclose(out); + } + } + return 0; +}