From 13313a77bef56d7c71add72753bb91e2841d4060 Mon Sep 17 00:00:00 2001 From: Leon Hafner <60394289+LeonHafner@users.noreply.github.com> Date: Sat, 4 Jan 2025 20:23:36 +0100 Subject: [PATCH] add index intersection --- .../local/counts/calculate_tpm/templates/calculate_tpm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/local/counts/calculate_tpm/templates/calculate_tpm.py b/modules/local/counts/calculate_tpm/templates/calculate_tpm.py index 8dad632..730d0ba 100755 --- a/modules/local/counts/calculate_tpm/templates/calculate_tpm.py +++ b/modules/local/counts/calculate_tpm/templates/calculate_tpm.py @@ -34,7 +34,10 @@ def format_yaml_like(data: dict, indent: int = 0) -> str: df_lengths = df_lengths / 1e3 df_lengths = df_lengths.groupby(df_lengths.index).mean() -df_lengths = df_lengths.loc[df_lengths.index.isin(df_counts.index)] +# Subset gene lengths and counts to common index +shared_index = df_lengths.index.intersection(df_counts.index) +df_lengths = df_lengths.loc[shared_index] +df_counts = df_counts.loc[shared_index] # Calculate TPM df_rpk = df_counts.div(df_lengths["length"], axis=0)