code: def mitosomatic(args):
      
      import pandas as pd
  
      p = OptionParser(mitosomatic.__doc__)
      p.add_option("--minaf", default=.005, type="float",
                   help="Minimum allele fraction")
      p.add_option("--maxaf", default=.1, type="float",
                   help="Maximum allele fraction")
      opts, args = p.parse_args(args)
  
      if len(args) != 1:
          sys.exit(not p.print_help())
  
      df, = args
      af_file = df.rsplit(".", 1)[0] + ".af"
      fw = open(af_file, "w")
      df = pd.read_csv(df, sep="\t")
      for i, row in df.iterrows():
          na = row["num_A"]
          nt = row["num_T"]
          nc = row["num_C"]
          ng = row["num_G"]
          nd = row["num_D"]
          ni = row["num_I"]
          depth = row["depth"]
          #major, minor = sorted([na, nt, nc, ng], reverse=True)[:2]
          #af = minor * 1. / (major + minor)
          af = (nd + ni) * 1. / depth
          if not (opts.minaf <= af <= opts.maxaf):
              continue
          print("{}\t{}\t{:.6f}".format(row["chrom"], row["start"], af), file=fw)
      fw.close()
  
      logging.debug("Allele freq written to `{}`".format(af_file))
docs: %prog mitosomatic t.piledriver
  
      Find mito mosaic somatic mutations in piledriver results.