public QsarAddin(Dictionary <string, string> Modelinfo, TbScale ScaleDeclaration, TbObjectId objectId) { this.Modelinfo = Modelinfo; this.ScaleDeclaration = ScaleDeclaration; this.objectId = objectId; //CHANGED TO UNITNAME, not anymore log units this.qsarUnit = new TbUnit(ScaleDeclaration.Name, Modelinfo["UnitName"]); }
public static TbScalarData ConvertData(string stringvalue, TbScale ScaleDeclaration, Dictionary <string, string> Modelinfo) { //understand how to pass qualitative predictions if (ScaleDeclaration is TbQualitativeScale scaleDeclaration) { // TbQualitativeScale scaleD = (TbQualitativeScale)this.ScaleDeclaration; if (!scaleDeclaration.Labels.Any <string>((Func <string, bool>)(l => l.Equals(stringvalue, StringComparison.InvariantCultureIgnoreCase)))) { throw new Exception(string.Format("\"{0}\" is not a prediction for the declared scale.", (object)stringvalue)); } return((TbData) new TbData(new TbUnit(ScaleDeclaration.Name, stringvalue), new double?())); } if (Modelinfo["Unit"] == "a-dimensional") { //labda is read from csv, for this reason should follow different rules than other parsers double lambda = DoubleParser(Modelinfo["Lambda"]); double value = DoubleParser(stringvalue); return((TbData) new TbData(new TbUnit(ScaleDeclaration.Name, "mmol/L"), BoxCox(lambda, value))); //AFTER INTANTIATING ALL CLASSIFICATION MODELS RUN THIS //} //if (this.Modelinfo["Unit"] == "no unit") //{ // return (TbData)new TbData(qsarUnit, runmodel(target, this.Modelinfo["tag"], "prediction")); } //workaroud for the lack of conversion for Log unitfamily Regex regexloginv = new Regex(@"log\(1/.*"); //Doesn't work, don't ask why if (regexloginv.IsMatch(Modelinfo["Unit"])) { double value = DoubleParser(stringvalue); return((TbData) new TbData(new TbUnit(ScaleDeclaration.Name, Modelinfo["UnitName"]), Math.Pow(10, value * -1))); } Regex regex = new Regex(@"log\(.*"); //Doesn't work, don't ask why if (regex.IsMatch(Modelinfo["Unit"]) & Modelinfo["Unit"] != "log(cm/h)") { double value = DoubleParser(stringvalue); return((TbData) new TbData(new TbUnit(ScaleDeclaration.Name, Modelinfo["UnitName"]), Math.Pow(10, value))); } else { double value = DoubleParser(stringvalue); return((TbData) new TbData(new TbUnit(ScaleDeclaration.Name, Modelinfo["UnitName"]), value)); } }
public static IReadOnlyList <ChemicalWithData> getSet(Dictionary <string, string> Modelinfo, TbScale ScaleDeclaration, string set) { TbUnit qsarunit = new TbUnit(ScaleDeclaration.Name, Modelinfo["Unit"]); List <ChemicalWithData> DataSet = new List <ChemicalWithData>(); List <Dictionary <string, string> > ChemicalsDict = CSVtoDict(Modelinfo); foreach (Dictionary <string, string> ChemicalDict in ChemicalsDict) { int Cas = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(ChemicalDict["CAS"], "[^\\d]"))); string name = ChemicalDict["ID"]; string smiles = ChemicalDict["SMILES"]; string SetInfo = ChemicalDict["Set"]; double Experimental = double.Parse(ChemicalDict["Exp"], CultureInfo.InvariantCulture); if (SetInfo == set) { ChemicalWithData chemical = new ChemicalWithData(Cas, new[] { name }, smiles, new[] { new TbDescribedData(new TbData(qsarunit, new double?()), null) }, new TbDescribedData(new TbData(qsarunit, Experimental), null)); DataSet.Add(chemical); } } return(DataSet); }
public static IReadOnlyList <ChemicalWithData> GetSet(Dictionary <string, string> Modelinfo, TbScale ScaleDeclaration, String Set) { List <ChemicalWithData> SetList = new List <ChemicalWithData>(); var setup = new BridgeSetup(false); //setup.AddAllJarsClassPath(@"B:\ToolboxAddinExamples\lib"); setup.AddAllJarsClassPath(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)); Bridge.CreateJVM(setup); Bridge.RegisterAssembly(typeof(ChemicalinSet).Assembly); java.util.List list = ChemicalinSet.getDataset(Modelinfo["tag"], Set); if (list.size() == 0) { return(SetList); } for (int i = 0; i < list.size(); i++) { TbData Mockdescriptordata = new TbData(new TbUnit(TbScale.EmptyRatioScale.FamilyGroup, TbScale.EmptyRatioScale.BaseUnit), new double?()); ChemicalinSet cur_Chemical = (ChemicalinSet)list.get(i); TbData cur_exp = (TbData)Utilities.ConvertData(cur_Chemical.getExperimental(), ScaleDeclaration, Modelinfo); SetList.Add(new ChemicalWithData(cur_Chemical.getCAS(), new[] { "N.A." }, cur_Chemical.getSmiles(), new TbDescribedData[] { new TbDescribedData(Mockdescriptordata, null) }, new TbDescribedData(cur_exp, null))); } return(SetList); }