Beispiel #1
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);
        }
        // TODO maybe this should be extension of CigarAlignment?
        public static bool CigarMatchesPattern(this BamAlignment alignment, string pattern)
        {
            if (alignment.CigarData.Count != pattern.Length)
            {
                return(false);
            }

            for (int i = 0; i < pattern.Length; i++)
            {
                var op = alignment.CigarData[i];
                if (pattern[i] != op.Type)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        ///  Copy constructor.
        /// </summary>
        public BamAlignment(BamAlignment a)
        {
            AlignmentFlag  = a.AlignmentFlag;
            Bases          = a.Bases;
            Bin            = a.Bin;
            CigarData      = new CigarAlignment(a.CigarData.ToString());
            FragmentLength = a.FragmentLength;
            MapQuality     = a.MapQuality;
            MatePosition   = a.MatePosition;
            MateRefID      = a.MateRefID;
            Name           = a.Name;
            Position       = a.Position;
            Qualities      = new byte[a.Qualities.Length];
            Array.Copy(a.Qualities, Qualities, Qualities.Length);

            RefID        = a.RefID;
            TagData      = a.TagData;
            _endPosition = a._endPosition;
        }
 /// <summary>
 /// Returns the "one-based end position", which is the end position of the alignment + 1 (Isas BamAlignment is zero-based). Note that this will return a different value (-1) than before the update to Isas BamAlignment.
 /// </summary>
 /// <param name="alignment"></param>
 /// <returns></returns>
 public static int OneBasedEndPosition(this BamAlignment alignment)
 {
     // NOTE this will return a different value (-1) than before the update to Isas BamAlignment. Nothing internal to Pisces is using it.
     return(alignment.GetEndPosition() + 1);
 }
 /// <summary>
 /// Returns the "one-based position" of the alignment (Isas BamAlignment is zero-based).
 /// </summary>
 /// <param name="alignment"></param>
 /// <returns></returns>
 public static int OneBasedPosition(this BamAlignment alignment)
 {
     return(alignment.Position + 1);
 }
 public static string StringRepresentation(this BamAlignment alignment)
 {
     return(string.Format("{0},{1},{2},{3},{4}", alignment.Name, alignment.RefID, alignment.Position,
                          alignment.FragmentLength, alignment.CigarData, alignment.MateRefID, alignment.MatePosition));
 }
 //TODO may be able to get rid of this and just use !IsPrimary
 public static bool IsSecondary(this BamAlignment alignment)
 {
     return((alignment.AlignmentFlag & 256) != 0);
 }
 /// <summary>
 /// Return the position of the last base in the read. Note that this is equivalent to the result before the update to Isas BamAlignment at c348f98 in PICS-847.
 /// </summary>
 /// <param name="alignment"></param>
 /// <returns></returns>
 public static int GetLastBasePosition(this BamAlignment alignment)
 {
     return(alignment.GetEndPosition());
 }
 public static bool ContainsPosition(this BamAlignment alignment, long position, int refId, bool startInclusive = true, bool endInclusive = true)
 {
     return(alignment.RefID == refId &&
            (startInclusive ? alignment.Position <= position : alignment.Position < position) &&
            (endInclusive ? alignment.GetLastBasePosition() >= position : alignment.GetLastBasePosition() > position));
 }
Beispiel #10
0
 public static int OneBasedEndPosition(this BamAlignment alignment)
 {
     return(alignment.GetEndPosition() + 1);
 }