Aggregation¶
For a full list of aggregators, see the aggregators section of the API reference.
Table Aggregations¶
Aggregate Over Rows Into A Local Value¶
One aggregation¶
description: | Compute the fraction of rows where |
---|---|
code: | >>> ht.aggregate(hl.agg.fraction(ht.SEX == 'M'))
0.5
|
dependencies: |
Multiple aggregations¶
description: | Compute two aggregation statistics, the fraction of rows where
|
---|---|
code: | >>> ht.aggregate(hl.struct(fraction_male = hl.agg.fraction(ht.SEX == 'M'),
... mean_x = hl.agg.mean(ht.X)))
Struct(fraction_male=0.5, mean_x=6.5)
|
dependencies: |
|
Aggregate Per Group¶
description: | Group the table |
---|---|
code: | >>> result_ht = ht.group_by(ht.ID).aggregate(mean_x=hl.agg.mean(ht.X))
|
dependencies: |
|
Matrix Table Aggregations¶
Aggregate Entries Per Row (Over Columns)¶
description: | Count the number of occurrences of each unique Methods |
---|---|
code: | >>> result_mt = mt.annotate_rows(gt_counter=hl.agg.counter(mt.GT))
|
dependencies: |
Aggregate Entries Per Column (Over Rows)¶
description: | Compute the mean of the Methods |
---|---|
code: | >>> result_mt = mt.annotate_cols(gq_mean=hl.agg.mean(mt.GQ))
|
dependencies: |
Aggregate Column Values Into a Local Value¶
One aggregation¶
description: | Aggregate over the column-indexed field |
---|---|
code: | >>> mt.aggregate_cols(hl.agg.fraction(mt.pheno.is_female))
0.5
|
dependencies: |
Multiple aggregations¶
description: | Perform multiple aggregations over column-indexed fields by using
a struct expression. The result is a single struct containing
two nested fields, |
---|---|
code: | >>> mt.aggregate_cols(hl.struct(
... fraction_female=hl.agg.fraction(mt.pheno.is_female),
... case_ratio=hl.agg.count_where(mt.is_case) / hl.agg.count()))
Struct(fraction_female=0.5, case_ratio=1.0)
|
dependencies: |
|
Aggregate Row Values Into a Local Value¶
One aggregation¶
description: | Compute the mean value of the row-indexed field |
---|---|
code: | >>> mt.aggregate_rows(hl.agg.mean(mt.qual))
404051.99
|
dependencies: |
Multiple aggregations¶
description: | Perform two row aggregations: count the number of row values of |
---|---|
code: | >>> mt.aggregate_rows(
... hl.struct(n_high_quality=hl.agg.count_where(mt.qual > 40),
... mean_qual=hl.agg.mean(mt.qual)))
Struct(n_high_quality=10, mean_qual=404051.99)
|
dependencies: |
|
Aggregate Entry Values Into A Local Value¶
description: | Compute the mean of the entry-indexed field |
---|---|
code: | >>> mt.aggregate_entries(
... hl.struct(global_gq_mean=hl.agg.mean(mt.GQ),
... call_rate=hl.agg.fraction(hl.is_defined(mt.GT))))
Struct(global_gq_mean=56.73, call_rate=0.976)
|
dependencies: |
|
Aggregate Per Column Group¶
description: | Group the columns of the matrix table by the column-indexed
field |
---|---|
code: | >>> result_mt = (mt.group_cols_by(mt.cohort)
... .aggregate(call_rate=hl.agg.fraction(hl.is_defined(mt.GT))))
|
dependencies: |
|
understanding: | Group the columns of the matrix table by
the column-indexed field The result is a matrix table with an entry field |
Aggregate Per Row Group¶
description: | Compute the number of calls with one or more non-reference alleles per gene group. |
---|---|
code: | >>> result_mt = (mt.group_rows_by(mt.gene)
... .aggregate(n_non_ref=hl.agg.count_where(mt.GT.is_non_ref())))
|
dependencies: |
|
understanding: | Group the rows of the matrix table by the row-indexed field The result is a matrix table with an entry field |