import logging


def Aggregate_median_SABV_AGE(rnaseq):
  """Compute median TPM by gene+tissue+sex+age."""
  logging.info("=== Aggregate_median_SABV_AGE:")
  logging.info(f"Aggregate_median_SABV_AGE IN: nrows = {rnaseq.shape[0]}, cols: {str(rnaseq.columns.tolist())}")
  rnaseq = rnaseq[["ENSG", "SMTSD", "SEX", "AGE", "TPM"]].groupby(by=["ENSG", "SMTSD", "SEX", "AGE"], as_index=False).median()
  logging.info(f"Aggregate_median_SABV_AGE OUT: nrows = {rnaseq.shape[0]}, cols: {str(rnaseq.columns.tolist())}")
  return rnaseq