<commit_before>"""Manage optional GO-DAG attributes."""

__copyright__ = "Copyright (C) 2015-2018, <NAME>, <NAME>, All rights reserved."
__author__ = "<NAME>"

import re
import collections as cx


class OboOptionalAttrs(object):
    """Manage optional GO-DAG attributes."""

    def __init__(self, optional_attrs):
        assert optional_attrs
        self.optional_attrs = optional_attrs
        self.attr2cmp = self._init_compile_patterns(optional_attrs)

    def update_rec(self, rec, line):
        """Update current GOTerm with optional record."""
        if 'def' in self.optional_attrs and line[:5] == "def: ":
            assert not hasattr(rec, 'defn'), "ATTR(defn) ALREADY SET({VAL})".format(VAL=rec.defn)
            # Use 'defn' because 'def' is a reserved word in python
            rec.defn = line[5:]
        elif 'synonym' in self.optional_attrs and line[:9] == "synonym: ":
            rec.synonym.append(self._get_synonym(line[9:]))
        elif 'relationship' in self.optional_attrs and line[:14] == "relationship: ":
            # relationships are stored in a dict of sets, mirroring
            # the structure implied in the GO DAG. Example:
            #
            #  relationship = {
            #     'part_of': set(['GO:0021513', 'GO:0006310']),
            #     'regulates': set(['GO:0006313']),
            #     'negatively_regulates': set(['GO:0021910']),
            #     'positively_regulates': set(['GO:0006313']),
            # }
            rel, goid = line[14:].split()[:2]
            if rel not in rec.relationship:
                rec.relationship[rel] = set([goid])
            else:
                rec.relationship[rel].add(goid)
        elif 'xref' in self.optional_attrs and line[:6] == "xref: ":<commit_msg>Added set of relationships present in GO-DAG<commit_after>"""Manage optional GO-DAG attributes."""

__copyright__ = "Copyright (C) 2015-2018, <NAME>, <NAME>, All rights reserved."
__author__ = "<NAME>"

import re
import collections as cx


class OboOptionalAttrs(object):
    """Manage optional GO-DAG attributes."""

    relationships = set(['part_of', 'regulates', 'negatively_regulates', 'positively_regulates'])

    def __init__(self, optional_attrs):
        assert optional_attrs
        self.optional_attrs = optional_attrs
        self.attr2cmp = self._init_compile_patterns(optional_attrs)

    def update_rec(self, rec, line):
        """Update current GOTerm with optional record."""
        if 'def' in self.optional_attrs and line[:5] == "def: ":
            assert not hasattr(rec, 'defn'), "ATTR(defn) ALREADY SET({VAL})".format(VAL=rec.defn)
            # Use 'defn' because 'def' is a reserved word in python
            rec.defn = line[5:]
        elif 'synonym' in self.optional_attrs and line[:9] == "synonym: ":
            rec.synonym.append(self._get_synonym(line[9:]))
        elif 'relationship' in self.optional_attrs and line[:14] == "relationship: ":
            # relationships are stored in a dict of sets, mirroring
            # the structure implied in the GO DAG. Example:
            #
            #  relationship = {
            #     'part_of': set(['GO:0021513', 'GO:0006310']),
            #     'regulates': set(['GO:0006313']),
            #     'negatively_regulates': set(['GO:0021910']),
            #     'positively_regulates': set(['GO:0006313']),
            # }
            rel, goid = line[14:].split()[:2]
            if rel not in rec.relationship:
                rec.relationship[rel] = set([goid])
            else:
                rec.relationship[rel].add(goid)
        elif 'xref' in self.optional_attrs and line[:6] == "xref: ":
{'fraction_non_alphanumeric': 0.1374108612177729, 'fraction_numerical': 0.029621503017004936, 'mean_word_length': 2.5168756027000962, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 9, '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': '5204631', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1074, 'n_words': 277}