コード例 #1
0
        public void CnvOverlspTest()
        {
            var interval = new AnnotationInterval(16764333, 17483981);

            var overlap = interval.OverlapFraction(16886175, 17054465);

            Assert.Equal(0.23385150260752116, overlap);// full overlap

            var variant        = new AnnotationInterval(16886175, 17054465);
            var variantOverlap = variant.OverlapFraction(16764333, 17483981);

            Assert.Equal(1.0, variantOverlap);
        }
コード例 #2
0
        /// <summary>
        /// returns the number of transcripts within flanking distance
        /// </summary>
        private bool HasOverlap(VariantFeature variant)
        {
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var transcript in OverlappingTranscripts)
            {
                var overlapInterval = new AnnotationInterval(transcript.Start - FlankingLength, transcript.End + FlankingLength);
                if (variant.AlternateAlleles.Any(altAllele => overlapInterval.Overlaps(altAllele.Start, altAllele.End)))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        public void OverlapFraction()
        {
            var interval = new AnnotationInterval(101, 110);

            var overlap = interval.OverlapFraction(99, 110);

            Assert.Equal(1.0, overlap);// full overlap

            overlap = interval.OverlapFraction(90, 105);
            Assert.Equal(0.50, overlap);

            overlap = interval.OverlapFraction(105, 111);
            Assert.Equal(0.60, overlap);

            overlap = interval.OverlapFraction(101, 101);
            Assert.Equal(0.10, overlap);
        }
コード例 #4
0
        /// <summary>
        /// sets both the exon and intron number strings according to which were affected by the variant [BaseTranscriptVariation.pm:474 _exon_intron_number]
        /// </summary>
        public static void ExonIntronNumber(CdnaCoordinateMap[] cdnaMaps, SimpleInterval[] introns, bool onReverseStrand,
                                            TranscriptAnnotation ta, out string exonNumber, out string intronNumber)
        {
            int exonCount = 0;

            var altAllele       = ta.AlternateAllele;
            var variantInterval = new AnnotationInterval(altAllele.Start, altAllele.End);

            var overlappedExons   = new List <int>();
            var overlappedIntrons = new List <int>();

            var prevExon = CdnaCoordinateMap.Null();

            foreach (var exon in cdnaMaps)
            {
                exonCount++;

                if (variantInterval.Overlaps(exon.GenomicStart, exon.GenomicEnd))
                {
                    overlappedExons.Add(exonCount);
                }

                if (!prevExon.IsNull)
                {
                    int intronStart = prevExon.GenomicEnd + 1;
                    int intronEnd   = exon.GenomicStart - 1;

                    if (variantInterval.Overlaps(intronStart, intronEnd))
                    {
                        overlappedIntrons.Add(exonCount - 1);
                    }
                }

                prevExon = exon;
            }

            exonNumber   = GetExonIntronNumber(overlappedExons, cdnaMaps.Length, onReverseStrand);
            intronNumber = introns != null?GetExonIntronNumber(overlappedIntrons, introns.Length, onReverseStrand) : null;

            if (overlappedExons.Count > 0)
            {
                ta.HasExonOverlap = true;
            }
        }
コード例 #5
0
ファイル: UnifiedJson.cs プロジェクト: YuJiang01/Nirvana
        private void PopulateSuppIntervalFields(List <ISupplementaryInterval> suppIntervals)
        {
            if (suppIntervals == null)
            {
                return;
            }
            var supplementaryIntervals = new List <JsonSupplementaryInterval>();

            foreach (var interval in suppIntervals)
            {
                var jsonSuppInterval = new JsonSupplementaryInterval(interval);

                supplementaryIntervals.Add(jsonSuppInterval);

                //compute reciprocal overlap

                if (ReferenceBegin == null || _referenceEnd == null)
                {
                    continue;
                }
                if (ReferenceBegin >= _referenceEnd)
                {
                    continue;                                                  //do not calculate reciprocal overlap for insertion
                }
                if (interval.Start >= interval.End)
                {
                    continue;                                 //donot compute reciprocal overlap if supp interval is insertion
                }
                var variantInterval = new AnnotationInterval(ReferenceBegin.Value + 1, _referenceEnd.Value);

                var intervalOverlap = interval.OverlapFraction(variantInterval.Start, variantInterval.End);
                var variantOverlap  = variantInterval.OverlapFraction(interval.Start, interval.End);

                jsonSuppInterval.ReciprocalOverlap = Math.Min(intervalOverlap, variantOverlap);
            }

            SupplementaryIntervals = supplementaryIntervals;
        }
コード例 #6
0
        public int Extract()
        {
            var count = 0;

            using (_reader)
                using (_writer)
                {
                    for (var i = _begin; i <= _end; i++)
                    {
                        var sa = _reader.GetAnnotation(i) as SupplementaryAnnotationPosition;

                        if (sa != null)
                        {
                            count++;
                            _writer.Write(new SupplementaryPositionCreator(sa), i);
                        }
                    }
                    var miniSaInterval = new AnnotationInterval(_begin, _end);

                    // get the supplementary intervals overlapping the mini SA interval

                    var suppIntervals      = new List <SupplementaryInterval>();
                    var readerSuppInterval = _reader.GetSupplementaryIntervals(_renamer);
                    if (readerSuppInterval != null)
                    {
                        foreach (var interval in readerSuppInterval)
                        {
                            if (miniSaInterval.Overlaps(interval.Start, interval.End))
                            {
                                suppIntervals.Add(interval as SupplementaryInterval);
                            }
                        }
                    }
                    Console.WriteLine("Found {0} supplementary intervals.", suppIntervals.Count);
                    _writer.SetIntervalList(suppIntervals);
                }
            return(count);
        }