<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def summary_permutation(context_counts, context_to_mut, seq_context, gene_seq, score_dir, num_permutations=10000, min_frac=0.0, min_recur=2, drop_silent=False):
 """Performs null-permutations and summarizes the results as features over the gene. Parameters context_counts : pd.Series number of mutations for each context context_to_mut : dict dictionary mapping nucleotide context to a list of observed somatic base changes. seq_context : SequenceContext Sequence context for the entire gene sequence (regardless of where mutations occur). The nucleotide contexts are identified at positions along the gene. gene_seq : GeneSequence Sequence of gene of interest num_permutations : int, default: 10000 number of permutations to create for null drop_silent : bool, default=False Flage on whether to drop all silent mutations. Some data sources do not report silent mutations, and the simulations should match this. Returns ------- summary_info_list : list of lists list of non-silent and silent mutation counts under the null along with information on recurrent missense counts and missense positional entropy. """

    mycontexts = context_counts.index.tolist()
    somatic_base = [base
                    for one_context in mycontexts
                    for base in context_to_mut[one_context]]

    # get random positions determined by sequence context
    tmp_contxt_pos = seq_context.random_pos(context_counts.iteritems(),
                                            num_permutations)
    tmp_mut_pos = np.hstack(pos_array for base, pos_array in tmp_contxt_pos)

    # determine result of random positions
    gene_name = gene_seq.bed.gene_name
    gene_len = gene_seq.bed.cds_len
    summary_info_list = []
    for i, row in enumerate(tmp_mut_pos):
        # get info about mutations
        tmp_mut_info = mc.get_aa_mut_info(row,
                                          somatic_base,
                                          gene_seq)

        # Get all metrics summarizing each gene
        tmp_summary = cutils.calc_summary_info(tmp_mut_info['Reference AA'],
                                               tmp_mut_info['Somatic AA'],
                                               tmp_mut_info['Codon Pos'],
                                               gene_name,
                                               score_dir,
                                               min_frac=min_frac,
                                               min_recur=min_recur)

        # drop silent if needed
        if drop_silent:
            # silent mutation count is index 1
            tmp_summary[1] = 0

        # limit the precision of floats
        #pos_ent = tmp_summary[-1]
        #tmp_summary[-1] = '{0:.5f}'.format(pos_ent)

        summary_info_list.append([gene_name, i+1, gene_len]+tmp_summary)
    return summary_info_list