Skip to content

Commit

Permalink
Added optional argument interlocus2 to compute_epitopic_charge
Browse files Browse the repository at this point in the history
Signed-off-by: JasonMendoza2008 <[email protected]>
  • Loading branch information
JasonMendoza2008 committed Oct 28, 2022
1 parent 99d1ba6 commit 6d2c6f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
6 changes: 4 additions & 2 deletions pecc/epitope_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def compute_epitopic_charge(
class_ii: bool = True,
verifiedonly: bool = False,
exclude: list[int | str] | None = None,
interlocus2: bool = True
) -> None:
"""
:param input_df_donor: Input Donors Typing pandas.DataFrame
Expand All @@ -28,6 +29,7 @@ def compute_epitopic_charge(
:param class_ii: Compute class II epitopes comparison?
:param verifiedonly: How should the peitopic charge be computed Verified epitopes only? Or all epitopes?
:param exclude: list of indices to exclude
:param interlocus2: whether or not to take into account interlocus eplets for HLA of class II
:return: None
"""
Expand Down Expand Up @@ -94,10 +96,10 @@ def compute_epitopic_charge(
input_df_donor, input_df_recipient = remove_unexpected_other_individual(input_df_donor, input_df_recipient)

donors_epitopes_per_allele: pd.DataFrame = _allele_df_to_epitopes_df(
input_df_donor, df_a, df_b, df_c, df_dr, df_dq, df_dp
input_df_donor, df_a, df_b, df_c, df_dr, df_dq, df_dp, interlocus2
)
recipients_epitopes_per_allele: pd.DataFrame = _allele_df_to_epitopes_df(
input_df_recipient, df_a, df_b, df_c, df_dr, df_dq, df_dp
input_df_recipient, df_a, df_b, df_c, df_dr, df_dq, df_dp, interlocus2
)

# Concatenate all loci
Expand Down
28 changes: 19 additions & 9 deletions pecc/epitope_comparison_aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ def split_dataframe(df: pd.DataFrame) -> tuple[pd.DataFrame, pd.DataFrame]:
return df.filter(regex='_D').copy(), df.filter(regex='_R').copy()


def _convert_to_epitopes(allele: str, df_ref: pd.DataFrame, suffix: str) -> list[str]:
def _convert_to_epitopes(allele: str, df_ref: pd.DataFrame, suffix: str, interlocus2: bool) -> list[str]:
"""
:param allele: allele to convert
:param df_ref: reference pandas.DataFrame for the locus of the allele
:param suffix: which locus the allele belongs to
:param interlocus2: whether or not to take into account interlocus eplets for HLA of class II
:return: list of epitopes corresponding the allele
"""
Expand All @@ -27,15 +29,16 @@ def _convert_to_epitopes(allele: str, df_ref: pd.DataFrame, suffix: str) -> list
for epitope in df_ref.loc[allele].values:
if not pd.isnull(epitope):
if epitope[0] in ["r", "q", "p"]:
epitope_list.append(epitope)
if interlocus2:
epitope_list.append(epitope)
else:
epitope_list.append(f"{epitope}_{suffix}")

return epitope_list



def _allele_df_to_epitopes_df(df, df_a, df_b, df_c, df_dr, df_dq, df_dp):
def _allele_df_to_epitopes_df(df, df_a, df_b, df_c, df_dr, df_dq, df_dp, interlocus2: bool):
"""
Extraction of the allele dataframe to transform it into an epitope dictionary
Expand All @@ -46,53 +49,60 @@ def _allele_df_to_epitopes_df(df, df_a, df_b, df_c, df_dr, df_dq, df_dp):
:param df_dr: reference dataframe HLA DRB1
:param df_dq: reference dataframe HLA DQB1
:param df_dp: reference dataframe HLA DPB1
:param interlocus2: whether or not to take into account interlocus eplets for HLA of class II
"""

epitope_per_allele_dataframe: pd.DataFrame = df.applymap(
lambda allele:
_convert_to_epitopes(
allele,
df_a,
"ABC"
"ABC",
interlocus2
)
if allele[0] == "A"
else (
_convert_to_epitopes(
allele,
df_b,
"ABC"
"ABC",
interlocus2
)
if allele[0] == "B"
else
(
_convert_to_epitopes(
allele,
df_c,
"ABC"
"ABC",
interlocus2
)
if allele[0] == "C"
else
(
_convert_to_epitopes(
allele,
df_dr,
"DR"
"DR",
interlocus2
)
if allele[0:2] == "DR"
else
(
_convert_to_epitopes(
allele,
df_dq,
"DQ"
"DQ",
interlocus2
)
if allele[0:2] == "DQ"
else
(
_convert_to_epitopes(
allele,
df_dp,
"DP"
"DP",
interlocus2
)
if allele[0:2] == "DP"
else
Expand Down

0 comments on commit 6d2c6f4

Please sign in to comment.