import csv
import re


def load_peptides(input_file, peptide_column, column_separator):
    """
    Parses the input file and extracts all peptides occuring within the file. Peptide strings
    are cleaned (only valid characters retained) and returned as a set.

    :param input_file: The file to parse
    :param peptide_column: The column header to extract the peptides from.
    :param column_separator: The separator used for the columns
    :return: A set of strings representing the peptides.
    """
    with open(input_file, "r") as input_stream:
        csv_reader = csv.DictReader(input_stream, delimiter=column_separator)

        peptides = set()

        for row in csv_reader:
            if peptide_column not in row:
                raise Exception("Specified peptide column '" + peptide_column + "' not found in input file.")

            sequence = row[peptide_column]
            clean_sequence = re.sub("[^A-Z]", "", sequence)
            peptides.add(clean_sequence)

        return peptides