The genome of any living organism includes a succession of genes and non-coding fragments. These genes code for the proteins that perform a vast array of functions that control the cells that make up the organism. Genes may be oriented forward or backward, and we make the simplified assumption here that they never overlap. In between two successive genes there might be fragments that do not code for proteins. These non-coding fragments are sometimes also called junk DNA. Genome fragments can be represented in two different ways: graphical or symbolic. A genome fragment can be graphically represented in the following way:

According to these rules, the string ----==>--<===--<==|===>---- is the graphical representation of a genome fragment with a forward gene, followed by two successive backward genes and another forward gene. All genes are separated in this example by non-coding fragments, except for the last two genes. Because the last two genes are an example of the case described as the last item in the above list, a vertical bar must be included in between their graphical representation.

In the symbolic representation of a genome fragment, each gene or non-coding fragment is given as a code that is composed of a letter followed by a number. The letter indicates the type of the fragment (see table below) and the number gives the length of the fragment. As such, the code F4 describes a forward gene of length four, B1 a backward gene of length one, and N3 a non-coding fragment of length three. The codes for all successive fragments of the genome fragment are then concatenated into a single string. According to these rules, the genome fragment that was given above in its graphical representation, can be represented symbolically as N4F3N2B4N2B3F4N4.

fragment letter example graphical
forward gene F F4 ===>
backward gene B B1 <
non-coding fragment N N3 ---

 

Assignment

  1. Write a function code2graph, that translates a given code as used in the symbolic representation of a genome fragment into its corresponding graphical representation. A code must be passed as an argument to the function, and the function must return the corresponding graphical representation as a result. As such, if the code B3 is passed as an argument the function must return the string <==.

  2. Use the function code2graph to write a function symb2graph. A symbolic representation of a genome fragment must be passed as an argument to this function. As such, if the string N4F3N2B4N2B3F4N4 is passed as an argument the function must return the string ----==>--<===--<==|===>----.

  3. Write a function graph2symb. A graphical representation of a genome fragment must be passed as an argument to this function. The function must return the corresponding symbolic representation of the genome fragment as its result. As such, if the string ----==>--<===--<==|===>---- is passed as an argument the function must return the string N4F3N2B4N2B3F4N4.

Example

>>> code2graph('F4')
'===>'
>>> code2graph('B3')
'<=='

>>> symb2graph('N4F3N2B4N2B3F4N4')
'----==>--<===--<==|===>----'
>>> symb2graph('N2F4N2F4N2F4N2')
'--===>--===>--===>--'
>>> symb2graph('B1F1B1F1B1F1B1F1')
'<><><><>'
>>> symb2graph('B2F2B2F2B2F2B2F2')
'<=|=><=|=><=|=><=|=>'
>>> symb2graph('B2F1B1F2B2F1B1F2')
'<=|><|=><=|><|=>'

>>> graph2symb('----==>--<===--<==|===>----')
'N4F3N2B4N2B3F4N4'
>>> graph2symb('--===>--===>--===>--')
'N2F4N2F4N2F4N2'
>>> graph2symb('<><><><>')
'B1F1B1F1B1F1B1F1'
>>> graph2symb('<=|=><=|=><=|=><=|=>')
'B2F2B2F2B2F2B2F2'
>>> graph2symb('<=|><|=><=|><|=>')
'B2F1B1F2B2F1B1F2'