public void Dispose()
        {
            if (_writer != null)
            {
                _writer.Close();
                _writer.Dispose();

                _writer = null;
            }
        }
 public void WriteAlignment(BamAlignment alignment)
 {
     if (alignment == null)
     {
         _writer?.Dispose();
     }
     else
     {
         _writer.WriteAlignment(alignment);
     }
 }
Beispiel #3
0
        public void FinishAll()
        {
            FlushAllBufferedRecords();

            _bamWriter.Close();
            _bamWriter.Dispose();

            using (var writer = GetWriter(_temp2File))
            {
                AdjustMates(_temp1File, writer);
                if (_copyUnaligned)
                {
                    WriteUnalignedReads(writer);
                }
            }

            if (_createIndex)
            {
                Logger.WriteToLog("Creating index");
                new BamIndex().CreateIndexFromBamFile(_temp2File);
                Logger.WriteToLog("Completed creating index");
            }

            // if everything goes well, rename to final destination
            File.Delete(_temp1File);
            File.Delete(_outputFile);

            File.Move(_temp2File, _outputFile);
            if (_createIndex)
            {
                var outputBaiFile = _outputFile + ".bai";
                File.Delete(outputBaiFile);

                File.Move(_temp2File + ".bai", outputBaiFile);
            }
        }