Project: s41467-025-60789-z | Function: run_maund (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Main MAUND algorithm for comprehensive base editing analysis from NGS data. Processes FASTQ files, aligns reads to reference sequence, identifies base editing events, calculates editing frequencies per position, and generates detailed mutation statistics. Implements complete bioinformatics pipeline for base editor characterization.

**KEY TERMS:** {
  "seq_wt": "wild-type reference sequence",
  "RGEN_seq": "CRISPR guide RNA sequence",
  "mismatch_cutoff": "alignment quality threshold",
  "mutation_ratio": "base editing efficiency",
  "nt_target": "target nucleotide for editing (C)",
  "window": "editing window for analysis"
}

**CONTEXT CODE:** 
from pathlib import Path


import pandas as pd
import numpy as np
import Levenshtein as ed


write_to_tsv = lambda df, output : df.to_csv(output,header=False,index=False,sep='\t')
toCharArray = lambda seq : np.array([seq]).astype('S').view('S1')

trans=str.maketrans("ATGC", "TACG")
revertedSeq = lambda seq : seq.translate(trans)[::-1]

def mismatch(seq1,seq2):
    n = min(len(seq1),len(seq2))
    m = max(len(seq1),len(seq2))
    mismatch = np.sum(toCharArray(seq1[:n])!=toCharArray(seq2[:n]))
    return mismatch + m-n

def matchUpto1(target, seq):
    # MASKED: Performs sequence alignment with up to 1 mismatch tolerance using half-length subsequence matching and position validation implementation
    raise NotImplementedError("This function is masked for testing purposes.")



def countPerLocation2(df_target_regions, s_seq, len_rgen):
    zero = lambda nt : {'targetRegion':nt*len(s_seq), 'n_seq':0}
    df_reads = df_target_regions[['targetRegion','n_seq']].append([zero('A'),zero('C'),zero('G'),zero('T')], ignore_index=True)

    df_sseq = pd.DataFrame(np.array([s_seq]).astype('S%d'%len_rgen).view('int8'))
    df = pd.DataFrame(df_reads.targetRegion.astype('S%d'%len_rgen).values.view('int8').reshape(-1,len_rgen))
    df.index = df_reads.index
    #df2 : idx nc n_seq
    df2 = df.stack().reset_index(level=1).merge(df_reads[['n_seq']],left_index=True,right_index=True)
    df2.columns = ['idx', 'nc', 'n_seq']
    df3 = pd.pivot_table(df2, values='n_seq', index=['idx'], columns=['nc'], aggfunc=np.sum, fill_value=0)
    df_subst = df3.unstack().drop(list(zip(*[df_sseq[0],df_sseq.index])), errors='ignore').groupby(level=1).sum()
    df_count = pd.concat([df3,df_subst],axis=1)
    return df_count

def countPerLocation(df_reads, is_rev_match, s_seq, rgen_cridx_beg, rgen_cridx_end, len_rgen):
    a = rgen_cridx_beg
    b = rgen_cridx_end
    df = df_reads.copy()
    df['targetRegion'] = df_reads.seq.str.slice(a,b)    
    return countPerLocation2(df, s_seq, len_rgen)


def run_maund(args, logger):
    # MASKED: Comprehensive base editing analysis pipeline including FASTQ processing, sequence alignment, mutation analysis, and statistical reporting implementation
    raise NotImplementedError("This function is masked for testing purposes.")




Complete the function implementation replacing "raise NotImplementedError".