Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
            public override void MoveToNextRecord()
            {
                _isEnd = !_bamReader.GetNextAlignment(ref _currentBamAlignment, false);

                if (_isEnd)
                {
                    return;
                }

                // No memory allocation
                _currentSerializedAlignment.RefID           = _currentBamAlignment.RefID;
                _currentSerializedAlignment.Position        = _currentBamAlignment.Position;
                _currentSerializedAlignment.AlignmentFlag   = _currentBamAlignment.AlignmentFlag;
                _currentSerializedAlignment.FragmentLength  = _currentBamAlignment.FragmentLength;
                _currentSerializedAlignment.MapQuality      = _currentBamAlignment.MapQuality;
                _currentSerializedAlignment.MatePosition    = _currentBamAlignment.MatePosition;
                _currentSerializedAlignment.MateRefID       = _currentBamAlignment.MateRefID;
                _currentSerializedAlignment.IsReverseStrand = _currentBamAlignment.IsReverseStrand();
                _currentSerializedAlignment.Name            = _currentBamAlignment.Name;
            }