public void vid_compute_correctly(string refAllele, string altAllele, string expId)
        {
            var chrom = new Mock <IChromosome>();

            chrom.Setup(x => x.EnsemblName).Returns("1");
            var variant = SmallVariantCreator.Create(chrom.Object, 100, refAllele, altAllele, false, false);

            Assert.Equal(expId, variant.VariantId);
        }
        public void Create_Insertion_ReturnVariant()
        {
            var variant = SmallVariantCreator.Create(ChromosomeUtilities.Chr1, 101, 100, "", "CG", false, false, null, null, false);

            Assert.False(variant.IsRefMinor);
            Assert.Equal(AnnotationBehavior.SmallVariants, variant.Behavior);
            Assert.Equal("1", variant.Chromosome.EnsemblName);
            Assert.Equal(101, variant.Start);
            Assert.Equal(100, variant.End);
            Assert.Equal("", variant.RefAllele);
            Assert.Equal("CG", variant.AltAllele);
            Assert.Equal(VariantType.insertion, variant.Type);
            Assert.False(variant.IsDecomposed);
            Assert.False(variant.IsRecomposed);
            Assert.Null(variant.LinkedVids);
        }
Beispiel #3
0
        private static IAnnotatedPosition GetPosition(IChromosome chrom, int start, string refAllele, string[] altAlleles)
        {
            var position          = new Mock <IAnnotatedPosition>();
            var annotatedVariants = new List <IAnnotatedVariant>();

            foreach (string altAllele in altAlleles)
            {
                VariantType type = SmallVariantCreator.GetVariantType(refAllele, altAllele);
                int         end  = start + altAllele.Length - 1;

                annotatedVariants.Add(new AnnotatedVariant(new Variant(chrom, start, end, refAllele, altAllele, type, null, false, false, false,
                                                                       null, null, AnnotationBehavior.SmallVariantBehavior)));
            }

            position.SetupGet(x => x.AnnotatedVariants).Returns(annotatedVariants.ToArray);
            return(position.Object);
        }
Beispiel #4
0
        private static void UpdateVariantType(ClinvarVariant variant)
        {
            var refAllele = variant.RefAllele;
            var altAllele = variant.AltAllele;

            if (refAllele == null || altAllele == null)
            {
                return;
            }

            var variantType = SmallVariantCreator.GetVariantType(refAllele, altAllele);

            switch (variantType)
            {
            case VariantType.deletion:
                variant.VariantType = "Deletion";
                break;

            case VariantType.insertion:
                variant.VariantType = "Insertion";
                break;

            case VariantType.indel:
                variant.VariantType = "Indel";
                break;

            case VariantType.duplication:
                variant.VariantType = "Duplication";
                break;

            case VariantType.SNV:
                variant.VariantType = "SNV";
                break;

            case VariantType.MNV:
                variant.VariantType = "MNV";
                break;
            }
        }
        public void Small_variant_created_correctly()
        {
            var chrom = new Mock <IChromosome>();

            chrom.Setup(x => x.EnsemblName).Returns("1");
            var variant = SmallVariantCreator.Create(chrom.Object, 100, "A", "ACG", false, false, null);

            Assert.False(variant.IsRefMinor);
            Assert.True(variant.Behavior.NeedFlankingTranscript);
            Assert.True(variant.Behavior.NeedSaPosition);
            Assert.False(variant.Behavior.NeedSaInterval);
            Assert.False(variant.Behavior.ReducedTranscriptAnnotation);
            Assert.False(variant.Behavior.StructuralVariantConsequence);
            Assert.Equal("1", variant.Chromosome.EnsemblName);
            Assert.Equal(101, variant.Start);
            Assert.Equal(100, variant.End);
            Assert.Equal("", variant.RefAllele);
            Assert.Equal("CG", variant.AltAllele);
            Assert.Equal(VariantType.insertion, variant.Type);
            Assert.False(variant.IsDecomposed);
            Assert.False(variant.IsRecomposed);
            Assert.Null(variant.LinkedVids);
        }
Beispiel #6
0
        internal static (int Start, int End, string Ref, string Alt, List <int> VarPosIndexesInAlleleBlock, List <string> decomposedVids) GetPositionsAndRefAltAlleles(AlleleBlock alleleBlock, AlleleSet alleleSet, string totalRefSequence, int regionStart, List <ISimplePosition> simplePositions)
        {
            int numPositions       = alleleBlock.AlleleIndexes.Length;
            int firstPositionIndex = alleleBlock.PositionIndex;
            int lastPositionIndex  = alleleBlock.PositionIndex + numPositions - 1;

            int    blockStart     = alleleSet.Starts[firstPositionIndex];
            int    blockEnd       = alleleSet.Starts[lastPositionIndex];
            string lastRefAllele  = alleleSet.VariantArrays[lastPositionIndex][0];
            int    blockRefLength = blockEnd - blockStart + lastRefAllele.Length;
            var    refSequence    = totalRefSequence.Substring(blockStart - regionStart, blockRefLength);

            int refSequenceStart               = 0;
            var altSequenceSegments            = new LinkedList <string>();
            var variantPosIndexesInAlleleBlock = new List <int>();
            var vidListsNeedUpdate             = new List <List <string> >();
            var decomposedVids = new List <string>();

            for (int positionIndex = firstPositionIndex; positionIndex <= lastPositionIndex; positionIndex++)
            {
                int indexInBlock = positionIndex - firstPositionIndex;
                int alleleIndex  = alleleBlock.AlleleIndexes[indexInBlock];
                //only non-reference alleles considered
                if (alleleIndex == 0)
                {
                    continue;
                }

                variantPosIndexesInAlleleBlock.Add(positionIndex - firstPositionIndex);
                string refAllele                     = alleleSet.VariantArrays[positionIndex][0];
                string altAllele                     = alleleSet.VariantArrays[positionIndex][alleleIndex];
                int    positionOnRefSequence         = alleleSet.Starts[positionIndex] - blockStart;
                int    refRegionBetweenTwoAltAlleles = positionOnRefSequence - refSequenceStart;

                if (refRegionBetweenTwoAltAlleles < 0)
                {
                    string previousAltAllele = alleleSet.VariantArrays[positionIndex - 1][alleleIndex];
                    throw new UserErrorException($"Conflicting alternative alleles identified at {alleleSet.Chromosome.UcscName}:{alleleSet.Starts[positionIndex]}: both \"{previousAltAllele}\" and \"{altAllele}\" are present.");
                }

                string refSequenceBefore = refSequence.Substring(refSequenceStart, refRegionBetweenTwoAltAlleles);
                altSequenceSegments.AddLast(refSequenceBefore);
                altSequenceSegments.AddLast(altAllele);
                refSequenceStart = positionOnRefSequence + refAllele.Length;

                if (simplePositions == null)
                {
                    continue;
                }
                var thisPosition = simplePositions[positionIndex];
                // alleleIndex is 1-based for altAlleles
                int varIndex = alleleIndex - 1;

                //Only SNVs get recomposed for now
                if (thisPosition.Vids[varIndex] == null)
                {
                    thisPosition.Vids[varIndex] = SmallVariantCreator.GetVid(alleleSet.Chromosome.EnsemblName,
                                                                             thisPosition.Start, thisPosition.End, thisPosition.AltAlleles[varIndex], VariantType.SNV);
                    thisPosition.IsDecomposed[varIndex] = true;
                }
                decomposedVids.Add(thisPosition.Vids[varIndex]);

                if (thisPosition.LinkedVids[varIndex] == null)
                {
                    thisPosition.LinkedVids[varIndex] = new List <string>();
                }
                vidListsNeedUpdate.Add(thisPosition.LinkedVids[varIndex]);
            }
            altSequenceSegments.AddLast(refSequence.Substring(refSequenceStart));
            var recomposedAllele    = string.Concat(altSequenceSegments);
            var blockRefEnd         = blockStart + blockRefLength - 1;
            var recomposedVariantId = SmallVariantCreator.GetVid(alleleSet.Chromosome.EnsemblName, blockStart, blockRefEnd, recomposedAllele, VariantType.MNV);

            vidListsNeedUpdate.ForEach(x => x.Add(recomposedVariantId));
            return(blockStart, blockRefEnd, refSequence, recomposedAllele, variantPosIndexesInAlleleBlock, decomposedVids);
        }