The immune system protects organisms from infection with layered defenses of increasing specificity. In simple terms, physical barriers prevent pathogens such as bacteria and viruses from entering the organism. If a pathogen breaches these barriers, the innate immune system provides an immediate, but non-specific response. Innate immune systems are found in all plants and animals. If pathogens successfully evade the innate response, vertebrates possess a second layer of protection, the adaptive immune system, which is activated by the innate response. Here, the immune system adapts its response during an infection to improve its recognition of the pathogen. This improved response is then retained after the pathogen has been eliminated, in the form of an immunological memory, and allows the adaptive immune system to mount faster and stronger attacks each time this pathogen is encountered.
Define a class Organism that can be used to represent organisms that have a simplified model of an immune system. This immune system has both innate and adaptive properties that protect the organism against viruses — other kinds of pathogens are ignored in this exercise for the sake of simplicity. A certain type of virus is represented in this model as an integer. The innate component of the immune system protects the organism against a given series of virus types. In addition, over time the adaptive component of the immune system can make the organism resistant for other virus types. The latter happens if sufficient antibodies for a particular virus type have been formed. When a certain type of virus mutates, the organism looses its resistance (both innate and adaptive) against the old form of the virus, and if necessary, should start making new antibodies against the new form of the virus. The class Organism must support at least the following methods:
An initialization method that can be used to create a new organism that initially has no antibodies in its adaptive component of the immune system. The method has an optional parameter to which the location of a text file can be passed. This text file contains the list of viruses (a list of integers, each on a separate line) the organism is protected against by its innate immune system. If no text file is passed during the initialization of a new organism, then the immune system of the organism has no innate component.
A method isresistant that takes a virus (an integer) as an argument for the parameter virus. This method must return a Boolean value that indicates whether or not the organism is resistant against the given virus type. The organism is resistant if it is protected against the virus by its innate immune system, or else the adaptive component of the immune system comes into play. In the latter case, the adaptive immune system first creates a new antibody against the virus type for which resistance is tested. The adaptive component of the immune system then only protects the organism against a virus type if it has at least three antibodies for that virus.
A method mutation that takes a virus (an integer) as an argument for the parameter virus. If this method is called, the immune system of the organism looses any form of resistance (both innate and adaptive) against (the old form of) the virus. Later on, the organism can become resistant against (the new form of) the virus if it has created a sufficient amount of new antibodies (by calling the method isresistant).
In the following interactive session we assume that the text file immune_system.txt3 is located in the current directory. This file has five lines containing the integers 1, 2, 3, 4 and 5.
>>> organism = Organism('immune_system.txt4')
>>> organism.isresistant(1)
True
>>> organism.isresistant(88)
False
>>> organism.isresistant(virus=99)
False
>>> organism.isresistant(2)
True
>>> organism.isresistant(virus=99)
False
>>> organism.isresistant(virus=99)
True
>>> organism.isresistant(virus=99)
True
>>> organism.mutation(virus=1)
>>> organism.isresistant(virus=1)
False
>>> organism.isresistant(virus=1)
False
>>> organism.isresistant(virus=1)
True
>>> organism.mutation(virus=99)
>>> organism.isresistant(virus=99)
False
>>> organism.isresistant(virus=99)
False
>>> organism.isresistant(virus=99)
True