package org.intermine.bio.dataconversion;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import org.intermine.dataconversion.MockItemWriter;
import org.intermine.metadata.Model;

/*
 * Copyright (C) 2002-2009 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

public class ModEncodeMetaDataProcessorTest extends TestCase {
    ModEncodeMetaDataProcessor processor;
    
    public void setUp() throws Exception {
        MockItemWriter itemWriter =
            new MockItemWriter(new HashMap<String, org.intermine.model.fulldata.Item>());
        ChadoDBConverter converter =
            new ChadoDBConverter(null, Model.getInstanceByName("genomic"), itemWriter);
        processor = new ModEncodeMetaDataProcessor(converter);
        
    }
    
    public void testCorrectOfficialName() throws Exception {

        // actual examples from metadata
        assertEquals("Adult Female", processor.correctOfficialName("Adult_Female", "DevelopmentalStage"));
        assertEquals("Embryo 0-4 h", processor.correctOfficialName("E0-4h", "DevelopmentalStage"));
        assertEquals("Embryo 0-12 h", processor.correctOfficialName("Embryo 0-12h", "DevelopmentalStage"));
        assertEquals("Embryo 0-4 h", processor.correctOfficialName("E0-4", "DevelopmentalStage"));
        assertEquals("Embryo 2-4 h", processor.correctOfficialName("Embryo 2-4 hr", "DevelopmentalStage"));
        assertEquals("L1 stage larvae", processor.correctOfficialName("DevStage: L1 stage larvae", "DevelopmentalStage"));
        assertEquals("L1 stage larvae", processor.correctOfficialName("L1", "DevelopmentalStage"));
        assertEquals("White prepupae (WPP) + 12 h", processor.correctOfficialName("WPP + 12 h", "DevelopmentalStage"));
    }
    
    
    public void testInferExperimentType() throws Exception {
        String[] test = new String[] {"chromatin_immunoprecipitation", "dummy"};
        assertEquals("ChIP-seq", processor.inferExperimentType(makeProtocols(test)));
        
        test = new String[] {"chromatin_immunoprecipitation", "hybridization"};
        assertEquals("ChIP-chip", processor.inferExperimentType(makeProtocols(test)));
    
        test = new String[] {"nucleic_acid_extraction", "sequencing_protocol", "reverse_transcription"};
        assertEquals("RTPCR", processor.inferExperimentType(makeProtocols(test)));
        
        test = new String[] {"RNA extraction", "sequencing_protocol"};
        assertEquals("RNA-seq", processor.inferExperimentType(makeProtocols(test)));
        
        test = new String[] {"RNA extraction", "sequencing"};
        assertEquals("RNA-seq", processor.inferExperimentType(makeProtocols(test)));
        
        test = new String[] {"reverse_transcription", "PCR"};
        assertEquals("RTPCR", processor.inferExperimentType(makeProtocols(test)));
        
        test = new String[] {"reverse_transcription", "PCR_amplification", "RACE"};
        assertEquals("RACE", processor.inferExperimentType(makeProtocols(test)));
        
        test = new String[] {"hybridization"};
        assertEquals("RNA tiling array", processor.inferExperimentType(makeProtocols(test)));
        
        test = new String[] {"annotation"};
        assertEquals("Computational annotation", processor.inferExperimentType(makeProtocols(test)));
    
        test = new String[] {"grow"};
        assertEquals("RNA sample creation", processor.inferExperimentType(makeProtocols(test)));
    }
    
    private Set<String> makeProtocols(String[] types) {
        Set<String> protocolTypes = new HashSet<String>();
        for (String type : types) {
            protocolTypes.add(type);
        }
        return protocolTypes;
    }
}

@@ -1203,25 +1203,25 @@
 t_Female%22, %22
-D
+d
 evelopmental
@@ -1212,33 +1212,34 @@
 , %22developmental
-S
+ s
 tage%22));%0A       
@@ -1304,25 +1304,25 @@
 e(%22E0-4h%22, %22
-D
+d
 evelopmental
@@ -1313,33 +1313,34 @@
 , %22developmental
-S
+ s
 tage%22));%0A       
@@ -1413,25 +1413,25 @@
 yo 0-12h%22, %22
-D
+d
 evelopmental
@@ -1422,33 +1422,34 @@
 , %22developmental
-S
+ s
 tage%22));%0A       
@@ -1513,25 +1513,25 @@
 me(%22E0-4%22, %22
-D
+d
 evelopmental
@@ -1522,33 +1522,34 @@
 , %22developmental
-S
+ s
 tage%22));%0A       
@@ -1622,25 +1622,25 @@
 o 2-4 hr%22, %22
-D
+d
 evelopmental
@@ -1631,33 +1631,34 @@
 , %22developmental
-S
+ s
 tage%22));%0A       
@@ -1746,25 +1746,25 @@
 e larvae%22, %22
-D
+d
 evelopmental
@@ -1755,33 +1755,34 @@
 , %22developmental
-S
+ s
 tage%22));%0A       
@@ -1847,25 +1847,25 @@
 Name(%22L1%22, %22
-D
+d
 evelopmental
@@ -1856,33 +1856,34 @@
 , %22developmental
-S
+ s
 tage%22));%0A       
@@ -1972,17 +1972,17 @@
 12 h%22, %22
-D
+d
 evelopme
@@ -1985,17 +1985,18 @@
 opmental
-S
+ s
 tage%22));

Fix test.