def deduplicate(pairs, aa=False, ignore_primer_regions=False):
nr_pairs = []<EOL>just_pairs = [p for p in pairs if p.is_pair]<EOL>single_chains = [p for p in pairs if not p.is_pair]<EOL>_pairs = just_pairs + single_chains<EOL>for p in _pairs:<EOL><INDENT>duplicates = []<EOL>for nr in nr_pairs:<EOL><INDENT>identical = True<EOL>vdj = '<STR_LIT>' if aa else '<STR_LIT>'<EOL>offset = <NUM_LIT:4> if aa else <NUM_LIT:12><EOL>if p.heavy is not None:<EOL><INDENT>if nr.heavy is None:<EOL><INDENT>identical = False<EOL><DEDENT>else:<EOL><INDENT>heavy = p.heavy[vdj][offset:-offset] if ignore_primer_regions else p.heavy[vdj]<EOL>nr_heavy = nr.heavy[vdj][offset:-offset] if ignore_primer_regions else nr.heavy[vdj]<EOL>if heavy != nr_heavy:<EOL><INDENT>identical = False<EOL><DEDENT><DEDENT><DEDENT>if p.light is not None:<EOL><INDENT>if nr.light is None:<EOL><INDENT>identical = False<EOL><DEDENT>else:<EOL><INDENT>light = p.light[vdj][offset:-offset] if ignore_primer_regions else p.light[vdj]<EOL>nr_light = nr.light[vdj][offset:-offset] if ignore_primer_regions else nr.light[vdj]<EOL>if light != nr_light:<EOL><INDENT>identical = False<EOL><DEDENT><DEDENT><DEDENT>duplicates.append(identical)<EOL><DEDENT>if any(duplicates):<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>nr_pairs.append(p)<EOL><DEDENT><DEDENT>return nr_pairs<EOL>
Removes duplicate sequences from a list of Pair objects.

If a Pair has heavy and light chains, both chains must identically match heavy and light chains
from another Pair to be considered a duplicate. If a Pair has only a single chain,
identical matches to that chain will cause the single chain Pair to be considered a duplicate,
even if the comparison Pair has both chains.

Note that identical sequences are identified by simple string comparison, so sequences of
different length that are identical over the entirety of the shorter sequence are not
considered duplicates.

By default, comparison is made on the nucleotide sequence. To use the amino acid sequence instead,
set aa=True.