/*
 *                      Nividic development code
 *
 * 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.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the cole Normale Suprieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

package fr.ens.transcriptome.nividic.om.io;

import java.io.IOException;
import java.io.InputStream;

import fr.ens.transcriptome.nividic.om.BioAssay;
import fr.ens.transcriptome.nividic.om.BioAssayUtils;

import junit.framework.TestCase;

public class ImaGeneOutputFileIOTest extends TestCase {

  public void testReader() throws NividicIOException, IOException {

    InputStream is1 = this.getClass().getResourceAsStream(
        "/files/imagene_1_1.txt");
    InputStream is2 = this.getClass().getResourceAsStream(
        "/files/imagene_1_2.txt");

    ImaGeneOutputFileReader igofr = new ImaGeneOutputFileReader(is1, is2);

    BioAssay ba = igofr.read();

    int[] locs = ba.getLocations();
    String[] ids = ba.getIds();
    int[] reds = ba.getReds();
    int[] greens = ba.getGreens();

    int last = locs.length - 1;

    assertNotNull(locs);
    assertNotNull(ids);
    assertNotNull(reds);
    assertNotNull(greens);
    
    
    assertEquals(1, BioAssayUtils.getMetaRow(locs[10]));
    assertEquals(1, BioAssayUtils.getMetaColumn(locs[10]));
    assertEquals(1, BioAssayUtils.getRow(locs[10]));
    assertEquals(11, BioAssayUtils.getColumn(locs[10]));

    assertEquals(4, BioAssayUtils.getMetaRow(locs[last]));
    assertEquals(8, BioAssayUtils.getMetaColumn(locs[last]));
    assertEquals(20, BioAssayUtils.getRow(locs[last]));
    assertEquals(21, BioAssayUtils.getColumn(locs[last]));

    assertEquals(875, greens[0]);
    assertEquals(3314, greens[10]);
    assertEquals(0, reds[0]);
    assertEquals(2268, reds[10]);

    assertEquals(4, BioAssayUtils.getMetaRow(locs[last]));
    assertEquals(8, BioAssayUtils.getMetaColumn(locs[last]));
    assertEquals(20, BioAssayUtils.getRow(locs[last]));
    assertEquals(21, BioAssayUtils.getColumn(locs[last]));

    assertEquals("NO_DATA 5BOV1A8 NO_DATA", ids[0]);
    assertEquals("NO_DATA 5BOV11M23 NO_DATA", ids[10]);
    assertEquals("", ids[last]);

    // 1 1 1 11 NO_DATA 5BOV11M23 NO_DATA 0 3915.3076923076924 (10)

    // 4 8 20 21 (13483)

    /*
     * for (int i = 0; i < locs.length; i++) { int mr =
     * BioAssayUtils.getMetaRow(locs[i]); int mc =
     * BioAssayUtils.getMetaColumn(locs[i]); int r =
     * BioAssayUtils.getRow(locs[i]); int c = BioAssayUtils.getColumn(locs[i]);
     * System.out.println(mr + "\t" + mc + "\t" + r + "\t" + c + "\t[" + locs[i] +
     * "]" + "\t" + ids[i] + "\t" + greens[i] + "\t" + reds[i]); }
     */

    is1.close();
    is2.close();

  }

}


@@ -733,49 +733,158 @@
 .io.
-IOException;%0Aimport java.io.InputStream;%0A
+File;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A%0Aimport fr.ens.transcriptome.nividic.om.AnnotationUtils;
 %0Aimp
@@ -982,16 +982,71 @@
 ayUtils;
+%0Aimport fr.ens.transcriptome.nividic.util.NividicUtils;
 %0A%0Aimport
@@ -1220,16 +1220,24 @@
 am is1 =
+%0A       
  this.ge
@@ -1261,33 +1261,24 @@
 rceAsStream(
-%0A        
 %22/files/imag
@@ -1313,16 +1313,24 @@
 am is2 =
+%0A       
  this.ge
@@ -1358,25 +1358,16 @@
 sStream(
-%0A        
 %22/files/
@@ -1491,24 +1491,85 @@
 fr.read();%0A%0A
+    // AnnotationUtils.printAnnotation(ba.getAnnotation());%0A%0A
     int%5B%5D lo
@@ -1825,25 +1825,16 @@
 reens);%0A
-    %0A    
 %0A    ass
@@ -3347,11 +3347,677 @@
 ;%0A%0A  %7D%0A%0A
+  public void testReadWrite() throws NividicIOException, IOException %7B%0A%0A    InputStream is1 =%0A        this.getClass().getResourceAsStream(%22/files/imagene_1_1.txt%22);%0A%0A    ImaGeneOutputFileReader igofr = new ImaGeneOutputFileReader(is1, %22%22);%0A%0A    igofr.addAllFieldsToRead();%0A    BioAssay ba = igofr.read();%0A%0A    File tmpFile = File.createTempFile(%22ImaGene%22, %22.txt%22);%0A%0A    ImaGeneOutputFileWriter aw = new ImaGeneOutputFileWriter(tmpFile);%0A%0A    aw.setBioAssay(ba);%0A    aw.addAllFieldsToWrite();%0A    aw.write(ba);%0A%0A    is1 = this.getClass().getResourceAsStream(%22/files/imagene_1_1.txt%22);%0A%0A    assertTrue(NividicUtils.compareFile(is1, new FileInputStream(tmpFile)));%0A%0A  %7D%0A
 %7D%0A
-%0A

Test if the ouput file is binary equals to input file