def evidences(args):
    """
    %prog evidences

    Plot distribution of evidences against two factors:
    - Sample mean coverage
    - Longer allele
    """
    p = OptionParser(evidences.__doc__)
    p.add_option("--csv", default="hli.20170328.tred.tsv",
                 help="TRED csv output to plot")
    opts, args, iopts = p.set_image_options(args, format="pdf")

    if len(args) != 0:
        sys.exit(not p.print_help())

    format = iopts.format

    # Extract sample coverage first
    df = pd.read_csv("qc-export-MeanCoverage.csv", header=None,
                     names=["Samplekey", "MeanCoverage"], index_col=0)

    # Find coverage for HD
    xf = pd.read_csv(opts.csv, sep="\t", index_col=0)
    dp = {}
    tred = "HD"
    for sk, row in xf.iterrows():
        sk = str(sk)
        a1 = row[tred + ".1"]
        a2 = row[tred + ".2"]
        fdp = row[tred + ".FDP"]
        pdp = row[tred + ".PDP"]
        pedp = row[tred + ".PEDP"]
        dp[sk] = (a1, a2, fdp, pdp, pedp)

    # Build a consolidated dataframe
    ef = pd.DataFrame.from_dict(dp, orient="index")
    ef.columns = [tred + ".1", tred + ".2", tred + ".FDP",
                  tred + ".PDP", tred + ".PEDP"]
    ef.index.name = "SampleKey"
    mf = df.merge(ef, how="right", left_index=True, right_index=True)

    # Plot a bunch of figures
    outdir = "output"
    mkdir(outdir)
    xlim = ylim = (0, 100)
    draw_jointplot(outdir + "/A", "MeanCoverage", "HD.FDP",
                   data=mf, xlim=xlim, ylim=ylim, format=format)
    draw_jointplot(outdir + "/B", "MeanCoverage", "HD.PDP",
                   data=mf, color='g', xlim=xlim, ylim=ylim, format=format)
    draw_jointplot(outdir + "/C", "MeanCoverage", "HD.PEDP",
                   data=mf, color='m', xlim=xlim, ylim=ylim, format=format)

    xlim = (0, 50)
    draw_jointplot(outdir + "/D", "HD.2", "HD.FDP",
                   data=mf, xlim=xlim, ylim=ylim, format=format)
    draw_jointplot(outdir + "/E", "HD.2", "HD.PDP",
                   data=mf, color='g', xlim=xlim, ylim=ylim, format=format)
    draw_jointplot(outdir + "/F", "HD.2", "HD.PEDP",
                   data=mf, color='m', xlim=xlim, ylim=ylim, format=format)
def evidences ( args ) : p = OptionParser ( evidences . __doc__ ) p . add_option ( "--csv" , default = "hli.20170328.tred.tsv" , help = "TRED csv output to plot" ) opts , args , iopts = p . set_image_options ( args , format = "pdf" ) if len ( args ) != 0 : sys . exit ( not p . print_help ( ) ) format = iopts . format df = pd . read_csv ( "qc-export-MeanCoverage.csv" , header = None , names = [ "Samplekey" , "MeanCoverage" ] , index_col = 0 ) xf = pd . read_csv ( opts . csv , sep = "\t" , index_col = 0 ) dp = { } tred = "HD" for sk , row in xf . iterrows ( ) : sk = str ( sk ) a1 = row [ tred + ".1" ] a2 = row [ tred + ".2" ] fdp = row [ tred + ".FDP" ] pdp = row [ tred + ".PDP" ] pedp = row [ tred + ".PEDP" ] dp [ sk ] = ( a1 , a2 , fdp , pdp , pedp ) ef = pd . DataFrame . from_dict ( dp , orient = "index" ) ef . columns = [ tred + ".1" , tred + ".2" , tred + ".FDP" , tred + ".PDP" , tred + ".PEDP" ] ef . index . name = "SampleKey" mf = df . merge ( ef , how = "right" , left_index = True , right_index = True ) outdir = "output" mkdir ( outdir ) xlim = ylim = ( 0 , 100 ) draw_jointplot ( outdir + "/A" , "MeanCoverage" , "HD.FDP" , data = mf , xlim = xlim , ylim = ylim , format = format ) draw_jointplot ( outdir + "/B" , "MeanCoverage" , "HD.PDP" , data = mf , color = 'g' , xlim = xlim , ylim = ylim , format = format ) draw_jointplot ( outdir + "/C" , "MeanCoverage" , "HD.PEDP" , data = mf , color = 'm' , xlim = xlim , ylim = ylim , format = format ) xlim = ( 0 , 50 ) draw_jointplot ( outdir + "/D" , "HD.2" , "HD.FDP" , data = mf , xlim = xlim , ylim = ylim , format = format ) draw_jointplot ( outdir + "/E" , "HD.2" , "HD.PDP" , data = mf , color = 'g' , xlim = xlim , ylim = ylim , format = format ) draw_jointplot ( outdir + "/F" , "HD.2" , "HD.PEDP" , data = mf , color = 'm' , xlim = xlim , ylim = ylim , format = format )
%prog evidences

    Plot distribution of evidences against two factors:
    - Sample mean coverage
    - Longer allele