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)); }
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))); }