Skip to content

Commit

Permalink
fix up macos warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hasindu2008 committed Sep 9, 2022
1 parent fcead63 commit 523c1ec
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 80 deletions.
63 changes: 63 additions & 0 deletions src/f5c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<beg){
ERROR("Malformed bed entry at line %ld",line_no);
exit(EXIT_FAILURE);
}

if(reg_i>=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) {
Expand Down
64 changes: 0 additions & 64 deletions src/f5cmisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<beg){
ERROR("Malformed bed entry at line %ld",line_no);
exit(EXIT_FAILURE);
}

if(reg_i>=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;
Expand Down
20 changes: 4 additions & 16 deletions src/resquiggle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 523c1ec

Please sign in to comment.