/// <summary> /// Given a set of structure and alignments between chains, and directionality to identify which structure contributes the N and C-terminus, /// return selections corresponding to each block of structure that is left remaining between fusion regions, and selections constituting the fusion /// regions themselves. /// </summary> /// <param name="structures"></param> /// <param name="alignments"></param> /// <param name="ncDirections"></param> /// <param name="blocks"></param> /// <param name="junctions"></param> public static void GetSelections(IStructure[] structures, SequenceAlignment[] alignments, bool[] ncDirections, out Selection[] blocks, out Selection[] junctions, out Selection[] removed) { junctions = new Selection[alignments.Length]; blocks = new Selection[structures.Length]; removed = new Selection[structures.Length]; // Mark which aas to remove without actually removing them at first, so that their indices remain unchanged while // those to be removed are being computed Selection remove = new Selection(); // Determine junction residues and residues that are removed due to splicing for (int alignmentIndex = 0; alignmentIndex < alignments.Length; alignmentIndex++) { Selection junction = new Selection(); bool ncDirection = ncDirections[alignmentIndex]; SequenceAlignment alignment = ncDirection ? alignments[alignmentIndex] : SequenceAlignment.Reversed(alignments[alignmentIndex]); // N as chain1 IStructure structureN = ncDirection ? structures[alignmentIndex] : structures[alignmentIndex + 1]; IStructure structureC = ncDirection ? structures[alignmentIndex + 1] : structures[alignmentIndex]; IChain chainN = structureN[alignment.ChainIndex1]; IChain chainC = structureC[alignment.ChainIndex2]; remove.Aas.UnionWith(chainN[alignment.Range1.Middle + 1, chainN.Count - 1]); remove.Aas.UnionWith(chainC[0, alignment.Range2.Middle]); junction.Aas.UnionWith(chainN[alignment.Range1.Start, alignment.Range1.Middle]); junction.Aas.UnionWith(chainC[alignment.Range2.Middle + 1, alignment.Range2.End]); junctions[alignmentIndex] = junction; } // Determine blocks as the set of aas in the original structure, minus junction residues and residues that are lost from fusion for (int structureIndex = 0; structureIndex < structures.Length; structureIndex++) { IStructure structure = structures[structureIndex]; Selection block = new Selection(structure.SelectMany(chain => chain)); removed[structureIndex] = Selection.Intersect(block, remove); block.ExceptWith(remove); if (structureIndex > 0) { block.ExceptWith(junctions[structureIndex - 1]); } if (structureIndex < junctions.Length) { block.ExceptWith(junctions[structureIndex]); } blocks[structureIndex] = block; } }
protected virtual IndexInsertAction[] CreateGroupedIndexInsertActions(IStructureSchema structureSchema, IStructure[] structures) { var indexesTableNames = structureSchema.GetIndexesTableNames(); var insertActions = new Dictionary<DataTypeCode, IndexInsertAction>(indexesTableNames.All.Length); foreach (var group in structures.SelectMany(s => s.Indexes).GroupBy(i => i.DataTypeCode)) { var insertAction = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, group.Key, group.ToArray()); if (insertAction.HasData) insertActions.Add(group.Key, insertAction); } var mergeStringsAndEnums = insertActions.ContainsKey(DataTypeCode.String) && insertActions.ContainsKey(DataTypeCode.Enum); if (mergeStringsAndEnums) { var strings = insertActions[DataTypeCode.String]; var enums = insertActions[DataTypeCode.Enum]; insertActions.Remove(DataTypeCode.Enum); insertActions[DataTypeCode.String] = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, DataTypeCode.String, strings.Data.MergeWith(enums.Data).ToArray()); } return insertActions.Values.ToArray(); }
protected virtual void InsertUniques(IStructureSchema structureSchema, IStructure[] structures) { if (!structures.Any()) return; var uniques = structures.SelectMany(s => s.Uniques).ToArray(); if (!uniques.Any()) return; if (uniques.Length == 1) MainDbClient.SingleInsertOfUniqueIndex(uniques[0], structureSchema); else MainDbClient.BulkInsertUniques(structureSchema, uniques); }