<commit_before>from ..schema_utils import (
    load_schema,
)
from ..contentbase import (
    location,
)
from .base import (
    ACCESSION_KEYS,
    ALIAS_KEYS,
    Collection,
    paths_filtered_by_status,
)
from pyramid.traversal import (
    find_resource,
    resource_path,
)


def lot_reviews(root, characterizations, targets):
    characterizations = paths_filtered_by_status(root, characterizations)

    if characterizations:
        compliant_secondary = False
        not_compliant_secondary = False
        pending_secondary = False
        not_reviewed_secondary = False
        has_lane_review = False
        not_reviewed = False
        histone_mod_target = False
        lab_not_reviewed_chars = 0
        not_reviewed_chars = 0
        in_progress_chars = 0
        total_characterizations = 0
        num_compliant_celltypes = 0
        organisms = []
        review_targets = []
        histone_organisms = []
        char_reviews = dict()
        primary_chars = []
        secondary_chars = []
        antibody_lot_reviews = []

        for characterization_path in characterizations:
            characterization = find_resource(root, characterization_path)
            target = find_resource(root, characterization.properties['target'])
            organism = find_resource(root, target.properties['organism'])

            if resource_path(target, '') not in review_targets:
                review_targets.append(resource_path(target, ''))

            if 'histone modification' in target.upgrade_properties(finalize=False)['investigated_as']:
                histone_mod_target = True

            if resource_path(organism, '') not in organisms:
                organisms.append(resource_path(organism, ''))

            if characterization.properties['status'] == 'deleted':
                continue
            elif characterization.properties['status'] == 'not submitted for review by lab':
                lab_not_reviewed_chars += 1
                total_characterizations += 1
            elif characterization.properties['status'] == 'not reviewed':
                not_reviewed_chars += 1
                total_characterizations += 1
            elif characterization.properties['status'] == 'in progress':
                in_progress_chars += 1
                total_characterizations += 1
            else:
                total_characterizations += 1

            # Split into primary and secondary to treat separately
            if 'primary_characterization_method' in characterization.properties:
                primary_chars.append(characterization)
            else:
                secondary_chars.append(characterization)

        base_review = {
            'biosample_term_name': 'not specified',
            'biosample_term_id': 'NTR:00000000',
            'organisms': organisms,
            'targets': review_targets,
            'status': 'awaiting lab characterization'
        }

        # Deal with the easy cases where both characterizations have the same statuses not from DCC reviews
        if lab_not_reviewed_chars == total_characterizations and total_characterizations > 0:
            base_review['status'] = 'not pursued'
            antibody_lot_reviews.append(base_review)
        elif not_reviewed_chars == total_characterizations and total_characterizations > 0:
            base_review['status'] = 'not eligible for new data'
            antibody_lot_reviews.append(base_review)
        elif in_progress_chars == total_characterizations and total_characterizations > 0:
            antibody_lot_reviews.append(base_review)
        elif (lab_not_reviewed_chars + not_reviewed_chars) == total_characterizations and total_characterizations > 0:
            antibody_lot_reviews.append(base_review)
        else:
            # Done with easy cases, the remaining require reviews.
            # Go through the secondary characterizations first
            for secondary in secondary_chars:
                if secondary.properties['status'] == 'compliant':
                    compliant_secondary = True
                    break
                elif secondary.properties['status'] == 'pending dcc review':
                    pending_secondary = True
                elif secondary.properties['status'] == 'not compliant':
                    not_compliant_secondary = True
                else:
                    not_reviewed_secondary = True
                    continue

            # Now check the primaries and update their status accordingly
            for primary in primary_chars:
                has_lane_review = False
                if primary.properties['status'] in ['deleted', 'not reviewed', 'not submitted for review by lab']:
                    not_reviewed = True
                    continue

                if 'characterization_reviews' in primary.properties:
                    for lane_review in primary.properties['characterization_reviews']:
                        new_review = {
                            'biosample_term_name': lane_review['biosample_term_name'],<commit_msg>No need to consider deleted characterizations as they are already filtered out.<commit_after>from ..schema_utils import (
    load_schema,
)
from ..contentbase import (
    location,
)
from .base import (
    ACCESSION_KEYS,
    ALIAS_KEYS,
    Collection,
    paths_filtered_by_status,
)
from pyramid.traversal import (
    find_resource,
    resource_path,
)


def lot_reviews(root, characterizations, targets):
    characterizations = paths_filtered_by_status(root, characterizations)

    if characterizations:
        compliant_secondary = False
        not_compliant_secondary = False
        pending_secondary = False
        not_reviewed_secondary = False
        has_lane_review = False
        not_reviewed = False
        histone_mod_target = False
        lab_not_reviewed_chars = 0
        not_reviewed_chars = 0
        in_progress_chars = 0
        total_characterizations = 0
        num_compliant_celltypes = 0
        organisms = []
        review_targets = []
        histone_organisms = []
        char_reviews = dict()
        primary_chars = []
        secondary_chars = []
        antibody_lot_reviews = []

        for characterization_path in characterizations:
            characterization = find_resource(root, characterization_path)
            target = find_resource(root, characterization.properties['target'])
            organism = find_resource(root, target.properties['organism'])

            if resource_path(target, '') not in review_targets:
                review_targets.append(resource_path(target, ''))

            if 'histone modification' in target.upgrade_properties(finalize=False)['investigated_as']:
                histone_mod_target = True

            if resource_path(organism, '') not in organisms:
                organisms.append(resource_path(organism, ''))

            if characterization.properties['status'] == 'not submitted for review by lab':
                lab_not_reviewed_chars += 1
                total_characterizations += 1
            elif characterization.properties['status'] == 'not reviewed':
                not_reviewed_chars += 1
                total_characterizations += 1
            elif characterization.properties['status'] == 'in progress':
                in_progress_chars += 1
                total_characterizations += 1
            else:
                total_characterizations += 1

            # Split into primary and secondary to treat separately
            if 'primary_characterization_method' in characterization.properties:
                primary_chars.append(characterization)
            else:
                secondary_chars.append(characterization)

        base_review = {
            'biosample_term_name': 'not specified',
            'biosample_term_id': 'NTR:00000000',
            'organisms': organisms,
            'targets': review_targets,
            'status': 'awaiting lab characterization'
        }

        # Deal with the easy cases where both characterizations have the same statuses not from DCC reviews
        if lab_not_reviewed_chars == total_characterizations and total_characterizations > 0:
            base_review['status'] = 'not pursued'
            antibody_lot_reviews.append(base_review)
        elif not_reviewed_chars == total_characterizations and total_characterizations > 0:
            base_review['status'] = 'not eligible for new data'
            antibody_lot_reviews.append(base_review)
        elif in_progress_chars == total_characterizations and total_characterizations > 0:
            antibody_lot_reviews.append(base_review)
        elif (lab_not_reviewed_chars + not_reviewed_chars) == total_characterizations and total_characterizations > 0:
            antibody_lot_reviews.append(base_review)
        else:
            # Done with easy cases, the remaining require reviews.
            # Go through the secondary characterizations first
            for secondary in secondary_chars:
                if secondary.properties['status'] == 'compliant':
                    compliant_secondary = True
                    break
                elif secondary.properties['status'] == 'pending dcc review':
                    pending_secondary = True
                elif secondary.properties['status'] == 'not compliant':
                    not_compliant_secondary = True
                else:
                    not_reviewed_secondary = True
                    continue

            # Now check the primaries and update their status accordingly
            for primary in primary_chars:
                has_lane_review = False
                if primary.properties['status'] in ['not reviewed', 'not submitted for review by lab']:
                    not_reviewed = True
                    continue

                if 'characterization_reviews' in primary.properties:
                    for lane_review in primary.properties['characterization_reviews']:
                        new_review = {
                            'biosample_term_name': lane_review['biosample_term_name'],
{'fraction_non_alphanumeric': 0.06882230792049837, 'fraction_numerical': 0.004746366063482646, 'mean_word_length': 2.1945672773215414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '952627', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2343, 'n_words': 593}