// Path: src/main/java/org/drpowell/tabix/TabixIndex.java
// public static class TabixConfig {
// 	public final int preset, seqCol, beginCol, endCol, commentChar, linesToSkip;
// 	public final String commentString;
// 	public TabixConfig (int p, int sc, int bc, int ec, int comment, int skipLines) {
// 		preset = p; seqCol = sc; beginCol = bc; endCol = ec; commentChar = comment; linesToSkip = skipLines; 
// 		commentString = Character.toString((char) commentChar);
// 	}
// 	public static final TabixConfig GFF = new TabixConfig(0, 1, 4, 5, '#', 0);
//     public static final TabixConfig BED = new TabixConfig(TBX_FLAG_UCSC, 1, 2, 3, '#', 0);
//     public static final TabixConfig PSLTBL = new TabixConfig(TBX_FLAG_UCSC, 15, 17, 18, '#', 0);
//     public static final TabixConfig SAM = new TabixConfig(TBX_PRESET_SAM, 3, 4, 0, '@', 0);
//     public static final TabixConfig VCF = new TabixConfig(TBX_PRESET_VCF, 1, 2, 0, '#', 0);
// }
// 
// Path: src/main/java/org/drpowell/util/LineIterator.java
// public class LineIterator extends AbstractPeekableIterator<String> {
// 	public final BufferedReader reader;
// 	
// 	public boolean handleException(Exception e) {
// 		Logger.getGlobal().log(Level.WARNING, e.toString());
// 		return true;
// 	}
// 	
// 	public LineIterator(BufferedReader reader) {
// 		this.reader = reader;
// 	}
// 
// 	@Override
// 	protected String computeNext() {
// 		String next = null;
// 		try {
// 			next = reader.readLine();
// 		} catch (IOException e) {
// 			if (!handleException(e)) {
// 				return computeNext();
// 			}
// 		}
// 		return next == null ? endOfData() : next;
// 	}
// 
// }


import java.util.List;
import net.sf.samtools.util.BlockCompressedFilePointerUtil;
import net.sf.samtools.util.BlockCompressedInputStream;
import net.sf.samtools.util.BlockCompressedOutputStream;
import org.drpowell.tabix.TabixIndex.TabixConfig;
import org.drpowell.util.LineIterator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
/* The MIT License

   Copyright (c) 2012 Baylor College of Medicine.

   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.drpowell.tabix;




public class TabixBuilder {
	private final TabixIndex tabix;
	private int tidCurr = -1;
	private BinIndex currBinningIndex = new BinIndex();
	private LinearIndex currLinearIndex = new LinearIndex();
	
	// FIXME- arguably could just stick with '\n'...
	private static final byte [] LINE_SEPARATOR = System.getProperty("line.separator").getBytes();
	
// Path: src/main/java/org/drpowell/tabix/TabixIndex.java
// public static class TabixConfig {
// 	public final int preset, seqCol, beginCol, endCol, commentChar, linesToSkip;
// 	public final String commentString;
// 	public TabixConfig (int p, int sc, int bc, int ec, int comment, int skipLines) {
// 		preset = p; seqCol = sc; beginCol = bc; endCol = ec; commentChar = comment; linesToSkip = skipLines; 
// 		commentString = Character.toString((char) commentChar);
// 	}
// 	public static final TabixConfig GFF = new TabixConfig(0, 1, 4, 5, '#', 0);
//     public static final TabixConfig BED = new TabixConfig(TBX_FLAG_UCSC, 1, 2, 3, '#', 0);
//     public static final TabixConfig PSLTBL = new TabixConfig(TBX_FLAG_UCSC, 15, 17, 18, '#', 0);
//     public static final TabixConfig SAM = new TabixConfig(TBX_PRESET_SAM, 3, 4, 0, '@', 0);
//     public static final TabixConfig VCF = new TabixConfig(TBX_PRESET_VCF, 1, 2, 0, '#', 0);
// }
// 
// Path: src/main/java/org/drpowell/util/LineIterator.java
// public class LineIterator extends AbstractPeekableIterator<String> {
// 	public final BufferedReader reader;
// 	
// 	public boolean handleException(Exception e) {
// 		Logger.getGlobal().log(Level.WARNING, e.toString());
// 		return true;
// 	}
// 	
// 	public LineIterator(BufferedReader reader) {
// 		this.reader = reader;
// 	}
// 
// 	@Override
// 	protected String computeNext() {
// 		String next = null;
// 		try {
// 			next = reader.readLine();
// 		} catch (IOException e) {
// 			if (!handleException(e)) {
// 				return computeNext();
// 			}
// 		}
// 		return next == null ? endOfData() : next;
// 	}
// 
// }


// Path: src/main/java/org/drpowell/tabix/TabixBuilder.java
import java.util.List;
import net.sf.samtools.util.BlockCompressedFilePointerUtil;
import net.sf.samtools.util.BlockCompressedInputStream;
import net.sf.samtools.util.BlockCompressedOutputStream;
import org.drpowell.tabix.TabixIndex.TabixConfig;
import org.drpowell.util.LineIterator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

/* The MIT License

   Copyright (c) 2012 Baylor College of Medicine.

   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.drpowell.tabix;




public class TabixBuilder {
	private final TabixIndex tabix;
	private int tidCurr = -1;
	private BinIndex currBinningIndex = new BinIndex();
	private LinearIndex currLinearIndex = new LinearIndex();
	
	// FIXME- arguably could just stick with '\n'...
	private static final byte [] LINE_SEPARATOR = System.getProperty("line.separator").getBytes();
	
	private TabixBuilder(String fileName, TabixConfig config) throws IOException {