<commit_before>from flask import request
from flask_classful import FlaskView
from flask import jsonify
from models import Mutation
from website.helpers.filters import FilterManager
from website.views._global_filters import common_filters
from website.views._commons import get_genomic_muts
from website.views._commons import get_protein_muts
from website.views._commons import represent_mutation
from website.views._commons import get_source_field
from operator import attrgetter


def represent_mutations(mutations, filter_manager):

    source_name = filter_manager.get_value('Mutation.sources')

    if source_name:
        source_field_name = get_source_field(source_name)
        get_source_data = attrgetter(source_field_name)

    get_mimp_data = attrgetter('meta_MIMP')

    data_filter = filter_manager.apply

    response = []

    for mutation in mutations:

        needle = represent_mutation(mutation, data_filter)

        closest_sites = mutation.find_closest_sites(
            site_filter=data_filter
        )
        needle['closest_sites'] = [
            '%s %s' % (site.position, site.residue)
            for site in closest_sites
        ]

        if source_name:
            field = get_source_data(mutation)
            metadata = {
                source_name: field.to_json(data_filter)
            }
            needle['summary'] = field.summary
            needle['value'] = field.get_value(data_filter)

        else:
            metadata = {
                name: field.to_json(data_filter)
                for name, field in mutation.sources_dict
            }

        mimp = get_mimp_data(mutation)

        if mimp:
            metadata['MIMP'] = mimp.to_json()

        needle['in_datasets'] = metadata
        needle['protein'] = mutation.protein.refseq
        needle['ptm_impact'] = mutation.impact_on_ptm(data_filter)

        response.append(needle)

    return response


class ChromosomeView(FlaskView):

    def _make_filters(self):
        filters = common_filters(default_source=None, source_nullable=False)
        filter_manager = FilterManager(filters)
        filter_manager.update_from_request(request)
        return filters, filter_manager

    def mutation(self, chrom, dna_pos, dna_ref, dna_alt):<commit_msg>Fix: add items() for directory iteration<commit_after>from flask import request
from flask_classful import FlaskView
from flask import jsonify
from models import Mutation
from website.helpers.filters import FilterManager
from website.views._global_filters import common_filters
from website.views._commons import get_genomic_muts
from website.views._commons import get_protein_muts
from website.views._commons import represent_mutation
from website.views._commons import get_source_field
from operator import attrgetter


def represent_mutations(mutations, filter_manager):

    source_name = filter_manager.get_value('Mutation.sources')

    if source_name:
        source_field_name = get_source_field(source_name)
        get_source_data = attrgetter(source_field_name)

    get_mimp_data = attrgetter('meta_MIMP')

    data_filter = filter_manager.apply

    response = []

    for mutation in mutations:

        needle = represent_mutation(mutation, data_filter)

        closest_sites = mutation.find_closest_sites(
            site_filter=data_filter
        )
        needle['closest_sites'] = [
            '%s %s' % (site.position, site.residue)
            for site in closest_sites
        ]

        if source_name:
            field = get_source_data(mutation)
            metadata = {
                source_name: field.to_json(data_filter)
            }
            needle['summary'] = field.summary
            needle['value'] = field.get_value(data_filter)

        else:
            metadata = {
                name: field.to_json(data_filter)
                for name, field in mutation.sources_dict.items()
            }

        mimp = get_mimp_data(mutation)

        if mimp:
            metadata['MIMP'] = mimp.to_json()

        needle['in_datasets'] = metadata
        needle['protein'] = mutation.protein.refseq
        needle['ptm_impact'] = mutation.impact_on_ptm(data_filter)

        response.append(needle)

    return response


class ChromosomeView(FlaskView):

    def _make_filters(self):
        filters = common_filters(default_source=None, source_nullable=False)
        filter_manager = FilterManager(filters)
        filter_manager.update_from_request(request)
        return filters, filter_manager

    def mutation(self, chrom, dna_pos, dna_ref, dna_alt):
{'fraction_non_alphanumeric': 0.07397680017509302, 'fraction_numerical': 0.0, 'mean_word_length': 2.9160239931448158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5973773', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1276, 'n_words': 270}