/// <summary> /// rebuild the interfaces from XML coordinate file and the interface definition /// </summary> /// <param name="pdbId"></param> /// <param name="type"></param> /// <returns></returns> public InterfaceChains[] GetCrystInterfacesFromXmlFile(string pdbId, string type) { ContactInCrystal crystInterfaceRetriever = new ContactInCrystal(); string queryString = string.Format("Select Distinct * From CrystEntryInterfaces " + " Where PdbID = '{0}';", pdbId); DataTable interfaceDefTable = ProtCidSettings.protcidQuery.Query(queryString); Dictionary <int, string> interfaceDefHash = GetInterfaceDefHash(interfaceDefTable); string xmlFile = Path.Combine(ProtCidSettings.dirSettings.coordXmlPath, pdbId + ".xml.gz"); string coordXmlFile = ParseHelper.UnZipFile(xmlFile, ProtCidSettings.tempDir); bool interfaceExist = false; try { crystInterfaceRetriever.FindInteractChains(coordXmlFile, interfaceDefHash, out interfaceExist); SetInterfaceEntities(crystInterfaceRetriever.InterfaceChainsList, interfaceDefTable); } catch { return(null); } finally { File.Delete(coordXmlFile); } return(crystInterfaceRetriever.InterfaceChainsList); }
/// <summary> /// interfaces in crystal structures /// </summary> /// <param name="pdbId"></param> /// <param name="interfaceExist"></param> /// <returns></returns> private InterfaceChains[] GetCrystInterfacesFromDb(string pdbId) { string xmlFile = Path.Combine(ProtCidSettings.dirSettings.coordXmlPath, pdbId + ".xml.gz"); if (!File.Exists(xmlFile)) { return(null); } string coordXmlFile = ParseHelper.UnZipFile(xmlFile, ProtCidSettings.tempDir); Dictionary <int, string> interfaceDefHash = null; Dictionary <int, string> interfaceEntityInfoHash = null; bool interfaceExist = true; GetCrystInterfaceDef(pdbId, ref interfaceDefHash, ref interfaceEntityInfoHash); contactInCrystal.FindInteractChains(coordXmlFile, interfaceDefHash, interfaceEntityInfoHash, out interfaceExist); if (!interfaceExist) { return(null); } File.Delete(coordXmlFile); return(contactInCrystal.InterfaceChainsList); }
/// <summary> /// /// </summary> /// <param name="pdbId"></param> /// <param name="interfaceIds"></param> /// <param name="type"></param> /// <returns></returns> public InterfaceChains[] GetCrystInterfacesFromXmlFile(string pdbId, int[] interfaceIds, string type) { ContactInCrystal crystInterfaceRetriever = new ContactInCrystal(); string queryString = string.Format("Select Distinct * From CrystEntryInterfaces " + " Where PdbID = '{0}';", pdbId); DataTable interfaceDefTable = ProtCidSettings.protcidQuery.Query(queryString); if (interfaceDefTable.Rows.Count == 0) { return(null); } Dictionary <int, string> interfaceDefHash = GetInterfaceDefHash(interfaceDefTable, interfaceIds); string xmlFile = Path.Combine(ProtCidSettings.dirSettings.coordXmlPath, pdbId + ".xml.gz"); string coordXmlFile = ParseHelper.UnZipFile(xmlFile, ProtCidSettings.tempDir); bool interfaceExist = false; crystInterfaceRetriever.FindInteractChains(coordXmlFile, interfaceDefHash, out interfaceExist); /* InterfaceChains[] chainInterfaces = new InterfaceChains[interfaceIds.Length]; * int count = 0; * foreach (int interfaceId in interfaceIds) * { * foreach (InterfaceChains crystInterface in crystInterfaceRetriever.InterfaceChainsList) * { * if (crystInterface.interfaceId == interfaceId) * { * chainInterfaces[count] = crystInterface; * count++; * } * } * }*/ File.Delete(coordXmlFile); SetInterfaceEntities(crystInterfaceRetriever.InterfaceChainsList, interfaceDefTable); return(crystInterfaceRetriever.InterfaceChainsList); // return chainInterfaces; }
/// <summary> /// /// </summary> /// <param name="pdbId"></param> /// <param name="isUpdate"></param> /// <returns></returns> public InterfaceChains[] FindUniquePfamInterfaces(string pdbId, bool isUpdate) { string spaceGroup = GetEntrySpaceGroup(pdbId); string xmlFile = Path.Combine(ProtCidSettings.dirSettings.coordXmlPath, pdbId + ".xml.gz"); if (!Directory.Exists(ProtCidSettings.tempDir)) { Directory.CreateDirectory(ProtCidSettings.tempDir); } string coordXmlFile = ParseHelper.UnZipFile(xmlFile, ProtCidSettings.tempDir); InterfaceChains[] entryInterfaces = null; AsuInterfaces asuInterfacesNonCryst = new AsuInterfaces(); try { if (spaceGroup == "NMR") { entryInterfaces = asuInterfacesNonCryst.GetAsuInterfacesFromXml(coordXmlFile); if (entryInterfaces == null) { ProtCidSettings.progressInfo.progStrQueue.Enqueue("NMR entry " + pdbId + " is a monomer."); #if DEBUG ProtCidSettings.logWriter.WriteLine("NMR entry " + pdbId + " is a monomer."); ProtCidSettings.logWriter.Flush(); #endif } } else { ContactInCrystal contactInCrystal = new ContactInCrystal(); int numOfChainsInUnitCell = contactInCrystal.FindInteractChains(coordXmlFile); if (numOfChainsInUnitCell > 64) { ProtCidSettings.progressInfo.progStrQueue.Enqueue("The number of chains of " + pdbId + " in a unit cell: " + numOfChainsInUnitCell.ToString()); #if DEBUG ProtCidSettings.logWriter.WriteLine("The number of chains of " + pdbId + " in a unit cell: " + numOfChainsInUnitCell.ToString()); ProtCidSettings.logWriter.Flush(); #endif } if (contactInCrystal.InterfaceChainsList == null) { ProtCidSettings.progressInfo.progStrQueue.Enqueue("No interfaces exist in entry: " + pdbId); } entryInterfaces = contactInCrystal.InterfaceChainsList; } } catch (Exception ex) { ProtCidSettings.progressInfo.progStrQueue.Enqueue("Retrieving interfaces from " + pdbId + " errors: " + ex.Message); #if DEBUG ProtCidSettings.logWriter.WriteLine("Retrieving interfaces from " + pdbId + " errors: " + ex.Message); ProtCidSettings.logWriter.Flush(); #endif } finally { if (File.Exists(coordXmlFile)) { File.Delete(coordXmlFile); } } return(entryInterfaces); }
/// <summary> /// find unique interfaces in a crystal /// </summary> /// <param name="xmlFile"></param> /// <returns></returns> public void FindUniqueInterfaces(string xmlFile, string sg_asu, ref InterfaceChains[] uniqueEntryinterfaces) { string pdbId = xmlFile.Substring(xmlFile.LastIndexOf("\\") + 1, 4); string coordXmlFile = ParseHelper.UnZipFile(xmlFile, ProtCidSettings.tempDir);; string queryString = string.Format("Select * From CrystEntryInterfaces Where PdbID = '{0}';", pdbId); DataTable crystInterfaceTable = ProtCidSettings.protcidQuery.Query(queryString); Dictionary <int, string> interfaceDefHash = new Dictionary <int, string> (); Dictionary <int, string> interfaceEntityInfoHash = new Dictionary <int, string> (); if (crystInterfaceTable.Rows.Count > 0) { // build cryst interfaces based on database info foreach (DataRow dRow in crystInterfaceTable.Rows) { string symOpString1 = dRow["AsymChain1"].ToString().Trim() + "_" + dRow["SymmetryString1"].ToString().Trim(); string symOpString2 = dRow["AsymChain2"].ToString().Trim() + "_" + dRow["SymmetryString2"].ToString().Trim(); if (!interfaceDefHash.ContainsKey(Convert.ToInt32(dRow["InterfaceId"].ToString()))) { interfaceDefHash.Add(Convert.ToInt32(dRow["InterfaceId"].ToString()), symOpString1 + ";" + symOpString2); interfaceEntityInfoHash.Add(Convert.ToInt32(dRow["InterfaceId"].ToString()), dRow["EntityID1"].ToString() + "_" + dRow["EntityID2"].ToString()); } } } try { ContactInCrystal contactInCrystal = new ContactInCrystal(); if (interfaceDefHash.Count > 0) // interfaces defined in db { bool interfaceExist = true; contactInCrystal.FindInteractChains(coordXmlFile, interfaceDefHash, interfaceEntityInfoHash, out interfaceExist); if (interfaceExist) { uniqueEntryinterfaces = contactInCrystal.InterfaceChainsList; foreach (InterfaceChains interfaceChains in uniqueEntryinterfaces) { DataRow[] interfaceDefRows = crystInterfaceTable.Select (string.Format("InterfaceId = '{0}'", interfaceChains.interfaceId)); interfaceChains.entityId1 = Convert.ToInt32(interfaceDefRows[0]["EntityID1"].ToString()); interfaceChains.entityId2 = Convert.ToInt32(interfaceDefRows[0]["EntityID2"].ToString()); } } } else // no interface definition in db, retrieve interfaces from coordinate file { int numOfChainsInUnitCell = contactInCrystal.FindInteractChains(coordXmlFile); if (numOfChainsInUnitCell > 64) { #if DEBUG ProtCidSettings.logWriter.WriteLine("The number of chains of " + pdbId + " in a unit cell: " + numOfChainsInUnitCell.ToString()); #endif } if (contactInCrystal.InterfaceChainsList != null) { uniqueEntryinterfaces = contactInCrystal.InterfaceChainsList; AssignEntryInterfacesToTable(uniqueEntryinterfaces, pdbId, sg_asu); AssignEntryInterfaceCompToTable(pdbId, uniqueEntryinterfaces); } } } catch (Exception ex) { if (ex.Message.ToLower().IndexOf("no protein chains") < -1 && ex.Message.ToLower().IndexOf("no symmetry operators") < -1) { throw new Exception(pdbId + ": " + ex); } } finally { if (File.Exists(coordXmlFile)) { File.Delete(coordXmlFile); } } }
/// <summary> /// find unique interfaces in a crystal /// </summary> /// <param name="xmlFile"></param> /// <returns></returns> public void FindUniqueInterfaces(string repEntry, string[] pdbIdList) { CrystInterfaceTables.InitializeTables(); asuInterfacesNonCryst = new AsuInterfaces(); List <string> entryList = new List <string> (pdbIdList); entryList.Insert(0, repEntry); if (!Directory.Exists(ProtCidSettings.tempDir)) { Directory.CreateDirectory(ProtCidSettings.tempDir); } ProtCidSettings.progressInfo.ResetCurrentProgressInfo(); ProtCidSettings.progressInfo.currentOperationLabel = "Computing Interfaces."; ProtCidSettings.progressInfo.totalStepNum = entryList.Count; ProtCidSettings.progressInfo.totalOperationNum = entryList.Count; ProtCidSettings.progressInfo.progStrQueue.Enqueue("Computing interfaces from crystal structures."); Dictionary <string, InterfaceChains[]> entryInterfacesHash = new Dictionary <string, InterfaceChains[]> (); Dictionary <string, string> entrySgHash = GetEntrySgAsu(entryList); foreach (string pdbId in entryList) { ProtCidSettings.progressInfo.currentFileName = pdbId; ProtCidSettings.progressInfo.currentOperationNum++; ProtCidSettings.progressInfo.currentStepNum++; InterfaceChains[] entryInterfaces = null; string xmlFile = Path.Combine(ProtCidSettings.dirSettings.coordXmlPath, pdbId + ".xml.gz"); string coordXmlFile = ParseHelper.UnZipFile(xmlFile, ProtCidSettings.tempDir); try { if ((string)entrySgHash[pdbId] == "NMR") { entryInterfaces = asuInterfacesNonCryst.GetAsuInterfacesFromXml(coordXmlFile); } else { ContactInCrystal contactInCrystal = new ContactInCrystal(); int numOfChainsInUnitCell = contactInCrystal.FindInteractChains(coordXmlFile); if (numOfChainsInUnitCell > 64) { ProtCidSettings.progressInfo.progStrQueue.Enqueue("The number of chains of " + pdbId + " in a unit cell: " + numOfChainsInUnitCell.ToString()); } if (contactInCrystal.InterfaceChainsList == null) { continue; } entryInterfaces = contactInCrystal.InterfaceChainsList; } AssignEntryInterfacesToTable(entryInterfaces, pdbId, (string)entrySgHash[pdbId]); entryInterfacesHash.Add(pdbId, entryInterfaces); string deleteString = string.Format("Delete From CrystEntryInterfaces Where PdbID = '{0}'", pdbId); ProtCidSettings.protcidQuery.Query(deleteString); dbInsert.InsertDataIntoDBtables (ProtCidSettings.protcidDbConnection, CrystInterfaceTables.crystInterfaceTables[CrystInterfaceTables.CrystEntryInterfaces]); CrystInterfaceTables.crystInterfaceTables[CrystInterfaceTables.CrystEntryInterfaces].Clear(); } catch (Exception ex) { if (ex.Message.ToLower().IndexOf("no protein chains") < -1 && ex.Message.ToLower().IndexOf("no symmetry operators") < -1) { ProtCidSettings.progressInfo.progStrQueue.Enqueue(pdbId + ": " + ex.Message); #if DEBUG ProtCidSettings.logWriter.WriteLine(pdbId + ": " + ex.Message); #endif } } finally { if (File.Exists(coordXmlFile)) { File.Delete(coordXmlFile); } } } Directory.Delete(ProtCidSettings.tempDir, true); // compare interfaces between representative entry and its homology entries // save data into db crystInterfaceComp.CompareRepHomoEntryInterfacesInGroup(repEntry, pdbIdList, entryInterfacesHash); ProtCidSettings.progressInfo.progStrQueue.Enqueue("Done!"); ProtCidSettings.progressInfo.threadFinished = true; }