Exemple #1
0
 public SAMAlignedSequence ReadSAMAlignedSequence()
 {
     if (_parser.IsEOF())
     {
         return(null);
     }
     return(_parser.GetAlignedSequence(true));
 }
Exemple #2
0
        /// <summary>
        /// Gets Aligned seqeunces in the Specified BAM file.
        /// </summary>
        /// <param name="textReader">BAM file stream.</param>
        private IEnumerable <SAMAlignedSequence> GetAlignedSequence(Stream bamStream)
        {
            bool isFilterRequired = IsFilterApplied();
            bool display          = true;

            while (!bamparser.IsEOF())
            {
                SAMAlignedSequence alignedSequence = bamparser.GetAlignedSequence(false);
                if (isFilterRequired)
                {
                    display = Filter(alignedSequence);
                }

                if (display)
                {
                    yield return(alignedSequence);
                }
            }
        }
Exemple #3
0
        // Search the BAM file for the next valid read aligned against the current contig.
        // Update read/base pairs statistics.
        private void Search_Reads(BAMParser parser, ref SAMAlignedSequence next_alignment, string contig_name,
                                  ref long number_of_aligned_reads, ref long number_of_aligned_base_pairs, ref long number_of_used_reads,
                                  ref long number_of_used_base_pairs, Queue <Padded_Read> read_queue, long current_position)
        {
            while (next_alignment != null &&
                   !next_alignment.IsDummyRead &&
                   next_alignment.RName == contig_name &&
                   (next_alignment.Pos - 1) == current_position)
            {
                // The next alignment overlaps with current position, so continue.
                number_of_aligned_reads++;
                number_of_aligned_base_pairs += next_alignment.QuerySequence.Count;

                // Maybe we should let the mininum alignment quality be a parameter.
                // We currently leave it for the user to pre-filter the BAM file.
                if (next_alignment.MapQ > 0)
                {
                    number_of_used_reads++;
                    number_of_used_base_pairs += next_alignment.QuerySequence.Count;
                    read_queue.Enqueue(new Padded_Read(next_alignment));
                }

                #region Parse BAM file until next alignment is found
                if (!parser.IsEOF())
                {
                    next_alignment = parser.GetAlignedSequence(true);

                    while ((next_alignment == null || next_alignment.RName == "*" || next_alignment.IsDummyRead) && !parser.IsEOF())
                    {
                        next_alignment = parser.GetAlignedSequence(true);
                    }
                }
                else
                {
                    next_alignment = null;
                }
                #endregion Parse BAM file until next alignment is found
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets Aligned sequences in the Specified BAM file.
        /// </summary>
        /// <param name="bamStream"></param>
        private IEnumerable <SAMAlignedSequence> GetAlignedSequence(Stream bamStream)
        {
            bool isFilterRequired = IsFilterApplied();
            bool display          = true;

            while (!bamparser.IsEOF())
            {
                SAMAlignedSequence alignedSequence = bamparser.GetAlignedSequence(false);
                //TODO: The parser should probably never return a null sequence
                //this may be a band aid over a lurking problem, fix in future
                if (alignedSequence != null)
                {
                    if (isFilterRequired)
                    {
                        display = Filter(alignedSequence);
                    }

                    if (display)
                    {
                        yield return(alignedSequence);
                    }
                }
            }
        }