Skip to content

Commit

Permalink
#183 ruff reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
jalew188 committed Jul 23, 2024
1 parent 503ca25 commit dc0326c
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions peptdeep/hla/hla_class1.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,17 @@ def predict_from_proteins(
peptide_df["sequence"] = get_seq_series(peptide_df, self._cat_protein_sequence)
return peptide_df

def _concat_neg_df(self, precursor_df, column_to_train='HLA'):
def _concat_neg_df(self, precursor_df, column_to_train="HLA"):
precursor_df = append_nAA_column_if_missing(precursor_df)
precursor_df[column_to_train] = 1
df_list = [precursor_df]
for nAA, group_df in precursor_df.groupby('nAA'):
for nAA, group_df in precursor_df.groupby("nAA"):
rnd_seqs = get_random_sequences(
self.protein_df,
n=len(group_df),
pep_len = nAA
self.protein_df, n=len(group_df), pep_len=nAA
)
df_list.append(
pd.DataFrame({"sequence": rnd_seqs, "nAA": nAA, column_to_train: 0})
)
df_list.append(pd.DataFrame(
{'sequence':rnd_seqs,'nAA':nAA,column_to_train:0}
))
return pd.concat(df_list).reset_index(drop=True)

def test(self, precursor_df):
Expand All @@ -402,17 +400,21 @@ def test(self, precursor_df):
precision_list = []
recall_list = []
fp_list = []
for prob in [0.5,0.6,0.7,0.8, 0.9]:
for prob in [0.5, 0.6, 0.7, 0.8, 0.9]:
prob_list.append(prob)
precision_list.append(df[df.HLA_prob_pred>prob].HLA.mean())
recall_list.append(df[df.HLA_prob_pred>prob].HLA.sum()/len(df)*2)
fp_list.append(1-(1-df[df.HLA_prob_pred<prob].HLA).sum()/len(df)*2)
return pd.DataFrame(dict(
HLA_prob_pred=prob_list,
precision=precision_list,
recall=recall_list,
false_positive=fp_list
))
precision_list.append(df[df.HLA_prob_pred > prob].HLA.mean())
recall_list.append(df[df.HLA_prob_pred > prob].HLA.sum() / len(df) * 2)
fp_list.append(
1 - (1 - df[df.HLA_prob_pred < prob].HLA).sum() / len(df) * 2
)
return pd.DataFrame(
dict(
HLA_prob_pred=prob_list,
precision=precision_list,
recall=recall_list,
false_positive=fp_list,
)
)

def _download_pretrained_hla_model(self):
download_models(url=self._model_url, target_path=self._model_zip)
Expand Down

0 comments on commit dc0326c

Please sign in to comment.