public static bool HasSupplementaryAlignment(this BamAlignment alignment)
        {
            if (alignment.TagData == null)
            {
                return(false);
            }

            var saTag = alignment.GetStringTag("SA");

            return(saTag != null);
        }
Ejemplo n.º 2
0
        public static List <BamAlignment> GetSupplementaryAlignments(this BamAlignment alignment, Dictionary <string, int> refIdMapping = null)
        {
            var supplementaries = new List <BamAlignment>();

            if (!alignment.HasSupplementaryAlignment())
            {
                return(supplementaries);
            }

            var tag = alignment.GetStringTag("SA");
            var supplementaryAlignments = tag.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var supplementaryAlignment in supplementaryAlignments)
            {
                // SA tag format: (rname,pos,strand,CIGAR,mapQ,NM ;)+
                var splitTag      = supplementaryAlignment.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var tagChromosome = splitTag[0];
                var tagPosition   = int.Parse(splitTag[1]);
                var tagStrand     = splitTag[2];
                var tagCigar      = splitTag[3];
                var tagMapq       = splitTag[4];
                var tagNM         = splitTag[5];

                var bamAlignment = new BamAlignment()
                {
                    Position  = tagPosition - 1, // Deal with the fact that BamAlignment obj is 0-indexed, whereas SA is 1-indexed
                    CigarData = new CigarAlignment(tagCigar),
                };

                if (tagStrand == "-")
                {
                    bamAlignment.SetIsReverseStrand(true);
                }

                if (refIdMapping != null)
                {
                    Console.WriteLine(tagChromosome);
                    bamAlignment.RefID = refIdMapping[tagChromosome];
                }

                supplementaries.Add(bamAlignment);
            }

            return(supplementaries);
        }