def test_load_pcs_from_file():
    pcs_dict = an.load_pcs_from_file(path.join(data_path, 'pcs.hdf5'))
    assert type(pcs_dict) == dict
    populations = pcs_dict['populations']
    assert type(populations) == dict
    assert len(populations.keys()) == 5
    assert pcs_dict['pcs'].shape == (2504, 2)
def get_pcs_forplotting(platform,pc1,pc2,region='world'):
   pcs = ancestry.load_pcs_from_file('%s/AN_DATA/hapmap_%s_%s_pcs.hdf5' % (settings.DATA_PATH,platform,region))
   num_pop = len(pcs['populations'].keys())
   header = ['PC1']
   data =  []
   data.append(header)
   for population, mask in pcs['populations'].items():
       header.append(population)
       pc2_ix = len(header)-1
       pop_pcs = pcs['pcs'][mask]
       for pc in pop_pcs:
           value = [pc[0]]
           value.extend([None]*(pc2_ix-1))
           value.append(pc[1])
           value.extend([None]*(num_pop - pc2_ix +1))
           data.append(value)
   header.append('YOU')
   value = [None]*(num_pop+2)
   value[0] = float(pc1)
   value[-1] = float(pc2)
   data.append(value)
   return data     
def get_pcs_for_population(platform,region='world',population=None):
    '''Returns the PCS for a given population'''
    pcs = _transform_pcs(ancestry.load_pcs_from_file('%s/AN_DATA/hapmap_%s_%s_pcs.hdf5' % (settings.DATA_PATH,platform,region)))
    if population is not None:
        return pcs[population] 
    return pcs