Skip to content

Commit

Permalink
compatibility when using 'quant_id'
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarcsj committed Nov 7, 2023
1 parent dc5691b commit ca164d1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions directlfq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,15 +785,24 @@ def import_data(input_file, input_type_to_use = None, samples_subset = None, fil
"""

samples_subset = add_ion_protein_headers_if_applicable(samples_subset)
if ("aq_reformat" in input_file) | (input_type_to_use == "directlfq"):
file_is_already_formatted = ("aq_reformat" in input_file) | (input_type_to_use == "directlfq")
if file_is_already_formatted:
file_to_read = input_file
else:
file_to_read = reformat_and_save_input_file(input_file=input_file, input_type_to_use=input_type_to_use, filter_dict=filter_dict)

input_reshaped = pd.read_csv(file_to_read, sep = "\t", encoding = 'latin1', usecols=samples_subset)
input_reshaped = adapt_table_for_alphabaseformat_backward_compatibility(file_is_already_formatted, input_reshaped)
input_reshaped = input_reshaped.drop_duplicates(subset='ion')

return input_reshaped

def add_ion_protein_headers_if_applicable(samples_subset):
if samples_subset is not None:
return samples_subset + ["ion", "protein"]
else:
return None


def reformat_and_save_input_file(input_file, input_type_to_use = None, filter_dict = None):

Expand All @@ -814,13 +823,12 @@ def reformat_and_save_input_file(input_file, input_type_to_use = None, filter_di
return outfile_name


def adapt_table_for_alphabaseformat_backward_compatibility(file_is_already_formatted, input_reshaped):
if file_is_already_formatted:
if 'quant_id' in input_reshaped.columns:
return input_reshaped.rename(columns = {'quant_id' : 'ion'})


def add_ion_protein_headers_if_applicable(samples_subset):
if samples_subset is not None:
return samples_subset + ["ion", "protein"]
else:
return None
return input_reshaped



Expand Down

0 comments on commit ca164d1

Please sign in to comment.