Example #1
0
        private static bool CanBeSame(AlleleBlock alleleBlock, AlleleBlock seedBlock, out int missingBasesBefore, out int missingBasesAfter)
        {
            missingBasesBefore = 0;
            missingBasesAfter  = 0;
            int endIndexSeedBlock = seedBlock.PositionIndex + seedBlock.AlleleIndexes.Length - 1;
            int endIndexThisBlock = alleleBlock.PositionIndex + alleleBlock.AlleleIndexes.Length - 1;

            if (endIndexThisBlock > endIndexSeedBlock)
            {
                return(false);
            }

            missingBasesBefore = alleleBlock.PositionIndex - seedBlock.PositionIndex;
            if (alleleBlock.NumRefPositionsBefore < missingBasesBefore)
            {
                return(false);
            }

            missingBasesAfter = endIndexSeedBlock - endIndexThisBlock;
            if (alleleBlock.NumRefPositionsAfter < missingBasesAfter)
            {
                return(false);
            }

            for (var i = 0; i < missingBasesBefore; i++)
            {
                if (seedBlock.AlleleIndexes[i] != 0)
                {
                    return(false);
                }
            }

            for (var i = 0; i < alleleBlock.AlleleIndexes.Length; i++)
            {
                if (alleleBlock.AlleleIndexes[i] != seedBlock.AlleleIndexes[i + missingBasesBefore])
                {
                    return(false);
                }
            }

            for (int i = missingBasesBefore + alleleBlock.AlleleIndexes.Length;
                 i < seedBlock.AlleleIndexes.Length;
                 i++)
            {
                if (seedBlock.AlleleIndexes[i] != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        internal static AlleleBlock ExtendAlleleBlock(AlleleBlock alleleBlock, int extendBefore, int extendAfter)
        {
            if (extendBefore > alleleBlock.NumRefPositionsBefore)
            {
                throw new ArgumentOutOfRangeException($"Can't extend an allele block with {alleleBlock.NumRefPositionsBefore} trimmed leading reference positions by adding {extendBefore} reference positions before it");
            }
            if (extendAfter > alleleBlock.NumRefPositionsAfter)
            {
                throw new ArgumentOutOfRangeException($"Can't extend an allele block with {alleleBlock.NumRefPositionsAfter} trimmed trailing reference positions by adding {extendAfter} reference positions after it");
            }
            int lengthOldAlleleIndexes = alleleBlock.AlleleIndexes.Length;
            var newAlleleIndexes       = new int[extendBefore + lengthOldAlleleIndexes + extendAfter];

            Array.Copy(alleleBlock.AlleleIndexes, 0, newAlleleIndexes, extendBefore, lengthOldAlleleIndexes);
            return(new AlleleBlock(alleleBlock.PositionIndex - extendBefore, newAlleleIndexes, -1, -1));
        }
Example #3
0
        public static PositionSet CreatePositionSet(List <ISimplePosition> simpleSimplePositions, List <int> functionBlockRanges)
        {
            var positionSet = new PositionSet(simpleSimplePositions, functionBlockRanges);

            positionSet.AlleleSet = GenerateAlleleSet(positionSet);
            positionSet._allelesWithUnsupportedTypes = GetAllelesWithUnsupportedTypes(positionSet);
            positionSet._sampleInfo = GetSampleInfo(positionSet);

            var phaseSetAndGqIndexes = positionSet.GetSampleTagIndexes(new[] { "GT", "PS", "GQ" });

            positionSet.GtInfo = TagInfo <Genotype> .GetTagInfo(positionSet._sampleInfo, phaseSetAndGqIndexes[0], ExtractSampleValue, Genotype.GetGenotype);

            positionSet.PsInfo = TagInfo <string> .GetTagInfo(positionSet._sampleInfo, phaseSetAndGqIndexes[1], ExtractSampleValue, x => x);

            positionSet.GqInfo = TagInfo <string> .GetTagInfo(positionSet._sampleInfo, phaseSetAndGqIndexes[2], ExtractSampleValue, x => x);

            var genotypeToSampleIndex        = GetGenotypeToSampleIndex(positionSet);
            var alleleBlockToSampleHaplotype = AlleleBlock.GetAlleleBlockToSampleHaplotype(genotypeToSampleIndex, positionSet._allelesWithUnsupportedTypes, positionSet.AlleleSet.Starts, positionSet.FunctionBlockRanges, out var alleleBlockGraph);

            positionSet.AlleleBlockToSampleHaplotype = AlleleBlockMerger.Merge(alleleBlockToSampleHaplotype, alleleBlockGraph);
            return(positionSet);
        }
Example #4
0
 private static bool SeedOutOfRange(AlleleBlock alleleBlock, AlleleBlock seedBlock) => seedBlock.PositionIndex + seedBlock.AlleleIndexes.Length - 1 < alleleBlock.PositionIndex;