package baseCode.bio.geneset;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

import junit.framework.TestCase;

/**
 * <hr>
 * <p>
 * Copyright (c) 2004-2005 Columbia University
 * 
 * @author pavlidis
 * @version $Id$
 */
public class TestGeneAnnotations extends TestCase {

    InputStream is;
    List probes;
    List geneIds;
    List goIds;

    /*
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
        probes = new ArrayList();
        probes.add( "a" );
        probes.add( "b" );
        probes.add( "c" );
        geneIds = new ArrayList();
        geneIds.add( "aGene" );
        geneIds.add( "bGene" );
        geneIds.add( "cGene" );
        goIds = new ArrayList();
        goIds.add( new HashSet() );
        goIds.add( new HashSet() );
        goIds.add( new HashSet() );

        ( ( Collection ) goIds.get( 0 ) ).add( "1" );
        ( ( Collection ) goIds.get( 1 ) ).add( "1" );
        ( ( Collection ) goIds.get( 2 ) ).add( "1" );
        ( ( Collection ) goIds.get( 0 ) ).add( "2" );
        ( ( Collection ) goIds.get( 1 ) ).add( "2" );
        // ( ( Collection ) goIds.get( 2 ) ).add( "2" );
        is = TestGeneAnnotations.class.getResourceAsStream( "/data/HG-U133_Plus_2_annot_sample.csv" );
        if ( is == null ) throw new IllegalStateException();
    }

    /*
     * @see TestCase#tearDown()
     */
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public final void testReadAffyCsv() throws Exception {
        GeneAnnotations ga = new GeneAnnotations();
        ga.readAffyCsv( is, null );
        ga.setUp( null );
        List geneSets = new ArrayList( ga.getGeneSetToGeneMap().keySet() );
        Collections.sort( geneSets );
        assertTrue( geneSets.size() > 0 );
    }

    public void testGeneAnnotationsApiA() throws Exception {
        GeneAnnotations val = new GeneAnnotations( probes, geneIds, null, goIds );
        int actualValue = val.numGenes();
        int expectedValue = 3;
        assertEquals( expectedValue, actualValue );
    }

    public void testGeneAnnotationsApiB() throws Exception {
        GeneAnnotations val = new GeneAnnotations( probes, geneIds, null, goIds );
        int actualValue = val.numProbesForGene( "aGene" );
        int expectedValue = 1;
        assertEquals( expectedValue, actualValue );
    }

    public void testGeneAnnotationsApiC() throws Exception {
        GeneAnnotations val = new GeneAnnotations( probes, geneIds, null, goIds );
        int actualValue = ( ( Collection ) val.getGeneToGeneSetMap().get( "aGene" ) ).size();
        int expectedValue = 2;
        assertEquals( expectedValue, actualValue );
    }

}

@@ -407,16 +407,36 @@
 eam is;%0A
+    InputStream im;%0A
     List
@@ -444,16 +444,16 @@
 probes;%0A
-
     List
@@ -1406,24 +1406,121 @@
 ple.csv%22 );%0A
+        im = TestGeneAnnotations.class.getResourceAsStream( %22/data/geneAnnotation.sample.txt%22 );%0A
         if (
@@ -2844,24 +2844,24 @@
 ) ).size();%0A
-
         int 
@@ -2938,10 +2938,332 @@
 %0A    %7D%0A%0A
+    public void testReadDescription() throws Exception %7B%0A        GeneAnnotations ga = new GeneAnnotations();%0A        ga.read( im, null );%0A        String actualValue = ga.getProbeDescription( %2232304_at%22 );%0A        String expectedValue = %22protein kinase C, alpha%22;%0A        assertEquals( expectedValue, actualValue );%0A    %7D%0A%0A
 %7D%0A

test for pasing of gene descriptions