/*
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

package org.broad.igv.feature.tribble;

import org.broad.igv.AbstractHeadlessTest;
import org.broad.igv.feature.BasicFeature;
import org.broad.igv.feature.FeatureCodecParser;
import org.broad.igv.feature.tribble.reader.TribbleFeatureReader;
import org.broad.igv.track.GFFFeatureSource;
import org.broad.igv.track.TribbleFeatureSource;
import org.broad.igv.util.ResourceLocator;
import org.broad.igv.util.TestUtils;
import org.broad.tribble.Feature;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Iterator;
import java.util.List;

import static junit.framework.Assert.assertEquals;

/**
 * User: jacob
 * Date: 2013-Mar-21
 */
public class GFFCodecTest extends AbstractHeadlessTest {

    /**
     * Make sure we parse the attributes to get the name of this feature
     * GTF has a bunch of different ones
     *
     * @throws Exception
     */
    @Test
    public void testGetNameGTF() throws Exception {
        String path = TestUtils.DATA_DIR + "gtf/transcript_id.gtf";
        String expName = "YAL069W";

        GFFFeatureSource src = new GFFFeatureSource(TribbleFeatureSource.getFeatureSource(new ResourceLocator(path), null));

        Iterator<Feature> iter = src.getFeatures("I", 0, Integer.MAX_VALUE);
        while (iter.hasNext()) {
            BasicFeature bf = (BasicFeature) iter.next();
            assertEquals(expName, bf.getName());
        }

    }

    /**
     * Insure we can parse a GFF file that includes a fasta section.
     *
     * @throws Exception
     */
    @Test
    public void testGFFWithFasta() throws Exception {

        String path = TestUtils.DATA_DIR + "gff/gffWithFasta.gff";
        final ResourceLocator locator = new ResourceLocator(path);
        TribbleFeatureReader reader = new TribbleFeatureReader(locator, CodecFactory.getCodec(locator, null));

        int featureCount = 0;
        Iterator<Feature> iter = reader.iterator();
        while (iter.hasNext()) {
            BasicFeature bf = (BasicFeature) iter.next();
            featureCount++;
        }
        assertEquals(20, featureCount);

    }
}

@@ -693,23 +693,21 @@
 igv.
-feature
+track
 .Feature
 Code
@@ -706,85 +706,14 @@
 ture
-CodecParser;%0Aimport org.broad.igv.feature.tribble.reader.TribbleFeatureReader
+Source
 ;%0Aim
@@ -958,102 +958,21 @@
 ava.
-io.BufferedReader;%0Aimport java.io.FileReader;%0Aimport java.util.Iterator;%0Aimport java.util.List
+util.Iterator
 ;%0A%0Ai
@@ -2130,16 +2130,17 @@
 (path);%0A
+%0A
         
@@ -2157,94 +2157,166 @@
 ture
-Reader reader = new TribbleFeatureReader(locator, CodecFactory.getCodec(locator, null)
+Source tribbleFeatureSource = TribbleFeatureSource.getFeatureSource(locator, genome);%0A        FeatureSource source = new GFFFeatureSource(tribbleFeatureSource
 );%0A%0A
@@ -2382,24 +2382,55 @@
 r = 
-reader.iterator(
+source.getFeatures(%22chr7%22, 0, Integer.MAX_VALUE
 );%0A 
@@ -2579,17 +2579,16 @@
 Equals(2
-0
 , featur

Update GFFCodecTest to mimic GFF reader better