def test_take(self): a = np.rec.array(variant_table_data, dtype=variant_table_dtype) vt = VariantTable(a) # take variants not in original order indices = [2, 0] t = vt.take(indices) eq(2, t.n_variants) expect = a.take(indices) aeq(expect, t)
def filter_phasing( genotypes_un: allel.GenotypeArray, variants_un: allel.VariantTable, window_size: int = 100) -> (allel.GenotypeArray, allel.VariantTable): """ Filters 'genotypes_un' and 'variants_un' whether there are phasing genotypes. Parameters: genotypes_un (allel.GenotypeArray): GenotypeArray object. variants_un (allel.VariantTable): VariantTable object. window_size (int): Number of previous heterozygous sites to include when phasing each parent. Returns: Tuple (allel.GenotypeArray, allel.VariantTable): - allel.GenotypeArray: GenotypeArray object - allel.VariantTable: VariantTable object """ # Phasing by transmission genotypes_phased = allel.phase_by_transmission(genotypes_un, window_size=window_size) # locate variants where all genotype calls were phased np_array_loc_phased_all = np.all(genotypes_phased.is_phased, axis=1) count_loc_phased_all = np.count_nonzero(np_array_loc_phased_all) if count_loc_phased_all == 0: # At least 1 variant could not be phased logger.warning("Could not find enough phased calls. Using all calls") return genotypes_phased[:], variants_un logger.debug("Found {num_phased} phased variant calls".format( num_phased=count_loc_phased_all)) genotypes_phased_all = genotypes_phased[np_array_loc_phased_all] variants_un_phased_all = variants_un.compress(np_array_loc_phased_all) return genotypes_phased_all, variants_un_phased_all
def test_get_item_types(self): vt = VariantTable(variant_table_data, dtype=variant_table_dtype) # row slice s = vt[1:] assert isinstance(s, VariantTable) # row index s = vt[0] assert isinstance(s, np.record) assert not isinstance(s, VariantTable) # col access s = vt['CHROM'] assert isinstance(s, np.ndarray) assert not isinstance(s, VariantTable) s = vt[['CHROM', 'POS']] assert isinstance(s, VariantTable)
def test_constructor(self): # missing data arg with pytest.raises(TypeError): # noinspection PyArgumentList VariantTable()
def setup_instance(self, data, index=None, **kwargs): return VariantTable(data, index=index, **kwargs)
def variants_filter(variants: allel.VariantTable, filter_expression: str) -> np.ndarray: variant_selection = variants.eval(filter_expression) return variant_selection