You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following post was exported from discuss.hail.is, a forum for asking questions about Hail which has since been deprecated.
(Dec 20, 2023 at 18:05) mgarcia said:
I am trying to annotate a MatrixTable with sample IDs written as integers, but I am encountering the key type mismatch error below. Is there a way to import the values into samples as strings to avoid this error? Should I use hl.import_lines? Thank you in advance.
Traceback (mostrecentcalllast):
File "/opt/notebooks/hail_variant_qc_V10.py, line485, in<module>sa=samples [vcf.s]
File "/opt/conda/lib/python3.9/site-packages/hail/table-py, line379, ingetitemreturnself.index(*wrap_to_tuple(item))
File"/opt/conda/lib/python3.9/site-packages/hail/table-py", line1840, inindexraiseExpressionException(f"Key type mismatch: cannot index table with given expressions: \n"hail.expr.expressions.base_expression. ExpressionException: Keytypemismatch: cannotindextablewithgivenexpressions:
Tablekey:
int32IndexExpressions: str
(Jan 02, 2024 at 14:41) danking said:
Hey mgarcia !
You probably don’t want hl.import_lines. hl.import_table is the recommended way to import delimited text files.
The issue is that Hail is guessing that your TSV/CSV file’s SAMPLE column is an integer (because they’re all parsable as integers), but your matrix table is probably coming from a VCF. hl.import_vcf unconditionally imports sample ids as strings. The fix is simple: hl.import_table accepts a types argument which overrides type imputation for the specified fields:
Note
The following post was exported from discuss.hail.is, a forum for asking questions about Hail which has since been deprecated.
(Dec 20, 2023 at 18:05) mgarcia said:
I am trying to annotate a MatrixTable with sample IDs written as integers, but I am encountering the key type mismatch error below. Is there a way to import the values into
samples
as strings to avoid this error? Should I usehl.import_lines
? Thank you in advance.(Jan 02, 2024 at 14:41) danking said:
Hey mgarcia !
You probably don’t want
hl.import_lines
.hl.import_table
is the recommended way to import delimited text files.The issue is that Hail is guessing that your TSV/CSV file’s SAMPLE column is an integer (because they’re all parsable as integers), but your matrix table is probably coming from a VCF.
hl.import_vcf
unconditionally imports sample ids as strings. The fix is simple:hl.import_table
accepts atypes
argument which overrides type imputation for the specified fields:The text was updated successfully, but these errors were encountered: