示例#1
0
        public void CreateAndAdd()
        {
            var candidates = new List <CandidateAllele>()
            {
                new CandidateAllele("chr1", 100, "A", "AT", AlleleCategory.Insertion),
                new CandidateAllele("chr1", 100, "A", "A", AlleleCategory.Reference),
                new CandidateAllele("chr1", 100, "A", "T", AlleleCategory.Snv),
                new CandidateAllele("chr1", 200, "A", "T", AlleleCategory.Mnv)
            };

            var batch           = new CandidateBatch(candidates);
            var batchCandidates = batch.GetCandidates();

            Assert.Equal(4, batchCandidates.Count);
            foreach (var candidate in candidates)
            {
                Assert.True(batchCandidates.Contains(candidate));
            }

            // add new candidate
            var newCandidate = new CandidateAllele("chr1", 200, "AT", "A", AlleleCategory.Deletion);

            batch.Add(new List <CandidateAllele>()
            {
                newCandidate
            });

            Assert.Equal(5, batchCandidates.Count);
            Assert.True(batchCandidates.Contains(newCandidate));
        }
        /// <summary>
        /// Only pass back candidates from blocks where the entire block region is less than upToPosition.
        /// The second criteria is to ensure variants that span blocks have fully completed info in either flanking block.
        /// </summary>
        /// <param name="upToPosition"></param>
        /// /// <param name="chrReference"></param>
        /// /// <param name="intervalSet"></param>
        /// <returns></returns>
        public virtual ICandidateBatch GetCandidatesToProcess(int?upToPosition, ChrReference chrReference = null, HashSet <Tuple <string, int, string, string> > forcesGtAlleles = null)
        {
            try
            {
                // only create a real batch if we haved moved onto another block
                if (upToPosition.HasValue && GetBlockKey(upToPosition.Value) == _lastUpToBlockKey)
                {
                    return(null);
                }

                var batch = new CandidateBatch {
                    MaxClearedPosition = upToPosition.HasValue ? -1 : (int?)null
                };

                var blockKeys = upToPosition.HasValue
                    ? _regionLookup.Keys.Where(k => k * _regionSize <= upToPosition).ToArray()
                    : _regionLookup.Keys.ToArray();

                var blocks = new List <MyRegionState>();

                Array.Sort(blockKeys); // need to sort the keys so we can bounce out as soon as we hit a held block

                foreach (var key in blockKeys)
                {
                    var block = _regionLookup[key];
                    if (upToPosition != null && block.MaxAlleleEndpoint > upToPosition)
                    {
                        break;
                    }
                    //Console.WriteLine("block start="+ block.StartPosition+" ;block end = "+ block.EndPosition);
                    batch.Add(block.GetAllCandidates(_includeRefAlleles, chrReference, _intervalSet, forcesGtAlleles));
                    batch.BlockKeys.Add(key);
                    blocks.Add(block);
                }

                if (blocks.Any())
                {
                    batch.ClearedRegions     = new List <Region>(blocks.Select(b => b as Region));
                    batch.MaxClearedPosition = blocks.Max(b => b.EndPosition);

                    if (upToPosition.HasValue && blocks.Max(b => b.MaxAlleleEndpoint) > batch.MaxClearedPosition.Value && _trackOpenEnded)
                    {
                        AddCollapsableFromOtherBlocks(batch,
                                                      batch.MaxClearedPosition.Value,
                                                      upToPosition.Value);
                    }
                }

                return(batch);
            }
            finally
            {
                _lastUpToBlockKey = upToPosition.HasValue ? GetBlockKey(upToPosition.Value) : -1;
                // doesnt matter what we set to for last round
            }
        }
        public override ICandidateBatch GetCandidatesToProcess(int?upToPosition, ChrReference chrReference = null, HashSet <Tuple <string, int, string, string> > forcedGtAlleles = null)
        {
            try
            {
                // only create a real batch if we haved moved onto another block
                if (upToPosition.HasValue && GetBlockKey(upToPosition.Value) == _lastUpToBlockKey)
                {
                    return(null);
                }

                var batch = new CandidateBatch {
                    MaxClearedPosition = upToPosition.HasValue ? -1 : (int?)null
                };

                var blockKeys = upToPosition.HasValue
                    ? _regionLookup.Keys.Where(k => k * _regionSize <= upToPosition).ToArray()
                    : _regionLookup.Keys.ToArray();

                var blocksToRealign = new List <MyRegionState>();

                Array.Sort(blockKeys); // need to sort the keys so we can bounce out as soon as we hit a held block

                foreach (var key in blockKeys)
                {
                    // add candidates from everyone
                    var block = _regionLookup[key];
                    batch.Add(block.GetAllCandidates(false, chrReference, null));

                    // only realign blocks that havent been cleared and are one window away from upToPosition
                    if (block.StartPosition > _lastMaxClearedPosition &&
                        (upToPosition.HasValue && block.EndPosition + _regionSize < upToPosition))
                    {
                        batch.BlockKeys.Add(key);
                        blocksToRealign.Add(block);
                    }
                }

                if (blocksToRealign.Any())
                {
                    batch.ClearedRegions     = new List <Region>(blocksToRealign.Select(b => b as Region));
                    batch.MaxClearedPosition = blocksToRealign.Max(b => b.EndPosition);
                }

                return(batch);
            }
            finally
            {
                _lastUpToBlockKey = upToPosition.HasValue ? GetBlockKey(upToPosition.Value) : -1;
                // doesnt matter what we set to for last round
            }
        }
示例#4
0
        /// <summary>
        /// Only pass back candidates from blocks where the entire block region is less than upToPosition
        /// and there's a fully completed block after it.  The second criteria is to ensure variants that
        /// span blocks have fully completed info in either flanking block.
        /// </summary>
        /// <param name="upToPosition"></param>
        /// /// <param name="chrReference"></param>
        /// /// <param name="intervalSet"></param>
        /// <returns></returns>
        public ICandidateBatch GetCandidatesToProcess(int?upToPosition, ChrReference chrReference = null)
        {
            var batch = new CandidateBatch {
                MaxClearedPosition = upToPosition.HasValue ? -1 : (int?)null
            };

            // only create a real batch if we haved moved onto another block
            if (!upToPosition.HasValue || GetBlockKey(upToPosition.Value) != _lastUpToKey)
            {
                var blockKeys = upToPosition.HasValue
                    ? _regionLookup.Keys.Where(k => (k + 1) * _regionSize <= upToPosition).ToArray()
                    : _regionLookup.Keys.ToArray();

                var blocks = new List <RegionState>();

                Array.Sort(blockKeys); // need to sort the keys so we can bounce out as soon as we hit a held block

                foreach (var key in blockKeys)
                {
                    var block = _regionLookup[key];
                    if (upToPosition != null && block.MaxAlleleEndpoint > upToPosition)
                    {
                        break;
                    }
                    batch.Add(block.GetAllCandidates(_includeRefAlleles, chrReference, _intervalSet));
                    batch.BlockKeys.Add(key);
                    blocks.Add(block);
                }

                if (blocks.Any())
                {
                    batch.ClearedRegions     = new List <Region>(blocks.Select(b => b as Region));
                    batch.MaxClearedPosition = blocks.Max(b => b.EndPosition);
                }
            }

            _lastUpToKey = upToPosition.HasValue ? GetBlockKey(upToPosition.Value) : -1;  // doesnt matter what we set to for last round

            return(batch);
        }