示例#1
0
        public static IWittyerSample CreateFromVariant(IVcfVariant baseVariant, [CanBeNull] IVcfSample sample, bool isReference)
        {
            if (isReference)
            {
                return(CreateReferenceSample(baseVariant, sample));
            }

            if (sample == null)
            {
                return(WittyerSampleInternal.Create(null));
            }

            var wittyerSample = WittyerSampleInternal.Create(sample);

            var hasGt = sample.SampleDictionary.ContainsKey(VcfConstants.GenotypeKey);

            if (!sample.SampleDictionary.TryGetValue(VcfConstants.CnSampleFieldKey, out var cnString))
            {
                return(hasGt
                    ? WittyerGenotypedSample.Create(wittyerSample, GenotypeInfo.CreateFromSample(sample))
                       as IWittyerSample
                    : wittyerSample);
            }

            uint?cnNumber;

            if (cnString == VcfConstants.MissingValueString)
            {
                cnNumber = null;
            }
            else if (uint.TryParse(cnString, out var cnNumberLocal))
            {
                cnNumber = cnNumberLocal;
            }
            else
            {
                throw new InvalidDataException($"{VcfConstants.CnSampleFieldKey} does not have a valid value in {baseVariant}");
            }

            var cnSample = WittyerCopyNumberSample.Create(wittyerSample, cnNumber);

            if (!hasGt)
            {
                return(cnSample);
            }

            var gtInfo = GenotypeInfo.CreateFromSample(sample);

            return(WittyerGenotypedCopyNumberSample.Create(cnSample, gtInfo));
        }
示例#2
0
        internal static IWittyerGenotypedCopyNumberSample CreateReferenceSample([NotNull] IVcfVariant baseVariant, [CanBeNull] IVcfSample sample)
        {
            var ploidy = 2;

            if (sample == null)
            {
                return(WittyerGenotypedCopyNumberSample.Create(
                           WittyerCopyNumberSample.Create(WittyerSampleInternal.Create(null), (uint)ploidy),
                           GenotypeInfo.CreateRef(ploidy, false)));
            }

            var isPhased = false;

            if (sample.SampleDictionary.TryGetValue(VcfConstants.GenotypeKey, out var originalGt))
            {
                isPhased = originalGt.Contains(VcfConstants.GtPhasedValueDelimiter);
                ploidy   = originalGt
                           .Split(isPhased ? VcfConstants.GtPhasedValueDelimiter : VcfConstants.GtUnphasedValueDelimiter).Length;
            }

            var cnSample = WittyerCopyNumberSample.Create(WittyerSampleInternal.Create(sample), (uint)ploidy);

            return(WittyerGenotypedCopyNumberSample.Create(cnSample, GenotypeInfo.CreateRef(ploidy, isPhased)));
        }
 internal static IWittyerGenotypedSample Create([NotNull] WittyerSampleInternal sample, [NotNull] IGenotypeInfo gt)
 => new WittyerGenotypedSample(sample, gt);
 private WittyerGenotypedSample(WittyerSampleInternal baseSample, IGenotypeInfo gt)
 {
     BaseSample = baseSample;
     Gt         = gt;
 }
示例#5
0
 public static IWittyerSample Create([NotNull] IVcfSample baseSample, WitDecision wit,
                                     [NotNull] IImmutableList <MatchEnum> what, [NotNull] IImmutableList <FailedReason> why)
 => WittyerSampleInternal.Create(baseSample, wit, what, why);
 internal static WittyerCopyNumberSample Create([NotNull] WittyerSampleInternal baseSample, uint?cn)
 => new WittyerCopyNumberSample(baseSample, cn);
 private WittyerCopyNumberSample([NotNull] WittyerSampleInternal baseSample, uint?cn)
 {
     BaseSample = baseSample;
     Cn         = cn;
 }