<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 operator import attrgetter
from collections import OrderedDict


def represent_mutations(mutations, filter_manager):

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

    if source_name:
        get_source_data = attrgetter(Mutation.source_fields[source_name])

    get_mimp_data = attrgetter('meta_MIMP')

    data_filter = filter_manager.apply

    response = []

    for mutation in mutations:

        needle = represent_mutation(
            mutation,
            data_filter,
            representation_type=OrderedDict
        )

        needle['protein'] = mutation.protein.refseq
        needle['gene'] = mutation.protein.gene.name

        # place protein refseq id on the beginning
        needle.move_to_end('protein', last=False)
        needle.move_to_end('gene', last=False)

        needle['ptm_impact'] = mutation.impact_on_ptm(data_filter)

        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

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

        needle.move_to_end('sites')<commit_msg>Move the most complex entity (in_datasets) to the end #92<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 operator import attrgetter
from collections import OrderedDict


def represent_mutations(mutations, filter_manager):

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

    if source_name:
        get_source_data = attrgetter(Mutation.source_fields[source_name])

    get_mimp_data = attrgetter('meta_MIMP')

    data_filter = filter_manager.apply

    response = []

    for mutation in mutations:

        needle = represent_mutation(
            mutation,
            data_filter,
            representation_type=OrderedDict
        )

        needle['protein'] = mutation.protein.refseq
        needle['gene'] = mutation.protein.gene.name

        # place protein refseq id on the beginning
        needle.move_to_end('protein', last=False)
        needle.move_to_end('gene', last=False)

        needle['ptm_impact'] = mutation.impact_on_ptm(data_filter)

        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()

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

        needle.move_to_end('sites')

        needle['in_datasets'] = metadata
{'fraction_non_alphanumeric': 0.07825484764542937, 'fraction_numerical': 0.0004616805170821791, 'mean_word_length': 2.5928689883913765, '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': '7121424', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1203, 'n_words': 258}