Skip to content

Give user more specific error information about input_type #347

@elephantoid

Description

@elephantoid

Describe the bug
I was going to run alphaquant pipeline. I ran pipeline with something input type and then I wanted to run also other types.
but i got an error like "format not specified in intable_config.yaml!".
This message is not enough for resolving problems. so I had to go through all the relevant code.
It was really terrible user experience.

To Reproduce
Steps to reproduce the behavior:

  1. Prepare the Spectronnut Report without FG.Quantity column
  2. Run AlphaQuant pipeline with spectronaut_precursor_fragion_ms1_protein
  3. See error

Expected behavior
When I think, when a failure occurs, I think enough information should be provided to solve it.
so this is my suggest for that

def get_input_type_and_config_dict(input_file, input_type_to_use=None):
    all_config_dicts = _load_config(INTABLE_CONFIG)
    type2relevant_columns = _get_type2relevant_cols(all_config_dicts)

    if "aq_reformat.tsv" in input_file:
        input_file = _get_original_file_from_aq_reformat(input_file)

    sep = _get_seperator(input_file)

    uploaded_data_columns = quantreader_utils.read_columns_from_file(
        input_file, sep=sep
    )

    missing_columns = []
    available_columns = []
    failed_input_type = None

    for input_type in type2relevant_columns:
        if (input_type_to_use is not None) and (input_type != input_type_to_use):
            continue
        relevant_columns = type2relevant_columns.get(input_type)
        relevant_columns = [x for x in relevant_columns if x]  # filter None values
        if set(relevant_columns).issubset(uploaded_data_columns):
            config_dict = all_config_dicts.get(input_type)
            return input_type, config_dict, sep
        else:
            if input_type_to_use is not None and input_type == input_type_to_use:
                failed_input_type = input_type
                missing_columns = list(
                    set(relevant_columns) - set(uploaded_data_columns)
                )
                available_columns = list(
                    set(relevant_columns) & set(uploaded_data_columns)
                )

    if input_type_to_use is not None and failed_input_type is not None:
        raise ValueError(
            f"Input type '{input_type_to_use}' requires columns that are missing from your data file.\n"
            f"Missing columns: {missing_columns}\n"
            f"Available columns: {available_columns}\n"
            f"Data file columns: {uploaded_data_columns}\n\n"
            f"Please check your data file or try a different input_type_to_use."
        )
    else:
        available_types = list(type2relevant_columns.keys())
        raise ValueError(
            f"No suitable input type found for the given data file.\n"
            f"Data file columns: {uploaded_data_columns}\n"
            f"Available input types: {available_types}\n\n"
            f"Please check your data file or specify a different input_type_to_use."
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions