internal static IInterval <uint> ConvertPositionToCiInterval( this uint position, [NotNull] IVcfVariant variant, [NotNull] string ciInfoTag) { if (!variant.Info.TryGetValue(ciInfoTag, out var posString)) { return(BedInterval.Create(position > 0 ? position - 1 : 0, position == 0 ? 1 : position)); } var split = posString.Split(WittyerConstants.InfoValueDel); if (split.Length != 2) { throw VcfVariantFormatException.Create(variant.ToString(), ImmutableHashSet.Create(VcfColumn.Info), $"Invalid {ciInfoTag} found: {posString}", variant.ToStrings().ToList().AsReadOnly()); } var(start, stop) = ConvertPositionToCiInterval(position, (GetParsedAbsValue(split[0]), GetParsedAbsValue(split[1]))); return(BedInterval.Create(start, stop)); uint GetParsedAbsValue(string val) { var parsed = int.Parse(val); return((uint)(parsed < 0 ? -parsed : parsed)); } }
internal static IInterval <uint> ConvertPositionToCiInterval( this uint position, [NotNull] IVcfVariant variant, [NotNull] string ciInfoTag) { if (!variant.Info.TryGetValue(ciInfoTag, out var posString)) { return(BedInterval.Create(position > 0 ? position - 1 : 0, position == 0 ? 1 : position)); } var split = posString.Split(WittyerConstants.InfoValueDel); if (split.Length != 2) { throw VcfVariantFormatException.Create(variant.ToString(), ImmutableHashSet.Create(VcfColumn.Info), $"Invalid {ciInfoTag} found: {posString}", variant.ToStrings().ToList().AsReadOnly()); } var parsedStart = GetParsedAbsValue(split[0]); if (parsedStart == null) { throw new InvalidOperationException($"Failed to parse {ciInfoTag}={posString}!"); } var parsedStop = GetParsedAbsValue(split[1]); if (parsedStop == null) { throw new InvalidOperationException($"Failed to parse {ciInfoTag}={posString}!"); } var(start, stop) = ConvertPositionToCiInterval(position, (parsedStart.Value, parsedStop.Value)); return(BedInterval.Create(start, stop)); uint?GetParsedAbsValue(string val) => !int.TryParse(val, out var parsed) ? (uint?)null : (uint)(parsed < 0 ? -parsed : parsed); }
internal static InclusiveInterval <int> ParseCi([NotNull] this IVcfVariant variant, string tag) { if (!variant.Info.TryGetValue(tag, out var posString)) { return(new InclusiveInterval <int>(0, 0)); } var split = posString.Split(WittyerConstants.InfoValueDel); if (split.Length != 2) { throw VcfVariantFormatException.Create(variant.ToString(), ImmutableHashSet.Create(VcfColumn.Info), $"Invalid {tag} found: {posString}", variant.ToStrings().ToList().AsReadOnly()); } return(new InclusiveInterval <int>(int.Parse(split[0]), int.Parse(split[1]))); }