<commit_before>"""init.py lists all the collections that do not have a dedicated types file."""

from snovault.attachment import ItemWithAttachment
from snovault.crud_views import collection_add as sno_collection_add
from snovault import (
    # calculated_property,
    collection,
    load_schema,
    CONNECTION
)
# from pyramid.traversal import find_root
from .base import (
    Item,
    set_namekey_from_title
)


def includeme(config):
    """include me method."""
    config.scan()


@collection(
    name='analysis-steps',
    unique_key='analysis_step:name',
    properties={
        'title': 'AnalysisSteps',
        'description': 'Listing of analysis steps for 4DN analyses',
    })
class AnalysisStep(Item):
    """The AnalysisStep class that descrbes a step in a workflow."""

    item_type = 'analysis_step'
    schema = load_schema('encoded:schemas/analysis_step.json')
    embedded_list = Item.embedded_list + ['software_used.*', 'qa_stats_generated.*']


@collection(
    name='biosample-cell-cultures',
    properties={
        'title': 'Biosample Cell Culture Information',
        'description': 'Listing Biosample Cell Culture Information',
    })
class BiosampleCellCulture(Item):
    """Cell culture details for Biosample."""

    item_type = 'biosample_cell_culture'
    schema = load_schema('encoded:schemas/biosample_cell_culture.json')


@collection(
    name='constructs',
    properties={
        'title': 'Constructs',
        'description': 'Listing of Constructs',
    })
class Construct(Item):
    """Construct class."""

    item_type = 'construct'
    schema = load_schema('encoded:schemas/construct.json')


@collection(
    name='documents',
    properties={
        'title': 'Documents',
        'description': 'Listing of Documents',
    })
class Document(ItemWithAttachment, Item):
    """Document class."""

    item_type = 'document'
    schema = load_schema('encoded:schemas/document.json')

    def display_title(self):
        if self.properties.get('attachment'):
            attach = self.properties['attachment']
            if attach.get('download'):
                return attach['download']


@collection(
    name='enzymes',
    unique_key='enzyme:name',
    properties={
        'title': 'Enzymes',
        'description': 'Listing of enzymes',
    })
class Enzyme(Item):
    """Enzyme class."""

    item_type = 'enzyme'
    schema = load_schema('encoded:schemas/enzyme.json')
    name_key = 'name'
    embedded_list = Item.embedded_list + ['enzyme_source.title']


@collection(
    name='experiment-types',
    unique_key='experiment_type:experiment_name',
    properties={
        'title': 'Experiment Types',
        'description': 'Listing of experiment types for 4DN items',
    })
class ExperimentType(Item):
    """The ExperimentType class that descrbes an experiment type that can be associated with an experiment."""

    item_type = 'experiment_type'
    schema = load_schema('encoded:schemas/experiment_type.json')
    name_key = 'experiment_name'
    rev = {
        'additional_protocols': ('Protocol', 'experiment_type')
    }
    embedded_list = [
        "static_headers.content",
        "static_headers.title",
        "static_headers.filetype",
        "static_headers.section_type",
        "static_headers.options.default_open",
        "static_headers.options.title_icon"
        ]

    def _update(self, properties, sheets=None):
        # set name based on what is entered into title
        properties['experiment_name'] = set_namekey_from_title(properties)

        static_keys = ['processed_files', 'assay_description', 'data_analysis']
        if len([properties[key] for key in static_keys if properties.get(key)]) > 0:
            headers = [properties.get('assay_description'), properties.get('processed_files')]
            headers += properties.get('data_analysis', [])
            properties['static_headers'] = [header for header in headers if header]

        super(ExperimentType, self)._update(properties, sheets)


@collection(
    name='file-formats',
    unique_key='file_format:file_format',
    lookup_key='file_format',
    properties={
        'title': 'File Formats',
        'description': 'Listing of file formats used by 4DN'
    }
)
class FileFormat(Item, ItemWithAttachment):
    """The class to store information about 4DN file formats"""
    item_type = 'file_format'
    schema = load_schema('encoded:schemas/file_format.json')
    name_key = 'file_format'

    def display_title(self):
        return self.properties.get('file_format')


@collection(
    name='genomic-regions',
    properties={<commit_msg>Edits to ExperimentType collection info in types/__init__.py<commit_after>"""init.py lists all the collections that do not have a dedicated types file."""

from snovault.attachment import ItemWithAttachment
from snovault.crud_views import collection_add as sno_collection_add
from snovault import (
    calculated_property,
    collection,
    load_schema,
    CONNECTION
)
# from pyramid.traversal import find_root
from .base import (
    Item,
    set_namekey_from_title
)


def includeme(config):
    """include me method."""
    config.scan()


@collection(
    name='analysis-steps',
    unique_key='analysis_step:name',
    properties={
        'title': 'AnalysisSteps',
        'description': 'Listing of analysis steps for 4DN analyses',
    })
class AnalysisStep(Item):
    """The AnalysisStep class that descrbes a step in a workflow."""

    item_type = 'analysis_step'
    schema = load_schema('encoded:schemas/analysis_step.json')
    embedded_list = Item.embedded_list + ['software_used.*', 'qa_stats_generated.*']


@collection(
    name='biosample-cell-cultures',
    properties={
        'title': 'Biosample Cell Culture Information',
        'description': 'Listing Biosample Cell Culture Information',
    })
class BiosampleCellCulture(Item):
    """Cell culture details for Biosample."""

    item_type = 'biosample_cell_culture'
    schema = load_schema('encoded:schemas/biosample_cell_culture.json')


@collection(
    name='constructs',
    properties={
        'title': 'Constructs',
        'description': 'Listing of Constructs',
    })
class Construct(Item):
    """Construct class."""

    item_type = 'construct'
    schema = load_schema('encoded:schemas/construct.json')


@collection(
    name='documents',
    properties={
        'title': 'Documents',
        'description': 'Listing of Documents',
    })
class Document(ItemWithAttachment, Item):
    """Document class."""

    item_type = 'document'
    schema = load_schema('encoded:schemas/document.json')

    def display_title(self):
        if self.properties.get('attachment'):
            attach = self.properties['attachment']
            if attach.get('download'):
                return attach['download']


@collection(
    name='enzymes',
    unique_key='enzyme:name',
    properties={
        'title': 'Enzymes',
        'description': 'Listing of enzymes',
    })
class Enzyme(Item):
    """Enzyme class."""

    item_type = 'enzyme'
    schema = load_schema('encoded:schemas/enzyme.json')
    name_key = 'name'
    embedded_list = Item.embedded_list + ['enzyme_source.title']


@collection(
    name='experiment-types',
    unique_key='experiment_type:experiment_name',
    properties={
        'title': 'Experiment Types',
        'description': 'Listing of experiment types for 4DN items',
    })
class ExperimentType(Item):
    """The ExperimentType class that descrbes an experiment type that can be associated with an experiment."""

    item_type = 'experiment_type'
    schema = load_schema('encoded:schemas/experiment_type.json')
    name_key = 'experiment_name'
    rev = {
        'additional_protocols': ('Protocol', 'experiment_type')
    }

    @calculated_property(schema={
        "title": "Other Protocols",
        "description": "Other protocols associated with this experiment type besides the SOP",
        "type": "string",
        "linkTo": "Protocol"
    })
    def other_protocols(self, request, sop=None):
        protocol_paths = self.rev_link_atids(request, 'additional_protocols')
        protocols = [request.embed('/', path, '@@object') for path in protocol_paths if path != sop]
        if protocols:
            return protocols

    def _update(self, properties, sheets=None):
        # set name based on what is entered into title
        properties['experiment_name'] = set_namekey_from_title(properties)
        super(ExperimentType, self)._update(properties, sheets)


@collection(
    name='file-formats',
    unique_key='file_format:file_format',
    lookup_key='file_format',
    properties={
        'title': 'File Formats',
        'description': 'Listing of file formats used by 4DN'
    }
)
class FileFormat(Item, ItemWithAttachment):
    """The class to store information about 4DN file formats"""
    item_type = 'file_format'
    schema = load_schema('encoded:schemas/file_format.json')
    name_key = 'file_format'

    def display_title(self):
        return self.properties.get('file_format')


@collection(
    name='genomic-regions',
    properties={
{'fraction_non_alphanumeric': 0.12018861717293564, 'fraction_numerical': 0.0009869503235003837, 'mean_word_length': 3.5260545905707197, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2109396', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2555, 'n_words': 625}