예제 #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)));
        }
예제 #3
0
 internal static WittyerGenotypedCopyNumberSample Create([NotNull] WittyerCopyNumberSample sample,
                                                         [NotNull] IGenotypeInfo gt)
 => new WittyerGenotypedCopyNumberSample(sample, gt);
예제 #4
0
 private WittyerGenotypedCopyNumberSample(WittyerCopyNumberSample sample, IGenotypeInfo gt)
 {
     BaseSample = sample;
     Gt         = gt;
 }