code: def reference_contexts_for_variant(
          variant,
          context_size,
          transcript_id_whitelist=None):
      
      overlapping_transcripts = reference_transcripts_for_variant(
          variant=variant,
          transcript_id_whitelist=transcript_id_whitelist)
  
      # dictionary mapping SequenceKeyWithReadingFrame keys to list of
      # transcript objects
      sequence_groups = defaultdict(list)
  
      for transcript in overlapping_transcripts:
          sequence_key_with_reading_frame = \
              ReferenceCodingSequenceKey.from_variant_and_transcript(
                  variant=variant,
                  transcript=transcript,
                  context_size=context_size)
          if sequence_key_with_reading_frame is not None:
              sequence_groups[sequence_key_with_reading_frame].append(transcript)
  
      reference_contexts = [
          ReferenceContext.from_reference_coding_sequence_key(
              key, variant, matching_transcripts)
          for (key, matching_transcripts) in sequence_groups.items()
      ]
      reference_contexts.sort(
          key=ReferenceContext.sort_key_decreasing_max_length_transcript_cds)
      return reference_contexts
docs: variant : varcode.Variant
  
      context_size : int
          Max of nucleotides to include to the left and right of the variant
          in the context sequence.
  
      transcript_id_whitelist : set, optional
          If given, then only consider transcripts whose IDs are in this set.
  
      Returns list of ReferenceContext objects, sorted by maximum length of
      coding sequence of any supporting transcripts.