/// <summary> /// Execute the change order, assigning tags as required /// </summary> void ExecuteChangeOrder(ChangeOrder order) { int affectedItems = 0; Log("Executing {0} | Excl:{1} Params:{2} Tag:{3}", order.Type, order.ExcludeAlreadyTagged, string.Join(", ", order.Parameters), order.Tag); if (order.Type == ChangeOrderType.TagByChainId) { foreach (var item in ProteinDB.Where(x => order.Parameters.Contains(x.ChainId))) { if (!string.IsNullOrWhiteSpace(order.Tag) || !order.ExcludeAlreadyTagged) { item.Tag = order.Tag; affectedItems++; } } } else if (order.Type == ChangeOrderType.TagByDescription) { foreach (var item in ProteinDB.Where(x => order.Parameters.Contains(x.Description))) { if (!string.IsNullOrWhiteSpace(order.Tag) || !order.ExcludeAlreadyTagged) { item.Tag = order.Tag; affectedItems++; } } } else if (order.Type == ChangeOrderType.TagByTag) { if (order.ExcludeAlreadyTagged) { throw new InvalidOperationException("Change Order TagByTag can not exclude already tagged chains"); } foreach (var item in ProteinDB.Where(x => order.Parameters.Contains(x.Description))) { item.Tag = order.Tag; affectedItems++; } } else { throw new NotImplementedException("Change Order not implemented"); } Log("Afected {0} chains", affectedItems); BuildChainNames(); }
/// <summary> /// Extract and group chain names from all chains /// </summary> private void BuildChainNames() { ChainNames = ProteinDB .Where(x => string.IsNullOrWhiteSpace(x.Tag)) .GroupBy(x => x.Description ?? string.Empty) .Select(x => new ChainNameGroup { Name = x.Key, Count = x.Count(), LengthMax = x.Max(y => y.Length), LengthMin = x.Min(y => y.Length), LengthAvg = x.Average(y => y.Length), Chains = x.AsEnumerable() }); Log("{0} chain names found in {1} chains", ChainNames.Count(), ProteinDB.Count()); Stats = ProteinDB .GroupBy(x => x.Tag) .Select(x => new { Tag = x.Key, Count = x.Count() }); OnSelectedChainNamesChanged(); }