<commit_before>import random
import sys

class BioMolecule(object):
    """
    A generic molecule that has basic attributes like id, name and
    mass.

    @type id: int
    @type name: str
    @type mass: float
    """
    def __init__(self, id, name, mass=None):
        self._id = id
        self.name = name
        self.mass = mass

    # 1. Write setter and getter methods for all attributes.
    #    Use @property decorators as dicussed in the lecture
    # 2. In the setter methods check for the type of each attribute.

class Polymer(BioMolecule):
    """
    A polymer molecule that has a sequence attribute which is
    accessible via indexing the object. 

    @type id: int
    @type name: str
    @type sequence: str
    @type mass: float
    """
    def __init__(self, id, name, sequence, mass=None):
        # 3. Initialize the parent class correctly
        self._sequence = sequence

    
    # 4. Write getter and setter for sequence, again check for type
    # 5. run in ipython, instantiate this class, and test it
    def __getitem__(self, value):
        """
        Makes the sequence accessible via the indexing operators:
<        p[10] returns the tenth character in the sequence.
        """
        return self.sequence[value]

    def __setitem__(self, key, value):
        """
         Enables changing of sequence characters via the indexing operators.       
        """
        self.sequence[key] = value


class MRNA(Polymer):
    def __init__(self, id, name, sequence, mass=None):
        # 6. Initialize the parent class correctly

        # 7. Create a list that stores if a ribosome is bound for each
        # codon (triplet).
        self.binding = [] # use this attribute for 7.

    def calculate_mass(self):
        NA_mass = {'A': 1.0, 'U': 2.2, 'G':2.1, 'C':1.3}
        # 8. calculate the mass for the whole sequence

class Protein(Polymer):
    """Protein with Polymer features and mass calculation. A global class
    attribute counts the number of proteins that have been instantiated.
    
    A protein can be elongated using the "+" operator:
    
    >> protein = Protein(1, "prot", "MVFT")
    >> protein + "A"
    >> protein.sequence
    MVFTA

    <commit_msg>Codon<commit_after>import random
import sys

class BioMolecule(object):
    """
    A generic molecule that has basic attributes like id, name and
    mass.

    @type id: int
    @type name: str
    @type mass: float
    """
    def __init__(self, id, name, mass=None):
        self._id = id
        self.name = name
        self.mass = mass

    @property 
    def mass(self):
        return self.__mass

    @mass.setter 
    def mass(self, value):
        if not isinstance(value, float):
            raise TypeError("Mass must be Float.")
        self.__mass = value

    @property 
    def name(self):
        return self.__name

    @name.setter
    def name(self, word):
        if not isinstance(word, str):
            raise TypeError("Name must be String.")
        self.__name = word

    @property 
    def _id(self):
        return self.__id

    @_id.setter
    def _id(self, number):
        if not isinstance(number, int):
            raise TypeError("ID must be Integer.")
        self.__id = number
    # 1. Write setter and getter methods for all attributes.
    #    Use @property decorators as dicussed in the lecture
    # 2. In the setter methods check for the type of each attribute.

class Polymer(BioMolecule):
    """
    A polymer molecule that has a sequence attribute which is
    accessible via indexing the object. 

    @type id: int
    @type name: str
    @type sequence: str
    @type mass: float
    """
    def __init__(self, _id, name, sequence, mass=0.0):
        # 3. Initialize the parent class correctly
        # None durch 0.0 ersetzt, weil None ist kein Float
        self._sequence = sequence
        super(Polymer, self).__init__(_id, name, mass)
    
    # 4. Write getter and setter for sequence, again check for type
    @property
    def sequence(self):
        return self.__sequence

    @sequence.setter
    def sequence(self, seq):
        if not isinstance(seq, str):
            raise TypeError("Sequence must be String.")
        self.__sequence = seq


    # 5. run in ipython, instantiate this class, and test it
    def __getitem__(self, value):
        """
        Makes the sequence accessible via the indexing operators:
<        p[10] returns the tenth character in the sequence.
        """
        return self.sequence[value]

    def __setitem__(self, key, value):
        """
         Enables changing of sequence characters via the indexing operators.       
        """
        self.sequence[key] = value


class MRNA(Polymer):
    def __init__(self, _id, name, sequence, mass=0.0):
        super(MRNA, self).__init__(_id, name, sequence, mass)
        # 6. Initialize the parent class correctly

        # 7. Create a list that stores if a ribosome is bound for each
        # codon (triplet).
        #self.binding = xrange[0:len(sequence)/3] # use this attribute for 7. 0 nicht gebunden
        #for codon in self.binding:
            


        UUUUAUUUUUGA
    def calculate_mass(self):
        NA_mass = {'A': 1.0, 'U': 2.2, 'G':2.1, 'C':1.3}
        # 8. calculate the mass for the whole sequence

class Protein(Polymer):
    """Protein with Polymer features and mass calculation. A global class
    attribute counts the number of proteins that have been instantiated.
    
    A protein can be elongated using the "+" operator:
    
    >> protein = Protein(1, "prot", "MVFT")
    >> protein + "A"
    >> protein.sequence
    MVFTA

    
{'fraction_non_alphanumeric': 0.09010287335934729, 'fraction_numerical': 0.008691025186236254, 'mean_word_length': 2.2784883720930234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '1666645', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1561, 'n_words': 621}