Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(2)  |  Derive(0)  |  Import(2)
It draws an ASCII histogram

        def draw_histogram(bin_limits, counts):
    'It draws an ASCII histogram'

    fill_char = '*'

    assert len(bin_limits) == len(counts) + 1
    # pylint: disable=W0108
    number_to_str = lambda n: '{:d}'.format(n) if isinstance(n, int) else '{:.2f}'.format(n)

    # we gather all bin limits and we calculate the longest number
    bin_start = None
    bin_end = bin_limits[0]
    max_ndigits = len(number_to_str(bin_end))
    max_count_ndigits = 0
    bins = []
    for bin_limit, cnt in zip(bin_limits[1:], counts):
        bin_start, bin_end = bin_end, bin_limit
        n_digits = len(number_to_str(bin_end))
        if max_ndigits < n_digits:
            max_ndigits = n_digits
        n_digits = len(number_to_str(cnt))
        if max_count_ndigits < n_digits:
            max_count_ndigits = n_digits
        bins.append((bin_start, bin_end))

    limit_fmt_int = '{:>' + str(max_ndigits) + 'd}'
    limit_fmt_float = '{:>' + str(max_ndigits) + '.5f}'
    limit_to_padded_str = lambda n: limit_fmt_int.format(n) if isinstance(n, int) else limit_fmt_float.format(n)

    count_fmt = '{:>' + str(max_count_ndigits) + 'd}'
    count_to_padded_str = lambda n: count_fmt.format(n)

    result = []
    for bin_, cnt in zip(bins, counts):
        line = ''
        line += '['
        line += limit_to_padded_str(bin_[0])
        line += ' , '
        line += limit_to_padded_str(bin_[1])
        line += '[ ('
        line += count_to_padded_str(cnt)
        line += '): '
        result.append(line)

    # pylint: disable=W0141
    max_count = max(counts)
    max_header_len = max(map(len, result))
    max_hist_width = get_setting('MAX_WIDTH_ASCII_PLOT') - max_header_len
    counts_ratio = max_hist_width / max_count

    result2 = []
    for line, cnt in zip(result, counts):
        line += fill_char * int(cnt * counts_ratio)
        line += '\n'
        result2.append(line)

    return ''.join(result2)
        


src/s/e/seq_crumbs-HEAD/crumbs/filters.py   seq_crumbs(Download)
from crumbs.exceptions import WrongFormatError
from crumbs.blast import Blaster, BlasterForFewSubjects
from crumbs.statistics import calculate_dust_score, IntCounter, draw_histogram
from crumbs.settings import get_setting
from crumbs.mapping import (get_or_create_bowtie2_index, map_with_bowtie2,
            counts = distribution['counts']
            bin_limits = distribution['bin_limits']
            print draw_histogram(bin_limits, counts)
 

src/s/e/seq_crumbs-HEAD/test/test_statistics.py   seq_crumbs(Download)
from Bio.Seq import Seq
 
from crumbs.statistics import (IntCounter, draw_histogram, IntBoxplot,
                               calculate_sequence_stats, NuclFreqsPlot,
                               KmerCounter, calculate_dust_score,
    def test_ascii_histogram(self):
        'It plots an ASCII histogram'
        hist = draw_histogram(bin_limits=[-2, -1, 0, 1, 2],
                              counts=[9, 20, 30, 40])
        assert '[-2 , -1[ ( 9): ****************' in hist