예제 #1
0
        internal static ulong GetMinOffset(ReferenceSequence refSeq, int begin)
        {
            int bin = BinUtilities.FirstBin(Constants.NumLevels) + (begin >> Constants.MinShift);

            do
            {
                if (refSeq.IdToChunks.ContainsKey(bin))
                {
                    break;
                }

                int firstBin = (BinUtilities.ParentBin(bin) << 3) + 1;

                if (bin > firstBin)
                {
                    bin--;
                }
                else
                {
                    bin = BinUtilities.ParentBin(bin);
                }
            } while (bin != 0);

            int bottomBin = BinUtilities.BottomBin(bin);

            return(refSeq.LinearFileOffsets[bottomBin]);
        }
예제 #2
0
        // ReSharper disable once UnusedMember.Global
        public static long GetOffset(this Index index, string chromosomeName, int begin)
        {
            var refSeq = index.GetTabixReferenceSequence(chromosomeName);

            if (refSeq == null)
            {
                return(-1);
            }

            // N.B. tabix assumes begin is 0-based and end is 1-based
            int end = begin;

            begin = AdjustBegin(begin);

            if (begin == 0)
            {
                return(refSeq.LinearFileOffsets.FirstNonZeroValue());
            }

            ulong minOffset = GetMinOffset(refSeq, begin);
            ulong maxOffset = GetMaxOffset(refSeq, end);

            int bin = BinUtilities.ConvertPositionToBin(begin);

            if (refSeq.IdToChunks.TryGetValue(bin, out Interval[] chunks))
예제 #3
0
        protected override void WriteContent(BinaryWriter bw)
        {
            bw.Write((byte)BinUtilities.PackType(this.ValueType));
            bw.Write(this.Value is not null);

            if (this.Value is not null)
            {
                this.Value.Write(bw, false);
            }
        }
예제 #4
0
        internal BinTreeOptional(BinaryReader br, IBinTreeParent parent, uint nameHash) : base(parent, nameHash)
        {
            this.ValueType = BinUtilities.UnpackType((BinPropertyType)br.ReadByte());
            bool isSome = br.ReadBoolean();

            if (isSome)
            {
                this.Value = BinTreeProperty.Read(br, this, this.ValueType);
            }
        }
예제 #5
0
 private string GetPropertyTypeDeclaration(MetaDumpProperty property, Dictionary <uint, string> classNames)
 {
     return(BinUtilities.UnpackType(property.Type) switch
     {
         BinPropertyType.Container => GetContainerTypeDeclaration(property.OtherClass, property.Container, false, classNames),
         BinPropertyType.UnorderedContainer => GetContainerTypeDeclaration(property.OtherClass, property.Container, true, classNames),
         BinPropertyType.Structure => GetStructureTypeDeclaration(property.OtherClass, classNames),
         BinPropertyType.Embedded => GetEmbeddedTypeDeclaration(property.OtherClass, classNames),
         BinPropertyType.Optional => GetOptionalTypeDeclaration(property.OtherClass, property.Container, classNames),
         BinPropertyType.Map => GetMapTypeDeclaration(property.OtherClass, property.Map, classNames),
         BinPropertyType type => GetPrimitivePropertyTypeDeclaration(type, true)
     });
예제 #6
0
        private void WritePropertyAttribute(StreamWriter sw, MetaDumpProperty property, Dictionary <uint, string> propertyNames)
        {
            BinPropertyType propertyType = BinUtilities.UnpackType(property.Type);

            if (propertyNames.TryGetValue(property.Hash, out string propertyName))
            {
                sw.WriteLineIndented(2, @"[MetaProperty(""{0}"", BinPropertyType.{1})]", propertyName, propertyType);
            }
            else
            {
                sw.WriteLineIndented(2, @"[MetaProperty({0}, BinPropertyType.{1})]", property.Hash, propertyType);
            }
        }
예제 #7
0
        public void OverlappingBinsWithVariants_EndBeyondMaxRefLen_CorrectEnd()
        {
            const int expectedBinId = 6310;

            var idToChunks = new Dictionary <int, Interval[]>
            {
                [expectedBinId] = new[] { new Interval(1, 1) }
            };

            List <int> results = BinUtilities.OverlappingBinsWithVariants(10, int.MaxValue, idToChunks).ToList();

            Assert.Single(results);
            Assert.Equal(expectedBinId, results[0]);
        }
예제 #8
0
        public static long GetOffset(this Index index, string chromosomeName, int begin)
        {
            var refSeq = index.GetTabixReferenceSequence(chromosomeName);

            if (refSeq == null)
            {
                return(-1);
            }

            // N.B. tabix assumes begin is 0-based and end is 1-based
            int end = begin;

            begin = AdjustBegin(begin);

            if (begin == 0)
            {
                return(refSeq.LinearFileOffsets.FirstNonZeroValue());
            }

            ulong minOffset = GetMinOffset(refSeq, begin);
            ulong maxOffset = GetMaxOffset(refSeq, end);

            int bin = BinUtilities.ConvertPositionToBin(begin);

            if (refSeq.IdToChunks.TryGetValue(bin, out var chunks))
            {
                return(GetMinOverlapOffset(chunks, minOffset, maxOffset));
            }

            int linearIndex = begin >> Constants.MinShift;

            if (linearIndex >= refSeq.LinearFileOffsets.Length)
            {
                return(-1);
            }

            return((long)refSeq.LinearFileOffsets[linearIndex]);
        }
예제 #9
0
        internal static ulong GetMaxOffset(ReferenceSequence refSeq, int end)
        {
            int bin = BinUtilities.FirstBin(Constants.NumLevels) + ((end - 1) >> Constants.MinShift) + 1;

            while (true)
            {
                while (bin % 8 == 1)
                {
                    bin = BinUtilities.ParentBin(bin);
                }

                if (bin == 0)
                {
                    return(ulong.MaxValue);
                }
                if (refSeq.IdToChunks.TryGetValue(bin, out var chunks) && chunks.Length > 0)
                {
                    return(chunks[0].Begin);
                }

                bin++;
            }
        }
예제 #10
0
        public void BottomBin_Nominal()
        {
            int observedResults = BinUtilities.BottomBin(12517);

            Assert.Equal(7836, observedResults);
        }
예제 #11
0
        public void ConvertPositionToBin_Nominal()
        {
            int observedResults = BinUtilities.ConvertPositionToBin(26699126);

            Assert.Equal(6310, observedResults);
        }
예제 #12
0
        public void OverlappingBinsWithVariants_EndBeforeBegin_ReturnEmptyList()
        {
            IEnumerable <int> results = BinUtilities.OverlappingBinsWithVariants(20, 10, null);

            Assert.Empty(results);
        }