Skip to content

Commit

Permalink
vdjsearch 0.0.5: Fix memory allocation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
torognes committed May 14, 2021
1 parent 4ed4730 commit c568ff3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void cluster(char * filename)
progress_init("Clustering: ", seqcount);

/* for each non-clustered item, look for subseeds ... */

uint64_t x = 0;
for(unsigned int seed = 0; seed < seqcount; seed++)
{
struct iteminfo_s * ap = iteminfo + seed;
Expand All @@ -315,13 +315,15 @@ void cluster(char * filename)

/* find initial matches */
process_seed(seed);
progress_update(++x);

unsigned int subseed = ap->next;

/* process all subseeds */
while(subseed != no_cluster)
{
process_seed(subseed);
progress_update(++x);
subseed = iteminfo[subseed].next;
}

Expand All @@ -339,7 +341,6 @@ void cluster(char * filename)
sp->size = clustersize;
clustercount++;
}
progress_update(seed+1);
}

progress_done();
Expand Down
34 changes: 30 additions & 4 deletions src/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,26 @@ void db_init()
void db_exit()
{
if (v_gene_list)
xfree(v_gene_list);
v_gene_list = 0;
{
for (uint64_t i = 0; i < v_gene_count; i++)
{
xfree(v_gene_list[i]);
v_gene_list[i] = 0;
}
xfree(v_gene_list);
v_gene_list = 0;
}

if (j_gene_list)
xfree(j_gene_list);
j_gene_list = 0;
{
for (uint64_t i = 0; i < j_gene_count; i++)
{
xfree(j_gene_list[i]);
j_gene_list[i] = 0;
}
xfree(j_gene_list);
j_gene_list = 0;
}
}

uint64_t list_insert(char * * * list, uint64_t * alloc, uint64_t * count, char * item)
Expand Down Expand Up @@ -382,6 +397,17 @@ void db_hash(struct db * d)

void db_free(struct db * d)
{
if (d->sample_list)
{
for (uint64_t i = 0; i < d->sample_count; i++)
{
xfree(d->sample_list[i]);
d->sample_list[i] = 0;
}
xfree(d->sample_list);
d->sample_list = 0;
}

if (d->residues_p)
xfree(d->residues_p);
if (d->seqindex)
Expand Down
11 changes: 9 additions & 2 deletions src/overlap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static hashtable_s * hashtable = nullptr;

const uint64_t CHUNK = 1000;

inline void hash_insert(uint64_t amp)
void hash_insert(uint64_t amp)
{
/* set 2 */
/* find the first empty bucket */
Expand Down Expand Up @@ -310,9 +310,13 @@ void overlap(char * set1_filename, char * set2_filename)
{
/* find overlaps between repertoires of samples */

db_init();


/**** Set 1 ****/

fprintf(logfile, "Immune receptor repertoire set 1\n");

db_init();
d = db_create();
db_read(d, set1_filename);

Expand Down Expand Up @@ -380,6 +384,9 @@ void overlap(char * set1_filename, char * set2_filename)
fprintf(logfile, "Sum\t%" PRIu64 "\t%7.5lf\n", sum_size, sum_freq);
fprintf(logfile, "\n");


/**** Set 2 ****/

fprintf(logfile, "Immune receptor repertoire set 2\n");

d2 = db_create();
Expand Down
2 changes: 1 addition & 1 deletion src/vdjsearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void args_show()

void args_usage()
{
fprintf(stderr, "Usage: %s [OPTIONS] TSVFILE1 [TSVFILE2]\n", PROG_NAME);
fprintf(stderr, "Usage: %s [OPTIONS] TSVFILE1 [TSVFILE2]\n", PROG_CMD);
fprintf(stderr, "\n");
fprintf(stderr, "Commands:\n");
fprintf(stderr, " -h, --help display this help and exit\n");
Expand Down
7 changes: 4 additions & 3 deletions src/vdjsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ static_assert(INT_MAX > 32767, "Your compiler uses very short integers.");

/* constants */

#define PROG_NAME "vdjsearch"
#define PROG_VERSION "0.0.4"
#define PROG_BRIEF "Immune repertoire analysis"
#define PROG_CMD "vdjsearch"
#define PROG_NAME "VDJsearch"
#define PROG_VERSION "0.0.5"
#define PROG_BRIEF "Compare Adaptive Immune Receptor Repertoires"

const unsigned int MAX_THREADS = 256;

Expand Down

0 comments on commit c568ff3

Please sign in to comment.