@classmethod<EOL><INDENT>def sequences_to_fixed_length_index_encoded_array(<EOL>klass, sequences, left_edge=<NUM_LIT:4>, right_edge=<NUM_LIT:4>, max_length=<NUM_LIT:15>):<DEDENT>
<EOL>result = numpy.full(<EOL>fill_value=amino_acid.AMINO_ACID_INDEX['<STR_LIT:X>'],<EOL>shape=(len(sequences), max_length),<EOL>dtype="<STR_LIT>")<EOL>df = pandas.DataFrame({"<STR_LIT>": sequences})<EOL>df["<STR_LIT>"] = df.peptide.str.len()<EOL>middle_length = max_length - left_edge - right_edge<EOL>for (length, sub_df) in df.groupby("<STR_LIT>"):<EOL><INDENT>if length < left_edge + right_edge:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (<EOL>sub_df.iloc[<NUM_LIT:0>].peptide, length, left_edge + right_edge,<EOL>len(sub_df)))<EOL><DEDENT>if length > max_length:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (<EOL>sub_df.iloc[<NUM_LIT:0>].peptide, length, max_length,<EOL>len(sub_df)))<EOL><DEDENT>fixed_length_sequences = numpy.stack(<EOL>sub_df.peptide.map(<EOL>lambda s: numpy.array([<EOL>amino_acid.AMINO_ACID_INDEX[char] for char in s<EOL>])).values)<EOL>num_null = max_length - length<EOL>num_null_left = int(math.ceil(num_null / <NUM_LIT:2>))<EOL>num_middle_filled = middle_length - num_null<EOL>middle_start = left_edge + num_null_left<EOL>result[sub_df.index, :left_edge] = fixed_length_sequences[<EOL>:, :left_edge<EOL>]<EOL>result[<EOL>sub_df.index,<EOL>middle_start : middle_start + num_middle_filled<EOL>] = fixed_length_sequences[<EOL>:, left_edge : left_edge + num_middle_filled<EOL>]<EOL>result[<EOL>sub_df.index,<EOL>-right_edge:<EOL>] = fixed_length_sequences[:, -right_edge:]<EOL><DEDENT>return result<EOL>
Transform a sequence of strings, where each string is of length at least
left_edge + right_edge and at most max_length into strings of length
max_length using a scheme designed to preserve the anchor positions of
class I peptides.

The first left_edge characters in the input always map to the first
left_edge characters in the output. Similarly for the last right_edge
characters. The middle characters are filled in based on the length,
with the X character filling in the blanks.

For example, using defaults:

AAAACDDDD -> AAAAXXXCXXXDDDD

The strings are also converted to int categorical amino acid indices.

Parameters
----------
sequence : string
left_edge : int
right_edge : int
max_length : int

Returns
-------
numpy array of shape (len(sequences), max_length) and dtype int