# Running impute\_sex

**URL:** <https://discuss.hail.is/t/running-impute-sex/2323>\
**Category:** Hail Query & hailctl\
**Created:** [November 2, 2021, 10:31am UTC](https://discuss.hail.is/t/running-impute-sex/2323 "2021-11-02T10:31:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnyr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnnyr/32/572_2.png) [@johnnyr](https://discuss.hail.is/u/johnnyr)\
**Post date:** [November 2, 2021, 10:31am UTC](https://discuss.hail.is/t/running-impute-sex/2323/1 "2021-11-02T10:31:09Z")

</div>

Hey, I have a problem when running impute\_sex. Can you help me on this ?  
Here is what I get as output:

```auto
---------------------------------------------------------------------------
ExpressionException Traceback (most recent call last)
~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/expr/expressions/expression_typecheck.py in check(self, x, caller, param)
     76 try:
---> 77 return self.coerce(to_expr(x))
     78 except ExpressionException as e:

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/expr/expressions/base_expression.py in to_expr(e, dtype)
    206 return e
--> 207 return cast_expr(e, dtype)
    208 

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/expr/expressions/base_expression.py in cast_expr(e, dtype)
    211 if not dtype:
--> 212 dtype = impute_type(e)
    213 x = _to_expr(e, dtype)

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/expr/expressions/base_expression.py in impute_type(x)
    157 if len(x) == 0:
--> 158 raise ExpressionException("Cannot impute type of empty list. Use 'hl.empty_array' to create an empty array.")
    159 ts = {impute_type(element) for element in x}

ExpressionException: Cannot impute type of empty list. Use 'hl.empty_array' to create an empty array.

The above exception was the direct cause of the following exception:

TypecheckFailure Traceback (most recent call last)
~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/typecheck/check.py in check_all(f, args, kwargs, checks, is_method)
    540 arg = args[i]
--> 541 args_.append(checker.check(arg, name, arg_name))
    542 # passed as keyword

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/expr/expressions/expression_typecheck.py in check(self, x, caller, param)
     78 except ExpressionException as e:
---> 79 raise TypecheckFailure from e
     80 

TypecheckFailure: 

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
<ipython-input-381-6636ce6405c8> in <module>
----> 1 imputed_sex = hl.impute_sex(mt.GT)

<decorator-gen-1558> in impute_sex(call, aaf_threshold, include_par, female_threshold, male_threshold, aaf)

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/typecheck/check.py in wrapper(__original_func, *args, **kwargs)
    612 def wrapper(__original_func, *args, **kwargs):
    613 args_, kwargs_ = check_all(__original_func, args, kwargs, checkers, is_method=is_method)
--> 614 return __original_func(*args_, **kwargs_)
    615 
    616 return wrapper

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/methods/statgen.py in impute_sex(call, aaf_threshold, include_par, female_threshold, male_threshold, aaf)
    146 rg = mt.locus.dtype.reference_genome
    147 mt = hl.filter_intervals(mt,
--> 148 hl.map(lambda x_contig: hl.parse_locus_interval(x_contig, rg), rg.x_contigs),
    149 keep=True)
    150 if not include_par:

<decorator-gen-934> in map(f, collection)

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/typecheck/check.py in wrapper(__original_func, *args, **kwargs)
    611 @decorator
    612 def wrapper(__original_func, *args, **kwargs):
--> 613 args_, kwargs_ = check_all(__original_func, args, kwargs, checkers, is_method=is_method)
    614 return __original_func(*args_, **kwargs_)
    615 

~/anaconda3/envs/hail/lib/python3.7/site-packages/hail/typecheck/check.py in check_all(f, args, kwargs, checks, is_method)
    565 expected=checker.expects(),
    566 found=checker.format(arg)
--> 567 )) from e
    568 elif param.kind == param.VAR_POSITIONAL:
    569 # consume the rest of the positional arguments

TypeError: map: parameter 'collection': expected expression of type set<any> or array<any> or ndarray<any>, found list: []

```

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [November 2, 2021, 12:24pm UTC](https://discuss.hail.is/t/running-impute-sex/2323/2 "2021-11-02T12:24:38Z")

</div>

can you share the script where you’re using this?

Also, what reference genome are you using?

---

<div class="post-metadata">

**Author:** ![johnnyr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnnyr/32/572_2.png) [@johnnyr](https://discuss.hail.is/u/johnnyr)\
**Post date:** [November 2, 2021, 12:38pm UTC](https://discuss.hail.is/t/running-impute-sex/2323/3 "2021-11-02T12:38:22Z")

</div>

```auto
my_rg =hl.ReferenceGenome("hg38", ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","X","Y","MT"], {"1": 248956422, "2": 242193529, "3": 198295559, "4": 190214555, "5": 181538259,"6": 170805979, "7": 159345973, "8": 145138636, "9": 138394717, "10": 133797422,"11": 135086622, "12": 133275309, "13": 114364328, "14": 107043718, "15": 101991189,"16": 90338345, "17": 83257441, "18": 80373285, "19": 58617616, "20": 64444167, "21": 46709983, "22": 50818468, "X": 156040895, "Y": 57227415, "MT": 16569})

hl.import_vcf('my_vcf.vcf', reference_genome=my_rg).write('my_mt.mt', overwrite=True)

mt = hl.read_matrix_table('my_mt.mt')

imputed_sex = hl.impute_sex(mt.GT)

```
