PROG0242 - Blood types

no tags 

In the 19th century, blood transfusions were a very risky undertaking. Patients could of course survive the procedure, but the number of deaths was extremely high. For this reason, blood transfusions were only carried out in cases of extreme loss of blood, if there were no other possibilities to save the life of the patient. In 1900, Austrian scientist Karl Landsteiner discovered the reason for the high number of deaths. There are namely different blood groups and when mixed, the red blood cells could clump together. Landsteiner received the Nobel prize in 1930 for Physiology and Medicine. By taking a sample of blood from donor and recipient before a transfusion and comparing the blood groups, blood transfusions became a lifesaving procedure.

bloedgroep

Every person's blood contains two markers that are called ABO alleles. Each of these markers is represented by one of the following letters: A, B or O. This way, each person can have one of six combinations of alleles, that result in a certain ABO blood group for this person as given in the table below.

crossing ABO blood group
A and A A
A and B AB
A and O A
B and B B
B and O B
O and O O

Completely analogous, every person's blood contains two alleles for the Rhesus factor. This Rhesus factor is represented by the characters + and -. A person that is Rhesus positive, has at least one + allele but can also have two. A person that is Rhesus negative, always has two - alleles. This is illustrated in the table below.

crossing Rhesus factor
+ and + +
+ and - +
- and - -

A person's blood group is determined by the combination of the ABO blood group and the Rhesus factor. This blood group is written as the letter combination of the ABO blood group, followed by the plus or minus that represents the Rhesus factor. E.g. A+, AB- and O-.

Bloodgroups are inherited: every biological parent gives one ABO allel (randomly chosen of out the two) and one rhesus allele to his/her child. For example, assume that both parents of a child have bloodgroup A-, then the child can either have bloodgroup A- or bloodgroup O-. A child with parents with bloodgroup A+ and B+ can have any possible bloodgroup.

Assignment

For this assignment you get the blood groups of two parents or those of a parent and his or her child. Based on this data you must determine the (possibly empty) collection of all possible blood groups a child or another parent can have.

  • Write a function bloodgroupChild to which two strings must be given as an argument. These respectively represent the blood group of the father and mother. The function must print a collection (of strings) as a result, containing all possible blood groups of the children of those parents. 
  • Write a function bloodgroupParent to which two strings must be given as an argument. These respectively represent the blood groups of one parent and its child. As a result, the function must print a collection (of strings) that contain all possible blood groups of the second parent of the child. Note that the collection of blood groups can also be empty in this case.

Note: For this problem, the uppercase letter O is used for the notation of blood groups, not the digit 0 (zero).

Example

>>> bloodgroupChild('O+', 'O-')
{'O+', 'O-'}
>>> bloodgroupChild('O-', 'O-')
{'O-'}
>>> bloodgroupChild('AB-', 'AB+')
{'A+', 'A-', 'AB+', 'AB-', 'B+', 'B-'}

>>> bloodgroupParent('O+', 'O-')
{'A-', 'A+', 'B-', 'B+', 'O-', 'O+'}
>>> bloodgroupParent('AB+', 'O+')
set()

In de 19e eeuw waren bloedtransfusies een zeer riskante onderneming. Patiënten konden de ingreep weliswaar overleven, maar het aantal sterfgevallen lag bijzonder hoog. Om die reden werden bloedtransfusies enkel en alleen maar uitgevoerd bij zeer ernstig bloedverlies, als er geen andere mogelijkheden meer waren om het leven van de patiënt te redden. In 1900 ontdekte de Oostenrijkse wetenschapper Karl Landsteiner de oorzaak voor het grote aantal sterfgevallen. Er bestaan namelijk verschillende bloedgroepen en door de vermenging ervan kunnen rode bloedcellen aan elkaar klonteren. Landsteiner ontving in 1930 de Nobelprijs voor Fysiologie en Geneeskunde voor zijn werk. Door voorafgaand aan bloedtransfusies een monster bloed van donor en ontvanger te vermengen en zo de bloedgroep te vergelijken, werden bloedtransfusies een levensreddende ingreep.

bloedgroep

Het bloed van elke persoon heeft twee merkers die ABO allelen genoemd worden. Elk van deze merkers wordt voorgesteld door één van drie letters: A, B of O. Hierdoor kan elke persoon één van zes mogelijke combinaties van deze allelen hebben, die elk resulteren in een bepaalde ABO bloedgroep voor deze persoon zoals aangegeven in onderstaande tabel.

kruising ABO bloedgroep
A en A A
A en B AB
A en O A
B en B B
B en O B
O en O O

Volledig analoog heeft het bloed van elke persoon twee allelen voor de rhesusfactor. Deze rhesusfactor wordt voorgesteld door de karakters + en -. Een persoon die rhesuspositief is, heeft ten minste één + allel maar kan er ook twee hebben. Iemand die rhesusnegatief is, heeft altijd twee - allelen. Dit wordt geïllustreerd in onderstaande tabel.

kruising rhesusfactor
+ en + +
+ en - +
- en - -

De bloedgroep van een persoon wordt bepaald door de combinatie van de ABO bloedgroep en de rhesusfactor. Deze bloedgroep wordt genoteerd door de lettercombinatie van de ABO bloedgroep te laten volgen door een plus- of minteken dat de rhesusfactor voorstelt. Voorbeelden zijn A+, AB- en O-.

Bloedgroepen worden overgeërfd: elke biologische ouder geeft één ABO allel (willekeurig gekozen uit de twee aanwezige allelen) en één rhesusallel door aan zijn of haar kind. Op die manier bepalen de 2 ABO allelen en 2 rhesusallelen van de ouders de bloedgroep van het kind. Stel bijvoorbeeld dat beide ouders van een kind bloedgroep A- hebben, dan kan het kind ofwel bloedgroep A- of bloedgroep O- hebben. Een kind met ouders die bloedgroep A+ en B+ hebben kan elke mogelijke bloedgroep hebben.

Opgave

Bij deze opgave krijg je telkens de bloedgroep van beide ouders of van één ouder en zijn of haar kind. Op basis van deze gegevens moet je de (mogelijk lege) verzameling bepalen van alle mogelijke bloedgroepen die het kind of de andere ouder kan hebben.

  • Schrijf een functie bloedgroepKind waaraan twee strings als argument moeten doorgegeven worden. Deze stellen respectievelijk de bloedgroep van een vader en van een moeder voor. De functie moet als resultaat een verzameling (van strings) teruggeven die alle mogelijke bloedgroepen bevat die kinderen van deze twee ouders kunnen hebben.
  • Schrijf een functie bloedgroepOuder waaraan twee strings als argument moeten doorgegeven worden. Deze stellen respectievelijk de bloedgroep van een ouder en één van diens kinderen voor. De functie moet als resultaat een verzameling (van strings) teruggeven die alle mogelijke bloedgroepen bevat die de andere ouder van het kind kan hebben. Merk op dat in dit geval de verzameling bloedgroepen ook leeg kan zijn.

Opmerking: Bij dit probleem wordt de hoofdletter O gebruikt in de notatie van bloedgroepen, en niet het cijfer 0 (nul).

Voorbeeld

>>> bloedgroepKind('O+', 'O-')
{'O+', 'O-'}
>>> bloedgroepKind('O-', 'O-')
{'O-'}
>>> bloedgroepKind('AB-', 'AB+')
{'A+', 'A-', 'AB+', 'AB-', 'B+', 'B-'}

>>> bloedgroepOuder('O+', 'O-')
{'A-', 'A+', 'B-', 'B+', 'O-', 'O+'}
>>> bloedgroepOuder('AB+', 'O+')
set()


Added by:Peter Dawyndt
Date:2012-03-30
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None