Commit 69d04ac4 authored by Romain Feron's avatar Romain Feron
Browse files

Moved counting of males and females into get_haplotypes function

parent 147ce822
......@@ -87,14 +87,22 @@ def get_haplotypes(parameters, individuals_only=False):
tabs = line.split('\t')
locus_id = tabs[2]
indiv_ids = tabs[8].split(',')
haplotypes_data[locus_id] = {}
if not individuals_only:
haplotypes_data[locus_id] = {}
haplotypes_data[locus_id]['sequence'] = tabs[9]
haplotypes_data[locus_id]['individuals'] = {}
for individual in indiv_ids:
haplotypes_data[locus_id]['individuals'][individual.split('_')[0]] = individual.split('_')[1]
haplotypes_data[locus_id]['n_males'] = len({i for i in haplotypes_data[locus_id]['individuals'].keys() if
parameters.popmap[parameters.order[i]] is 'M'})
haplotypes_data[locus_id]['n_females'] = len({i for i in haplotypes_data[locus_id]['individuals'].keys() if
parameters.popmap[parameters.order[i]] is 'F'})
else:
haplotypes_data[locus_id] = [individual.split('_')[0] for individual in indiv_ids]
haplotypes_data[locus_id]['individuals'] = [individual.split('_')[0] for individual in indiv_ids]
haplotypes_data[locus_id]['n_males'] = len({i for i in haplotypes_data[locus_id]['individuals'] if
parameters.popmap[parameters.order[i]] is 'M'})
haplotypes_data[locus_id]['n_females'] = len({i for i in haplotypes_data[locus_id]['individuals'] if
parameters.popmap[parameters.order[i]] is 'F'})
catalog.close()
......
......@@ -13,9 +13,7 @@ def fill_loci_matrix(parameters):
print(' - Generating loci matrix ...')
for locus_id, data in haplotypes.items():
n_males = len({i for i in data if parameters.popmap[parameters.order[i]] is 'M'})
n_females = len({i for i in data if parameters.popmap[parameters.order[i]] is 'F'})
loci_matrix[n_females][n_males] += 1
loci_matrix[data['n_females']][data['n_males']] += 1
print(' - Generating output ...')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment