Ejemplo n.º 1
0
        /// <summary>
        /// Returns the reference ploidy for <paramref name="referenceInterval"/><para/>
        /// If <paramref name="referenceInterval"/> spans regions with different ploidy an exception is thrown
        /// </summary>
        public static int GetSingleReferencePloidy(this ReferencePloidy referencePloidy, ReferenceInterval referenceInterval)
        {
            var referencePloidies = referencePloidy.GetReferencePloidyIntervals(referenceInterval).ToList();

            if (referencePloidies.Count != 1)
            {
                var differentPloidyIntervals = referencePloidies.Select(ploidy => ploidy.Interval);
                throw new ArgumentException(
                          $"Reference interval '{referenceInterval}' overlaps regions with different ploidy: '{string.Join(", ", differentPloidyIntervals)}'");
            }

            return(referencePloidies.Single().ReferencePloidy);
        }
Ejemplo n.º 2
0
        private static ReferencePloidy LoadReferencePloidy(IEnumerable <ReferencePloidyInterval> ploidyVcfIntervals,
                                                           bool useSymbolicAltAlleleInPloidyVcf = true)
        {
            var sampleId = new SampleId("sampleId");
            var vcf      = GetVcfAsString(sampleId, ploidyVcfIntervals, useSymbolicAltAlleleInPloidyVcf);

            using (var textReader = new StringReader(vcf))
                using (var reader = new GzipOrTextReader(textReader))
                    using (var vcfReader = new VcfReader(reader))
                    {
                        return(ReferencePloidy.Load(vcfReader, sampleId));
                    }
        }
Ejemplo n.º 3
0
 private static IEnumerable <CNInterval> GetKnownCopyNumberWithReferencePloidy(List <CNInterval> knownCnIntervals, ReferencePloidy referencePloidy)
 {
     foreach (var knownCnInterval in knownCnIntervals)
     {
         var interval  = new ReferenceInterval(knownCnInterval.Chromosome, new Interval(knownCnInterval.Start + 1, knownCnInterval.End));
         var refPloidy = referencePloidy.GetSingleReferencePloidy(interval);
         yield return(new CNInterval(knownCnInterval.Chromosome,
                                     knownCnInterval.Start, knownCnInterval.End, knownCnInterval.Cn)
         {
             ReferenceCopyNumber = refPloidy
         });
     }
 }
Ejemplo n.º 4
0
 private static Dictionary <string, List <CNInterval> > GetKnownCopyNumberWithReferencePloidy(ReferencePloidy referencePloidy, Dictionary <string, List <CNInterval> > knownCn)
 {
     return(knownCn.SelectValues(knownCnIntervals =>
                                 GetKnownCopyNumberWithReferencePloidy(knownCnIntervals, referencePloidy).ToList()));
 }