Skip to content

Commit

Permalink
Properly manage individuals with no ancestors nor sex specified
Browse files Browse the repository at this point in the history
Former-commit-id: 892ec87
  • Loading branch information
Cristina Yenyxe Gonzalez Garcia committed Feb 14, 2013
1 parent a48fbf4 commit 26cce9d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libs/bioinfo-libs
Submodule bioinfo-libs updated from dead2c to e9997a
2 changes: 2 additions & 0 deletions src/gwas/assoc/assoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void assoc_count_individual(individual_t *individual, vcf_record_t *record, int
int A1 = 0, A2 = 0, A0 = 0;
int U1 = 0, U2 = 0, U0 = 0;

assert(individual);

if (!strncmp("X", record->chromosome, record->chromosome_len)) {
if (individual->condition == AFFECTED) { // if affected
if (!allele1 && !allele2) {
Expand Down
35 changes: 29 additions & 6 deletions src/gwas/assoc/assoc_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ int run_association_test(shared_options_data_t* shared_options_data, assoc_optio
{
// Guarantee that just one thread performs this operation
if (!initialization_done) {

// Sort individuals in PED as defined in the VCF file
individuals = sort_individuals(file, ped_file);
individuals = sort_individuals(file, ped_file);

// Add headers associated to the defined filters
vcf_header_entry_t **filter_headers = get_filters_as_vcf_headers(filters, num_filters);
Expand Down Expand Up @@ -321,7 +322,7 @@ individual_t **sort_individuals(vcf_file_t *vcf, ped_file_t *ped) {

individual_t **individuals = calloc (get_num_vcf_samples(vcf), sizeof(individual_t*));
cp_hashtable *positions = associate_samples_and_positions(vcf);
int *pos;
int *pos = NULL;

for (int f = 0; f < num_families; f++) {
family = families[f];
Expand All @@ -330,26 +331,48 @@ individual_t **sort_individuals(vcf_file_t *vcf, ped_file_t *ped) {
cp_list *children = family->children;

if (father != NULL) {
pos = NULL;
LOG_DEBUG_F("father ID = %s\n", father->id);
pos = cp_hashtable_get(positions, father->id);
if (pos) {
individuals[*pos] = father;
}
}

if (mother != NULL) {
pos = NULL;
LOG_DEBUG_F("mother ID = %s\n", mother->id);
pos = cp_hashtable_get(positions, mother->id);
if (pos) {
individuals[*pos] = mother;
}
}

cp_list_iterator *children_iterator = cp_list_create_iterator(family->children, COLLECTION_LOCK_READ);
cp_list_iterator *iterator = cp_list_create_iterator(family->children, COLLECTION_LOCK_READ);
individual_t *child = NULL;
while ((child = cp_list_iterator_next(children_iterator)) != NULL) {
while (child = cp_list_iterator_next(iterator)) {
pos = NULL;
LOG_DEBUG_F("child ID = %s\n", child->id);
pos = cp_hashtable_get(positions, child->id);
individuals[*pos] = child;
if (pos) {
individuals[*pos] = child;
}
}
cp_list_iterator_destroy(iterator);

iterator = cp_list_create_iterator(family->unknown, COLLECTION_LOCK_READ);
individual_t *unknown = NULL;
while (unknown = cp_list_iterator_next(iterator)) {
pos = NULL;
LOG_DEBUG_F("unknown ID = %s\n", unknown->id);
pos = cp_hashtable_get(positions, unknown->id);
if (pos) {
individuals[*pos] = unknown;
}
}
cp_list_iterator_destroy(children_iterator);
cp_list_iterator_destroy(iterator);

assert(father || mother || !cp_list_is_empty(family->unknown));
}

cp_hashtable_destroy(positions);
Expand Down
1 change: 1 addition & 0 deletions src/gwas/assoc/assoc_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef ASSOC_RUNNER_H
#define ASSOC_RUNNER_H

#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down

0 comments on commit 26cce9d

Please sign in to comment.