/// <summary> /// Get subtree starting at specified node /// </summary> /// <param name="rootNodeName"></param> /// <returns></returns> public MetaTreeNode GetAfsSubtree(string rootNodeName) { if (ServiceFacade.UseRemoteServices) { NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod( ServiceCodes.MobiusMetaDataService, MobiusMetaDataService.GetAfsSubtree, new object[] { rootNodeName }); if (resultObject == null) { return(null); } MetaTreeNode mtn = resultObject.Value as MetaTreeNode; return(mtn); } else { if (MetaTreeFactoryInstance == null) { MetaTreeFactoryInstance = new Mobius.MetaFactoryNamespace.MetaTreeFactory(); } return(MetaTreeFactoryInstance.GetAfsSubtree(rootNodeName)); } }
/// <summary> /// Mark the MetaTree cache for rebuilding /// </summary> public void MarkCacheForRebuild() { if (ServiceFacade.UseRemoteServices) { NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod( ServiceCodes.MobiusMetaDataService, MobiusMetaDataService.MarkCacheForRebuild, null); return; } else { if (MetaTreeFactoryInstance == null) { MetaTreeFactoryInstance = new Mobius.MetaFactoryNamespace.MetaTreeFactory(); } MetaTreeFactoryInstance.MarkCacheForRebuild(); } }
/// <summary> /// Build & return the full MetaTree /// </summary> public Dictionary <string, MetaTreeNode> ReloadMetaTree() { if (ServiceFacade.UseRemoteServices) { NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod( ServiceCodes.MobiusMetaDataService, MobiusMetaDataService.GetFullTree, null); Dictionary <string, MetaTreeNode> metaTree = (resultObject != null) ? (Dictionary <string, MetaTreeNode>)resultObject.Value : null; return(metaTree); } else { if (MetaTreeFactoryInstance == null) { MetaTreeFactoryInstance = new Mobius.MetaFactoryNamespace.MetaTreeFactory(); } return(MetaTreeFactoryInstance.ReloadMetaTree()); } }
/// <summary> /// Create MetaTable for a PubChem assay /// </summary> public MetaTable GetMetaTable( string name) { MetaTable mt = null, mt2 = null, mt3 = null; MetaColumn mc, mcc; string txt, tok; string aid; string prefix = "pubchem_aid_"; if (!name.ToLower().StartsWith(prefix)) { return(null); } int t0 = TimeOfDay.Milliseconds(); aid = name.Substring(prefix.Length); XmlNode node; XmlNodeList nodes; TextReader rdr = GetAssayXml(aid); if (rdr == null) { return(null); } XmlDocument doc = new XmlDocument(); doc.Load(rdr); mt = new MetaTable(); mt.Name = "PUBCHEM_AID_" + aid.ToString(); mt.TableMap = "(select * " + "from mbs_owner.mbs_pbchm_rslt)"; mt.MetaBrokerType = MetaBrokerType.Pivot; mt.Parent = MetaTableCollection.Get("pubchem_structure"); mt.TableFilterColumns = Csv.SplitCsvString("mthd_vrsn_id"); mt.TableFilterValues = Csv.SplitCsvString(aid); mt.PivotMergeColumns = Csv.SplitCsvString("ext_cmpnd_id_nbr, rslt_grp_id"); mt.PivotColumns = Csv.SplitCsvString("rslt_typ_id"); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ab", "http://www.ncbi.nlm.nih.gov"); // must look within this namespace MetaTreeNode mtn = MetaTreeFactory.GetNode(mt.Name); // try to get label from contents tree mtn = null; if (mtn != null) { mt.Label = mtn.Label; } else { string dataSource = SelectNodeValue(doc, nsmgr, "//ab:PC-DBTracking_name"); string assayName = SelectNodeValue(doc, nsmgr, "//ab:PC-AssayDescription_name"); string outcomeMethod = SelectNodeValue(doc, nsmgr, "//ab:PC-AssayDescription_activity-outcome-method"); mt.Label = assayName; if (outcomeMethod == "1") { outcomeMethod = "Primary"; } else if (outcomeMethod == "2") { outcomeMethod = "Dose-Response"; } else if (outcomeMethod == "3") { outcomeMethod = "Probe Summary"; } else { outcomeMethod = ""; } if (outcomeMethod.Length > 0) { mt.Label += " (" + outcomeMethod + ")"; } } if (mt.Label == "") { mt.Label = mt.Name; } mt.Description = // reference PubChem description page "http://pubchem.ncbi.nlm.nih.gov/assay/assay.cgi?aid=" + aid; nodes = doc.SelectNodes("//ab:PC-ResultType", nsmgr); // result types // Build common metacolumns mc = mt.AddMetaColumn("PUBCHEM_CID", "CID", MetaColumnType.CompoundId, ColumnSelectionEnum.Selected, 14); mc.ColumnMap = "ext_cmpnd_id_nbr"; mc = mt.AddMetaColumn("PUBCHEM_SID", "SID", MetaColumnType.Integer, ColumnSelectionEnum.Selected, 7); mc.ColumnMap = "rslt_val_nbr"; mc.PivotValues = Csv.SplitCsvString("1001"); // assign codes that won't interfere with assay-specific codes mc = mt.AddMetaColumn("PUBCHEM_ACTIVITY_SCORE", "Activity Score", MetaColumnType.Integer, ColumnSelectionEnum.Selected, 7); mc.ColumnMap = "rslt_val_nbr"; mc.PivotValues = Csv.SplitCsvString("1002"); mc = mt.AddMetaColumn("PUBCHEM_ACTIVITY_OUTCOME", "Activity Outcome", MetaColumnType.DictionaryId, ColumnSelectionEnum.Selected, 7); mc.ColumnMap = "rslt_val_nbr"; mc.Dictionary = "PubChemActivityOutcome"; // code stored in db must be translated via dictionary mc.PivotValues = Csv.SplitCsvString("1003"); mc = mt.AddMetaColumn("PUBCHEM_ACTIVITY_URL", "Activity URL", MetaColumnType.Hyperlink, ColumnSelectionEnum.Selected, 7); mc.ColumnMap = "rslt_val_txt"; mc.PivotValues = Csv.SplitCsvString("1004"); // Build assay-specific metacolumns for (int ci = 0; ci < nodes.Count; ci++) { node = nodes[ci]; string typeId = SelectNodeValue(node, nsmgr, ".//ab:PC-ResultType_tid"); // get values relative to node (need "." in xpath string) string typeName = SelectNodeValue(node, nsmgr, ".//ab:PC-ResultType_type"); string colName = SelectNodeValue(node, nsmgr, ".//ab:PC-ResultType_name"); string desc = SelectNodeValue(node, nsmgr, ".//ab:PC-ResultType_description_E"); if (desc.IndexOf(", unit: ") > 0) // shorten label a bit { desc = desc.Replace(", unit: ", " ("); if (desc.EndsWith(".")) { desc = desc.Substring(0, desc.Length - 1); } desc += ")"; } string unit = SelectNodeValue(node, nsmgr, ".//ab:PC-ResultType_unit"); if (unit == "") { unit = SelectNodeValue(node, nsmgr, ".//ab:PC-ResultType_sunit"); } if (Lex.Eq(unit, "none") || Lex.Eq(unit, "unspecified")) { unit = ""; } if (unit.EndsWith("ml")) { unit = unit.Substring(0, unit.Length - 2) + "/mL"; } string transform = SelectNodeValue(node, nsmgr, ".//ab:PC-ResultType_transform"); mc = new MetaColumn(); mc.PivotValues = Csv.SplitCsvString(typeId); mc.Name = "R_" + typeId; mc.Label = colName; if (unit != "") { mc.Label += " (" + unit + ")"; } if (mc.Label == "") { mc.Label = mc.Name; } //mc.Label = desc; // user longer description for label //if (mc.Label == "") mc.Label = mc.Label; mc.Format = ColumnFormatEnum.Default; mc.Decimals = -1; mc.InitialSelection = ColumnSelectionEnum.Selected; if (Lex.Eq(typeName, "float")) { mc.DataType = MetaColumnType.Number; mc.Width = 8; mc.ColumnMap = "rslt_val_nbr"; } else if (Lex.Eq(typeName, "int")) { mc.DataType = MetaColumnType.Number; mc.Width = 8; mc.Format = ColumnFormatEnum.Decimal; mc.Decimals = 0; mc.ColumnMap = "rslt_val_nbr"; } else if (Lex.Eq(typeName, "bool")) { mc.DataType = MetaColumnType.Number; mc.Width = 8; mc.ColumnMap = "rslt_val_nbr"; } else if (Lex.Eq(typeName, "string")) { mc.DataType = MetaColumnType.String; mc.Width = 8; mc.ColumnMap = "rslt_val_txt"; } else { throw new Exception("Invalid type" + typeName); } mc.MetaTable = mt; mt.AddMetaColumn(mc); } mc = mt.AddMetaColumn("PUBCHEM_ASSAYDATA_COMMENT", "Comment", MetaColumnType.String, ColumnSelectionEnum.Unselected, 7); mc.ColumnMap = "rslt_val_txt"; mc.PivotValues = Csv.SplitCsvString("1005"); mc = mt.AddMetaColumn("PUBCHEM_EXT_DATASOURCE_REG", "Ext. Source. Reg. Id", MetaColumnType.String, ColumnSelectionEnum.Unselected, 7); mc.ColumnMap = "rslt_val_txt"; mc.PivotValues = Csv.SplitCsvString("1006"); mc = mt.AddMetaColumn("PUBCHEM_ASSAYDATA_REVOKE", "Revoked", MetaColumnType.String, ColumnSelectionEnum.Hidden, 7); mc.ColumnMap = "rslt_val_txt"; mc.PivotValues = Csv.SplitCsvString("1007"); MetaTableFactory.SetAnyNewMetaTableLabel(mt); // if table has been renamed the set new label foreach (MetaColumn mc2 in mt.MetaColumns) { MetaTableFactory.SetAnyNewMetaColumnLabel(mc2); // if col has been renamed then set new label } GetMetaTableCount++; t0 = TimeOfDay.Milliseconds() - t0; GetMetaTableTime += t0; GetMetaTableAvgTime = GetMetaTableTime / GetMetaTableCount; return(mt); }
/// <summary> /// Build platform / target / assay metatree /// </summary> public static void BuildPlatformMetaTree() { string assayId, assayDb; string sql = @" select gene_fmly, gene_symbl, assy_nm, assy_db, assy_id_txt from mbs_owner.cmn_assy_atrbts where gene_fmly is not null and gene_symbl is not null and assy_nm is not null order by lower(gene_fmly), lower(gene_symbl), lower(assy_nm)" ; sql = AssayAttributesDao.AdjustAssayAttrsTableName(sql); try { DbCommandMx drd = new DbCommandMx(); drd.Prepare(sql); drd.ExecuteReader(); string family = ""; string targetSymbol = ""; string assayName = ""; MetaTreeNode familyMtn = null, targetMtn = null, tsMtn = null, assayMtn = null; while (drd.Read()) { string nextFamily = drd.GetString(0); if (Lex.Ne(family, nextFamily)) // get current family node { family = nextFamily; string familyNodeName = "GFTA_" + family.Replace(" ", "_"); // build name to match node familyMtn = MetaTreeFactory.GetNode(familyNodeName); } string nextTargetSymbol = drd.GetString(1); // if (Lex.Eq(nextTargetSymbol, "Adr1a")) nextTargetSymbol = nextTargetSymbol; // debug if (Lex.Ne(targetSymbol, nextTargetSymbol)) // add new target node if going to new target { targetSymbol = nextTargetSymbol; targetMtn = new MetaTreeNode(); targetMtn.Type = MetaTreeNodeType.Target; targetMtn.Name = "TGT_ASSYS_" + targetSymbol.ToUpper(); targetMtn.Label = targetSymbol; targetMtn.Target = targetMtn.Name; MetaTreeFactory.AddNode(targetMtn); if (familyMtn != null) { familyMtn.Nodes.Add(targetMtn); } tsMtn = new MetaTreeNode(); // add node for summary view by gene symbol tsMtn.Type = MetaTreeNodeType.MetaTable; tsMtn.Name = MultiDbAssayDataNames.BasePivotTablePrefix + targetSymbol.ToUpper(); tsMtn.Label = targetSymbol + " Assay Results Summary"; tsMtn.Target = tsMtn.Name; MetaTreeNode mtn2 = MetaTreeFactory.GetNode(tsMtn.Name); // node with this name already exist? if (mtn2 == null) { MetaTreeFactory.AddNode(tsMtn); // add to tree if doesn't exist } else { tsMtn = mtn2; // use existing node otherwise since this label doesn't have priority } if (targetMtn != null) { targetMtn.Nodes.Add(tsMtn); } } string nextAssayName = drd.GetString(2); if (Lex.Ne(assayName, nextAssayName)) { assayName = nextAssayName; assayDb = drd.GetString(3); assayId = drd.GetString(4); assayMtn = new MetaTreeNode(); assayMtn.Type = MetaTreeNodeType.MetaTable; assayMtn.Name = assayId; assayMtn.Target = assayMtn.Name; assayMtn.Label = assayName; MetaTreeNode mtn2 = MetaTreeFactory.GetNode(assayMtn.Name); // node with this name already exist? if (mtn2 == null) { MetaTreeFactory.AddNode(assayMtn); // add to tree if doesn't exist } else { assayMtn = mtn2; // use existing node otherwise since this label doesn't have priority } if (targetMtn != null) { targetMtn.Nodes.Add(assayMtn); } } } drd.CloseReader(); drd.Dispose(); } catch (Exception ex) { DebugLog.Message("TargetAssayMetafactory.Build Error:\r\n" + DebugLog.FormatExceptionMessage(ex)); return; } }
/// <summary> /// Build pathway / target / assay metatree /// Depends on BuildPlatformMetaTree being called first /// and a node named Pathway_View already existing in the tree. /// </summary> public static void BuildPathwayMetaTree() { MetaTreeNode pathwayMtn = null, targetMtn; StreamReader sr; MetaTreeNode pathwayViewRoot = MetaTreeFactory.GetNode("Pathway_View"); if (pathwayViewRoot == null) { return; } string fileName = TargetMapDao.TargetMapDir + @"\pathway2gene.csv"; if (!File.Exists(fileName)) { return; } try { sr = new StreamReader(fileName); } catch (Exception ex) { return; } string rec = sr.ReadLine(); // read header line if (rec == null) { sr.Close(); return; } while (true) { rec = sr.ReadLine(); if (rec == null) { break; } List <string> toks = // Rec format: pathway, pathway_name, Target_Entrez_Gene_Id, target_gene_symbol, gene_family Csv.SplitCsvString(rec); string pathwayName = toks[0].Trim(); string pathwayCaption = toks[1].Trim(); string targetSymbol = toks[3].Trim(); string nodeName = "PATHWAY_" + pathwayName; pathwayMtn = MetaTreeFactory.GetNode(nodeName); // node with this name already exist? if (pathwayMtn == null) // add new pathway node { pathwayMtn = new MetaTreeNode(); pathwayMtn.Type = MetaTreeNodeType.SystemFolder; pathwayMtn.Name = nodeName; pathwayMtn.Label = pathwayCaption + " (" + pathwayName + ")"; MetaTreeFactory.AddNode(pathwayMtn); pathwayViewRoot.Nodes.Add(pathwayMtn); } nodeName = "TGT_ASSYS_" + targetSymbol.ToUpper(); targetMtn = MetaTreeFactory.GetNode(nodeName); if (targetMtn == null) { continue; } pathwayMtn.Nodes.Add(targetMtn); } sr.Close(); return; }