How to use the funcy.walk_values function in funcy

To help you get started, we’ve selected a few funcy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github idrdex / star-django / legacy / management / commands / fill_probes.py View on Github external
"""Queries mygene.info for current entrezid and sym, given an identifier."""
    if scopes == "dna":
        probes = get_dna_probes(platform, probes)
        scopes = "accession"

    def extract_queries(lines):
        lines = remove(r'^(IMAGE:\d+|--[\w>-]+)$', lines)
        queries = cat(re_iter(r'[\w+.-]+', l) for l in lines)
        queries = remove(r'_at$|^\d+-\d+$', queries)  # No such thing
        return queries
        # Clean unicode for mygene
        # http://stackoverflow.com/questions/15321138/removing-unicode-u2026-like-characters
        return [q.decode('unicode_escape').encode('ascii', 'ignore') for q in queries]

    _by_probe = group_values(probes.items())
    queries_by_probe = walk_values(extract_queries, _by_probe)

    # Collect all possible queries to make a single request to mygene
    queries = set(cat(queries_by_probe.values()))

    if not queries:
        return []
    mygenes = _mygene_fetch(queries, scopes, platform.specie)

    # Form results into rows
    results = []
    dups = 0
    for probe, queries in queries_by_probe.items():
        matches = ldistinct(keep(mygenes.get, queries))
        # Skip dups
        if len(matches) > 1:
            dups += 1
github idrdex / star-django / core / management / commands / initialize_historical_counters.py View on Github external
def distribute_series_and_sample_annotations(qs):
    series_annotations = distribute_by_created_on(qs)
    values = qs.values_list('created_on', 'samples')
    group = group_values(walk_keys(ceil_date, values.iterator()))
    return series_annotations, accumulate(walk_values(sum, group))
github idrdex / star-django / core / management / commands / initialize_historical_counters.py View on Github external
'series_tag_history': get_series_tag_history(),
        }

        data = {
            'users': users,
            'tags': tags,
        }

        with transaction.atomic():
            HistoricalCounter.objects.filter(created_on__lte=CURRENT_DATE).delete()
            HistoricalCounter.objects.bulk_create([
                HistoricalCounter(
                    created_on=key,
                    counters=merge(
                        walk_values(get_value(keys, index), data),
                        walk_values(lambda value:
                                    walk_values(get_value(keys, index), value),
                                    specie_data)))
                for index, key in enumerate(keys)])
github idrdex / star-django / core / management / commands / initialize_historical_counters.py View on Github external
def distribute_by_user_id(qs):
    data = group_values(qs.values_list('created_by_id', 'created_on'))
    return walk_values(lambda dates: accumulate(count_by(ceil_date, dates)), data)
github idrdex / star-django / djapi / __init__.py View on Github external
def values(self, *fields, **expressions):
            """
            Extended version supporting renames:
                .values('id', 'name', author__name='author')
            """
            renames = select_values(isa(six.string_types), expressions)
            if not renames:
                return base.values(self, *fields, **expressions)
            elif django.VERSION >= (1, 11):
                rename_expressions = walk_values(F, renames)
                expressions.update(rename_expressions)
                return base.values(self, *fields, **expressions)
            else:
                f_to_name = flip(renames)
                rename = lambda d: {f_to_name.get(k, k): v for k, v in d.items()}
                return base.values(self, *chain(fields, f_to_name)).map(rename)
github idrdex / star-django / core / management / commands / initialize_historical_counters.py View on Github external
walk_values(lambda value:
                                    walk_values(get_value(keys, index), value),
                                    specie_data)))
github idrdex / star-django / core / management / commands / initialize_historical_counters.py View on Github external
validations = list(tag.validations.all())
        series_tag_history['created'][ceil_date(tag.created_on)] += 1
        validated = silent(min)(
            v.created_on
            for v in validations
            if v.annotation_kappa == 1)
        if validated:
            series_tag_history['validated'][ceil_date(validated)] += 1
            invalidated = silent(min)(
                v.created_on
                for v in validations
                if v.agrees_with is not None)
            if invalidated:
                series_tag_history['invalidated'][ceil_date(invalidated)] += 1

    return walk_values(accumulate, series_tag_history)