Files

50 lines
1.1 KiB
C
Raw Permalink Normal View History

2007-02-15 13:33:32 +00:00
#include "ecoPCR.h"
#include <string.h>
#include <stdlib.h>
static int compareRankLabel(const void *label1, const void *label2);
ecorankidx_t *read_rankidx(const char *filename)
{
int32_t count;
FILE *f;
ecorankidx_t *index;
int32_t i;
int32_t rs;
char *buffer;
2025-06-12 13:35:06 +00:00
2007-02-15 13:33:32 +00:00
f = open_ecorecorddb(filename,&count,1);
2025-06-12 13:35:06 +00:00
2007-02-15 13:33:32 +00:00
index = (ecorankidx_t*) ECOMALLOC(sizeof(ecorankidx_t) + sizeof(char*) * (count-1),
"Allocate rank index");
2025-06-12 13:35:06 +00:00
index->count=count;
2007-02-15 13:33:32 +00:00
for (i=0; i < count; i++)
{
buffer = read_ecorecord(f,&rs);
index->label[i]=(char*) ECOMALLOC(rs+1,
"Allocate rank label");
strncpy(index->label[i],buffer,rs);
}
2025-06-12 13:35:06 +00:00
2007-02-15 13:33:32 +00:00
return index;
}
int32_t rank_index(const char* label,ecorankidx_t* ranks)
{
char **rep;
2025-06-12 13:35:06 +00:00
fprintf(stderr,"Looking for rank -%s-... ",label);
2007-02-15 13:33:32 +00:00
rep = bsearch(label,ranks->label,ranks->count,sizeof(char*),compareRankLabel);
2025-06-12 13:35:06 +00:00
2007-02-15 13:33:32 +00:00
if (rep)
return rep-ranks->label;
return -1;
}
int compareRankLabel(const void *label1, const void *label2)
{
return strcmp((const char*)label1,*(const char**)label2);
}