/// <summary> /// Update the cached TargetAssayDictionary file from the database /// </summary> public static string UpdateTargetAssayAttributesDictionaryCacheFileFromDatabase() { AssayDict tad = AssayAttributesDao.ReadAssayAttributesTable(); // get data from database string fileName = ServicesDirs.MetaDataDir + @"\AssayAttributes.bin"; tad.SerializeToFile(fileName); return("Assay attributes dictionary file updated, rows: " + tad.AssayList.Count); }
/// <summary> /// Summarize unpivoted unsummarized assay data by target /// </summary> /// <param name="parms"></param> /// <param name="qm2"></param> /// <returns></returns> public QueryManager SummarizeByTargetUnpivoted( TargetSummaryOptions summaryOptions, QueryManager qm2) { // This method takes an unpivoted input query, summarizes it according to the summarization parameters // and then formats the summarized data according to the specified output format. // If a targetMap is specified then then coordinates are included in the output, the summarization // level must be target, and the output format must be unpivoted. QueryTable qt, qt2; DataRowMx dr, dr2; DataRowAttributes dra; string cid = "", currentCid; int rti, rfi; AssayDict tad = TargetAssayDict; // be sure target assay dict has been loaded TargetAssaySummarizationLevel sumLevel = TargetAssaySummarizationLevel.Target; // target level SummarizationType sumMethod = summaryOptions.UseMeans ? SummarizationType.BioResponseMean : SummarizationType.MostPotent; OutputDest outputDest = OutputDest.WinForms; TargetMap targetMap = TargetMapDao.GetMapWithCoords(summaryOptions.TargetMapName); qt = Query.GetQueryTableByName(MultiDbAssayDataNames.CombinedNonSumTableName); if (qt == null) { throw new Exception("Query table not found: " + MultiDbAssayDataNames.CombinedNonSumTableName); } UnpivotedAssayResultFieldPositionMap voMap = UnpivotedAssayResultFieldPositionMap.NewOriginalMap(); // used for fast indexing of value by col name voMap.InitializeFromQueryTableVoPositions(qt, 0); if (qm2 == null) // need to create query manager? { qm2 = new QueryManager(); qm2 = InitializeSubqueryQm(MultiDbAssayDataNames.CombinedNonSumTableName); } Query q2 = qm2.Query; qt2 = q2.GetQueryTableByNameWithException(MultiDbAssayDataNames.BaseTableName); UnpivotedAssayResultFieldPositionMap voMap2 = UnpivotedAssayResultFieldPositionMap.NewOriginalMap(); // used for fast indexing of value by col name voMap2.InitializeFromQueryTableVoPositions(qt2, 0); // Summarize rows & store in DataSet qm2.DataTable.Clear(); Dictionary <string, object> includedTargets = null; if (summaryOptions.TargetsWithActivesOnly) { // scan data & make a list of targets to be included includedTargets = new Dictionary <string, object>(); // ... } List <UnpivotedAssayResult> tars = new List <UnpivotedAssayResult>(); // build list of TA rows here currentCid = ""; for (int dri = 0; dri <= DataTableMx.Rows.Count; dri++) { if (dri < DataTableMx.Rows.Count) { dr = DataTableMx.Rows[dri]; cid = dr[KeyValueVoPos] as string; dra = GetRowAttributes(dr); if (dra != null && dra.Filtered) { continue; } if (currentCid == "") { currentCid = cid; } } else { dr = null; } if (dr == null || cid != currentCid) { // summarize rows for current cid & add to new datatable if (tars.Count > 0) // { List <UnpivotedAssayResult> sumTars = TargetAssayUtil.SummarizeData( tars, sumLevel, sumMethod, true, NullValue.NullNumber, NullValue.NullNumber, targetMap); int voLength2 = qm2.DataTable.Columns.Count; foreach (UnpivotedAssayResult sumTar in sumTars) { object[] vo2 = sumTar.ToValueObject(voLength2, voMap2); dr2 = qm2.DataTable.NewRow(); dr2.ItemArrayRef = vo2; // copy ref for efficiency since vo won't be changed qm2.DataTable.Rows.Add(dr2); } } if (dr == null) { break; } tars.Clear(); currentCid = cid; } UnpivotedAssayResult tar = UnpivotedAssayResult.FromValueObjectNew(dr.ItemArray, voMap); tars.Add(tar); // store in form for summarization } qm2.DataTableManager.InitializeRowAttributes(); return(qm2); }
// Constructor public MultiDbAssayMetaBroker() { AssayDict tad = TargetAssayDict; // be sure we have target assay assoc info return; }
/// <summary> /// Read in assay attribute information /// </summary> /// <returns></returns> public static AssayDict ReadAssayAttributesTable() { int t0 = TimeOfDay.Milliseconds(); MetaTable mt = MetaTableCollection.Get(AssayAttrsTableName); if (mt == null) { throw new Exception("Can't get table " + AssayAttrsTableName); } UnpivotedAssayResultFieldPositionMap voMap = new UnpivotedAssayResultFieldPositionMap(); // used for fast indexing of value by col name string fList = ""; for (int mci = 0; mci < mt.MetaColumns.Count; mci++) { string colMap = mt.MetaColumns[mci].ColumnMap; voMap.TrySetVoi(colMap, mci); if (fList != "") { fList += ", "; } fList += colMap; } string sql = "select " + fList + " " + "from mbs_owner.cmn_assy_atrbts " + "order by lower(gene_fmly), lower(gene_symbl), lower(assy_nm)"; // sql = AdjustAssayAttrsTableName(sql); DbCommandMx dao = new DbCommandMx(); dao.Prepare(sql); dao.ExecuteReader(); AssayDict dict = new AssayDict(); int readCnt = 0; while (true) { if (!dao.Read()) { break; } //if (readCnt > 100) break; // debug !!! readCnt++; object[] vo = new object[mt.MetaColumns.Count]; for (int mci = 0; mci < mt.MetaColumns.Count; mci++) { vo[mci] = dao.GetObject(mci); } AssayAttributes row = AssayAttributes.FromValueObjectNew(vo, voMap); dict.AssayList.Add(row); dict.SetMaps(row); } dao.CloseReader(); dao.Dispose(); t0 = TimeOfDay.Milliseconds() - t0; return(dict); }
/// <summary> /// Execute query in preparation for retrieving rows /// </summary> /// <param name="parms"></param> public override void ExecuteQuery( ExecuteQueryParms eqp) { BufferedRows = new List <UnpivotedAssayResult>(); MultiTablePivotBrokerTypeData mpd = null; MetaTable mt; List <MultiDbAssayMetaBroker> mbList = null; MultiDbAssayMetaBroker mb, mb2 = null; UnpivotedAssayResult rr, rr2; List <UnpivotedAssayResult> rrList = new List <UnpivotedAssayResult>(); // list of results summarized by target & result type bool unpivotedTableIsFirst; object[] vo; string mtName = null; int t0 = TimeOfDay.Milliseconds(); mt = eqp.QueryTable.MetaTable; Dictionary <string, MultiTablePivotBrokerTypeData> mbsi = eqp.Qe.MetaBrokerStateInfo; if (PivotInCode) { mpd = mbsi[MpGroupKey]; if (PivotInCode && mpd.MbInstances.Count == 1 && UnpivotedAssayResult.IsUnpivotedSummarizedMdbAssayTable(mt.Name)) { PivotInCode = false; // don't multipivot if single unpivoted summary table } } if (!PivotInCode) // if not multipivot then call generic broker { base.ExecuteQuery(eqp); return; } if (mpd.FirstTableName != Qt.MetaTable.Name) { return; // retrieve data for all tables when we see first table } SetupSecondaryMetaBroker(eqp, mpd, out unpivotedTableIsFirst); mb2 = SecondaryMetaBroker; mpd.ClearBuffers(); // Retrieve data & store for associated metabrokers if (mb2 == this) { base.ExecuteQuery(eqp); // execute with the base generic broker } else { mb2.ExecuteQuery(Eqp2); // use the secondary broker that was created } AssayDict dict = new AssayDict(); rr = new UnpivotedAssayResult(); int readCnt = 0; bool includeResultDetail = MdbAssayVoMap.ResultDetailId.Voi >= 0; while (true) { if (mb2 == this) { vo = base.NextRow(); // get data via generic broker } else { vo = mb2.NextRow(); // get data with secondary broker } if (vo == null) { break; } rr.FromValueObject(vo, mb2.MdbAssayVoMap); // parse values into a UnpivotedAssayResult int rowsFetched = 0, vosCreated = 0; for (int pup = 0; pup < 2; pup++) // first pass for unpivoted table, 2nd for pivoted by gene { //try //{ if (pup == 0) { if (!unpivotedTableIsFirst) { continue; // if no unpivoted first table skip this } mtName = mpd.FirstTableName; // unpivoted table should be first } else // pivoted table { if (Lex.IsNullOrEmpty(rr.GeneSymbol)) { continue; // skip if no target symbol } if (Lex.Contains(mpd.FirstTableName, "CORP")) // mapped to pivoted corp only table { mtName = MultiDbAssayDataNames.BasePivotTablePrefix + rr.GeneSymbol.ToUpper(); // name of table mapped to } else // combined tables { mtName = MultiDbAssayDataNames.CombinedPivotTablePrefix + rr.GeneSymbol.ToUpper(); } } //} //catch (Exception ex) { ex = ex; } mt = MetaTableCollection.Get(mtName); if (mt == null) { continue; } if (!mpd.MbInstances.ContainsKey(mt.Name)) { continue; // have row hash for broker? } int mbIdx = 0; if (mpd.MbInstances[mtName] is MultiDbAssayMetaBroker) { mb = (MultiDbAssayMetaBroker)mpd.MbInstances[mtName]; // broker assoc w/table } else { mbList = (List <MultiDbAssayMetaBroker>)mpd.MbInstances[mtName]; mb = (MultiDbAssayMetaBroker)mbList[0]; } while (true) // copy out for each metabroker for metatable { UnpivotedAssayResultFieldPositionMap voMap = mb.MdbAssayVoMap; vo = rr.ToValueObject(mb.Qt.SelectedCount, voMap); if (mb.MultipivotRowList == null) { mb.MultipivotRowList = new List <object[]>(); } mb.MultipivotRowList.Add(vo); if (mbList == null) { break; // single broker } mbIdx++; // go to next broker if (mbIdx >= mbList.Count) { break; // at end of brokers? } mb = (MultiDbAssayMetaBroker)mbList[mbIdx]; } } // tables to copy data to loop } // row fetch loop return; }