/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2007-2015 Broad Institute
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.broad.igv.bbfile;

import htsjdk.tribble.Feature;
import org.junit.Test;

import java.io.IOException;
import java.util.Iterator;

import static org.junit.Assert.*;

/**
 * @author jrobinso
 * @date Jun 19, 2011
 */
public class BBDataSourceTest {


    @Test
    public void testBigGenePred() throws IOException {

        String path = "https://hgdownload.soe.ucsc.edu/hubs/GCA/009/914/755/GCA_009914755.4/bbi/GCA_009914755.4_T2T-CHM13v2.0.catLiftOffGenesV1/catLiftOffGenesV1.bb";

        BBFileReader bbReader = new BBFileReader(path);
        BBDataSource bbSource = new BBDataSource(bbReader, null);

        String chr = "chr21";
        int start = 26490012;
        int end = 42182827;

       Iterator<Feature> iter =  bbSource.getFeatures(chr, start, end);

       int count = 0;
        while (iter.hasNext()) {
            Feature f = iter.next();
            assertEquals(chr, f.getChr());
            assertTrue(f.getStart() <= end && f.getEnd() >= start);
            count++;
        }
        assertTrue(count > 0);
        System.out.println(count);

    }

    @Test
    public void testBigNarrowpeak() throws IOException {

        String path = "https://www.encodeproject.org/files/ENCFF154CVA/@@download/ENCFF154CVA.bigBed";

        BBFileReader bbReader = new BBFileReader(path);
        BBDataSource bbSource = new BBDataSource(bbReader, null);

        String chr = "chr21";
        int start = 26490012;
        int end = 42182827;

        Iterator<Feature> iter =  bbSource.getFeatures(chr, start, end);

        int count = 0;
        while (iter.hasNext()) {
            Feature f = iter.next();
            assertEquals(chr, f.getChr());
            assertTrue(f.getStart() <= end && f.getEnd() >= start);
            count++;
        }
        assertTrue(count > 0);
        System.out.println(count);

    }



}

@@ -1860,24 +1860,25 @@
 27;%0A%0A       
+ 
 Iterator%3CFea
@@ -1881,33 +1881,32 @@
 %3CFeature%3E iter =
- 
  bbSource.getFea
@@ -1926,24 +1926,25 @@
 art, end);%0A%0A
+ 
        int c
@@ -2199,43 +2199,8 @@
  0);
-%0A        System.out.println(count);
 %0A%0A  
@@ -2620,17 +2620,16 @@
 %3E iter =
- 
  bbSourc
@@ -2931,50 +2931,834 @@
 0);%0A
+%0A
     
+%7D%0A%0A
     
-System.out.println(count);%0A%0A    %7D%0A
+// NOTE:  bigInteract is not yet supported in IGV desktop, bigInteract is treated as a plain bed file.%0A    @Test%0A    public void testBigInteract() throws IOException %7B%0A%0A        String path = %22https://s3.amazonaws.com/igv.org.demo/interactExample3.inter.bb%22;%0A%0A        BBFileReader bbReader = new BBFileReader(path);%0A        BBDataSource bbSource = new BBDataSource(bbReader, null);%0A%0A        String chr = %22chr3%22;%0A        int start = 63081504;%0A        int end = 64501215;%0A%0A        Iterator%3CFeature%3E iter = bbSource.getFeatures(chr, start, end);%0A%0A        int count = 0;%0A        while (iter.hasNext()) %7B%0A            Feature f = iter.next();%0A            assertEquals(chr, f.getChr());%0A            assertTrue(f.getStart() %3C= end && f.getEnd() %3E= start);%0A            count++;%0A        %7D%0A        assertTrue(count %3E 0);%0A    %7D
 %0A%0A%0A%7D

Add test for bigInteract (for future)