/// <summary>
        /// Writes delta for query sequences.
        /// </summary>
        /// <param name="sorter">Sorter instance.</param>
        /// <param name="unsortedDeltaStream">Unsorted Delta Filename.</param>
        /// <param name="queryParser">Query/read sequences parser.</param>
        /// <param name="outputStream">Output file name.</param>
        public static void WriteSortedDelta(DeltaAlignmentSorter sorter, Stream unsortedDeltaStream, FastASequencePositionParser queryParser, Stream outputStream)
        {
            if (sorter == null)
            {
                throw new ArgumentNullException("sorter");
            }

            using (DeltaAlignmentParser unsortedDeltaParser = new DeltaAlignmentParser(unsortedDeltaStream, queryParser))
            {
                using (StreamWriter writer = new StreamWriter(outputStream))
                {
                    long deltaPositionInFile = 0;
                    foreach (long id in sorter.GetSortedIds())
                    {
                        DeltaAlignment deltaAlignment = unsortedDeltaParser.GetDeltaAlignmentAt(id);
                        deltaAlignment.Id = deltaPositionInFile;
                        string deltaString = Helper.GetString(deltaAlignment);
                        deltaPositionInFile += deltaString.Length;
                        writer.Write(deltaString);
                    }

                    writer.Flush();
                }
            }
        }
        /// <summary>
        /// Writes delta for query sequences.
        /// </summary>
        /// <param name="sorter">The Deltas.</param>
        private void WriteDelta(DeltaAlignmentSorter sorter)
        {
            TextWriter textWriterConsoleOutSave = Console.Out;
            StreamWriter streamWriterConsoleOut = null;

            try
            {
                using (var reads = File.OpenRead(this.FilePath[1]))
                using (var unsortedDeltas = File.OpenRead(UnsortedDeltaFile))
                using (var sequenceParser = new FastASequencePositionParser(reads, true))
                using (var unsortedDeltaParser = new DeltaAlignmentParser(unsortedDeltas, sequenceParser))
                {
                    if (!string.IsNullOrEmpty(this.OutputFile))
                    {
                        streamWriterConsoleOut = new StreamWriter(this.OutputFile);
                        Console.SetOut(streamWriterConsoleOut);
                    }

                    long deltaPositionInFile = 0;

                    foreach (long id in sorter.GetSortedIds())
                    {
                        DeltaAlignment deltaAlignment = unsortedDeltaParser.GetDeltaAlignmentAt(id);

                        deltaAlignment.Id = deltaPositionInFile;
                        string deltaString = Helper.GetString(deltaAlignment);
                        deltaPositionInFile += deltaString.Length;
                        Console.Write(deltaString);
                    }

                    Console.Out.Flush();
                }
            }
            finally
            {
                if (streamWriterConsoleOut != null)
                    streamWriterConsoleOut.Dispose();
                Console.SetOut(textWriterConsoleOutSave);
            }
        }
        /// <summary>
        /// Writes delta for query sequences.
        /// </summary>
        /// <param name="sorter">Sorter instance.</param>
        /// <param name="unsortedDeltaFilename">Unsorted Delta Filename.</param>
        /// <param name="queryParser">Query/Read parser</param>
        /// <param name="outputfilename">Output file name.</param>
        private static void WriteSortedDelta(DeltaAlignmentSorter sorter, string unsortedDeltaFilename, FastASequencePositionParser queryParser, string outputfilename)
        {
            using (var unsortedReads = File.OpenRead(unsortedDeltaFilename))
            using (DeltaAlignmentParser unsortedDeltaParser = new DeltaAlignmentParser(unsortedReads, queryParser))
            {
                TextWriter textWriterConsoleOutSave = Console.Out;
                StreamWriter streamWriterConsoleOut = null;
                try
                {
                    if (!string.IsNullOrEmpty(outputfilename))
                    {
                        Output.WriteLine(OutputLevel.Required);
                        streamWriterConsoleOut = new StreamWriter(outputfilename);
                        Console.SetOut(streamWriterConsoleOut);
                    }

                    long deltaPositionInFile = 0;
                    foreach (long id in sorter.GetSortedIds())
                    {
                        DeltaAlignment deltaAlignment = unsortedDeltaParser.GetDeltaAlignmentAt(id);
                        deltaAlignment.Id = deltaPositionInFile;
                        string deltaString = Helper.GetString(deltaAlignment);
                        deltaPositionInFile += deltaString.Length;
                        Console.Write(deltaString);
                    }

                    Console.Out.Flush();
                }
                finally
                {
                    if (streamWriterConsoleOut != null)
                        streamWriterConsoleOut.Dispose();
                    Console.SetOut(textWriterConsoleOutSave);
                }
            }
        }