// Path: halvade/src/be/ugent/intec/halvade/tools/QualityException.java
// public class QualityException extends Exception {
//     private boolean illegal = false;
//     private byte errorCode;
// 
//     QualityException(byte error) {
//         super();
//         errorCode = error;
//     }
//     
//     QualityException() {
//         super();
//         illegal = true;
//     }
// 
//     @Override
//     public String toString() {
//         if(illegal) 
//             return "Illegal Phred 64 or Phred 33 encoding";
//         else 
//             return "Error converting Phred 64 to Phred 33 quality : " + (int)errorCode; 
//     }
// }


import be.ugent.intec.halvade.tools.QualityEncoding;
import be.ugent.intec.halvade.tools.QualityException;
import org.seqdoop.hadoop_bam.SAMRecordWritable;
import java.util.Iterator;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMRecord;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.ugent.intec.halvade.utils;


/**
 *
 * @author ddecap
 */
public class SAMRecordIterator implements Iterator<SAMRecord> {
    protected Iterator<SAMRecordWritable> it;
    protected ChromosomeRange r;
    protected SAMRecord sam = null;
    protected int reads = 0;
    protected int currentStart = -1, currentEnd = -1, currentChr = -1;
    protected String chrString = "";
    protected boolean requireFixQuality = false;
    protected SAMFileHeader header;
    protected static final int INTERVAL_OVERLAP = 51;

// Path: halvade/src/be/ugent/intec/halvade/tools/QualityException.java
// public class QualityException extends Exception {
//     private boolean illegal = false;
//     private byte errorCode;
// 
//     QualityException(byte error) {
//         super();
//         errorCode = error;
//     }
//     
//     QualityException() {
//         super();
//         illegal = true;
//     }
// 
//     @Override
//     public String toString() {
//         if(illegal) 
//             return "Illegal Phred 64 or Phred 33 encoding";
//         else 
//             return "Error converting Phred 64 to Phred 33 quality : " + (int)errorCode; 
//     }
// }


// Path: halvade/src/be/ugent/intec/halvade/utils/SAMRecordIterator.java
import be.ugent.intec.halvade.tools.QualityEncoding;
import be.ugent.intec.halvade.tools.QualityException;
import org.seqdoop.hadoop_bam.SAMRecordWritable;
import java.util.Iterator;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMRecord;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.ugent.intec.halvade.utils;


/**
 *
 * @author ddecap
 */
public class SAMRecordIterator implements Iterator<SAMRecord> {
    protected Iterator<SAMRecordWritable> it;
    protected ChromosomeRange r;
    protected SAMRecord sam = null;
    protected int reads = 0;
    protected int currentStart = -1, currentEnd = -1, currentChr = -1;
    protected String chrString = "";
    protected boolean requireFixQuality = false;
    protected SAMFileHeader header;
    protected static final int INTERVAL_OVERLAP = 51;

    public SAMRecordIterator(Iterator<SAMRecordWritable> it, SAMFileHeader header, boolean requireFixQuality) throws QualityException {