/// <summary> /// Initialize with associated command line control /// </summary> /// <param name="commandLineControl"></param> public static QuickSearchPopup Initialize( MRUEdit commandLineControl, Form parentForm, ContentsTreeControl contentstree) { QuickSearchPopup qsp = null; AssertMx.IsNotNull(commandLineControl, "CommandLineControl"); AssertMx.IsNotNull(parentForm, "ParentForm"); foreach (Control c in parentForm.Controls) // see if already exists { if (c is QuickSearchPopup) { qsp = c as QuickSearchPopup; break; } } bool newPopup = false; if (qsp == null) // need to create new popup in parent form { qsp = new QuickSearchPopup(); parentForm.Controls.Add(qsp); newPopup = true; } qsp.Initialize2(commandLineControl, parentForm, contentstree, newPopup); return(qsp); }
/// <summary> /// Ignore criteria because they are used as parameters for formatting Rgroup table /// not as search criteria. /// </summary> /// <param name="mt"></param> /// <returns></returns> public override bool IgnoreCriteria( MetaTable mt) { AssertMx.IsNotNull(SpecificBroker, "SpecificBroker"); return(SpecificBroker.IgnoreCriteria(mt)); }
/// <summary> /// NextRow - Return the next matching row value object /// </summary> /// <returns></returns> public override Object[] NextRow() { AssertMx.IsNotNull(SpecificBroker, "SpecificBroker"); Object[] row = SpecificBroker.NextRow(); return(row); }
/// <summary> /// Execute a chunk of JavaScript, wait for completion & return response /// </summary> /// <param name="script"></param> public static object ExecuteScript( KekuleJsWinFormsBrowserMsft KekuleJsBrowser, string script) { //if (DebugMx.True) return new JavascriptResponse(); // disable - debug Stopwatch sw = Stopwatch.StartNew(); if (KekuleJsBrowser?.Browser?.Document == null) { AssertMx.IsNotNull(KekuleJsBrowser?.Browser?.Document, "KekuleJsBrowser?.Browser?.Document"); } WebBrowser browser = KekuleJsBrowser.Browser; if (Debug) { DebugLog.Message("Script: " + script + KekuleJsBrowser.IdText); } object result = browser.Document.InvokeScript("execScript", new Object[] { script, "JavaScript" }); if (Debug) { DebugLog.StopwatchMessage("Script complete, Time: ", sw); } return(result); }
internal void SetupColumnsTab() { QueryColumn qc = null; ColumnMapMsx map = null; AssertMx.IsNotNull(SVP, "ViewManager"); //AssertMx.IsNotNull(SVP.BaseQuery, "ViewQuery"); //ColumnsTabSourceQueryControl.Setup(SVM.SVP.DataMap); // Id column //IdColumnQc = CurrentMap.ColumnMapCollection.GetQueryColumnForSpotfireColumnName(V.IdColumnName); //if (IdColumnQc == null) //{ // IdColumnQc = SVP.BaseQuery.GetFirstMatchingQueryColumn(MetaColumnType.CompoundId, mustBeSelected: true); //} //IdColumnSelector.Setup(SVP, IdColumnQc, EditValueChanged); // Focus Column //FocusColumnQc = CurrentMap.ColumnMapCollection.GetQueryColumnForSpotfireColumnName(V.FocusColumnName); //if (FocusColumnQc == null) //{ // FocusColumnQc = SVP.BaseQuery.GetFirstMatchingQueryColumn(MetaColumnType.Structure, mustBeSelected: true); //} //FocusColumnSelector.Setup(SVP, FocusColumnQc, EditValueChanged); // Horizontal & vertical chart setups SetupCondFormatRulesFromColorCodingItems(HorizontalGradientBarChartControl, V.SelectedColumns, CondFormatStyle.ColorScale); SetupCondFormatRulesFromColorCodingItems(VerticalBarChartControl, V.FeatureColumns, CondFormatStyle.ColorSet); return; }
/// <summary> /// Do a quick validation on a node to be sure the key document links are defined /// </summary> public void ValidateNode() { AssertMx.IsNotNull(App, "App"); AssertMx.IsNotNull(App?.Document, "App.Document"); AssertMx.IsNotNull(App?.Document?.DataManager, "App.Document.DataManager"); AssertMx.IsNotNull(App?.Document?.DataManager?.TableCollection, "App.Document.TableCollection"); AssertMx.IsNotNull(App?.Document?.Pages, "App.Document.Pages"); }
/// <summary> /// GetFormValues /// </summary> /// <param name="tso"></param> /// <returns></returns> public bool GetFormValues( QueryColumn tso) { QueryColumn qc = QueryColumn; AssertMx.IsNotNull(qc, "QueryColumn"); return(true); }
/// <summary> /// Setup the control for specified view /// </summary> /// <param name="view"></param> public void Setup( DataTableMapMsx dataTableMap, EventHandler callerEditValueChangedEventHandler = null) { InSetup = true; DataTableMap = dataTableMap; CallerEditValueChangedHandler = callerEditValueChangedEventHandler; QueryTablesComboBox.Text = ""; QueryTablesComboBox.SelectedItem = null; ComboBoxItemCollection items = QueryTablesComboBox.Properties.Items; items.Clear(); QueryTablesComboBox.Text = ""; AssertMx.IsNotNull(Query, "Query"); foreach (QueryTable qtEnum in Query.Tables) { items.Add(new ComboBoxItem(new LabeledUiItem(qtEnum.ActiveLabel, qtEnum))); } items.Add(AllTablesItem); items.Add(NoTablesItem); QueryTable qt = DataTableMap?.QueryTable; if (dataTableMap.IsMappedToSingleQueryTable) { QueryTablesComboBox.Text = qt.ActiveLabel; QueryTablesComboBox.SelectedItem = new LabeledUiItem(qt.ActiveLabel, qt); } else if (dataTableMap.IsMappedToAllQueryTables) // if cols are mapped assume all tables { QueryTablesComboBox.Text = AllTablesItem.Label; QueryTablesComboBox.SelectedItem = AllTablesItem; } else // not mapped to any tables { QueryTablesComboBox.Text = NoTablesItem.Label; QueryTablesComboBox.SelectedItem = NoTablesItem; } InSetup = false; return; }
/// <summary> /// Build query to get summarization detail for RgroupMatrix data element /// </summary> /// <param name="mt"></param> /// <param name="mc"></param> /// <param name="resultId">act_code.compound_id</param> /// <returns></returns> public override Query GetDrilldownDetailQuery( MetaTable mt, MetaColumn mc, int level, string resultId) { AssertMx.IsNotNull(SpecificBroker, "SpecificBroker"); Query q = SpecificBroker.GetDrilldownDetailQuery(mt, mc, level, resultId); return(q); }
/// CopyCriteriaToKeyQueryCritera (Query.KeyCriteria has precedence over QC.Critera) public void CopyCriteriaToQueryKeyCritera( Query query) { AssertMx.IsNotNull(query, "Query"); string criteria = Criteria; string colName = MetaColumnName + " "; // prepend metacolumn name if not done yet if (Lex.StartsWith(criteria, colName)) // remove col name { criteria = criteria.Substring(colName.Length); } query.KeyCriteria = criteria; query.KeyCriteriaDisplay = CriteriaDisplay; return; }
/// <summary> /// Adding a new SasMap view to an existing query /// </summary> /// <param name="args"></param> /// <returns></returns> public DialogResult ShowInitialViewSetupDialog( QueryColumn sasQc, Query baseQuery) { MetaTable mt; QueryColumn qc = null; DialogResult dr; AssertMx.IsNotNull(sasQc, "SasQc"); AssertMx.IsNotNull(SasQuery, "SasMapQuery"); SasQc = sasQc; BaseQuery = baseQuery; Parms = GetParmsFromQueryColumnCriteria(SasQc); qc = BaseQuery?.GetFirstKeyColumn(); if (qc == null) { qc = QueryTable.GetDefaultRootQueryTable()?.KeyQueryColumn; } qc = qc.Clone(); Parms.KeyCriteriaQc = qc; // assign QC with undefined criteria QueryManager refQm = (baseQuery.QueryManager as QueryManager); List <string> resultsKeys = refQm?.DataTableManager?.ResultsKeys; if (resultsKeys != null && resultsKeys.Count > 0) { string listText = Csv.JoinCsvString(resultsKeys); qc.CriteriaDisplay = CidList.FormatAbbreviatedCidListForDisplay(qc, listText); qc.Criteria = qc.MetaColumn.Name + " IN (" + listText + ")"; } Parms.EndpointMc = BaseQuery?.GetFirstResultColumnByPriority(true)?.MetaColumn; // pick the highest priority result column as the default endpoint dr = Edit(); if (dr == DialogResult.OK) { StoreParmsInQueryColumnCriteria(Parms, SasQc); } return(dr); }
/// <summary> /// CopyCriteriaFromKeyQueryCritera - Query.KeyCriteria has precedence over QC.Critera /// </summary> public void CopyCriteriaFromQueryKeyCriteria( Query query) { AssertMx.IsNotNull(query, "Query"); Criteria = query.KeyCriteria; CriteriaDisplay = query.KeyCriteriaDisplay; if (Lex.IsUndefined(Criteria)) { return; // undefined } string colName = MetaColumnName + " "; // prepend metacolumn name if not done yet if (!Lex.StartsWith(Criteria, colName)) { Criteria = colName + Criteria; } return; }
/// <summary> /// Invoke the editor /// </summary> /// <param name="qc">QueryColumn to edit</param> /// <returns></returns> public static bool Edit( QueryColumn qc) { AssertMx.IsNotNull(qc, "qc"); if (Instance == null) { Instance = new CriteriaCompoundId(); } new JupyterGuiConverter().ConvertFormOrUserControl(Instance); if (qc.IsKey) // if key col be sure qc is in sync with Query.KeyCriteria { qc.CopyCriteriaFromQueryKeyCriteria(); } if (qc.Criteria.Trim().StartsWith("=") && qc.MetaColumn != null) { qc.Criteria = qc.MetaColumnName + " " + qc.Criteria; } Instance.Qc = qc; Instance.Setup(qc); DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm); if (dr == DialogResult.OK) { if (qc.IsKey) // if key col then update Query.KeyCriteria { qc.CopyCriteriaToQueryKeyCritera(); } return(true); } else { return(false); } }
/// <summary> /// Edit the Cids criteris /// </summary> /// <returns></returns> bool EditCids() { QueryColumn qc = QueryColumn; AssertMx.IsNotNull(qc, "QueryColumn"); if (!CriteriaEditor.GetCompoundIdCriteria(qc)) { return(false); } if (Lex.IsDefined(qc.CriteriaDisplay)) { Cids.Text = qc.CriteriaDisplay; } else { Cids.Text = qc.Criteria; } return(true); }
/// <summary> /// Search a single file /// </summary> void SearchSingleFile(int fi) { StructSearchMatch sm = null; AssertMx.IsNotNull(FpDao, "FpDao"); List <StructSearchMatch> matchList = FileMatchLists[fi]; AssertMx.IsNotNull(matchList, "matchList"); OpenBitSet queryObs = new OpenBitSet(QueryFpLongArray, QueryFpLongArray.Length); AssertMx.IsNotNull(queryObs, "queryObs"); OpenBitSet dbObs = new OpenBitSet(QueryFpLongArray, QueryFpLongArray.Length); // gets set to DB fp for intersect AssertMx.IsNotNull(dbObs, "dbObs"); FileStream fs = FileStreamReaders[fi]; AssertMx.IsNotNull(fs, "fs"); ReadFingerprintRecArgs a = new ReadFingerprintRecArgs(); a.Initialize(fs, QueryFpLongArray.Length); try { while (true) { bool readOk = FpDao.ReadRawFingerprintRec(a); if (!readOk) { break; } //if (IsSrcCidMatch("03435269", a)) a = a; // debug dbObs.Bits = a.fingerprint; dbObs.Intersect(queryObs); int commonCnt = (int)dbObs.Cardinality(); float simScore = commonCnt / (float)(a.cardinality + QueryFpCardinality - commonCnt); if (simScore >= MinimumSimilarity) { sm = ReadFingerprintRec_To_StructSearchMatch(a); sm.SearchType = StructureSearchType.MolSim; sm.MatchScore = simScore; matchList.Add(sm); } } } catch (Exception ex) { string msg = ex.Message; msg += string.Format("\r\nfi: {0}, fs.Name: {1}, sm: {2}", fi, fs.Name, sm != null ? sm.Serialize() : ""); DebugLog.Message(DebugLog.FormatExceptionMessage(ex, msg)); throw new Exception(msg, ex); } return; }
public static bool Edit( QueryColumn qc) { AssertMx.IsNotNull(qc, "qc"); MetaColumn mc = qc.MetaColumn; if (Instance == null) { Instance = new CriteriaYesNo(); } new JupyterGuiConverter().ConvertFormOrUserControl(Instance); Instance.Text = "Search criteria for " + qc.ActiveLabel; Instance.Prompt.Text = "Select a search option for " + qc.ActiveLabel + " from the list below."; ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(qc.Criteria); if (psc == null) { psc = new ParsedSingleCriteria(); // no criteria } if (Lex.Eq(psc.Value, "Y")) { Instance.YesCheckEdit.Checked = true; } else if (Lex.Eq(psc.Value, "N")) { Instance.NoCheckEdit.Checked = true; } else { Instance.None.Checked = true; } DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm); if (dr == DialogResult.OK) { if (Instance.YesCheckEdit.Checked) { qc.CriteriaDisplay = "= Y"; qc.Criteria = mc.Name + " = 'Y'"; } else if (Instance.NoCheckEdit.Checked) { qc.CriteriaDisplay = "= N"; qc.Criteria = mc.Name + " = 'N'"; } else if (Instance.None.Checked) { qc.CriteriaDisplay = ""; qc.Criteria = ""; } return(true); } else { return(false); } }
/// <summary> /// Try to get the row at the given index from the buffer or cache /// </summary> /// <param name="ri"></param> /// <returns></returns> /// public object[] GetRow( int ri) { object[] vo = null; if (ri < 0 || ri >= TotalRowCount) { string msg = string.Format("Row {0} not in cache or buffer (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count); throw new InvalidDataException(msg); } // See if in buffer if (ri >= RowsWrittenToCache) { vo = (object[])RowBuffer[ri - RowsWrittenToCache]; if (DebugCaching) { DebugLog.Message(string.Format("Row: {0} in Buffer (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count)); } return(vo); } // Get from cache if (ri < CacheReaderPosition + 1) // if already read past this then close current cursor { CloseCacheReader(); } if (CacheReader == null) // need to open reader? { AssertMx.IsNotNull(CacheWriter, "CacheWriter"); AssertMx.IsTrue(File.Exists(CacheFilePath), "CacheFilePath doesn't exist"); FileStream fs = File.Open(CacheFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); CacheReader = new BinaryReader(fs); CacheReaderPosition = -1; if (DebugCaching) { DebugLog.Message("Opening cache reader"); } } while (CacheReaderPosition + 1 <= ri) // read rows until we get the one we want { vo = VoArray.ReadBinaryVoArray(CacheReader, VoaLength); CacheReaderPosition++; } CacheReaderPosition = ri; if (DebugCaching) { DebugLog.Message(string.Format("Row: {0} in Cache (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count)); } return(vo); }
/// <summary> /// Read input data from database /// </summary> /// <param name="smp"> /// <returns></returns> List<CompoundStructureActivityData> ReadData( SasMapParms smp) { MetaColumn activityMc = smp.EndpointMc; QueryColumn keyCriteriaQc = smp.KeyCriteriaQc; AssertMx.IsNotNull(activityMc, "mc"); AssertMx.IsNotNull(keyCriteriaQc, "keyCriteriaQc"); MetaTable mt, mt2; MetaColumn mc2 = null; Query q = new Query(); mt = activityMc.MetaTable; QueryTable qt = new QueryTable(mt); if (mt.SummarizedExists && !mt.UseSummarizedData) { // retrieve summarized data if exists mt2 = MetaTableCollection.Get(mt.Name + MetaTable.SummarySuffix); if (mt2 != null) { mc2 = mt2.GetMetaColumnByName(activityMc.Name); if (mc2 == null) mc2 = mt2.GetMetaColumnByLabel(activityMc.Label); } if (mc2 != null) // same column available in summarized? { mt = mt2; activityMc = mc2; } } SMP.KeyCriteriaQc.CopyCriteriaToQueryKeyCritera(q); q.KeyCriteriaDisplay = SMP.KeyCriteriaQc.CriteriaDisplay; qt.SelectKeyOnly(); QueryColumn qc = qt.GetQueryColumnByName(activityMc.Name); qc.Selected = true; q.AddQueryTable(qt); QueryEngine qe = new QueryEngine(); List<string> keyList = qe.ExecuteQuery(q); // note that keylist may be empty if single-step query HashSet<string> keySet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); List<CompoundStructureActivityData> data = new List<CompoundStructureActivityData>(); int rowCount = 0; while (true) { object[] vo = qe.NextRow(); if (vo == null) break; CompoundStructureActivityData cd = new CompoundStructureActivityData(); string cid = (string)vo[0]; cd.Cid = cid; keySet.Add(cid); // accumulate keys object val = vo[2]; if (NullValue.IsNull(val)) continue; if (val is double) cd.Activity = (double)val; else if (val is Int32) cd.Activity = (Int32)val; else if (val is NumberMx) { NumberMx nex = val as NumberMx; cd.Activity = nex.Value; } else if (val is QualifiedNumber) { QualifiedNumber qn = val as QualifiedNumber; cd.Activity = qn.NumberValue; //if (qn.Qualifier != null && qn.Qualifier != "" && qn.Qualifier != "=") // continue; // (don't want to do this since may filter out good data (e.g. IC50 <0.0001)) } else continue; if (cd.Activity == NullValue.NullNumber) continue; data.Add(cd); rowCount++; } // Retrieve structures keyList = new List<string>(keySet); Dictionary<string, MoleculeMx> csDict = MoleculeUtil.SelectMoleculesForCidList(keyList, qt.MetaTable); // get the structures in a single step // Add structures and build/store fingerprints to data DebugLog.Message("========== Fingerprints ============"); foreach (CompoundStructureActivityData cd in data) { if (!csDict.ContainsKey(cd.Cid) || csDict[cd.Cid] == null) continue; if (cd.Cid == "111" || cd.Cid == "222") csDict = csDict; // debug MoleculeMx cs = csDict[cd.Cid]; cd.Structure = cs; FingerprintType fpType = FingerprintType.Circular; int fpSubtype = -1; if (SMP.SimilarityType == SimilaritySearchType.ECFP4) // some issue with ECFP4? { fpType = FingerprintType.Circular; fpSubtype = CircularFingerprintType.ECFP4; } else if (SMP.SimilarityType == SimilaritySearchType.Normal) { fpType = FingerprintType.MACCS; } cd.BitsetFingerprint = cs.BuildBitSetFingerprint(fpType, fpSubtype); if (cd.BitsetFingerprint == null) continue; // couldn't build fingerprint (e.g. no structure) if (Debug) DebugLog.Message(cd.Cid + ": " + Lex.Join(CdkMolUtil.GetBitSet(cd.BitsetFingerprint), ", ")); } return data; }
/// <summary> /// Close broker & release resources /// </summary> public override void Close() { AssertMx.IsNotNull(SpecificBroker, "SpecificBroker"); SpecificBroker.Close(); }