Skip to content

Commit

Permalink
fix nan bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarcsj committed Jul 27, 2023
1 parent 7a135fb commit ea99f42
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions directlfq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ def filter_input(filter_dict, input):
def merge_protein_and_ion_cols(input_df, config_dict):
protein_cols = config_dict.get("protein_cols")
ion_cols = config_dict.get("ion_cols")
input_df['protein'] = input_df.apply(lambda row : "_".join(row[protein_cols].astype('string')), axis = 1)
input_df['ion'] = input_df.apply(lambda row : "_".join(row[ion_cols].astype('string')), axis = 1)
input_df['protein'] = join_columns(input_df, protein_cols)
input_df['ion'] = join_columns(input_df, ion_cols)

input_df = input_df.rename(columns = {config_dict.get('quant_ID') : "quant_val"})
return input_df
Expand All @@ -458,7 +458,7 @@ def merge_protein_cols_and_ion_dict(input_df, config_dict):

ion_dfs = []
#concatenate multiple protein columns into one
input_df['protein'] = input_df.apply(lambda row: "_".join(row[protein_cols].astype('string')), axis=1)
input_df['protein'] = join_columns(input_df, protein_cols)

input_df = input_df.drop(columns = [x for x in protein_cols if x!='protein'])
for hierarchy_type in ion_hierarchy.keys():
Expand All @@ -483,6 +483,12 @@ def merge_protein_cols_and_ion_dict(input_df, config_dict):
input_df = pd.concat(ion_dfs, ignore_index=True)
return input_df

def join_columns(df, columns, separator='_'):
if len(columns) == 1:
return df[columns[0]].fillna('nan').astype(str)
else:
return df[columns].fillna('nan').astype(str).agg(separator.join, axis=1)


def get_quantitative_columns(input_df, hierarchy_type, config_dict, ion_headers_merged):
naming_columns = ion_headers_merged + ['protein']
Expand Down

0 comments on commit ea99f42

Please sign in to comment.