/*
 * Copyright (c) 2007-2011 by The Broad Institute of MIT and Harvard.  All Rights Reserved.
 *
 * 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.
 *
 * THE SOFTWARE IS PROVIDED "AS IS." THE BROAD AND MIT MAKE NO REPRESENTATIONS OR
 * WARRANTES OF ANY KIND CONCERNING THE SOFTWARE, EXPRESS OR IMPLIED, INCLUDING,
 * WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER
 * OR NOT DISCOVERABLE.  IN NO EVENT SHALL THE BROAD OR MIT, OR THEIR RESPECTIVE
 * TRUSTEES, DIRECTORS, OFFICERS, EMPLOYEES, AND AFFILIATES BE LIABLE FOR ANY DAMAGES
 * OF ANY KIND, INCLUDING, WITHOUT LIMITATION, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
 * ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER
 * THE BROAD OR MIT SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT
 * SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.broad.igv.sam;

import net.sf.samtools.util.CloseableIterator;
import org.broad.igv.sam.reader.BAMRemoteQueryReader;
import org.broad.igv.util.ResourceLocator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
 * @author jrobinso
 */
public class AlignmentPackerTest {

    public AlignmentPackerTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    /**
     * Test of packAlignments method, of class AlignmentPacker.
     */
    @Test
    public void testPackAlignments() {
        /*
        String path = "/Users/jrobinso/IGV/Alignments/303KY.8.paired.bam";
        String serverURL = "http://localhost:8080/webservices/igv";
        String chr = "chr7";
        int start = 2244149;
        int end = 2250144;
         * */

        String path = "http://www.broadinstitute.org/igvdata/1KG/pilot2Bams/NA12878.SLX.bam";
        String chr = "1";
        int start = 557000;  //98751004; //
        int end = 558000; //98751046; //
        boolean contained = false;

        ResourceLocator rl = new ResourceLocator(path);

        BAMRemoteQueryReader bamReader = new BAMRemoteQueryReader(rl);
        CloseableIterator<Alignment> iter = bamReader.query(chr, start, end, contained);
        boolean showDuplicates = false;
        int qualityThreshold = 0;
        int maxLevels = 1000;


        Map<String, List<AlignmentInterval.Row>> result = (new AlignmentPacker()).packAlignments(iter, end, false, null, "", 10000);

    }


}
@@ -1268,39 +1268,125 @@
 igv.
-sam.reader.BAMRemoteQueryReader
+Globals;%0Aimport org.broad.igv.sam.reader.AlignmentQueryReader;%0Aimport org.broad.igv.sam.reader.AlignmentReaderFactory
 ;%0Aim
@@ -1555,16 +1555,117 @@
 l.Map;%0A%0A
+import static junit.framework.Assert.assertEquals;%0Aimport static junit.framework.Assert.assertTrue;%0A%0A
 /**%0A * @
@@ -1826,32 +1826,67 @@
 ows Exception %7B%0A
+        Globals.setHeadless(true);%0A
     %7D%0A%0A    @Afte
@@ -2088,263 +2088,59 @@
 s() 
-%7B%0A        /*%0A        String path = %22/Users/jrobinso/IGV/Alignments/303KY.8.paired.bam%22;%0A        String serverURL = %22http://localhost:8080/webservices/igv%22;%0A        String chr = %22chr7%22;%0A        int start = 2244149;%0A        int end = 2250144;%0A         * */%0A
+throws Exception %7B%0A%0A        //Retrieve data to pack
 %0A   
@@ -2287,24 +2287,8 @@
 000;
-  //98751004; //
 %0A   
@@ -2313,23 +2313,8 @@
 000;
- //98751046; //
 %0A   
@@ -2402,25 +2402,24 @@
 (path);%0A
-%0A
         
 BAMRemot
@@ -2410,25 +2410,25 @@
         
-BAMRemote
+Alignment
 QueryRea
@@ -2431,17 +2431,17 @@
 yReader 
-b
+s
 amReader
@@ -2447,26 +2447,34 @@
 r = 
-new BAMRemoteQuery
+AlignmentReaderFactory.get
 Read
@@ -2525,17 +2525,17 @@
  iter = 
-b
+s
 amReader
@@ -2570,16 +2570,53 @@
 ained);%0A
+        ///////////////////////////%0A%0A
         
@@ -2712,17 +2712,16 @@
  1000;%0A%0A
-%0A
         
@@ -2845,16 +2845,654 @@
 10000);%0A
+        assertEquals(1, result.size());%0A        for (List%3CAlignmentInterval.Row%3E alignmentrows : result.values()) %7B%0A            for (AlignmentInterval.Row alignmentrow : alignmentrows) %7B%0A                List%3CAlignment%3E alignments = alignmentrow.alignments;%0A                for (int ii = 1; ii %3C alignments.size(); ii++) %7B%0A                    assertTrue(alignments.get(ii).getAlignmentStart() %3E alignments.get(ii - 1).getAlignmentStart());%0A                    assertTrue(alignments.get(ii).getAlignmentStart() - alignments.get(ii - 1).getAlignmentEnd() %3E= AlignmentPacker.MIN_ALIGNMENT_SPACING);%0A                %7D%0A            %7D%0A        %7D%0A%0A
 %0A    %7D%0A%0A

Modify data query so it actually runs. Add some meaningful asserts (not sure if they are meaningful enough, though).