from ..migrator import upgrade_step
from .shared import ENCODE2_AWARDS


@upgrade_step('library', '', '3')
def library_0_3(value, system):
    # http://redmine.encodedcc.org/issues/1295
    # http://redmine.encodedcc.org/issues/1307

    if 'status' in value:
        if value['status'] == 'DELETED':
            value['status'] = 'deleted'
        elif value['status'] == 'CURRENT':
            if value['award'] in ENCODE2_AWARDS:
                value['status'] = 'released'
            elif value['award'] not in ENCODE2_AWARDS:
                value['status'] = 'in progress'


@upgrade_step('library', '3', '4')
def library_3_4(value, system):
    # http://redmine.encodedcc.org/issues/2784
    # http://redmine.encodedcc.org/issues/2560

    if 'paired_ended' in value:
        del value['paired_ended']

@@ -804,8 +804,2103 @@
 ended'%5D%0A
+%0A    covaris_generic = %5B%0A        'A combination of random priming and covaris shearing',%0A        'covaris sheering',%0A        'covarius'%0A        %5D%0A%0A    sonication_generic = %5B%0A        'probe in',%0A        'probe-in',%0A        'sonication'%0A    %5D%0A%0A    chemical_generic = %5B%0A        'magnesium-catalyzed hydrolysis',%0A        'chemical'%0A    %5D%0A%0A    tagmentation = %5B%0A        'Illumina/Nextera tagmentation',%0A        'Nextera Tagmentation'%0A    %5D%0A%0A    bioruptor_twin = %5B%0A        'biorupter twin',%0A        'bioruptor twin'%0A    %5D%0A%0A    if 'fragmentation_method' in value:%0A        if value%5B'fragmentation_method'%5D in covaris_generic:%0A            value%5B'fragmentation_method'%5D = 'shearing (Covaris generic)'%0A        elif value%5B'fragmentation_method'%5D == 'Bioruptor 300':%0A            value%5B'fragmentation_method'%5D = 'sonication (Bioruptor Plus)'%0A        elif value%5B'fragmentation_method'%5D == 'Covaris S2':%0A            value%5B'fragmentation_method'%5D = 'shearing (Covaris S2)'%0A        elif value%5B'fragmentation_method'%5D == 'Diagenode Bioruptor':%0A            value%5B'fragmentation_method'%5D = 'sonication (Bioruptor generic)'%0A        elif value%5B'fragmentation_method'%5D in tagmentation:%0A            value%5B'fragmentation_method'%5D = 'chemical (Nextera tagmentation)'%0A        elif value%5B'fragmentation_method'%5D == 'None':%0A            value%5B'fragmentation_method'%5D = 'none'%0A        elif value%5B'fragmentation_method'%5D in bioruptor_twin:%0A            value%5B'fragmentation_method'%5D = 'sonication (Bioruptor Twin)'%0A        elif value%5B'fragmentation_method'%5D in chemical_generic:%0A            value%5B'fragmentation_method'%5D = 'chemical (generic)'%0A        elif value%5B'fragmentation_method'%5D == 'chemical (part of Illumina TruSeq mRNA Kit)':%0A            value%5B'fragmentation_method'%5D = 'chemical (Illumina TruSeq)'%0A        elif value%5B'fragmentation_method'%5D == 'not applicable':%0A            value%5B'fragmentation_method'%5D = 'n/a'%0A        elif value%5B'fragmentation_method'%5D in sonication_generic:%0A            value%5B'fragmentation_method'%5D = 'sonication (generic)'%0A        else:%0A            value%5B'fragmentation_method'%5D = 'see document'%0A

Add upgrade for fragmentation_enum mapping