public BamReaderContainer(Stream inStream, string filename)
 {
     _bamReader = new BamReader();
     _bamReader.Open(inStream);
     _filename                   = filename;
     _currentBamAlignment        = new BamAlignment();
     _currentSerializedAlignment = new SerializedBamAlignment();
     MoveToNextRecord();
 }
示例#2
0
        /// <summary>
        ///     Creates an index from a specified BAM file
        /// </summary>
        public void CreateIndexFromBamFile(string filename)
        {
            _numUnalignedWithoutCoordinates = 0;

            // open the BAM file and retrieve the reference data
            using (BamReader reader = new BamReader(filename))
            {
                // allocate space for the reference index
                List <GenomeMetadata.SequenceMetadata> references = reader.GetReferences();

                // iterate over all of the reads in the BAM file
                Initialize(references.Count, reader.Tell());

                BamAlignment al = new BamAlignment();
                while (reader.GetNextAlignment(ref al, true))
                {
                    if (!UpdateReferenceIndex(ref al, reader.Tell()))
                    {
                        break;
                    }
                }

                // perform some post-processing on the index
                PostProcessing(reader.Tell());

                if (_hasUnalignedReads)
                {
                    while (reader.GetNextAlignment(ref al, true))
                    {
                        ++_numUnalignedWithoutCoordinates;
                    }
                }
            }

            // write the index to a file
            WriteIndex(filename + ".bai");
        }