예제 #1
0
        /// <summary>
        /// Disposes the underlaying streams used.
        /// </summary>
        /// <param name="disposing">Flag to indicate whether it is called from dispose method or not.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (this.deltaAlignmentParser != null)
            {
                this.deltaAlignmentParser.Dispose();
                this.deltaAlignmentParser = null;
            }

            if (this.fastASequencePositionParser != null)
            {
                if (disposeFastASequencePositionParser)
                {
                    this.fastASequencePositionParser.Dispose();
                }

                this.fastASequencePositionParser = null;
            }

            if (this.collectionFileReader != null)
            {
                this.collectionFileReader.Dispose();
                this.collectionFileReader = null;
            }

            if (File.Exists(this.collectionFile))
            {
                File.Delete(this.collectionFile);
            }

            if (disposing)
            {
                this.readBuffer = null;
            }
        }
        /// <summary>
        /// Disposes the underlying streams used.
        /// </summary>
        /// <param name="disposing">Flag to indicate whether it is called from dispose method or not.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.DeltaAlignmentParser != null)
                {
                    this.DeltaAlignmentParser.Dispose();
                    this.DeltaAlignmentParser = null;
                }

                if (this._fastASequencePositionParser != null)
                {
                    if (_disposeFastASequencePositionParser)
                    {
                        this._fastASequencePositionParser.Dispose();
                    }
                    this._fastASequencePositionParser = null;
                }

                if (this._collectionFileReader != null)
                {
                    this._collectionFileReader.Dispose();
                    this._collectionFileReader = null;
                }

                this._readBuffer = null;
            }

            // Delete the collection file on Dispose or GC.
            if (File.Exists(this._collectionFile))
            {
                File.Delete(this._collectionFile);
            }
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the DeltaAlignmentCollection class.
 /// </summary>
 /// <param name="deltaAlignmentFilename">Delta alignment file name.</param>
 /// <param name="readsFilename">Query/Reads filename.</param>
 public DeltaAlignmentCollection(string deltaAlignmentFilename, string readsFilename)
 {
     this.DeltaAlignmentFilename      = deltaAlignmentFilename;
     this.QueryFilename               = readsFilename;
     this.fastASequencePositionParser = new FastASequencePositionParser(this.QueryFilename, true);
     this.deltaAlignmentParser        = new DeltaAlignmentParser(this.DeltaAlignmentFilename, this.fastASequencePositionParser);
     this.collectionFile              = Guid.NewGuid().ToString();
     this.collectionFileReader        = new FileStream(this.collectionFile, FileMode.Create, FileAccess.ReadWrite);
     this.LoadAllFromFile();
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the DeltaAlignmentCollection class.
 /// </summary>
 /// <param name="deltaAlignmentFilename">Delta alignment file name.</param>
 /// <param name="fastASequencePositionParser">Query/Reads filename.</param>
 public DeltaAlignmentCollection(string deltaAlignmentFilename, FastASequencePositionParser fastASequencePositionParser)
 {
     if (fastASequencePositionParser == null)
     {
         throw new ArgumentNullException("fastASequencePositionParser");
     }
     this.disposeFastASequencePositionParser = false;
     this.DeltaAlignmentFilename             = deltaAlignmentFilename;
     this.QueryFilename = fastASequencePositionParser.Filename;
     this.fastASequencePositionParser = fastASequencePositionParser;
     this.deltaAlignmentParser        = new DeltaAlignmentParser(this.DeltaAlignmentFilename, this.fastASequencePositionParser);
     this.collectionFile       = Guid.NewGuid().ToString();
     this.collectionFileReader = new FileStream(this.collectionFile, FileMode.Create, FileAccess.ReadWrite);
     this.LoadAllFromFile();
 }
예제 #5
0
        /// <summary>
        /// Disposes the underlying streams used.
        /// </summary>
        /// <param name="disposing">Flag to indicate whether it is called from dispose method or not.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.DeltaAlignmentParser != null)
                {
                    this.DeltaAlignmentParser.Dispose();
                    this.DeltaAlignmentParser = null;
                }

                if (this.fastASequencePositionParser != null)
                {
                    if (this.disposeFastASequencePositionParser)
                    {
                        this.fastASequencePositionParser.Dispose();
                    }
                    this.fastASequencePositionParser = null;
                }

                if (this.collectionFileReader != null)
                {
                    this.collectionFileReader.Dispose();
                    this.collectionFileReader = null;
                }

                this.readBuffer = null;
            }
        }
예제 #6
0
        /// <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);
            }
        }
예제 #7
0
        /// <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();
                }
            }
        }
예제 #8
0
        /// <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);
                }
            }
        }