Пример #1
0
        // GenotypeBlocks can be shared by multiple samples
        // We mainly utilize phase set information at this step to avoid duplicated calculation
        // These GenotypeBlocks could be further segmented when more details considered
        private static IEnumerable <GenotypeBlock> GetGenotypeBlocks(PositionSet positionSet, int sampleIndex)
        {
            var genotypes      = positionSet.GtInfo.Values[sampleIndex];
            var entireBlock    = new GenotypeBlock(genotypes);
            var blockRanges    = GetGenotypeBlockRange(positionSet.PsInfo.Values[sampleIndex], genotypes.Select(x => x.IsPhased).ToArray(), genotypes.Select(x => x.IsHomozygous).ToArray());
            var genotypeBlocks = new List <GenotypeBlock>();

            foreach (var range in blockRanges)
            {
                genotypeBlocks.Add(entireBlock.GetSubBlock(range.StartIndex, range.PositionCount));
            }

            return(genotypeBlocks);
        }
Пример #2
0
        private static void AddAlleleIndexBlocks(GenotypeBlock genotypeBlock, List <int> sampleIndexes, int[] starts,
                                                 List <int> functionBlockRanges, IDictionary <AlleleBlock, List <SampleHaplotype> > alleleIndexBlockToSampleAllele, Graph <AlleleBlock> alleleIndexBlockGraph)
        {
            int startPosition  = genotypeBlock.PosIndex;
            int ploidy         = genotypeBlock.Genotypes[0].AlleleIndexes.Length;
            var isRefPositions = genotypeBlock.Genotypes.Select(x => IsRefPosition(x.AlleleIndexes)).ToArray();

            foreach (var functionBlock in genotypeBlock.Split(starts, functionBlockRanges))
            {
                int startInThisBlock = functionBlock.PosIndex - startPosition;
                int numPositions     = functionBlock.Genotypes.Length;
                int endInThisBlock   = startInThisBlock + numPositions - 1;
                var(numRefPosBefore, numRefPosAfter) = GetRefPosNums(isRefPositions, startInThisBlock, endInThisBlock);

                var alleleIndexBlocks = new List <AlleleBlock>();
                for (int haplotypeIndex = 0; haplotypeIndex < ploidy; haplotypeIndex++)
                {
                    var alleleIndexes = new int[numPositions];
                    for (var i = 0; i < numPositions; i++)
                    {
                        alleleIndexes[i] = functionBlock.Genotypes[i].AlleleIndexes[haplotypeIndex];
                    }
                    var alleleIndexBlock = new AlleleBlock(functionBlock.PosIndex, alleleIndexes, numRefPosBefore,
                                                           numRefPosAfter);
                    alleleIndexBlocks.Add(alleleIndexBlock);
                    var currentSampleAlleles = GetSampleAlleles(sampleIndexes, (byte)haplotypeIndex);
                    UpdateBlockToSampleAlleleMapping(alleleIndexBlock, currentSampleAlleles,
                                                     alleleIndexBlockToSampleAllele);
                }
                for (var i = 0; i < alleleIndexBlocks.Count; i++)
                {
                    for (int j = i + 1; j < alleleIndexBlocks.Count; j++)
                    {
                        alleleIndexBlockGraph.AddEdge(alleleIndexBlocks[i], alleleIndexBlocks[j]);
                    }
                }
            }
        }