Prepare a facet plot of frequencies stratified by variant type and status (TP, FP, FN).

    Makes a nice plot with the output from validate.freq_summary
9524
def facet_freq_plot(freq_csv, caller):
    
    out_file = "%s.png" % os.path.splitext(freq_csv)[0]
    plt.ioff()
    sns.set(style='dark')
    df = pd.read_csv(freq_csv)
    g = sns.FacetGrid(df, row="vtype", col="valclass", margin_titles=True,
                      col_order=["TP", "FN", "FP"], row_order=["snp", "indel"],
                      sharey=False)
    g.map(plt.hist, "freq", bins=20, align="left")
    g.set(xlim=(0.0, 1.0))
    g.fig.set_size_inches(8, 6)
    g.fig.text(.05, .97, caller, horizontalalignment='center', size=14)
    g.fig.savefig(out_file)
819020
def plot(ts, title=None, show=True):
    
    ts = _remove_pi_crossings(ts)
    fig = plt.figure()
    ylabelprops = dict(rotation=0, 
                       horizontalalignment='right', 
                       verticalalignment='center', 
                       x=-0.01)
    if ts.ndim > 2: # multiple sim timeseries. collapse vars onto each subplot.
        num_subplots = ts.shape[ts.ndim - 1]
        if title is None:
            title = u'time series at each node'
        for i in range(num_subplots):
            ax = fig.add_subplot(num_subplots, 1, i+1)
            ax.plot(ts.tspan, ts[...,i])
            if ts.labels[-1] is not None:
                ax.set_ylabel(ts.labels[-1][i], **ylabelprops)
            else:
                ax.set_ylabel('node ' + str(i), **ylabelprops)
            plt.setp(ax.get_xticklabels(), visible=False)
        fig.axes[0].set_title(title)
        plt.setp(fig.axes[num_subplots-1].get_xticklabels(), visible=True)
        fig.axes[num_subplots-1].set_xlabel('time (s)')
    else: # single sim timeseries. show each variable separately.
        if ts.ndim is 1:
            ts = ts.reshape((-1, 1))
        num_ax = ts.shape[1]
        if title is None:
            title=u'time series'
        axprops = dict()
        if num_ax > 10:
            axprops['yticks'] = []
        colors = _get_color_list()
        for i in range(num_ax):
            rect = 0.1, 0.85*(num_ax - i - 1)/num_ax + 0.1, 0.8, 0.85/num_ax
            ax = fig.add_axes(rect, **axprops)
            ax.plot(ts.tspan, ts[...,i], color=colors[i % len(colors)])
            plt.setp(ax.get_xticklabels(), visible=False)
            if ts.labels[1] is not None:
                ax.set_ylabel(ts.labels[1][i], **ylabelprops)
        fig.axes[0].set_title(title)
        plt.setp(fig.axes[num_ax-1].get_xticklabels(), visible=True)
        fig.axes[num_ax-1].set_xlabel('time (s)')
    if show:
        fig.show()
    return fig
1148990
def allelefreq(args):
    
    p = OptionParser(allelefreq.__doc__)
    p.add_option("--nopanels", default=False, action="store_true",
                 help="No panel labels A, B, ...")
    p.add_option("--usereport", help="Use allele frequency in report file")
    opts, args, iopts = p.set_image_options(args, figsize="9x13")

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

    loci, = args
    fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(ncols=2, nrows=3,
                                                 figsize=(iopts.w, iopts.h))
    plt.tight_layout(pad=4)
    if opts.usereport:
        treds, df = read_treds(tredsfile=opts.usereport)
    else:
        treds, df = read_treds()

    df = df.set_index(["abbreviation"])

    axes = (ax1, ax2, ax3, ax4, ax5, ax6)
    loci = loci.split(",")
    for ax, locus in zip(axes, loci):
        plot_allelefreq(ax, df, locus)

    # Delete unused axes
    for ax in axes[len(loci):]:
        ax.set_axis_off()

    root = fig.add_axes([0, 0, 1, 1])
    pad = .03
    if not opts.nopanels:
        panel_labels(root, ((pad / 2, 1 - pad, "A"), (.5 + pad, 1 - pad, "B"),
                        (pad / 2, 2 / 3. - pad / 2, "C"), (.5 + pad, 2 / 3. - pad / 2, "D"),
                        (pad / 2, 1 / 3. , "E"), (.5 + pad, 1 / 3. , "F"),
                        ))
    normalize_axes(root)

    image_name = "allelefreq." + iopts.format
    savefig(image_name, dpi=iopts.dpi, iopts=iopts)
1135732
def _decorate_axes(ax, freq, kwargs):
    """"""
    if not hasattr(ax, '_plot_data'):
        ax._plot_data = []

    ax.freq = freq
    xaxis = ax.get_xaxis()
    xaxis.freq = freq
    if not hasattr(ax, 'legendlabels'):
        ax.legendlabels = [kwargs.get('label', None)]
    else:
        ax.legendlabels.append(kwargs.get('label', None))
    ax.view_interval = None
    ax.date_axis_info = None
1311423
def get_term_category_frequencies(self, scatterchartdata):
		'''
		
		'''

		df = self.term_category_freq_df.rename(
			columns={c: c + ' freq' for c in self.term_category_freq_df}
		)
		df.index.name = 'term'
		return df
88638
def computeFrequencyOfSignificantSNPs(options):
    
    # The plink command
    plinkCommand = ["plink", "--noweb", "--bfile", options.bfile, "--extract",
                    options.out + ".significant_SNPs.txt", "--freq", "--out",
                    options.out + ".significant_SNPs"]
    runCommand(plinkCommand)

    # Reading the frequency file
    maf = {}
    with open(options.out + ".significant_SNPs.frq", "r") as i_file:
        header = {
            name: i for i, name in
            enumerate(createRowFromPlinkSpacedOutput(i_file.readline()))
        }
        for required_col in ("SNP", "MAF"):
            if required_col not in header:
                msg = "{}: missing column {}".format(
                    script_prefix + ".significant_SNPs.frq",
                    required_col,
                )
                raise ProgramError(msg)

        for line in i_file:
            row = createRowFromPlinkSpacedOutput(line)
            maf[row[header["SNP"]]] = row[header["MAF"]]

    return maf
825849
def FreqDist_chart (self):
        
        # Take a log of the data before plotting so that we can
        # reduce the number of points to plot evenly
        pdata = {}
        for idx, s_name in enumerate(self.tagdir_data['FreqDistribution']):
            pdata[s_name] = {}
            for x, y in self.tagdir_data['FreqDistribution'][s_name].items():
                try:
                    pdata[s_name][math.log(float(x))] = y
                except ValueError:
                    pass
        pconfig = {
            'id': 'FreqDistribution',
            'title': 'Frequency Distribution',
            'ylab': 'Fraction of Reads',
            'xlab': 'Log10(Distance between regions)',
            'data_labels': ['Reads', 'Percent'],
            'smooth_points': 500,
            'smooth_points_sumcounts': False,
            'yLog' : True
        }
        return linegraph.plot(pdata, pconfig)
537295
def parse_wrap_facets(facets):
    
    valid_forms = ['~ var1', '~ var1 + var2']
    error_msg = ("Valid formula for 'facet_wrap' look like"
                 " {}".format(valid_forms))

    if isinstance(facets, (list, tuple)):
        return facets

    if not isinstance(facets, str):
        raise PlotnineError(error_msg)

    if '~' in facets:
        variables_pattern = r'(\w+(?:\s*\+\s*\w+)*|\.)'
        pattern = r'\s*~\s*{0}\s*'.format(variables_pattern)
        match = re.match(pattern, facets)
        if not match:
            raise PlotnineError(error_msg)

        facets = [var.strip() for var in match.group(1).split('+')]
    elif re.match(r'\w+', facets):
        # allow plain string as the variable name
        facets = [facets]
    else:
        raise PlotnineError(error_msg)

    return facets
1140399
def plotSuccessRate_varyNumColumns(noiseSigma, noiseEverywhere):
  

  #
  # Run the experiment
  #
  noiseLevels = [x * 0.01 for x in xrange(0, 101, 5)]
  l2Overrides = {"sampleSizeDistal": 20}
  columnCounts = [1, 2, 3, 4]

  results = defaultdict(list)

  for trial in xrange(1):
    print "trial", trial
    objectDescriptions = createRandomObjectDescriptions(10, 10)

    for numColumns in columnCounts:
      print "numColumns", numColumns
      for noiseLevel in noiseLevels:
        r = doExperiment(numColumns, l2Overrides, objectDescriptions,
                         noiseLevel, noiseSigma, numInitialTraversals=6,
                         noiseEverywhere=noiseEverywhere)
        results[(numColumns, noiseLevel)].extend(r)

  #
  # Plot it
  #
  numCorrectActiveThreshold = 30
  numIncorrectActiveThreshold = 10

  plt.figure()
  colors = dict(zip(columnCounts,
                    ('r', 'k', 'g', 'b')))
  markers = dict(zip(columnCounts,
                     ('o', '*', 'D', 'x')))

  for numColumns in columnCounts:
    y = []
    for noiseLevel in noiseLevels:
      trials = results[(numColumns, noiseLevel)]
      numPassed = len([True for numCorrect, numIncorrect in trials
                       if numCorrect >= numCorrectActiveThreshold
                       and numIncorrect <= numIncorrectActiveThreshold])
      y.append(numPassed / float(len(trials)))

    plt.plot(noiseLevels, y,
             color=colors[numColumns],
             marker=markers[numColumns])

  lgnd = plt.legend(["%d columns" % numColumns
                     for numColumns in columnCounts],
                    bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.0)
  plt.xlabel("Mean feedforward noise level")
  plt.xticks([0.01 * n for n in xrange(0, 101, 10)])
  plt.ylabel("Success rate")
  plt.yticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
  plt.title("Inference with normally distributed noise (stdev=%.2f)" % noiseSigma)

  plotPath = os.path.join("plots",
                          "successRate_varyColumnCount_sigma%.2f_%s.pdf"
                          % (noiseSigma, time.strftime("%Y%m%d-%H%M%S")))
  plt.savefig(plotPath, bbox_extra_artists=(lgnd,), bbox_inches="tight")
  print "Saved file %s" % plotPath
223983
def compare_variants_label_plot(data):
    
    keys = OrderedDict()

    keys['total_called_variants_known'] = {'name': 'Known Variants'}
    keys['total_called_variants_novel'] = {'name': 'Novel Variants'}

    pconfig = {
        'id': 'picard_variantCallingMetrics_variant_label',
        'title': 'Picard: Variants Called',
        'ylab': 'Counts of Variants',
     }

    return bargraph.plot(data, cats=keys, pconfig=pconfig)
278513
def freq(args):
    
    p = OptionParser(freq.__doc__)
    p.add_option("--mindepth", default=3, type="int",
                 help="Minimum depth [default: %default]")
    p.add_option("--minqual", default=20, type="int",
                 help="Minimum quality [default: %default]")
    p.set_outfile()
    opts, args = p.parse_args(args)

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

    fastafile, bamfile = args
    cmd = "freebayes -f {0} --pooled-continuous {1}".format(fastafile, bamfile)
    cmd += " -F 0 -C {0}".format(opts.mindepth)
    cmd += ' | vcffilter -f "QUAL > {0}"'.format(opts.minqual)
    cmd += " | vcfkeepinfo - AO RO TYPE"
    sh(cmd, outfile=opts.outfile)
800107
def _read_truth_freqs(in_file):
    
    out = {}
    with VariantFile(in_file) as bcf_in:
        for rec in bcf_in:
            freq = float(rec.info.get("VAF", 1.0))
            out[_get_key(rec)] = freq
    return out
26367
def _get_chart_info(df, vtype, cat, prep, callers):
    
    maxval_raw = max(list(df["value.floor"]))
    curdf = df[(df["variant.type"] == vtype) & (df["category"] == cat)
               & (df["bamprep"] == prep)]
    vals = []
    labels = []
    for c in callers:
        row = curdf[df["caller"] == c]
        if len(row) > 0:
            vals.append(list(row["value.floor"])[0])
            labels.append(list(row["value"])[0])
        else:
            vals.append(1)
            labels.append("")
    return vals, labels, maxval_raw
90690
def plot(self, data):
    

    import IPython

    if not isinstance(data, dict) or not all(isinstance(v, pd.DataFrame) for v in data.values()):
      raise ValueError('Expect a dictionary where the values are all dataframes.')

    gfsg = GenericFeatureStatisticsGenerator()
    data = [{'name': k, 'table': self._remove_nonascii(v)} for k, v in six.iteritems(data)]
    data_proto = gfsg.ProtoFromDataFrames(data)
    protostr = base64.b64encode(data_proto.SerializeToString()).decode("utf-8")
    html_id = 'f' + datalab.utils.commands.Html.next_id()

    HTML_TEMPLATE = """<link rel="import" href="/nbextensions/gcpdatalab/extern/facets-jupyter.html" >
        <facets-overview id="{html_id}"></facets-overview>
        <script>
          document.querySelector("#{html_id}").protoInput = "{protostr}";
        </script>"""
    html = HTML_TEMPLATE.format(html_id=html_id, protostr=protostr)
    return IPython.core.display.HTML(html)
820509
def _call_variants(example_dir, region_bed, data, out_file):
    
    tf_out_file = "%s-tfrecord.gz" % utils.splitext_plus(out_file)[0]
    if not utils.file_exists(tf_out_file):
        with file_transaction(data, tf_out_file) as tx_out_file:
            model = "wes" if strelka2.coverage_interval_from_bed(region_bed) == "targeted" else "wgs"
            cmd = ["dv_call_variants.py", "--cores", dd.get_num_cores(data),
                   "--outfile", tx_out_file, "--examples", example_dir,
                   "--sample", dd.get_sample_name(data), "--model", model]
            do.run(cmd, "DeepVariant call_variants %s" % dd.get_sample_name(data))
    return tf_out_file
570881
function summariser(results) {
    var response = [],
        callback = function(output) {
            response.push(output);
        };

    var passed = 0;
    if (results.hasOwnProperty('passed')) {
        passed = countSpecs(results.passed);
    }
    var failed = 0;
    if (results.hasOwnProperty('failed')) {
        failed = countSpecs(results.failed);
    }
    var pending = 0;

    if (results.hasOwnProperty('pending')) {
        pending = countSpecs(results.pending);
    }
    var total = passed + failed + pending;

    coloriseOutput(total + ' Specs defined', 'bold', callback);
    if (total > 0) {
        coloriseOutput(passed + ' Passed' + displayPercentage(total, passed), 'green', callback);
        coloriseOutput(failed + ' Failed' + displayPercentage(total, failed), 'red', callback);
        coloriseOutput(pending + ' Pending' + displayPercentage(total, pending), 'yellow', callback);
    }
    return response;
}
246945
def plot_rpha(self, filename, pmin=None, pmax=None, title=None):
        
        cmap = mpl.cm.get_cmap('viridis')
        SM = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
        colors = SM.to_rgba(np.linspace(0, 1, len(self.objects)))
        fig, ax = plt.subplots(1, 1, figsize=(15 / 2.54, 15 / 2.54))
        for nr, item in enumerate(self.objects):
            ax.semilogx(
                item.frequencies,
                -item.rpha,
                '.-',
                color=colors[nr],
                label=self.labels[nr],
            )
        ax.set_xlim(*self.xlim)
        ax.set_ylabel(sip_labels.get_label('rpha', 'meas', 'mathml'))
        ax.set_xlabel('frequency [Hz]')
        ax.set_ylim(pmin, pmax)
        if title is not None:
            ax.set_title(title)
        self._add_legend(ax)
        fig.tight_layout()
        fig.subplots_adjust(bottom=0.5)
        fig.savefig(filename, dpi=300)
        plt.close(fig)