// Path: src/main/java/org/seqdoop/hadoop_bam/FormatConstants.java
// public enum BaseQualityEncoding { Illumina, Sanger };


import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.ReflectionUtils;
import org.seqdoop.hadoop_bam.FormatConstants.BaseQualityEncoding;
import java.io.DataOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
// Copyright (C) 2011-2012 CRS4.
//
// This file is part of Hadoop-BAM.
//
// 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.seqdoop.hadoop_bam;




/**
 * Output format for the fastq format.
 */
// If a key is provided with the SequencedFragment, the key is used as the sequence
// id and the meta-info from the SequencedFragment (if any) is dropped.
// If the key is null, then the format will attempt to create an
// Illumina-style fastq id as specified in the Casava users' guide v1.8:
// @instrument:run number:flowcell ID:lane:tile:x-pos:y-pos \s+ read:is filtered:control number:index sequence
//
public class FastqOutputFormat extends TextOutputFormat<Text, SequencedFragment>
{
	public static final String CONF_BASE_QUALITY_ENCODING         = "hbam.fastq-output.base-quality-encoding";
	public static final String CONF_BASE_QUALITY_ENCODING_DEFAULT = "sanger";
	public static final Charset UTF8 = Charset.forName("UTF8");

	static final byte[] PLUS_LINE;
	static {
		try {
			PLUS_LINE = "\n+\n".getBytes("us-ascii");
		} catch (java.io.UnsupportedEncodingException e) {
			throw new RuntimeException("us-ascii encoding not supported!");
		}
	}

	public static class FastqRecordWriter extends RecordWriter<Text,SequencedFragment>
	{
		protected StringBuilder       sBuilder          = new StringBuilder(800);
		protected Text                buffer            = new Text();
		protected OutputStream        out;
// Path: src/main/java/org/seqdoop/hadoop_bam/FormatConstants.java
// public enum BaseQualityEncoding { Illumina, Sanger };


// Path: src/main/java/org/seqdoop/hadoop_bam/FastqOutputFormat.java
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.ReflectionUtils;
import org.seqdoop.hadoop_bam.FormatConstants.BaseQualityEncoding;
import java.io.DataOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;

// Copyright (C) 2011-2012 CRS4.
//
// This file is part of Hadoop-BAM.
//
// 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.seqdoop.hadoop_bam;




/**
 * Output format for the fastq format.
 */
// If a key is provided with the SequencedFragment, the key is used as the sequence
// id and the meta-info from the SequencedFragment (if any) is dropped.
// If the key is null, then the format will attempt to create an
// Illumina-style fastq id as specified in the Casava users' guide v1.8:
// @instrument:run number:flowcell ID:lane:tile:x-pos:y-pos \s+ read:is filtered:control number:index sequence
//
public class FastqOutputFormat extends TextOutputFormat<Text, SequencedFragment>
{
	public static final String CONF_BASE_QUALITY_ENCODING         = "hbam.fastq-output.base-quality-encoding";
	public static final String CONF_BASE_QUALITY_ENCODING_DEFAULT = "sanger";
	public static final Charset UTF8 = Charset.forName("UTF8");

	static final byte[] PLUS_LINE;
	static {
		try {
			PLUS_LINE = "\n+\n".getBytes("us-ascii");
		} catch (java.io.UnsupportedEncodingException e) {
			throw new RuntimeException("us-ascii encoding not supported!");
		}
	}

	public static class FastqRecordWriter extends RecordWriter<Text,SequencedFragment>
	{
		protected StringBuilder       sBuilder          = new StringBuilder(800);
		protected Text                buffer            = new Text();
		protected OutputStream        out;
		protected BaseQualityEncoding baseQualityFormat;