From 523c1ec35e86f051cedd2e29c601165943c14594 Mon Sep 17 00:00:00 2001 From: Hasindu Gamaarachchi Date: Fri, 9 Sep 2022 23:46:05 +1000 Subject: [PATCH] fix up macos warnings --- src/f5c.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ src/f5cmisc.h | 64 ------------------------------------------------ src/resquiggle.c | 20 +++------------ 3 files changed, 67 insertions(+), 80 deletions(-) diff --git a/src/f5c.c b/src/f5c.c index 86c3d919..5fcfd56b 100644 --- a/src/f5c.c +++ b/src/f5c.c @@ -24,6 +24,69 @@ Error counter for consecutive failures in the skip unreadable mode not all the memory allocations are needed for eventalign mode */ +//read bed file +static inline char **read_bed_regions(char *bedfile, int64_t *count){ + + FILE *bedfp = fopen(bedfile,"r"); + F_CHK(bedfp,bedfile); + + char* buffer = (char*)malloc(sizeof(char) * (100)); //READ+newline+nullcharacter + MALLOC_CHK(buffer); + + int64_t reg_capcacity = 1024; + int64_t reg_i = 0; + char **reg_list = (char **)malloc(reg_capcacity * sizeof(char *)); + MALLOC_CHK(reg_list); + + + size_t bufferSize = 100; + ssize_t readlinebytes = 0; + int64_t line_no = 0; + + + while ((readlinebytes = getline(&buffer, &bufferSize, bedfp)) != -1) { + + char *ref = (char *)malloc(sizeof(char)*readlinebytes); + MALLOC_CHK(ref); + int64_t beg=-1; + int64_t end=-1; + + //TODO can optimised though strtok etc later + int ret=sscanf(buffer,"%s\t%ld\t%ld",ref,&beg, &end); + if(ret!=3 || end=reg_capcacity){ + if(reg_capcacity>1000000){ + WARNING("The region bed file has over %ld regions. To reduce memory usage, you may consider merging bed regions.",reg_i); + } + reg_capcacity=reg_capcacity*2; + reg_list = (char **)realloc((void *)reg_list,reg_capcacity * sizeof(char *)); + MALLOC_CHK(reg_list); + + } + + reg_list[reg_i] = (char *)malloc(sizeof(char)*readlinebytes); + sprintf(reg_list[reg_i],"%s:%ld-%ld",ref, beg, end); + reg_i++; + + + free(ref); + + + + line_no++; + } + + fclose(bedfp); + free(buffer); + *count = reg_i; + + return reg_list; +} + /* initialise the core data structure */ core_t* init_core(const char* bamfilename, const char* fastafile, const char* fastqfile, const char* tmpfile, opt_t opt,double realtime0, int8_t mode, char *eventalignsummary, char *slow5file) { diff --git a/src/f5cmisc.h b/src/f5cmisc.h index 5046bc0c..a435103d 100644 --- a/src/f5cmisc.h +++ b/src/f5cmisc.h @@ -172,70 +172,6 @@ static inline void replace_char(char *str, char u, char t){ } } -//read bed file - -static inline char **read_bed_regions(char *bedfile, int64_t *count){ - - FILE *bedfp = fopen(bedfile,"r"); - F_CHK(bedfp,bedfile); - - char* buffer = (char*)malloc(sizeof(char) * (100)); //READ+newline+nullcharacter - MALLOC_CHK(buffer); - - int64_t reg_capcacity = 1024; - int64_t reg_i = 0; - char **reg_list = (char **)malloc(reg_capcacity * sizeof(char *)); - MALLOC_CHK(reg_list); - - - size_t bufferSize = 100; - ssize_t readlinebytes = 0; - int64_t line_no = 0; - - - while ((readlinebytes = getline(&buffer, &bufferSize, bedfp)) != -1) { - - char *ref = (char *)malloc(sizeof(char)*readlinebytes); - MALLOC_CHK(ref); - int64_t beg=-1; - int64_t end=-1; - - //TODO can optimised though strtok etc later - int ret=sscanf(buffer,"%s\t%ld\t%ld",ref,&beg, &end); - if(ret!=3 || end=reg_capcacity){ - if(reg_capcacity>1000000){ - WARNING("The region bed file has over %ld regions. To reduce memory usage, you may consider merging bed regions.",reg_i); - } - reg_capcacity=reg_capcacity*2; - reg_list = (char **)realloc((void *)reg_list,reg_capcacity * sizeof(char *)); - MALLOC_CHK(reg_list); - - } - - reg_list[reg_i] = (char *)malloc(sizeof(char)*readlinebytes); - sprintf(reg_list[reg_i],"%s:%ld-%ld",ref, beg, end); - reg_i++; - - - free(ref); - - - - line_no++; - } - - fclose(bedfp); - free(buffer); - *count = reg_i; - - return reg_list; -} - static inline int64_t mm_parse_num(const char* str) //taken from minimap2 { double x; diff --git a/src/resquiggle.c b/src/resquiggle.c index 1abd6aef..bd20fcd2 100644 --- a/src/resquiggle.c +++ b/src/resquiggle.c @@ -141,11 +141,6 @@ core_t* init_core_rsq(opt_t opt, const char *slow5file, double realtime0) { } core->kmer_size = kmer_size; - - - - - //realtime0 core->realtime0=realtime0; @@ -282,7 +277,6 @@ void free_db_tmp_rsq(db_t* db) { } - //high similarity with f5c.c - can be modularised void process_db_rsq(core_t* core, db_t* db) { @@ -404,20 +398,18 @@ void output_db_rsq(core_t* core, db_t* db, int8_t fmt) { if(signal_start_point<0){ printf(".\t"); } else { - printf("%ld\t", signal_start_point); + printf("%ld\t", (long)signal_start_point); } if(signal_end_point<0){ printf(".\t"); } else { - printf("%ld", signal_end_point); + printf("%ld", (long)signal_end_point); } printf("\n"); if(signal_start_point>=0 && signal_end_point>=0){ if(signal_end_point<=signal_start_point){ fprintf(stderr,"ERROR: signal_end_point(%ld)<=signal_start_point(%ld)\n",signal_end_point,signal_start_point); fprintf(stderr,"read_id=%s\tj=%d\tstartevent=%d\tendevent=%d\n",db->read_id[i],j,start_event_idx,end_event_idx); - fprintf(stderr,"startevent.start=%ld\tstartevent.length=%f\tendevent.start=%ld\tendevent.length=%f\n", - et.event[start_event_idx].start,et.event[start_event_idx].length,et.event[end_event_idx].start,et.event[end_event_idx].length); exit(EXIT_FAILURE); } } @@ -434,9 +426,9 @@ void output_db_rsq(core_t* core, db_t* db, int8_t fmt) { assert(signal_start_point2!=-1); assert(signal_end_point2!=-1); //query: name, start, end, strand - printf("%s\t%ld\t%ld\t%ld\t+\t", db->read_id[i], (long)db->sig[i]->nsample,signal_start_point2, signal_end_point2); + printf("%s\t%ld\t%ld\t%ld\t+\t", db->read_id[i], (long)db->sig[i]->nsample,(long)signal_start_point2, (long)signal_end_point2); //target: name, start, end - printf("%s\t%d\t%ld\t%ld\t", db->read_id[i], n_kmers,rna?n_kmers-read_start:read_start, rna?n_kmers-1-read_end:read_end+1); + printf("%s\t%d\t%ld\t%ld\t", db->read_id[i], n_kmers,(long)(rna?n_kmers-read_start:read_start), (long)(rna?n_kmers-1-read_end:read_end+1)); //residue matches, block len, mapq printf("%d\t%d\t%d\t",matches,n_kmers,255); printf("sc:f:%f\t",db->scalings->scale); @@ -513,10 +505,8 @@ static void read_slow5_single(core_t* core, db_t* db, int i){ slow5_rec_free(record); } - } - ret_status_t load_db_rsq(core_t* core, db_t* db, gzFile fp, kseq_t *seq) { double load_start = realtime(); @@ -561,7 +551,6 @@ ret_status_t load_db_rsq(core_t* core, db_t* db, gzFile fp, kseq_t *seq) { core->db_fasta_time += realtime() - t; - db->n_bam_rec = i; status.num_reads = i; @@ -706,7 +695,6 @@ int resquiggle_main(int argc, char **argv) { exit(EXIT_FAILURE); } - WARNING("%s","f5c resquiggle is experimental. Use with caution. Report any bugs under GitHub issues."); //open slow5