public void ClearGrid() { DataTableMx dt = Qm.DataTable; dt.Clear(); ToolHelper.RefreshDataDisplay(Qm); string title = "Related Structures"; Qm.MoleculeGrid.SetTableHeaderCaption(0, title); return; }
/// <summary> /// ClearDataAndGrid /// </summary> public void ClearDataAndGrid() { if (Qm == null || Qm.DataTable == null) { return; } DataTableMx dt = Qm.DataTable; dt.Clear(); ToolHelper.RefreshDataDisplay(Qm); SearchStatusLabel.Appearance.ForeColor = Color.Black; SearchStatusLabel.Text = "Matching Structures: 0"; //string title = "Matching Structures"; //Qm.MoleculeGrid.SetTableHeaderCaption(0, title); return; }
/// <summary> /// Update the match counts panel and structure view based on a set of structures and filter values /// </summary> /// <param name="excludeCurrentHitList"></param> /// <param name="rssrs"></param> public void DisplayRelatedStructures( List <StructSearchMatch> fml) { MoleculeMx cs; if (fml == null || fml.Count == 0) { DisplayEmptyStructureGrid(); return; } if (StructureDisplayQuery == null) { BuildStructureDisplayQuery(); // initial setup } Query q = StructureDisplayQuery; QueryTable qt = q.Tables[0]; DataTableMx dt = Qm.DataTable; MoleculeGridControl grid = Qm.MoleculeGrid; grid.BeginUpdate(); dt.Clear(); // filter table HashSet <string> cidSet = new HashSet <string>(); for (int mi = 0; mi < fml.Count; mi++) // build and add the rows to the datatable of structures { StructSearchMatch ssm = fml[mi]; DataRowMx dr = dt.NewRow(); dr[qt.Alias + ".CompoundId"] = ssm.SrcCid; cs = new MoleculeMx(ssm.MolStringFormat, ssm.MolString); if (Lex.IsDefined(ssm.SrcCid)) { cs.SetMolComments("CorpId=" + ssm.SrcCid); // Attach CorpId to Molfile so it will be rendered correctly } if (ssm.SearchType == StructureSearchType.SmallWorld && Lex.IsDefined(ssm.GraphicsString)) { cs.SvgString = ssm.GraphicsString; } dr[qt.Alias + ".Structure"] = cs; dr[qt.Alias + ".MatchType"] = ssm.SearchTypeName; dr[qt.Alias + ".MatchScore"] = ssm.MatchScore; dr[qt.Alias + ".Database"] = ssm.SrcName; dt.Rows.Add(dr); cidSet.Add(ssm.SrcCid); } Qm.DataTableManager.InitializeRowAttributes(); string title = "Related Structures - Matches: " + fml.Count + ", Compound Ids: " + cidSet.Count; Qm.MoleculeGrid.SetTableHeaderCaption(0, title); if (!RSC.MoleculeGridPageControl.Visible) { RSC.MoleculeGridPageControl.Visible = true; } grid.EndUpdate(); ToolHelper.RefreshDataDisplay(Qm); return; }
/// <summary> /// Attempt to read existing results file into the query DataTable /// </summary> /// <param name="qm"></param> public void ReadBinaryResultsFile(string fileName) { QueryTable qt; QueryColumn qc; BinaryReader br = null; Stopwatch sw = Stopwatch.StartNew(); try { bool saveHandlersEnabled = Qm.DataTable.EnableDataChangedEventHandlers(false); // disable for faster load bool saveUpdateMaxRowsPerKey = UpdateMaxRowsPerKeyEnabled; UpdateMaxRowsPerKeyEnabled = false; // disable for faster load int id = Query.UserObject.Id; if (id <= 0) { throw new Exception("Query not saved"); } if (DataTableMx == null || DataTableMx.Columns.Count == 0) { throw new Exception("DataTable not defined"); } br = BinaryFile.OpenReader(fileName); string sq = br.ReadString(); Query q0 = Query.Deserialize(sq); // deserialize the saved query QueryManager qm0 = new QueryManager(); qm0.LinkMember(q0); ResultsFormat rf0 = new ResultsFormat(qm0, OutputDest.WinForms); ResultsFormatFactory rff0 = new ResultsFormatFactory(qm0, OutputDest.WinForms); rff0.Build(); // build format with vo positions // The cached query cols should match those of the current query: however, // we'll create a mapping just in case they don't int voArrayLen0 = br.ReadInt32(); // cached vo array len int voArrayLen = DataTableMx.Columns.Count - KeyValueVoPos; // current query vo array len List <int> q0VoMap = new List <int>(); // vo position in cached query data List <int> qVoMap = new List <int>(); // vo position in current version of query q0VoMap.Add(0); // first position is the common key value qVoMap.Add(0); foreach (QueryTable qt0 in q0.Tables) // scan each table in cached data { foreach (QueryColumn qc0 in qt0.QueryColumns) // and each column { if (qc0.VoPosition < 0) { continue; // skip if not mapped to the vo in cached data } int q0VoPos = qc0.VoPosition - KeyValueVoPos; // where it is in cache int qvoPos = -1; // where it will go qt = Query.GetTableByName(qt0.MetaTable.Name); if (qt != null) { qc = qt.GetQueryColumnByName(qc0.MetaColumn.Name); if (qc != null) { qvoPos = qc.VoPosition - KeyValueVoPos; } } q0VoMap.Add(q0VoPos); // where it is in saved data qVoMap.Add(qvoPos); // where it will go (not including attributes & check cols) } } if (q0VoMap.Count != voArrayLen0) { throw new Exception("Cached Vo length doesn't match list of selected columns"); } DataTableMx.Clear(); // clear the rows CidList cidList = new CidList(); object[] voa = new object[voArrayLen]; // array to fill while (!BinaryFile.ReaderEof(br)) // process each row { for (int mi = 0; mi < q0VoMap.Count; mi++) // each col { object o = VoArray.ReadBinaryItem(br); if (mi == 0 && o != null) // add to key list if key { cidList.Add(o.ToString(), false); } if (qVoMap[mi] >= 0) // save in new buf if mapped { voa[qVoMap[mi]] = o; } } DataRowMx dr = AddDataRow(voa); } br.Close(); Qm.DataTable.EnableDataChangedEventHandlers(saveHandlersEnabled); UpdateMaxRowsPerKeyEnabled = saveUpdateMaxRowsPerKey; InitializeRowAttributes(false); ResultsKeys = cidList.ToStringList(); // include keys in DTM as well double ms = sw.Elapsed.TotalMilliseconds; return; } catch (Exception ex) { if (br != null) { br.Close(); } throw new Exception(ex.Message, ex); } }